gama-platform / gama.old

Main repository for developing the 1.x versions of GAMA
GNU General Public License v3.0
304 stars 99 forks source link

Consider points as geometries in spatial operators #3878

Closed AlexisDrogoul closed 10 months ago

AlexisDrogoul commented 1 year ago

Discussed in https://github.com/gama-platform/gama2/discussions/62

Originally posted by **tnguyenh** April 25, 2023 For some operators, points are not considered as geometry. This makes sense as point may be used for several purpose. However, from the user point of view, they may be naturally seen as geometries. For example, in the following example, I want to find all the points inside a shape: ``` model points_as_geometry global{ list liste <- [{20,30},{3,2},{30,44},{5,6},{12,4}, {105,30}]; list liste2 <- [{20,30},{3,2},{30,44},{5,6},{12,4}, {105,30}]; list liste3 <- [geometry({20,30}),{3,2},{30,44},{5,6},{12,4}, {105,30}]; init{ create forme; write liste inside first(forme).shape; write liste2 inside first(forme).shape; write liste3 inside first(forme).shape; } } species forme{ geometry shape <- square(100); point location <- {50,50}; aspect default{ draw shape color: #pink; loop l over: liste{ draw circle(1) at: l color: #purple; } } } experiment essai type: gui { output { display "My display" { species forme aspect: default; } } } ``` The first list is the raw list of points. The second one is casted as a list of geometries. For the third one, the first element is casted as a geometry. Only the third list provides the expected result. For a general user, this approach may be quite confusing, leading to incorrect results (and the user not being able to see it). Could point be casted automatically to geometries in usual spatial operators ?
AlexisDrogoul commented 1 year ago

This should be fixed in the latest commit. Please test ! point is actually a kind of geometry, but the reason for the misbehaviour was:

  1. A strict equality between IType.GEOMETRY and the id of the contents type of the list (so points were not considered)
  2. The downcasting automatically done by GAMA, which results in list<geometry> liste2 <- [{20,30},{3,2},{30,44},{5,6},{12,4}, {105,30}]; actually (and internally) transformed into a list<point> (as point is a specialised subtype of geometry).
lesquoyb commented 11 months ago

@tnguyenh could you have a look to check if it fits your needs ?

lesquoyb commented 10 months ago

I tested myself and it seems alright, closing for now, feel free to reopen if not in your examples @tnguyenh