Created
April 13, 2016 16:49
-
-
Save jczaplew/95aa1ac76bead7381563f94f59a4c146 to your computer and use it in GitHub Desktop.
PostGIS vs shapely union
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Download this - http://www.geologyontario.mndmf.gov.on.ca/mndmfiles/pub/data/imaging/MRD126-REV1//MRD126-REV1.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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