1

Why ST_AsText(location(ST_IsValidDetail(the_geom))) from LINESTRING return blank? From POLYGON, all ok... "POINT(...)"

For example:

SELECT ST_Astext(location(ST_IsValidDetail(ST_GeomFromText('POLYGON((0 0, 1 1, 0 1, 1 0, 0 0))')))) as location 

--> return one row with "POINT(0.5 0.5)"

location
|"POINT(0.5 0.5)"|

but

SELECT ST_Astext(location(ST_IsValidDetail(ST_GeomFromText('LINESTRING(0 0, 1 1, 0 1, 1 0, 0 0)')))) as location 

--> return one row with nothing

location
||

Documentation: http://postgis.net/docs/ST_IsValidDetail.html

 --simple example
 SELECT * FROM ST_IsValidDetail('LINESTRING(220227 150406,2220227 150407,222020 150410)');

 valid | reason | location
-------+--------+----------
 t     |        |
  • 1
    Please edit the question to expand it to several paragraphs, including the exact software in use (both database and extension) and including the WKT of some of the shapes you believe to be invalid. It would probably help if you took the Tour, to better understand what is expected in a Question. – Vince Jul 29 '16 at 12:53
1

ST_IsValidDetail — Returns a valid_detail (valid,reason,location) row stating if a geometry is valid or not and if not valid, a reason why and a location where.

Your POLYGON((0 0, 1 1, 0 1, 1 0, 0 0)) is a bad geometry that looks like a bowtie. ST_IsValidDetail is returning false showing the point of intersection at POINT(0.5 0.5).

There is nothing wrong in the geometry of a LINESTRING that crosses itself.

This page shows how to correct invalid geometries.

If you want to use ST_IsValidDetail() on a LINESTRING then you just need to convert it to a polygon (the LINESTRING must be closed for this to be accepted).

SELECT ST_Astext(location(ST_IsValidDetail(ST_MakePolygon('LINESTRING(0 0, 1 1, 0 1, 1 0, 0 0)'))));
  • I don want correct geometries, just want that points... See the example from 2 diferent linestring: SELECT ST_AsText(ST_Intersection(A, B)) FROM ( SELECT 'LINESTRING(180 330,150 270,225 232,180 330)'::geometry AS A, 'LINESTRING (131 315, 270 290, 170 220)'::geometry AS B ) AS data; Answer (all intersected points): "MULTIPOINT(169.075907590759 308.151815181518,191.918860526526 304.043370408898,203.038674033149 243.127071823204,215.791505791506 252.054054054054)" Now for same linestring that self-intersects? – Paulo Pires Jul 31 '16 at 23:38
  • @PauloPires updated answer to include conversion of LINESTRING to POLYGON for ST_IsValidDetail() – kttii Aug 1 '16 at 12:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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