Hi Luisa,
The idea is to define a filter in your relation and use it on a virtual complete graph to connect the pairs of entities that are valid for your filter.
If you have the models from the teaching sessions, you can look at the model Naruto. It creates a relation between Parcel
entities : relation NeighParc<Parcel p1, Parcel p2> { ...}
Inside that relation, you will find the filter definition :
filter near(Double dist) {
return (p1.geom.envelope.distance(p2.geom.envelope) < dist)
&& (p1.geom.distance(p2.geom) < dist)
}
A filter is a function that returns true
or false
. As you can see in this example, the near()
filter is a function that takes a distance in argument and it returns true
when the distance between two parcels if less than the dist
given in argument.
Then in the scenario you will see how this is used to connect the graph :
...
fix r_neighparc = new NeighParc
r_neighparc.addAllParcel(lparc)
r_neighparc.complete.near(30.0).connect
Instead of testing on a distance, you can define a filter that tests for example if one properties of both parcels are equal with something like :
filter same_landcover() { return p1.landcover == p2.landcover }
Just ask again if you need more details or a different example.