This repository defines a conversion process for RDF data to GeoJSON and implements a version of it in Python.
See the convert.convert()
function which does all the work.
Whatever RDF you give it, the conversion function will return either:
-
a valid
geojson.FeatureCollection
Python object, or -
an empty Python dictionary
A valid result can be serialized to GeoJSON like this:
from rdflib import Graph from rdf2geojson import convert from geojson import dumps gj = convert(Graph().parse(rdf_file)) dumps(gj)
The criteria for creating a valid FeatureCollection
output are:
-
the input must be valid RDF
-
it must also be valid GeoSPARQL
-
it must contain all the GeoSPARQL parts necessary for valid GeoJSON
-
See the GeoSPARQL → GeoJSON specification below
-
GeoSPARQL knows about the following main object classes:
-
FeatureCollection
-
Feature
-
GeometryCollection
-
Geometry
-
types of geometry:
-
MultiPolygon
-
Polygon
-
MultiLineString
-
LineString
-
MultiPoint
-
Point
-
The following rules are used to translate these classes to parts of GeoJSON:
-
FeatureCollection
→ GeoJSON FeatureCollection-
if no
FeatureCollection
is present in the RDF, one will be created in the GeoJSON
-
-
Feature
→ GeoJSON Feature -
GeometryCollection
currently has no mapping -
Geometry
→ the geometry of a Feature and such objects are ignored-
stand-alone Geometries are not handled
-
multiple geometries are not handled - only the first is used
-
-
types of geometry:
-
all types of geometry are supported
-
only WKT and GeoJSON serializations are currently supported
-
-
properties for
Feature
instances, other thanGeometry
instances, are added as GeoJSON key/valu pair properties
This code is made available for use using the BSD 3-Clause license. See the LICENSE
file for the deed.
This content is all copyrighted as follows:
© KurrawongAI, 2024
This code will always use this license, so contributors may contribute knowing this code will always be freely available for use.
See the Issue Tracker for this project, as well as TODO:
items within the codebase.
Nicholas J. Car
KurrawongAI
[email protected]