4

I'm trying to see if I can catch among other things a self-intersection which involves a start / end point of a geometry feature self-intersecting some other part of the same feature. Obviously the start and end points of a proper feature will be the same.

I ask because I've heard some tools ignore start and end points altogether when trying to determine a self-intersection. This can be a problem if either start or end points legitimately intersect some other point / line segment.

Would catching this specific kind of self-intersection be easily caught via ST_IsValid?

1 Answer 1

2

You can test it yourself.

enter image description here

Draw a polygon that starts from the red dot and touches the same point

A WKT of one such polygon is

POLYGON ((
        320 620, 
        460 620, 
        460 500, 
        320 620, 
        320 500, 
        180 500, 
        180 620, 
        320 620
    ))

Ask a question from PostGIS

select ST_IsValid(
ST_GeomFromText(
'POLYGON (( 320 620, 460 620, 460 500, 320 620, 320 500, 180 500, 180 620, 320 620 ))'
    ));

The answer is "f".

select ST_IsSimple(
 ST_GeomFromText(
 'POLYGON (( 320 620, 460 620, 460 500, 320 620, 320 500, 180 500, 180 620, 320 620 ))'
     ));

The answer is "t".

select ST_IsValidReason(
 ST_GeomFromText(
 'POLYGON (( 320 620, 460 620, 460 500, 320 620, 320 500, 180 500, 180 620, 320 620 ))'
     ));

The answer is "Ring Self-intersection[320 620]".

How about the polygon ring as LineString?

select ST_IsValid(
ST_GeomFromText(
'LINESTRING ( 320 620, 460 620, 460 500, 320 620, 320 500, 180 500, 180 620, 320 620 )'
    ));

The answer is "t".

select ST_IsSimple(
ST_GeomFromText(
'LINESTRING ( 320 620, 460 620, 460 500, 320 620, 320 500, 180 500, 180 620, 320 620 )'
    ));

The answer is "f".

The answer to your question seems to be that PostGIS does catch self-intersections involving the start / end points to a line or area. You must use ST_IsValid for polygons and ST_IsSimple for linestrings. What I do not understand is why IsSimple returns "true" for the polygon. I thought it should be false. The documentation at http://postgis.net/docs/ST_IsSimple.html says:

ST_IsSimple — Returns (TRUE) if this Geometry has no anomalous geometric points, such as self intersection or self tangency.

3
  • I don't actually have the tools to draw geometries to test things. I only have the tools to inspect the data I have and in this case wasn't sure if there was even something that would come up positive. I had the same thoughts about IsSimple. Your example with using ST_IsValidReason pretty much sums up my concern and how to catch what I described. I'm new to GIS and I wasn't for sure if "Ring Self-Intersection" was what you illustrated. Many thanks for your detailed explanation.
    – George
    Commented May 4, 2017 at 21:12
  • 1
    You can just take a piece of paper and write the coordinates by hand if you do not want to download OpenJUMP and use its excellent WKT viewer/editor.
    – user30184
    Commented May 4, 2017 at 21:19
  • I have no latitude in downloading and installing software at work. I could do so at home but wouldn't have access to the data I wanted to test... but many thanks for bringing up OpenJUMP. This will be something I can do at home if I need to figure out what a postgis query would / should result in.
    – George
    Commented May 4, 2017 at 23:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.