wso2siddhiwso2-cep

WSO2CEP Siddhi query error using geo within function


I am using the GEO extension within function into an execution plan. I have multiple event streams, which contain sensor information, including the location of each sensor (in geographical coordinates). Furthermore, I have a Polygon (example below, which contains the coordinates of each point). I would like to check if it's possible to determine whether the sensors are within the boundaries of this polygon.

My execution plan is the following:

@Plan:name('TestExecutionPlan')

define stream sensorStream (id string, lat double, longi double);

define stream outputStream (id string);

from sensorStream [geo:within(lat,longi,{"type": "Polygon", "coordinates": [[[37.9807986, 23.7262081],[37.9807986, 23.7262081],[37.9792256, 23.7302850],[37.9789888, 23.7268089],[37.9807986, 23.7262081]]]})]
select id
insert into outputStream;

When I'm running my execution plan in Siddhi Try It Tool of the WSO2CEP Management Console the following error is occurring:

You have an error in your SiddhiQL at line 16:108, no viable alternative at input 'geo:within(sensorStream.lat, sensorStream.longi,{'type':'Polygon','coordinates':[[[37.9807986, 23.7262081],[37.9807986, 23.7262081],[37.9792256, 23.7302850],[37.9789888, 23.7268089],[37.9807986, 23.7262081]]]}'

I do not know why that error occurs.

I would be very grateful if somebody could help me on this matter.

Thanks!


Solution

  • I solved the error. The error was existing because it needed to include the {"type": "Polygon", "coordinates": [[[-104.05,48.99],[-97.22,48.98],[-96.58,45.94],[-104.03,45.94],[-104.05,48.99]]]} with question marks i.e to be "{"type": "Polygon", "coordinates": [[[-104.05,48.99],[-97.22,48.98],[-96.58,45.94],[-104.03,45.94],[-104.05,48.99]]]}", because it is a string value as it explained in the syntax of the geo:within function in the Siddhi Geo Extension (https://docs.wso2.com/display/CEP420/Geo+Extension).

    So, the execution plan which worked is the following:

    @Plan:name('TestExecutionPlan')
    
    define stream sensorStream (id string, lat double, longi double);
    
    define stream outputStream (id string);
    
    from sensorStream [geo:within(lat, longi, " { 'type': 'Polygon', 'coordinates': [[[37.9807986, 23.7262081],[37.9807986, 23.7262081],[37.9792256, 23.7302850],[37.9789888, 23.7268089],[37.9807986, 23.7262081]]] } " )]
     select id 
     insert into outputStream;