Wednesday 19 April 2017

geometry - Defining spatial operators (Equals, Disjoint, Touches, Within, Overlaps, Crosses, Intersects, Contains, Relate)?


Ok, I have to admit, I don't really delve too deep into the semantics of the spatial operators list below, I'm more of a user, I write software to drive the SQL most of the time and don't really think about it too much.


However, I have a situation where a spatial operation I'm doing is going dog slow, on a table that has great indexes on and has never caused a problem before now.


As a result, I'm trying to figure out which of the following is my best bet to use, that will give me the best performance, however, sometimes I find my searches don't return anything when I know they should, and sometimes return stuff when they shouldn't.


SO I'm reaching out, to ask if some one can give me the actual definition, such as criteria to match, fully within enclosing geometry, or within outer ring etc etc of each of the following operations:


Equals(Geom1, Geom2):int
Disjoint(Geom1, Geom2):int

Touches(Geom1, Geom2):int
Within(Geom1, Geom2):int
Overlaps(Geom1, Geom2):int
Crosses(Geom1, Geom2):int
Intersects(Geom1, Geom2):int
Contains(Geom1, Geom2):int
Relate(Geom1, Geom2):int

If you can give a concrete example of when they will and will not match too, that would be great.


For reference, I'm searching on a table of Linestrings, using a rectangular polygon, rotated to be pointing in the direction of travel (It's part of a traffic managment app)



For further reference, here is a sample of the SQL the app generates to perform a search:


SELECT recordID,AsBinary(geometry) AS geometry,Distance(GeomFromText('POINT(-1.84101 54.85078)',4326), geometry) AS distanceFromGps FROM linegrid WHERE Intersects(GeomFromText('POLYGON ((-1.8413149820810311 54.850782468607292, -1.8409507853094111 54.850952257034713, -1.8408279009723911 54.850864894077496, -1.8411920982612455 54.850695105650068, -1.8413149820810311 54.850782468607292))'), geometry)

You can see in this example I'm using intersects trying the others as mentioned doesn't quite give the results I expect, hence why I'm asking the question.


Please note, I'm not particularly bothered about actual faster/other ways of doing this at the moment, BUT if you do happen to spot a better way do feel free to shout up :-)


For now all I'm mostly trying to understand is the differences between each of the operations.


As for doing it faster/better I intend to open a different question for that at a later date.


For more reference, the Spatial engine this is working against is Spatilite 2.3.0, and I can't upgrade it due to the devices it's running on not having a more up to date build for it (Windows CE)




I'm going to choose mintix'es answer here as that provided a super easy to understand grid and description of all the various operations, which answered my question.



I'm still faced with getting performance on the routines up, but I do now have a few strategies to try on that one, I may still seek advice here from the group with regards to that.


@Vince deserves some credit too, as that white paper is definitely the definitive answer, but it's also quite challenging to read (I had to read through it several times) , for anyone wanting the real I am on these operations The Clementini paper is the way to go, if you need an easy to understand overview while developing solutions however, the FME link should be open in another browser tab.



Answer



You're looking for the "Dimensionally Extended 9 Intersection Matrix" or DE-9IM for short.


DE-9IM by FME


That FME link has great examples of the spatial operators you listed above. It breaks it down into a 3x3 true/false matrix with examples and descriptions of each predicate attribute.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...