'How to use rdflib to represent Geometrical points in RDF data?

I am using rdflib to convert text files into n3 files for the purpose of saving bus station locations (GTFS).For example if we had latitude=8.0, longitude=5.0, the literal would be:

"POINT(5.0 8.0)"^^<http://www.openlinksw.com/schemas/virtrdf#Geometry>

Right now my code (for every line that I read from a text file) looks like this. I am simply saving the latitude, longitude as float xsd datatypes. We are adding each row in a graph(g).

data = fd.readline()
        data = re.split(',', data)

        row = {
          "stop_id": data[0] ,
          "stop_code": data[1] ,
          "stop_name": data[2].replace('"', '') ,
          "stop_desc": data[3] ,
          "stop_lat": data[4] ,
          "stop_lon": data[5] ,
          "location_type": data[6]
        }

        # Create a node for our movie
        stop_node = n['Stop/' + row['stop_id']] # Unique URI
        class_node = n['Stop']
        g.add((stop_node, n.HasStopId, Literal(row['stop_id'],datatype=XSD.int)))
        g.add((stop_node, n.HasStopCode, Literal(row['stop_code'],datatype=XSD.int)))
        g.add((stop_node, n.HasStopName , Literal(row['stop_name'],datatype=XSD.string)))
        g.add((stop_node, n.HasStopDesc, Literal(row['stop_desc'],  datatype=XSD.string)))
        g.add((stop_node, n.HasStopLat, Literal(row['stop_lat'], datatype=XSD.float)))
        g.add((stop_node, n.HasStopLon, Literal(row['stop_lon'], datatype=XSD.float)))
        g.add((stop_node, n.HasLocationType, Literal(row['location_type'], datatype=XSD.int)))
        g.add((stop_node, RDF.type, class_node))

Output example:

@prefix ns1: <http://www.stops.org/> .//I have defined that in another file, not important
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://www.stops.org/Stop/01034> a ns1:Stop ;
    ns1:HasLocationType "0"^^xsd:int ;
    ns1:HasStopCode "10001"^^xsd:int ;
    ns1:HasStopDesc "Outside National Hospital"^^xsd:string ;
    ns1:HasStopId "01034"^^xsd:int ;
    ns1:HasStopLat "8.0"^^xsd:float ;
    ns1:HasStopLon "5.0"^^xsd:float ;
    ns1:HasStopName "turn hospital"^^xsd:string .

  

I have been instructed in case I use OpenLink Virtuoso to import my n3 files into its database. I can find examples on how linkedgeodata uses this representation to query on the data. I haven't understood exactly whether I should first save it as it (two float values) and then convert it into a geometric point in OpenLink Virtuoso or whether I would convert the values as geometric points in the n3 file that Python produces with rdflib. I can't find anything else related on the internet.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source