Ticket #534 (new enhancement)

Opened 3 years ago

Last modified 17 months ago

Provide function to add new geometries to a collection

Reported by: jchamberlain Owned by: strk
Priority: medium Milestone: PostGIS Future
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

  Changed 3 years ago by robe

  • owner changed from pramsey to robe
  • status changed from new to assigned

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

follow-up: ↓ 5   Changed 3 years ago by 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));

follow-up: ↓ 6   Changed 3 years ago by 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 ?

  Changed 3 years ago by strk

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   Changed 3 years ago by jchamberlain

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   Changed 3 years ago by jchamberlain

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 ?

  Changed 2 years ago by robe

  • owner changed from robe to strk
  • status changed from assigned to new
  • milestone changed from PostGIS 1.5.2 to PostGIS 2.0.0

  Changed 17 months ago by strk

  • milestone changed from PostGIS 2.0.0 to PostGIS Future
Note: See TracTickets for help on using tickets.