Hi all, I implemented an if expression statement as followed by this picture:

my problem is that all variables before or after a bracket "(" or ")" are not recognized.


the result is


Does onyone has an idea how I have to use/implement the variables in the above-mentioned expression?

I tryed to implemet this algorithm:

https://stackoverflow.com/a/14998816

Hello,


Check if the local variable is assigned expected values prior.

Please share the oml.

Hi SaxoTom,


One thing that you need to be careful, if the value that you obtain after "/" is zero, this will brake (as it is happening). It's better to protect your code against that kind of situations.


Best regards,

Ricardo

Changalrao Bairaboyana wrote:

Hello,


Check if the local variable is assigned expected values prior.

Please share the oml.

in the statements before the asignement in works "as designed". In the expression above all variables are ok if they don`t have a bracket before or after the variable.

Does the provided oml work?


Ricardo Pereira wrote:

Hi SaxoTom,


One thing that you need to be careful, if the value that you obtain after "/" is zero, this will brake (as it is happening). It's better to protect your code against that kind of situations.


Best regards,

Ricardo

At the moment, when the algorithm reaches the if statemenet 

(polygon[j].y - polygon.Current.y)

j=9 and i=0 - so this part couldn´t be zero.  I think the result is like it is, because some of the variables are not defined.


SaxoTom wrote:

Hi all, I implemented an if expression statement as followed by this picture:

my problem is that all variables before or after a bracket "(" or ")" are not recognized.


the result is


Does onyone has an idea how I have to use/implement the variables in the above-mentioned expression?

I tryed to implemet this algorithm:

https://stackoverflow.com/a/14998816

This might not be available under in Use tab but you can add your point variable to debug watches like below.. Then it will be available under Watches tab.


Nikhil Gaur wrote:

SaxoTom wrote:

Hi all, I implemented an if expression statement as followed by this picture:

my problem is that all variables before or after a bracket "(" or ")" are not recognized.


the result is


Does onyone has an idea how I have to use/implement the variables in the above-mentioned expression?

I tryed to implemet this algorithm:

https://stackoverflow.com/a/14998816

This might not be available under in Use tab but you can add your point variable to debug watches like below.. Then it will be available under Watches tab.


does not work neither

It should work as you can see in the screen shot above values are visible inside Watches tab. Please make sure that you are accessing it inside Watches tab not under In Use Tab

Nikhil Gaur wrote:

It should work as you can see in the screen shot above values are visible inside Watches tab. Please make sure that you are accessing it inside Watches tab not under In Use Tab

Its nor problem, to see the variables inside the Watches tab. But, in the moment of the usage it works for 

SyntaxEditor Code Snippet

polygon.Current.x 

and

SyntaxEditor Code Snippet

point.x


but ist does not work for

SyntaxEditor Code Snippet

 (point.y

or 

SyntaxEditor Code Snippet

polygon.Current.y)


because the variabls are betweet two brackets ( ..... ).

Like mathematical expressions  A + (y - C) / (C - D) * (E - F) < x  

that´s the calculation.

If I delete all brackets in the expression, the variables are all "OK" - but it is mathematical wrong.

Solution

Hi,

Yes you are right that while debugging it is not showing corract value because of the brackets (looks like SS bug) but this won't create any issue in your calculation result. 

The issue you are getting "Attempt to divide by zero" is because of the expression you have used as denominator while dividing.

Your if condition

polygon.Current.x + ( point.y - polygon.Current.y ) / ( polygon[j].y - polygon.Current.y ) * ( polygon[j].x - polygon.Current.x ) < point.x

Parts of the condition causing the issue

polygon[j].y - polygon.Current.y

and

polygon[j].x - polygon.Current.x


If you calculate this value, it becomes zero (see first and last value of y in below image) which you can not use as denominator while dividing.


Solution
Processing Upload...

Hello everybody,


thank you all for your input. After a short discussion with my son, I understood the underlying algorithm. So I changed the If-then-else statements and solved the "devide by zero" problem. Maybe the attachment could help someone who is looking for "how do I calculate whether a point lies in a polygon or not."

Kind regards 

@SaxoTom

Attached you find the calculator

Meanwhile I have also implemented a point in multipolygon algorithm!

Hi Tom,

Any change your could create Forge components for those 2 algorithms? I'm sure there are others that can benefit from this :) 

Kind regards,

Vincent

Vincent Koning wrote:

Hi Tom,

Any change your could create Forge components for those 2 algorithms? I'm sure there are others that can benefit from this :) 

Kind regards,

Vincent

I think, I can do that. But first I have to finish my prototype. Today I checked over 700 geo referenced points from an api against an array of 7 polygons with triangle, squares and other polygons with up to 10 geo points. It worked very well.


Meanwhile I realized a Point-In-Multipolygon algorithm with a Geojsonfile (250MB), parsed with Outsystems API consumer call from Github dataset "countries.geojson". 255 Country Multipolygons with 4.182 polygons representing the country borders. A calculation over all polygons needs 193 seconds. Canada is represented by 410 geojson polygons.

Thats a long time. Perhaps you can filter the geojsons before checking if the point in inside it by boxing them (if your not doing that already)? Just take the most north, east, south and west point of the geojson and if the point falls inside that box then include that geojson for further processing. If not then skip it. This could save some valuable time. 

Vincent Koning wrote:

Thats a long time. Perhaps you can filter the geojsons before checking if the point in inside it by boxing them (if your not doing that already)? Just take the most north, east, south and west point of the geojson and if the point falls inside that box then include that geojson for further processing. If not then skip it. This could save some valuable time. 

yes, this could be one way to reduce calculation time. But, step by step. I´m an Outsystems beginner and I have to finish my other prototype first.