GeoJSON-LD with a modified JSON-LD parser
46
Copyright © 2015 Open Geospatial Consortium.
xsd: http:www.w3.org2001XMLSchema, geojson: http:ld.geojson.orgvocab,
schema: http:schema.org, ogc_geo: http:www.opengis.netontgeosparql,
id: id, url: id,
type: type, features: geojson:features,
geometry: _:, properties: _:,
asWKT: ogc_geo:wktLiteral, featureType: geojson:Feature,
featureCollectionType: geojson:FeatureCollection, lineStringType: geojson:LineString,
Feature: featureType, FeatureCollection: featureCollectionType,
LineString: lineStringType, ...
},
To demonstrate the feasibility of this approach, we have created a modified version of the http:json-ld.orgplaygroundindex.html that includes a small piece of code that
transforms the GeoJSON n-dimensional arrays of coordinates and the bbox into the WKT equivalents. The converted string is included as the value of the “asWKT” JSON key and
the “coordinates” key is removed. The transformation is requested before the JSON-LD engine reads and interprets the JSON-LD file. The code to transform the coordinates
array into WKT the following:
function geometryasWKTgeometry {
var identified=false;
if geometry.type==Point {
geometry.asWKT=POINT; for var i_dim=0; i_dimgeometry.coordinates.length;
i_dim++ {
geometry.asWKT+=geometry.coordinates[i_dim]; if i_dim+1geometry.coordinates.length
geometry.asWKT+= }
identified=true; }
Copyright © 2015 Open Geospatial Consortium.
47
else if geometry.type==MultiPoint {
geometry.asWKT=MULTIPOINT; for var i_vrt=0; i_vrtgeometry.coordinates.length;
i_vrt++ {
geometry.asWKT+=; for var i_dim=0;
i_dimgeometry.coordinates[i_vrt].length; i_dim++ {
geometry.asWKT+=geometry.coordinates[i_vrt][i_dim]; if i_dim+1geometry.coordinates[i_vrt].length
geometry.asWKT+= }
geometry.asWKT+=; if i_vrt+1geometry.coordinates.length
geometry.asWKT+=, }
identified=true; }
else if geometry.type==LineString {
geometry.asWKT=LINESTRING; for var i_vrt=0; i_vrtgeometry.coordinates.length;
i_vrt++ {
for var i_dim=0; i_dimgeometry.coordinates[i_vrt].length; i_dim++
{ geometry.asWKT+=geometry.coordinates[i_vrt][i_dim];
if i_dim+1geometry.coordinates[i_vrt].length geometry.asWKT+=
} if i_vrt+1geometry.coordinates.length
geometry.asWKT+=, }
identified=true; }
else if geometry.type==MultiLineString || geometry.type==Polygon
{ if geometry.type==MultiLineString
geometry.asWKT=MULTILINESTRING; else
geometry.asWKT=POLYGON; for var i_ls=0; i_lsgeometry.coordinates.length; i_ls++
{ geometry.asWKT+=;
for var i_vrt=0; i_vrtgeometry.coordinates[i_ls].length; i_vrt++
{
48
Copyright © 2015 Open Geospatial Consortium.
for var i_dim=0; i_dimgeometry.coordinates[i_ls][i_vrt].length; i_dim++
{ geometry.asWKT+=geometry.coordinates[i_ls][i_vrt][i_dim];
if i_dim+1geometry.coordinates[i_ls][i_vrt].length
geometry.asWKT+= }
if i_vrt+1geometry.coordinates[i_ls].length geometry.asWKT+=,
} geometry.asWKT+=;
if i_ls+1geometry.coordinates.length geometry.asWKT+=,
} identified=true;
} else if geometry.type==MultiPolygon
{ geometry.asWKT=MULTIPOLYGON;
for var i_pol=0; i_polgeometry.coordinates.length; i_pol++
{ geometry.asWKT+=;
for var i_ls=0; i_lsgeometry.coordinates[i_pol].length; i_ls++
{ geometry.asWKT+=;
for var i_vrt=0; i_vrtgeometry.coordinates[i_pol][i_ls].length; i_vrt++
{ for var i_dim=0;
i_dimgeometry.coordinates[i_pol][i_ls][i_vrt].length; i_dim++ {
geometry.asWKT+=geometry.coordinates[i_pol][i_ls][i_vrt][i_dim ];
if i_dim+1geometry.coordinates[i_pol][i_ls][i_vrt].length
geometry.asWKT+= }
if i_vrt+1geometry.coordinates[i_pol][i_ls].length geometry.asWKT+=,
} geometry.asWKT+=;
if i_ls+1geometry.coordinates[i_pol].length geometry.asWKT+=,
} geometry.asWKT+=;
Copyright © 2015 Open Geospatial Consortium.
49
if i_pol+1geometry.coordinates.length geometry.asWKT+=,
} identified=true;
} else if geometry.type==GeometryCollection
alertGeometryCollection; if identified==true
{ geometry.asWKT+=;
delete geometry.coordinates; delete geometry.type;
} }
function bboxasWKTfeature {
var n_dim=feature.bbox.length2; feature.asWKT=POLYGON;
for var i_dim=0; i_dimn_dim; i_dim++ {
feature.asWKT+=feature.bbox[i_dim]; if i_dim+1n_dim
feature.asWKT+= }
feature.asWKT+=,; for var i_dim=0; i_dimn_dim; i_dim++
{ if i_dim==1
feature.asWKT+=feature.bbox[n_dim+i_dim]; else
feature.asWKT+=feature.bbox[i_dim]; if i_dim+1n_dim
feature.asWKT+= }
feature.asWKT+=,; for var i_dim=0; i_dimn_dim; i_dim++
{ feature.asWKT+=feature.bbox[n_dim+i_dim];
if i_dim+1n_dim feature.asWKT+=
} feature.asWKT+=,;
for var i_dim=0; i_dimn_dim; i_dim++ {
if i_dim==1 feature.asWKT+=feature.bbox[i_dim];
else feature.asWKT+=feature.bbox[n_dim+i_dim];
if i_dim+1n_dim
50
Copyright © 2015 Open Geospatial Consortium.
feature.asWKT+= }
feature.asWKT+=,; for var i_dim=0; i_dimn_dim; i_dim++
{ feature.asWKT+=feature.bbox[i_dim];
if i_dim+1n_dim feature.asWKT+=
} feature.asWKT+=;
delete feature.bbox; }
function geoJSONasWKTgeojson {
if typeof geojson == object {
if geojson.length {
forvar i=0; igeojson.length; i++ {
geoJSONasWKTgeojson[i]; }
} else
{ forvar name in geojson
{
if geojson.hasOwnPropertyname {
if name == geometry typeof geojson[name] == object
{ if geojson[name].type
geojson[name].coordinates {
geometryasWKTgeojson[name]; }
}
else if name == geometries typeof geojson[name] == object geojson[name].length
{ forvar i=0; igeojson[name].length; i++
{ if geojson[name][i].type
geojson[name][i].coordinates {
geometryasWKTgeojson[name][i]; }
}
Copyright © 2015 Open Geospatial Consortium.
51
} else if name == bbox typeof geojson[name] ==
object geojson[name].length3 typeof geojson[name][0] == number typeof geojson[name][1] == number typeof
geojson[name][2] == number typeof geojson[name][3] == number
{ bboxasWKTgeojson;
} else if typeof geojson[name] == object
geoJSONasWKTgeojson[name]; }
} }
} return;
}
Bbox was converted to a rectangular polygon due to the fact that no equivalent element is present in WKT.
The result of the conversion is the same than in previous section and can be seen in the following illustration as a RDF graph:
Figure 1: River GeoJSON file example transformed to RDF through JSON-LD
Recommendation 14: Respect the original format of GeoJSON and apply a piece of code to transform GeoJSON into WKT JSON for simple features on the fly to obtain RDF notation from
GeoJSON. Target: OAB
Recommendation 15: Consider JSON-LD as an alternative for creating GML application schemas as a means of defining feature types and as a mean for validation.
Target: OWS Common.SWG and OAB
52
Copyright © 2015 Open Geospatial Consortium.
Recommendation 16: Add a BBOX element in the WKT standard. Target: CR to Simple Features for SQL
8 GeoJSON in OGC