Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
arneman opened this issue Aug 12, 2020 · 4 comments
Open

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

arneman opened this issue Aug 12, 2020 · 4 comments

Comments

@arneman
Copy link

arneman commented Aug 12, 2020

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?

@arneman arneman added the bug Something isn't working label Aug 12, 2020
@cvvergara
Copy link
Member

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 ..

  • Application A: give as input the collection of the geometry of the edges of the result of pgr_drivingDistance
  • Application B: give as input the collection of the geometry of the vertices of the result of pgr_drivingDistance
  • Application C: give as input the collection of the geometry of the edges & vertices of the result of pgr_drivingDistance
  • Application D: give as input the collection of the geometry of the edges of the result of pgr_kruskalBFS
  • Application E: give as input the collection of the geometry of the edges of the result of pgr_primDFS
  • Application F: needs something faster to calculate so it uses ST_ConvexHull with the geometry of the edges of the result of pgr_kruskalBFS

PS

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

@andregracioso
Copy link

Any updates on this? Tks.

@cvvergara
Copy link
Member

@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
Copy link
Member

robe2 commented Aug 20, 2024

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants