From d47e6da1f29f4d3e3a11bdfc155d75ac1c06a21c Mon Sep 17 00:00:00 2001 From: Danijel Schorlemmer Date: Thu, 27 Jan 2022 19:44:02 +0100 Subject: [PATCH] Changed the Shapely polygon creation from WKT to WKB to speed up the processing --- exposurejapan/database.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/exposurejapan/database.py b/exposurejapan/database.py index f153948..765c6db 100644 --- a/exposurejapan/database.py +++ b/exposurejapan/database.py @@ -22,6 +22,7 @@ import pandas import numpy import constants import shapely.wkt +import shapely.wkb import pyproj from shapely.ops import transform import csv @@ -634,11 +635,11 @@ class JapanDatabase(SpatialiteDatabase): # Calculate the area for each district using Albers equal area transformation # and update the Districts table - sql_statement = "SELECT id, ST_AsText(geom) FROM District" + sql_statement = "SELECT id, AsBinary(geom) FROM District" self.cursor.execute(sql_statement) districts = self.cursor.fetchall() for district in districts: - district_geom = shapely.wkt.loads(district[1]) + district_geom = shapely.wkb.loads(district[1]) district_size = ( self.albers_area_calculation(district_geom, "epsg:%d" % constants.WGS84) * 0.000001 # Convert from square meters to square kilometers -- GitLab