Friday, 13 May 2016

shapefile - Merging large amount of polygon-features in script with GDAL/OGR Tools or Python?


We have a very large shapefile with over 30000 features and want to merge it with a script on a server. Currently we try it with QGIS, but the processing takes way too much time.


Is there a way to do it with the GDAL/OGR Tools or Python?



Answer



In GIS context, the better is organize your data in a database (!).


Then, many kinds of operations will be simple. With PostGIS (using PostgreSQL as database) the command that solves your problem is


  SELECT ST_Collect(geom) FROM your30000features_table; 


And the commands are standard, see standard OGC functions ST_Collect and ST_Union.


Using as input "OSM-Coastline Polygons", you are using POLYGON OGC types in the database. The ST_Collect(geom) of a set of POLYGONs will return a GEOMETRYCOLLECTION, but you can convert it into a MULTIPOLYGON, or produce it directly by the ST_Union function.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...