[MarkLogic Dev General] Polygon intersection over large document collections

Nick Ardlie nick.ardlie at gmail.com
Mon Mar 9 18:15:34 PDT 2015


Is it correct to say that Geospatial indexes in MarkLogic (Version 8) are
specifically "Point" indexes?

Say I have a database with the following type of JSON documents (containing
GeoJSON Point/Polygon/LineString data):

// Point location
{
"id": "ID-1",
"location": {
"type": "Point",
"coordinates": [-10, 20]
}
}
// Simple Polygon location
{
"id": "ID-2",
"location": {
"type": "Polygon",
"coordinates":
[[[-30.0,-30.0],[-30.0,30.0],[30.0,30.0],[30.0,-30.0],[-30.0,-30.0]]]
}
}
// Complex Polygon location (with one interior hole)
{
"id": "ID-3",
"location": {
"type": "Polygon",
"coordinates":
[[[-20.0,-20.0],[-20.0,20.0],[20.0,20.0],[20.0,-20.0],[-20.0,-20.0]],[[-5.0,-5.0],[-5.0,5.0],[5.0,5.0],[5.0,-5.0],[-5.0,-5.0]]]
}
}
// LineString location
{
"id": "ID-4",
"location": {
"type": "LineString",
"coordinates": [[0.0,0.0],[10.0,10.0],[20.0,20.0],[30.0,30.0]]
}
}

I can add a Geospatial path index on "location/coordinates" but it would
appear to treat all coordinate pairs as points.
So if I'm interested in finding documents whose "location" (Point, Polygon
or LineString) intersects a given box I can run this type of query:
cts:search(doc(), cts:path-geospatial-query("location/coordinates",
cts:box(-10, -10, 10, 10), "type=long-lat-point"))[1 to 10]

This works when at least one of the vertices of the Polygon is within the
box but if the box is wholly within the polygon it doesn't detect the
intersection.
Of course I can convert the "location[type="Polygon"]/coordinates" property
to a cts:polygon() (or cts:complex-polygon()) to test for intersection but
it's a very costly operation over millions of documents.

Are there alternative approaches to performing this type of polygon
intersection over large data sets?
(In particular anything that would leverage MarkLogic indexes).


Regards,
Nick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20150310/ad52fd48/attachment.html 


More information about the General mailing list