http://qs321.pair.com?node_id=11142017


in reply to Solved! (was: Re^10: Geo Package files)
in thread Geo Package files

Good to hear it works now. It would be useful to have a generalised WKB reader (and writer) on CPAN.

WRT the midpoints - the centroid will work as a start. However, if your mid-point must correspond with a street address on the road then it is not too hard to find the mid-point along a series of vertices.

One approach is to convert the array of vertices to cumulative distances and then use a binary search to find the distance that is half the maximum (which is the last cumulative distance array element). It won't make much difference with small numbers of geometries but if you have many geometries with many vertices then it adds up as the average case will be of the order of (n+log(n)) calculations compared with 1.5n for a two pass search that exits when the half way point is found. (For 100,000 vertices this is ~100,011 compared with 150,000). There are binary search implementations on CPAN that will avoid the problems of implementing your own, two I have used are in List::MoreUtils and List::BinarySearch.

Edit - updated the n+log(n) value to use the natural log, and a typo.