pgRouting / pgrouting

Repository contains pgRouting library. Development branch is "develop", stable branch is "master"
https://pgrouting.org
GNU General Public License v2.0
1.17k stars 368 forks source link

pgr_alphaShape sometimes fails (parse error - invalid geometry) #1603

Open arneman opened 4 years ago

arneman commented 4 years ago

Describe the bug pgr_alphaShape sometimes fails with this exception:

QL-Fehler [XX000]: ERROR: parse error - invalid geometry
  Hinweis: "GEOMETRYCOLLECTION(POLYGON(())" <-- parse error at position 30 within geometry
  Wobei: SQL statement "WITH a AS (SELECT 'GEOMETRYCOLLECTION(' || string_agg(textgeom,',') || ')' as geome
        FROM _pgr_alphaShape(delauny_query, $2))
    SELECT ST_GeomFromText(geome) FROM a"
PL/pgSQL function pgr_alphashape(geometry,double precision) line 38 at SQL statement

We had this very weird situation: Buidling an alphashape for 149 points succeeded, but it fails if we build the alphashape with 148 of the 149 points.

To Reproduce Insert the points in sample_data.sql and execute the two sql commands at the bottom of the file to see the problem.

Expected behavior A valid (alpha shape) hull

Sample Data sample_data.zip

Specifications (please complete the following information): SELECT version(); PostgreSQL 12.3 (Debian 12.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit

SELECT postgis_full_version(); POSTGIS="3.0.1 ec2a9aa" [EXTENSION] PGSQL="120" GEOS="3.7.1-CAPI-1.11.1 27a5e771" PROJ="Rel. 5.2.0, September 15th, 2018" GDAL="GDAL 2.4.0, released 2018/12/14" LIBXML="2.9.4" LIBJSON="0.12.1" LIBPROTOBUF="1.3.1" WAGYU="0.4.3 (Internal)" TOPOLOGY RASTER

SELECT pgr_version(); 3.0.2

Additional context Despite the circumstance that we upgraded to pg12 & pgrouting3 only because of the new (easily usable) pgr_alphaShape function: Does this bug only affect Driving_Distance, or is pgr_alphaShape used in other pgr functions, too?

cvvergara commented 4 years ago

Additional context Despite the circumstance that we upgraded to pg12 & pgrouting3 only because of the new (easily usable) pgr_alphaShape function: Does this bug only affect Driving_Distance, or is pgr_alphaShape used in other pgr functions, too?

pgr_alphaShape is a geometry function, it should not be in pgRouting, it should be in PostGIS. Good to know that pgr_alphaShape is easily usable.

A story about it:

V2: pgr_alphaShape & pgr_pointsAsPolygon

I agree was very confusing, because pgr_alphaShape actually was the back-end function of pgr_pointsAsPolygon if you think about it: points as polygon could be: ST_ConvexHull, ST_ConcaveHull as they return a polygon if you give them points as input. There is no Alpha Shape functionality on PostGis. So the original developer created both functions in pgRouting when creating the driving distance function. It needs as dependency CGAL

V3 pgr_alphaShape

We removed the CGAL dependency an created a code of our own thinking in the not near future: Move the function to PostGIS The use is like if it was PostGIS function (which is no graph related) So basically the new usage is as if you are using a postGIS function that it just happens to be in pgRouting like ST_ConcaveHull

conclusion

On V2 was too tight on the result columns from pgr_drivingDistance But what if ..

PS

Will have a look to this issue, next week, keep in touch

andregracioso commented 3 years ago

Any updates on this? Tks.

cvvergara commented 1 year ago

@andregracioso

PostGIS has the alpha shape now, https://postgis.net/docs/manual-dev/ST_AlphaShape.html So in version 4.0 of pgrouting pgr_AlphaShape will be deprecated.

Please use PostGIS alpha shape.

robe2 commented 2 months ago

@andregracioso

PostGIS has the alpha shape now, https://postgis.net/docs/manual-dev/ST_AlphaShape.html So in version 4.0 of pgrouting pgr_AlphaShape will be deprecated.

Please use PostGIS alpha shape.

Please note that ST_AlphaShape is part of postgis_sfcgal which is not available on all distros.

Better to use ST_ConcaveHull, which was redone recently. If you are using GEOS 3.11, it's much faster than old ST_ConcaveHull.

As a side note, I got that error too. But only seems to happen if I don't pass in an alpha.