Given an arbitrary geometry, how can I most efficiently get the data points of each polygon?
I've tried iterating though nested loops in application code of GeometryN and PointN, with this query:
select X(PointN(ExteriorRing(GeometryN(geometry, ?)), ?)) as longitude
, Y(PointN(ExteriorRing(GeometryN(geometry, ?)), ?)) as latitude
from "Council" where id = ?
but it's quite slow.
I have tried joining with a sequence table that just contains id from 1 to an arbitrarily high number, greater than the number of data points I expect:
select X(PointN(ExteriorRing(geometry), "Sequence".id)) as longitude
, Y(PointN(ExteriorRing(geometry), "Sequence".id)) as latitude
from "Council"
join "Sequence" on "Sequence".id <= NumPoints(ExteriorRing(geometry))
order by "Sequence".id
It works and is faster than program code iteration, but seems like an artificial way to do it.
What I really need is some function that would explode the points for a given ExteriorRing, then I could just:
select AllPoints(ExteriorRing(GeometryN(geometry, ?)), ?)) as longitude
, Y(PointN(ExteriorRing(GeometryN(geometry, ?)), ?)) as latitude
from "Council" where id = ?
to get back one row for each data point.
Thanks,
Tom
BareFeetWare
--
Comparison of SQLite GUI tools:
http://www.barefeetware.com/sqlite/compare/?ml
--
iPhone/iPad/iPod and Mac software development, specialising in databases
deve...@barefeetware.com
Thanks for the quick reply.
On 13/06/2011, at 6:57 PM, a.furieri wrote:
> for sure this one is awfully slow ;-)
OK, so it's not just me then ;-)
> the OCG-SFS model is fully oriented toward complex Geometries, and support for single-vertex access isn't realistically feasible in pure SQL.
Ultimately, after manipulating geometries in spatialite, I need to be able to plot the resulting polygons in my UI. My platform is iOS (iPhone/iPad) using Objective C, Cocoa and mapKit. I don't know of any libraries that convert spatialite geometry blobs into MapKit polygons, so I'm left with the only avenue of extracting each point from a spatialite polygon and constructing the polygon in MapKit. Tell me if there's a better way.
> you are required to use some geometry-oriented C library to perform such a task; i.e. you can use the SpatiaLite's own C APIs (or alternatively the GDAL APIs) to access single vertices in an efficient way.
Can you please give me some sample code or a function to do this? How can I get a point N from polygon M in a geometry returned from spatialite?
Thanks,
Tom
BareFeetWare