Manoj Deshpande
Manoj Deshpande

Reputation: 311

How to store Polygon Coordinates as WKT Literal Values using RDFLIB?

I am working on GEOSPARQL queries. And I want to store Polygon Coordinates as wktLiteral values using RDF Graph (RDFLIB python). Currently I am doing that using the below code.

GEO = Namespace("http://www.opengis.net/ont/geosparql#")

if name == "wkt":
   self._graph.add((image, GEO["asWKT"], rl.Literal(value, datatype=GEO.wktGeneral)))

But when I see results in my Apache Fuseki server. I am not able to see proper datatype for "POLYGON(()) coordinates". Please let me know if anything is missing. Thank you.

Results Image

Upvotes: 0

Views: 720

Answers (1)

Nicholas Car
Nicholas Car

Reputation: 1251

Try this code:

from rdflib import Graph, Literal, URIRef, Namespace

GEO = Namespace("http://www.opengis.net/ont/geosparql#")

g = Graph()
g.bind("geo", GEO)
x = URIRef("x:")
g.add((x, GEO["asWKT"], Literal("value", datatype=GEO.wktLiteral)))


print(g.serialize(format="turtle").decode("utf-8"))

This returns the datatype just fine.

  • you need to set the type to wktLiteral, not wktGeneral
  • you need to use Literal() directly, not rl.Literal()

There may be other things but you've not presented enough code for me to tell.

Upvotes: 0

Related Questions