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 , 14 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
follow-up: 5 comment:2 by , 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));
follow-up: 6 comment:3 by , 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 , 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.
comment:5 by , 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));
comment:6 by , 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 , 14 years ago
Milestone: | PostGIS 1.5.2 → PostGIS 2.0.0 |
---|---|
Owner: | changed from | to
Status: | assigned → new |
comment:8 by , 13 years ago
Milestone: | PostGIS 2.0.0 → PostGIS Future |
---|
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