pgr_alphashape is returning a geometry collection?

Alexandre Neto senhor.neto at gmail.com
Tue Feb 6 03:02:35 PST 2024


Sure,

SELECT version();

> "PostgreSQL 15.5, compiled by Visual C++ build 1914, 64-bit"

SELECT PostGIS_full_version();

> "POSTGIS=""3.4.1 3.4.1"" [EXTENSION] PGSQL=""150"" GEOS=""3.12.1-CAPI-1.18.1"" PROJ=""8.2.1 NETWORK_ENABLED=OFF URL_ENDPOINT=https://cdn.proj.org <https://cdn.proj.org> USER_WRITABLE_DIRECTORY=C:\Windows\ServiceProfiles\NetworkService\AppData\Local/proj DATABASE_PATH=C:\Program Files\PostgreSQL\15\share\contrib\postgis-3.4\proj\proj.db"" LIBXML=""2.9.14"" LIBJSON=""0.12"" LIBPROTOBUF=""1.2.1"" WAGYU=""0.5.0 (Internal)"""



Both edges and nodes tables where created by osm2pgrouting using the cars_config:

CREATE TABLE IF NOT EXISTS public.ways ( gid bigint NOT NULL DEFAULT nextval('ways_gid_seq'::regclass), osm_id bigint, tag_id integer, length double precision, length_m double precision, name text COLLATE pg_catalog."default", source bigint, target bigint, source_osm bigint, target_osm bigint, cost double precision, reverse_cost double precision, cost_s double precision, reverse_cost_s double precision, rule text COLLATE pg_catalog."default", one_way integer, oneway text COLLATE pg_catalog."default", x1 double precision, y1 double precision, x2 double precision, y2 double precision, maxspeed_forward double precision, maxspeed_backward double precision, priority double precision DEFAULT 1, the_geom geometry(LineString,4326), CONSTRAINT ways_pkey PRIMARY KEY (gid), CONSTRAINT ways_source_fkey FOREIGN KEY (source) REFERENCES public.ways_vertices_pgr (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT ways_source_osm_fkey FOREIGN KEY (source_osm) REFERENCES public.ways_vertices_pgr (osm_id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT ways_tag_id_fkey FOREIGN KEY (tag_id) REFERENCES public.configuration (tag_id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT ways_target_fkey FOREIGN KEY (target) REFERENCES public.ways_vertices_pgr (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT ways_target_osm_fkey FOREIGN KEY (target_osm) REFERENCES public.ways_vertices_pgr (osm_id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION );
CREATE TABLE IF NOT EXISTS public.ways_vertices_pgr ( id bigint NOT NULL DEFAULT nextval('ways_vertices_pgr_id_seq'::regclass), osm_id bigint, eout integer, lon numeric(11,8), lat numeric(11,8), cnt integer, chk integer, ein integer, the_geom geometry(Point,4326), CONSTRAINT ways_vertices_pgr_pkey PRIMARY KEY (id), CONSTRAINT ways_vertices_pgr_osm_id_key UNIQUE (osm_id) );

The query that I am running is the following:

with result as ( SELECT * FROM pgr_drivingDistance( ' SELECT gid as id, -- Subquery to map our network table to the necessary fields source, target, length_m as cost, length_m as reverse_cost FROM ways', 6317, -- origin 1000 -- distance ) ) SELECT pgr_alphaShape((st_collect(v.the_geom))) as geom FROM ways_vertices_pgr as v, result as r WHERE r.node = v.id;
Getting the geometry with st_astext, this is what I get. Looks like a Multipolygon, but is considered a GeometryCollection:

> "GEOMETRYCOLLECTION(POLYGON((-9.15828 38.7401,-9.15801 38.7398,-9.15666 38.7395,-9.15649 38.7395,-9.15563 38.7398,-9.15485 38.7388,-9.15325 38.7391,-9.15307 38.7391,-9.15294 38.739,-9.15291 38.739,-9.15292 38.7386,-9.15447 38.7376,-9.15482 38.7359,-9.15409 38.7354,-9.15222 38.7356,-9.15168 38.7349,-9.15156 38.7347,-9.1516 38.7347,-9.15196 38.7336,-9.15183 38.7332,-9.15186 38.7331,-9.15219 38.7322,-9.15351 38.7323,-9.15504 38.7321,-9.15497 38.7323,-9.1551 38.7333,-9.15492 38.7339,-9.15512 38.7353,-9.15689 38.7353,-9.15721 38.7347,-9.15779 38.7345,-9.15826 38.7346,-9.15844 38.7344,-9.1587 38.7343,-9.15961 38.7331,-9.15955 38.7328,-9.15956 38.7323,-9.15936 38.7316,-9.1595 38.7316,-9.15992 38.7313,-9.16141 38.7304,-9.16058 38.7283,-9.15994 38.7285,-9.15986 38.7284,-9.16 38.7282,-9.16006 38.7281,-9.16038 38.7279,-9.16055 38.7278,-9.16064 38.7278,-9.16165 38.7277,-9.16233 38.7275,-9.16342 38.7273,-9.16346 38.7274,-9.16398 38.7289,-9.1644 38.73,-9.16423 38.7304,-9.16536 38.7321,-9.16536 38.7332,-9.16555 38.7335,-9.16565 38.7336,-9.16598 38.734,-9.1663 38.7349,-9.16646 38.7351,-9.16567 38.7354,-9.16419 38.7357,-9.16471 38.7375,-9.1639 38.7382,-9.16343 38.7371,-9.16246 38.7368,-9.16235 38.7368,-9.1618 38.7366,-9.16104 38.7364,-9.15963 38.738,-9.15963 38.7382,-9.15911 38.7384,-9.1586 38.74,-9.15866 38.7402,-9.15828 38.7401),(-9.15493 38.7355,-9.15488 38.7353,-9.15512 38.7353,-9.15493 38.7355),(-9.16211 38.7321,-9.16213 38.7319,-9.16224 38.732,-9.16211 38.7321),(-9.15995 38.7363,-9.16018 38.7362,-9.16009 38.7364,-9.15995 38.7363),(-9.15693 38.7376,-9.1568 38.7375,-9.15726 38.7373,-9.15693 38.7376),(-9.1626 38.732,-9.16244 38.7319,-9.16255 38.7318,-9.1626 38.732),(-9.16366 38.7368,-9.16362 38.737,-9.16349 38.737,-9.16366 38.7368)),POLYGON((-9.15488 38.7353,-9.15512 38.7353,-9.15493 38.7355,-9.15488 38.7353)),POLYGON((-9.1587 38.7343,-9.15956 38.7329,-9.15955 38.7328,-9.15961 38.7331,-9.1587 38.7343)),POLYGON((-9.15826 38.7346,-9.15779 38.7345,-9.15844 38.7344,-9.15826 38.7346)),POLYGON((-9.16211 38.7321,-9.16213 38.7319,-9.16224 38.732,-9.16211 38.7321)),POLYGON((-9.16018 38.7362,-9.16009 38.7364,-9.15995 38.7363,-9.16018 38.7362)),POLYGON((-9.1568 38.7375,-9.15726 38.7373,-9.15693 38.7376,-9.1568 38.7375)),POLYGON((-9.16255 38.7318,-9.1626 38.732,-9.16244 38.7319,-9.16255 38.7318)),POLYGON((-9.16362 38.737,-9.16349 38.737,-9.16366 38.7368,-9.16362 38.737)))"

Hope it helps to understand what may be wrong.

Alexandre Neto



I am running the following query

Sent with Shortwave <https://www.shortwave.com?utm_medium=email&utm_content=signature&utm_source=c2VuaG9yLm5ldG9AZ21haWwuY29t>

On Mon Feb 5, 2024, 04:08 PM GMT, Regina Obe <mailto:lr at pcorp.us> wrote:
> Can you give us an example you are getting this for? It should be returning a polygon.
> From: Alexandre Neto <senhor.neto at gmail.com>
> Sent: Monday, February 5, 2024 7:14 AM
> To: PostGIS Users Discussion <postgis-users at lists.osgeo.org>
> Subject: pgr_alphashape is returning a geometry collection?
> I am trying to use pgr_alphashape to convert a set of nodes into a polygon. The documentation description says:
> Returns the polygon part of an alpha shape.
> But instead I am getting a geometry_collection instead. I can solve it with st_CollectionExtract, but I m wondering if this is the expected behaviour.
> Alexandre Neto
> Sent with Shortwave <https://www.shortwave.com?utm_medium=email&utm_content=signature&utm_source=c2VuaG9yLm5ldG9AZ21haWwuY29t>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20240206/66a2bbf0/attachment.htm>


More information about the postgis-users mailing list