FloydATC has asked for the wisdom of the Perl Monks concerning the following question:
I have a hash containing data on about 200 locations on a map. These locations are not evenly distributed, they tend to clutter around a few central locations, like suburbs to a metropolis.
I use a complicated object hierarchy to manipulate the map and import/export a lot of stuff that really has no bearing on this particular problem. So, let's just say the data structure looks like this:
%sites = ( 1 => { x => 65.1231, y => 23.1512 }, 2 => { x => 64.2327, y => 17.5328 }, 3 => { x => 66.1634, y => 21.2512 }, # ... 200 => { x => 65.6231, y => 21.8924 } );
The thing is, when plotting these locations on a map, the central areas become a dense mess with a lot of empty space in between. I would like to rearrange the locations into a sort of 'grid' which guarantees a minimum space between each location, and removes any unnecessary empty space.
Guaranteeing the minimum space is relatively easy. Closing the gaps is the problem. Consider the following map with 6 locations:
XX... X.... ..... ....X ...XX
Examining %sites I would probably want to compress this to something like this:
XX. X.X .XX
For a human, this problem is trivial to solve visually but I have no idea how to do it efficiently in code. I can't help thinking that someone else must have had this problem before me, so perhaps there's a module for it?
Update: Plenty of good ideas here, I'll have to take some time to read about the different approaches suggested. Thank you :-)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Distribute locations evenly on a map
by blokhead (Monsignor) on Nov 30, 2009 at 23:48 UTC | |
|
Re: Distribute locations evenly on a map
by mpeg4codec (Pilgrim) on Nov 30, 2009 at 23:31 UTC | |
|
Re: Distribute locations evenly on a map
by Fletch (Bishop) on Nov 30, 2009 at 22:55 UTC | |
|
Re: Distribute locations evenly on a map
by pklausner (Scribe) on Dec 02, 2009 at 14:04 UTC |