Jobel
Jobel

Reputation: 643

How to make a ST_spatial query ST_Within Orientdb by selecting spatial classes

I am trying to understand how to use the LUCENE Spatial queries in Orientdb 2.2.17 using pyorient.

I have note yet figure it out how to select all the properties of a point vertex class that is within a polygon vertex from another class.This is a visual representation of the problem, where the labels represent the station_names.

Region Vertex Class has two properties:

  1. name
  2. coordinates (EMBEDDED OPolygon) LUCENE index

    CREATE CLASS Region EXTENDS V

    CREATE PROPERTY Region.name IF NOT EXISTS STRING

    CREATE PROPERTY Region.coordinates IF NOT EXISTS EMBEDDED OPolygon

    CREATE INDEX Region.coordinates ON Region(coordinates) SPATIAL ENGINE LUCENE

Points vertex class, also with two properties:

  1. station_name
  2. coordinates (EMBEDDED OPoint) LUCENE index

    CREATE CLASS Point EXTENDS V

    CREATE PROPERTY Point.station_name IF NOT EXISTS STRING

    CREATE PROPERTY Point.coordinates IF NOT EXISTS EMBEDDED OPoint

    CREATE INDEX Point.coordinates ON Point(coordinates) SPATIAL ENGINE LUCENE

Now, addding region polygon points:

INSERT INTO Region SET name = 'region01', coordinates = St_GeomFromText("POLYGON ((13.178784796476098 59.058001210852922,14.161006039084404 59.058001210852922,14.176596852459138 58.122552408368826,13.178784796476098 58.122552408368826,13.178784796476098 59.058001210852922))")

Adding the Points vertex:

INSERT INTO Point SET station_name = 0, coordinates = st_GeomFromText("POINT (13.459419437221328 58.808548196857167)")
INSERT INTO Point SET station_name = 1, coordinates = st_GeomFromText("POINT (14.332504986206489 58.605867622985606)")
INSERT INTO Point SET station_name = 2, coordinates = st_GeomFromText("POINT (13.724463264591824 57.779554514124655)")
INSERT INTO Point SET station_name = 3, coordinates = st_GeomFromText("POINT (12.617515514985637 58.66823087648455)")

I tried with something like and its variations but failed, here is the query example:

SELECT from Point WHERE ST_WITHIN(coordinates, ST_AsText(SELECT coordinates FROM Region where name='region01')) = true

I got the following error, I have tried different ways on the query without success.

Error parsing query: SELECT from Point WHERE ST_WITHIN(coordinates, ST_AsText(SELECT coordinates FROM Region where name='region01')) = true ^ Encountered "" at line 1, column 25. Was expecting one of: DB name="envlay-db"

The expected result is to retrieve the point with station_name=0 that is contained by the polygon.

Any help would be most appreciated.

;)

Jobel

Upvotes: 1

Views: 212

Answers (0)

Related Questions