Optic Geospatial
In MarkLogic 11, geospatial data can now be indexed using Template Driven Extraction and queried using the Optic engine, SPARQL, and SQL. This builds on the the rich geospatial capabilities already built into MarkLogic, and adds flexibility to how geospatial indexes are built and queried. It also increases interoperability by implementing subsets of the OGC (Open Geospatial Consortium) standard for SQL queries and OGC (Open Geospatial Consortium) GeoSPARQL standard for SPARQL queries.
TDE Indexing
The TDE "scalar-type" has been extended to support the following new scalar types: point
, box
, circle
, linestring
, polygon
, complexPolygon
, and a generic region
. Using these types, geospatial data can be selected for indexing using standard TDE XPath.
The TDE value expression must extract and/or construct content into one of the formats currently supported by the MarkLogic geospatial region index. See Geospatial Region Queries and Indexes in the Search Developer's Guide for more details.
The following code excerpt shows a fragment of a TDE that creates a row for each building and selects the building boundary polygon from the "boundary" element or property:
"rows": [ { "schemaName": "City", "viewName": "Buildings", "columns": [ { "name": "name", "scalarType": "string", "val": "name" }, { "name": "boundary", "scalarType": "polygon
", "val": "cts:polygon(boundary)
","coordinateSystem": "wgs84"
} ] } ]
See Template Driven Extraction in the Application Developer's Guide for more details on how to to use TDE.
Optic Query
Using the view from the above template, the Optic API can be used to query for buildings that intersect a circle with a center point and radius:
const op = require('/MarkLogic/optic'); op.fromView('City', 'Buildings') .where( op.geo.intersects( op.col('boundary'), geo.circlePolygon(cts.circle(10, cts.point(20.7, -156.4)), 0.5) ) ) .result()
The following functions have been added and are available under the existing "geo" namespace:
Function |
Returns |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SQL Query
Using the view from the above template, SQL can be used to query for buildings that intersect a circle with a center point and radius:
select * from Buildings where ST_Intersects( boundary, geo_circle_polygon(cts_circle(10, cts_point(20.7, -156.4)), 0.5) )
The following functions from the OGC standard for SQL queries are supported in MarkLogic 11:
Function |
Example SQL |
Returns |
---|---|---|
|
|
|
|
|
|
|
|
string |
|
|
binary |
|
|
boolean |
|
|
boolean |
|
|
boolean |
|
|
boolean |
|
|
boolean |
|
|
boolean |
|
|
boolean |
|
|
boolean |
|
|
boolean |
|
|
boolean |
|
|
double |
|
|
|
|
|
|
SPARQL Query
The following functions from the OGC (Open Geospatial Consortium) GeoSPARQL standard for SPARQL queries are supported in MarkLogic 11. These all use the SPARQL prefix: PREFIX geof: <http://www.opengis.net/def/function/geosparql/>
:
Function |
Returns |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The distance, in the units specified in |
The following functions are new built-in functions supported in MarkLogic 11:
Function |
Description |
---|---|
Compares geospatial regions to see if they fulfill the 'within' DE-9IM relation. |
|
Compares geospatial regions to see if they fulfill the 'contains' DE-9IM relation. |
|
Compares geospatial regions to see if they fulfill the 'overlaps' DE-9IM relation. |
|
Compares geospatial regions to see if they fulfill the 'equals' DE-9IM relation. |
|
Compares geospatial regions to see if they fulfill the 'disjoint' DE-9IM relation. |
|
Compares geospatial regions to see if they fulfill the 'intersects' DE-9IM relation. |
|
Compares geospatial regions to see if they fulfill the 'touches' DE-9IM relation. |
|
Compares geospatial regions to see if they fulfill the 'covers' DE-9IM relation. |
|
Compares geospatial regions to see if they fulfill the 'covered by' DE-9IM relation. |
Additional Information
See Query Geospatial Data in Optic for a detailed walkthrough of working with the new Optic Geospatial capability.
See Getting Started with Optic for more detail about working with the Optic API.
See Geospatial Search Applications in the Search Developer's Guide for more detail about working with geospatial data in MarkLogic.