I have multiple spatial records in a Postgres table, imported from a shapefile using PostGIS. I am also using QGIS to view & edit the spatial layers.
What is the easiest way to combine the geometry for multiple records into a single geometry value?
I have multiple spatial records in a Postgres table, imported from a shapefile using PostGIS. I am also using QGIS to view & edit the spatial layers.
What is the easiest way to combine the geometry for multiple records into a single geometry value?
if I am reading it correctly all you are trying to do is dissolve the geometry to one record? is so then you will just need a basic usage of st_union or a clever trick to use st_collect with st_buffer and type cast over to a multipolygon geometry (credit goes to @Alexandre Neto for the st_collect answer)
these two functions are aggregate functions, similar to using a standard SQL count,sum or avg function but st_union in particular, dissolves aka aggregates geometries together.
st_union:
create table noury as
select col1,col2, st_union(geom) as geom from table group by col1,col2
st_collect:
create table noury2 as
select col1,col2,
st_buffer(st_collect(geom),0)::geometry(multipolygon,102689) as geom from table group by col1,col2
ps** i included col1,col2 if you have other columns you need to dissolve down, they must go in the group by when using any aggregate function
CREATE VIEW as ...
.
You have a couple option you can try:
Create the (empty) table first, then use INSERT INTO...SELECT... FROM to get all the data from each of the original tables into the merged one.
Create the new table from one big UNION statement.