Keep It Simple, Stupid PerlMonks

### Re: Solved! (was: Re^10: Geo Package files)

by swl (Vicar)
 on Mar 11, 2022 at 23:21 UTC Need Help??

in reply to Solved! (was: Re^10: 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.

Replies are listed 'Best First'.
Re^2: Solved! (was: Re^10: Geo Package files)
by Bod (Priest) on Mar 11, 2022 at 23:57 UTC
It would be useful to have a generalised WKB reader (and writer) on CPAN.

As I write this code, I shall bear in mind that a WKB decoder would be a useful addition to CPAN. However, WKB is much more extensive than the limited scope I am looking at so whatever I produce will be a limited version that will be useful to some people. Either to use as-is or to build upon.

The first requirement I have from this USRN data is to find the nearest USRN to a given point. For that, the centre of the envelope is sufficient. In future, I will be wanting to plot the LineStrings so proper decoding will be needed but that's for another day.

Even a limited version would be a very useful thing. The seven types supported by GEOS would cover more than 90% of use cases (points, polylines and polygons, their multi-part variants and geometry collections).

Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11142017]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2023-02-02 14:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?