Loading GeoJson in Dgraph directly

I’ve added the ability to store geospatial data in Dgraph when expressed in RDF.

e.g. the the location of an airport may be encoded in RDF as:

<apt.a61zr1acn7x4> <location> "{\"type\":\"Point\",\"coordinates\":[-116.2227783,43.5644455]}"^^<geo:geojson> .

Here the value is the geometry object expressed in GeoJson.

Normally when you get a GeoJson dataset, it is not expressed in a line by line format as above. But instead, it is one complete JSON file which includes the geometry information for all features. (e.g. all the airports). Hence it requires some amount of preprocessing before it can be expressed in the RDF format as above.

Moreover, the GeoJson format expresses much more than just the geometry. e.g. the above airport information is available as:

    "Total Enpl":1420073.0,
    "Landing Fa":"BOI",
    "Name0":"Boise Air Terminal/Gowen Field",
    "County0":"Ada County"

The geojson file represents a FeatureCollection which is essentially an array of these Feature objects. This Feature can easily be expressed in RDF as:

<a61zr1acn7x4>    <Total_Enpl> 1420073.0^^<xs:int> .
<a61zr1acn7x4>    <State0>     "ID" .
<a61zr1acn7x4>    <Landing_Fa> "BOI" .
<a61zr1acn7x4>    <Name0>      "Boise Air Terminal/Gowen Field" .
<a61zr1acn7x4>    <County0>    "Ada County"  .
<a61zr1acn7x4>    <geometry>   "{\"type\":\"Point\",\"coordinates\":[-116.2227783,43.5644455]}"^^<geo:geojson> .

Now, instead of having the user have to preprocess the geojson file into something that we can consume, I am wondering if we should just modify the loader to accept the geojson file type and then convert it directly to NQuads as I have shown above.


Instead of the loader, let’s put more focus on the Go client that we have. We should extend it to allow sending mutations directly in NQuad formats. This would allow unnecessary conversion to-from RDFs, and also can then allow specifying these complicated data types easily.


So Go client already supports sending mutations in NQuad formats. Maybe we can have helper methods for GeoJson that convert a GeoJson format into RDF NQuads. Is that what you had in mind @mrjn?

1 Like

Yeah, exactly! Client can do the GeoJSON to NQuad conversion and send it to the server.

1 Like

Sounds good. I’ll take a look at the Go client.

Also, one more thing, though a bit out of context. I feel we could make our client a CLI so that we could just type in the queries and mutations without having to do (./dgraphgoclient …) everytime. Similar to the mysql-cli.

Wouldn’t that be the same as curl, which is what we currently do?

So a MySQL has a command like CLI apart from the language specific drivers. They are different things. It would actually be pretty similar to curl as pointed out.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.