0

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

Manoj Deshpande
  • 311
  • 2
  • 18

1 Answers1

0

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.

Nicholas Car
  • 1,164
  • 4
  • 7
  • Below is my code import rdflib as rl query_endpoint = "http://localhost:3030/example/query" update_endpoint = "http://localhost:3030/example/update" BACKEND = sparqlstore.SPARQLUpdateStore() BACKEND.open((query_endpoint, update_endpoint)) GEO = Namespace("http://www.opengis.net/ont/geosparql#") GRAPH = rl.Graph(BACKEND, identifier="http://project/base/default") ### Consider value ### value = "POLYGON(())" self_graph = GRAPH ex = Namespace("http://example.org/#") self_graph.add((ex, GEO["asWKT"], rl.Literal(value, datatype=GEO.wktLiteral))) – Manoj Deshpande Apr 23 '20 at 13:49
  • I am creating graph using RDFLIB and then trying to store in Apache Fuseki Jena – Manoj Deshpande Apr 23 '20 at 13:50
  • I get output like this in Fuseki server. "POLYGON((8.466972112655641 48.997951481364986,8.466972112655641 48.99809578146089,8.467175960540773 48.99809578146089,8.467175960540773 48.997951481364986,8.466972112655641 48.997951481364986))"^^ "POLYGON((8.467036485671999 48.99954579824209,8.467036485671999 48.99961618633192,8.467197418212892 48.99961618633192,8.467197418212892 48.99954579824209,8.467036485671999 48.99954579824209))"^^ – Manoj Deshpande Apr 23 '20 at 13:51