Skip to content

Instantly share code, notes, and snippets.

@jczaplew jczaplew/Data.txt

Created Apr 13, 2016
Embed
What would you like to do?
PostGIS vs shapely union
Download this - http://www.geologyontario.mndmf.gov.on.ca/mndmfiles/pub/data/imaging/MRD126-REV1//MRD126-REV1.zip
createdb union_test
psql -c "CREATE EXTENSION postgis" union_test
ogr2ogr ontario4326.shp -t_srs "EPSG:4326" ~/Downloads/MRD126-REV1/MRD126-REV1/Shapefiles/Geology/Geopoly.shp && shp2pgsql -s 4326 ontario4326.shp public.ontario | psql union_test
psql -c "VACUUM ANALYZE" union_test
psql -c "EXPLAIN ANALYZE SELECT ST_Union(geom) FROM ontario" union_test
import time
import psycopg2
from shapely.wkt import loads
from shapely.ops import cascaded_union
connection = psycopg2.connect(dbname="union_test")
cursor = connection.cursor()
start = time.time()
cursor.execute("SELECT ST_AsText(geom) FROM ontario")
polygons = cursor.fetchall()
unioned = cascaded_union([ loads(poly[0]) for poly in polygons ])
print time.time() - start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.