-
Notifications
You must be signed in to change notification settings - Fork 5
GeoJSON
GeoJSON geospatial data can be exposed as a feature service through configuration.
Assuming your data looks similar to the following:
{
"envelope": {
"header": {
"type": "geojson",
"ctsRegion": "POINT (125.6, 10.1)",
"pointId": 12312
},
"instance": {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [125.6, 10.1]
},
"properties": {
"name": "Dinagat Islands"
}
}
}
}
Reference: https://geojson.org/
Create a schema's database for your application. Add the marklogic-geo-data-services mlBundle. See the project README
dependencies {
mlBundle "com.marklogic:marklogic-geo-data-services-modules:1.1.0"
}
You first define your feature service.
{
"info": {
"name": "MyGeoData",
"description": "My GeoJSON data"
},
"layers": [
{
"id": 0,
"name": "GeoJSON Data",
"description": "My data in GeoJSON",
"geometryType": "Polygon",
"idField": "OBJECTID",
"extent": {
"xmin": 8,
"ymin": 119,
"xmax": 14,
"ymax": 128,
"spatialReference": {
"wkid": 4326,
"latestWkid": 4326
}
},
"schema": "GeoLocation",
"view": "GeoJSON",
"geometry": {
"type": "Polygon",
"format": "geojson",
"coordinateSystem": "wgs84",
"source": {
"xpath": "/envelope/instance/boundary"
}
}
}
]
}
A few notes on the Feature Service configuration:
- You can have multiple layers, each layer must have a unique incrementing
id
- Multiple layers may be defined in the
layers
array but do not need to make use of the same extent, schema, view, or geometry index. Increment theid
for each layer.
- Multiple layers may be defined in the
- If you are supporting Esri products, uou must identify an
idField
with a unique number for each document's data points. See the README for more information. - The feature service needs to identify the geospatial area (e.g. geospatial
extent
) the layer should return data for. -
schema
identifies the schema-name of the TDE used for this layer -
view
identifies the view-name of the TDE used for this layer -
geometry
specifies the geospatial index to use for geospatial queries and point responses
The Template Driven Extraction (TDE)
For the Feature Service defined above, the following TDE will extact data into the view used to return relevant feature data. Notice the context of the template identifies envelope data with a type of "geojson".
<template xmlns="http://marklogic.com/xdmp/tde">
<description>Example template for GeoJSON documents</description>
<context>/envelope[header/type="geojson"]</context>
<collections>
<collection>example-geojson</collection>
</collections>
<templates>
<template xmlns:tde="http://marklogic.com/xdmp/tde">
<context>./instance</context>
<rows>
<row>
<schema-name>GDS_Sample</schema-name>
<view-name>GeoJSON</view-name>
<view-layout>sparse</view-layout>
<columns>
<column>
<name>OBJECTID</name>
<scalar-type>long</scalar-type>
<val>../header/pointId</val>
</column>
<column>
<name>feature</name>
<scalar-type>string</scalar-type>
<val>type</val>
<nullable>true</nullable>
</column>
<column>
<name>name</name>
<scalar-type>string</scalar-type>
<val>properties/name</val>
<nullable>true</nullable>
</column>
</columns>
</row>
</rows>
</template>
</templates>
</template>
Please refer to the MarkLogic Documentation on TDE's for more information.
After deploying the template and some sample code, you can use MarkLogic Query Console to verify the TDE is extracting your data.
Verify the provided sample data and TDE.
SELECT * FROM GDS_Sample.GeoJSON
Result (raw):
[["GDS_Sample.GeoJSON.OBJECTID","GDS_Sample.GeoJSON.feature","GDS_Sample.GeoJSON.name"],[12312,"Feature","Dinagat Islands"]]
Result (as table):
GDS_Sample.GeoJSON.OBJECTID | GDS_Sample.GeoJSON.feature | GDS_Sample.GeoJSON.name |
---|---|---|
12312 | Feature | Dinagat Islands |
Using mlGradle, deploy to your MarkLogic system.
gradle mlDeploy -PenvironmentName=local
You can ingest your data using MarkLogic Content Pump mlcp, Apache Nifi processors, MarkLogic Data Hub input flow, and a several other methods.
Now that you have your application deployed with your verified TDE, you should be able to add marklogic-geo-data-services via an mlBundle to your application.
Consult the README on the marklogic-geo-data-services to configure and test your Feature Services.