Cartesian spatial schema 

How to create Cartesian spatial schema.

Three cartesian spatial data types,point, linestring, and polygon store data that can be searched with spatial shapes. After creating schema for these data types, Cartesian spatial queries can be constructed using them. For Cartesian queries that look for Cartesian points, points or linestrings within circles or polygons, DSE Search indexes must be created.

The examples below load Cartesian data with graph.addVertex(…) commands, but the DSE Graph Loader can be used to load Cartesian data starting with DSE 5.0.9 and DSE 5.1.2.

Procedure

Point schema

  • Create schema for a point and add a vertex with a property value for a point:
    schema.propertyKey('name').Text().create()
    schema.propertyKey('point').Point().withBounds(-3, -3, 3, 3).create()
    schema.vertexLabel('location').properties('name','point').create()
    graph.addVertex(label, 'location', 'name', 'p0', 'point', Geo.point(0.5, 0.5))
    A vertex label is created for location that has a point property. For Cartesian spatial points, the withBounds(x1, y1, x2, y2) method limit searches to a default valid range of values in the x-y grid.
    Check that the point exists:
    g.V().has('location', 'name', 'p0').valueMap()
    ==>{name=[p0], point=[POINT (0.5 0.5)]}

Linestring schema

  • Create schema for a linestring and add a vertex with a property value for a linestring:
    schema.propertyKey('name').Text().create()
    schema.propertyKey('line').Linestring().withBounds(-3, -3, 3, 3).create()
    schema.vertexLabel('lineLocation').properties('name','line').create()
    graph.addVertex(label, 'lineLocation', 'name', 'l1, 'line', "LINESTRING(0 0, 1 1)")
    A vertex label is created for lineLocation that has a LineString property. For Cartesian spatial linestrings, as with Cartesian spatial points, the withBounds(x1, y1, x2, y2) method limit searches to a default valid range of values in the x-y grid.
    Check that the linestring exists:
    g.V().has('lineLocation','name','l1').valueMap()
    ==>{line=[LINESTRING (0 0, 1 1)], name=[l1]}

Polygon schema

  • Create schema for a polygon and add a vertex with a property value for a polygon:
    schema.propertyKey('name').Text().create()
    schema.propertyKey('polygon').Polygon().withBounds(-3, -3, 3, 3).create()
    schema.vertexLabel('polyLocation').properties('name','polygon').create()
    graph.addVertex(label, 'polyLocation','name', 'g1', 'polygon',Geo.polygon(0,0,1,1,0,1,0,0))
    A vertex label is created for polyLocation that has a Polygon property. For Cartesian spatial polygons, as with Cartesian spatial points, the withBounds(x1, y1, x2, y2) method limit searches to a default valid range of values in the x-y grid.
    Check that the polygon exists:
     g.V().has('polyLocation','name','g1').valueMap()
    ==>{polygon=[POLYGON ((0 0, 1 1, 0 1, 0 0))], name=[g1]}

DSE Search indexes

  • While DSE Graph natively supports Cartesian searches, performing them without a Search index does not scale as the number of vertices in the graph increases. Doing such queries without a search index results in very inefficient query performance because full scans are required. DSE Search indexes can index points and linestrings, but not polygons.
    //SEARCH INDEX ONLY WORKS FOR POINT AND LINESTRING
    schema.vertexLabel('location').index('search').search().by('point').add()
    schema.vertexLabel('lineLocation').index('search').search().by('line').add()
    Note: DSE Search does not index polygons.