Opened 14 years ago

Last modified 7 years ago

#534 new enhancement

Provide function to add new geometries to a collection

Reported by: jchamberlain Owned by: strk
Priority: medium Milestone: PostGIS Fund Me
Component: postgis Version: 1.5.X
Keywords: Cc:

Description

I would like to be able to add new geometries to an existing collection. Two examples that would be useful for me would be to add a new Point to an existing MultiPoint and a new Polygon to an existing MultiPolygon. For my purposes order is important which rules out using union to accomplish this. I like the functionality of ST_AddPoint() to append, but don't want to be limited to working with LineStrings. On the mailing list ST_AddGeometry was recommended, but I can't find a reference to that function, but if available that might work just great.

Thanks,

James

Change History (9)

comment:1 by robe, 14 years ago

Owner: changed from pramsey to robe
Status: newassigned

Have you looked at the ST_Collect function (the array version) which takes an array of geometries. As I recall, it maintains the order of the elements in the array.

http://www.postgis.org/documentation/manual-1.5/ST_Collect.html

see the last example

comment:2 by robe, 14 years ago

One problem with ST_Collect is if you are adding a point to a multipoint, you would end up with a geometry collection.

You would probably want to combine with ST_CollectionExtract http://www.postgis.org/documentation/manual-1.5/ST_CollectionExtract.html

-- adding a point to a multipoint
SELECT ST_AsText(ST_CollectionExtract(ST_Collect(ST_GeomFromText('MULTIPOINT(1 2, 3 4)'), ST_GeomFromText('POINT(5 5)')),1));
-- adding an array of points to a multipoint
SELECT ST_AsText(ST_CollectionExtract(ST_Collect(ARRAY[ST_GeomFromText('MULTIPOINT(1 2, 3 4)'), ST_GeomFromText('POINT(5 5)'), ST_GeomFromText('POINT(0 0 )')] ),1));

comment:3 by strk, 14 years ago

I was the one suggesting ST_AddGeometry. I'm surprised it isn't available :)

Should be an easy addition as I'm pretty sure I added that kind of support in liblwgeom.

James: have time to produce a patch or funding to sponsor it ?

comment:4 by strk, 14 years ago

For the record, I checked and no, the liblwgeom support isn't there (sorry). But a close enough lwcollection_add_lwgeom is there.

in reply to:  2 comment:5 by jchamberlain, 14 years ago

I'll give this a shot and see how it works out. Thx

Replying to robe:

One problem with ST_Collect is if you are adding a point to a multipoint, you would end up with a geometry collection.

You would probably want to combine with ST_CollectionExtract http://www.postgis.org/documentation/manual-1.5/ST_CollectionExtract.html

-- adding a point to a multipoint
SELECT ST_AsText(ST_CollectionExtract(ST_Collect(ST_GeomFromText('MULTIPOINT(1 2, 3 4)'), ST_GeomFromText('POINT(5 5)')),1));
-- adding an array of points to a multipoint
SELECT ST_AsText(ST_CollectionExtract(ST_Collect(ARRAY[ST_GeomFromText('MULTIPOINT(1 2, 3 4)'), ST_GeomFromText('POINT(5 5)'), ST_GeomFromText('POINT(0 0 )')] ),1));

in reply to:  3 comment:6 by jchamberlain, 14 years ago

Unfortunately I have no way to provide funding to sponsor the work. I'm not so sure about a providing a patch. I'll give it a look and see if that's a way I could contribute back.

Replying to strk:

I was the one suggesting ST_AddGeometry. I'm surprised it isn't available :)

Should be an easy addition as I'm pretty sure I added that kind of support in liblwgeom.

James: have time to produce a patch or funding to sponsor it ?

comment:7 by robe, 14 years ago

Milestone: PostGIS 1.5.2PostGIS 2.0.0
Owner: changed from robe to strk
Status: assignednew

comment:8 by strk, 13 years ago

Milestone: PostGIS 2.0.0PostGIS Future

comment:9 by robe, 7 years ago

Milestone: PostGIS FuturePostGIS Fund Me

Milestone renamed

Note: See TracTickets for help on using tickets.