in reply to Re: Search file of coordinates
in thread Search file of coordinates
Sorry, but unless there are errors in either your supplied data or your description, I cannot make sense of the layout of your data.
I know you said that map 001 would be top right, but the contiguous values you supplied for maps 62/63 show that the X values increase as the map/grid/subgrid numbers increase (within any given horizontally adjacent set of maps/grids/subgrids), so if the maps are arranged right-left, top-bottom, then both the grids and the subgrids must also be so and the X-coordinate values must run right-left also. So, as it will make no difference if I reverse all the schemes and model this as having X-coords, maps, grids and subgrids running left-right, (being simply the mirror image) and as this is more intuative for my brain, that is what I have done for the rest of this analysis.
I tried laying the map numbers out on a 17x12 grid, left-right, top-bottom and reassuringly maps 62 and 63 are adjacent. However, map 44 comes out one row up and one to the left of map 62 but that didn't fit with the coordinates you supplied, its x-values being higher than those of map62 & 63.
I also noted that as each subgrid has an x-dimension of 1066.67, then a map must have a x-dim of 1066.67*3*5= 16000, and as the boundary between cells 62 and 63 was at 32000, this placed 0 in the X-axis roughly central in your 17x12 grid., which didn't make sense.
Then I thought maybe you made a typo and meant to say 'The maps are arranged 17 high by 12 wide' instead of "The maps are arranged 17 wide by 12 high", So I tried that.
Again maps 62 and 63 are adjacent and this time they are only one map away from the left hand edge, which fitted perfectly with the x-coords supplied.
Whats more, map 44 was way over to the right, which made sense from the supplied data. Looking good.
154000 +---+---+---+---+---+---+---+---+
|037|038|039|040|041|042|043|044|
140000 +---+---+---+---+---+---+---+---+
|049|050|051| | +->128000
126000 +---+---+---+ +->112000
|061|062|063|
112000 +---+---+---+
| | | +048000
| | +->032000b
| +->016000
+->000000
However, as you can see from the above, this layout puts the x-boundaries of map 44 at 112000 and 128000. The data you supplied was
044, 15, 2, 061866, 133466, 062933, 134399
A quick cross-reference with map 107 showed that its x-boundaries should be at 150000 and 166000 but again this doesn't fit the supplied data.
I also found a caveat with my previous attempt at a solution to this problem. I attempted to create a 2D array of hashes each containing 7 elements as I had proposed, but on my machine (with 256MB ram) this resulted in an 'Out of memory' error from perl. (I'm not sure why it doesn't just get paged as other programs do. I can, (albeit slowly) edit a 500MB file with my in-memory editor without problems, but that's a side issue!). Anyway, whilst I could see ways of reducing the memory requirements of that solution, it was already halfway to the possible solution below. So I abondoned that in favour of what follows.
In theory, if your layout is regular, you shouldn't need to use the grids file to map your thingy coordinates to Map/Grid/subgrid. It should be possible to derive them mathematically.
If your data fitted my model (:^)..then the following code would map your coords directly. As its stands (with MapXN=12 and MapYN=17) it maps those subgrids supplied for maps 62/63 perfectly, but gets the map # wrong on those supplied for map 44 and 107 although the grid and subgrid numbers again are calculated correctly.
If you switch these back to your stated 17x12, all the map numbers are wrong, but again the grid and subgrid calculate correctly.
#! perl -sw use strict; use constant BaseX => 0; use constant BaseY => 196_000; use constant MapX => 16_000; use constant MapXN => 17; use constant MapY => 14_000; use constant MapYN => 12; use constant GridX => 3_200; use constant GridY => 2_800; use constant SubX => 1066+ 2/3; use constant SubY => 933+ 1/3; while (<DATA>) { print,next if /^\s*$/ or /^#/; my ($thing, $x, $y)= split','; $y = BaseY-$y; #! invert Y my $mapX = int($x/MapX); my $mapY = int($y/MapY); my $map = $mapY*MapXN + $mapX + 1; my $gridX = int( ($x - $mapX*MapX)/GridX ); my $gridY = int( ($y - $mapY*MapY)/GridY ); my $grid = $gridY*5 + $gridX + 1; my $subX = int( ($x - ($mapX*MapX + $gridX*GridX) )/SubX ); my $subY = int( ($y - ($mapY*MapY + $gridY*GridY) )/SubY ); my $sub = $subY*3 + $subX + 1; print "$thing => Map:$map Grid:$grid Subgrid:$sub\n"; } __DATA__ # Test data, points just inside the topleft, topright, bottomleft and +bottomright # of each supplied subgrid. # 062, 25, 6, 030933, 112933, 032000, 113866 Left Top 062:25:6, 030934, 113866 Left Bot 062:25:6, 030934, 112934 Right Top 062:25:6, 031999, 113866 Right Bot 062:25:6, 031999, 112934 # 062, 25, 7, 028800, 112000, 029866, 112933 Left Top 062:25:7, 028801, 112932 Left Bot 062:25:7, 028801, 112001 Right Top 062:25:7, 029865, 112932 Right Bot 062:25:7, 029865, 112001 # 062, 25, 8, 029866, 112000, 030933, 112933 Left Top 062:25:8, 029867, 112932 Left Bot 062:25:8, 029867, 112001 Right Top 062:25:8, 030932, 112932 Right Bot 062:25:8, 030932, 112001 # 062, 25, 9, 030933, 112000, 032000, 112933 Left Top 062:25:9, 030934, 112932 Left Bot 062:25:9, 030934, 112001 Right Top 062:25:9, 031999, 112932 Right Bot 062:25:9, 031999, 112001 #063, 01, 1, 032000, 125066, 033066, 125999 Left Top 063:01:1, 032001, 125998 Left Bot 063:01:1, 032001, 125067 Right Top 063:01:1, 033065, 125998 Right Bot 063:01:1, 033065, 125067 # 063, 01, 2, 033066, 125066, 034133, 125999 Left Top 063:01:1, 033067, 125998 Left Bot 063:01:1, 033067, 125067 Right Top 063:01:1, 034132, 125998 Right Bot 063:01:1, 034132, 125067 # 044, 15, 2, 061866, 133466, 062933, 134399 Left Top 044:15:2, 061867, 134398 Left Bot 044:15:2, 061867, 133467 Right Top 044:15:2, 062932, 134398 Right Bot 044:15:2, 062932, 133467 # 107, 14, 4, 105600, 090533, 106666, 091466 Left Top 107:14:4, 105601, 091465 Left Bot 107:14:4, 105601, 090534 Right Top 107:14:4, 106665, 091465 Right Bot 107:14:4, 106665, 090534
I suspect that the reason is that your statement that
Some maps around the edges are nonexistant because the area in question is not rectangular. Map 001, which happens to be one of the missing, would be in the upper right corner.
is somewhat abiguous and that instead of numbering the maps 1-17 on the first row and 18-34 on the second and not using the map numbers for those outside the area. Instead, only those squares (maps) that contain part of the area in question are numbered.
A 'picture' might clarify that.
Instead of this (or its mirror image) +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ |001|002|003|004|005|006|007|008|009|010|011|012|013|014|015|016|017| +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ |018|019|020|021|022|023|024|025|026|027|028|029|030|031|032|033|034| +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ The maps are numbered +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | | | |001|002|003|004|005|006|007|008|009|010|011|012| | | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | |013|014|015|016|017|018|019|020|021|022|023|024|025|026|027| | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ |028|029|030|031|032|033|034|035|036|037|038|039|040|041|042|043|044| +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
And this is why I cannot make sense of the sample data.
If this is the case, then you still don't need to have a file containing the mapping for all the individual map/grid/subgrid triples. You only need a mapping from the calculated map number to the actual map number. For example, in the above case these mapping would take considerably less memory.
| Calculated map # | Actual map# |
|---|---|
| 1-3 | Error |
| 4-15 | 1-12 |
| 16-18 | Error |
| 19-33 | 13-27 |
| 34 | Error |
| 35-51 | 28-44 |
| etc. |
I hope that this is of some help in getting you started on a solution. Thankyou for presenting an interesting problem.
If you have any problems implementing this (or an alternative solution), come back with your code and I'm sure you'll get further assistance here, especially if you take the time to sign up and become a member. It's free, and well worth the insignificant trouble.
Good luck.
|
|---|