Created
September 12, 2019 02:52
-
-
Save pmarshwx/e773cbe3ccca0a06c6b89a8870bf9a3f to your computer and use it in GitHub Desktop.
pyproj testing
This file contains hidden or 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
Create python environment with pyproj 1.9.6 (and proj 5.2). | |
Create a different python environment with pyproj 2.2.0 (and proj 6.1.0) | |
Download (for now) the zipfile at http://pmarshwx.com/tmp/usa.zip which is a folder of a shapefile | |
Run the test.py script (below) with the unzipped file (which is a folder) from above in same directory as the python script in each environment | |
My results on a MBP (ballparks after running multiple times): | |
pyproj=1.9.6 (proj=5.2.0) vs pyproj=2.2.1 (proj=6.1.0) | |
read USbounds shpfile: 0.015 seconds vs 0.015 seconds | |
read USbounds shpfile & project: 0.045 seconds vs 16.67 seconds | |
ratio (read+project)/read: 3 vs 1000 | |
This file contains hidden or 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
from functools import partial | |
import fiona | |
import pyproj | |
import shapely.geometry as sgeom | |
from shapely.ops import transform | |
import timeit | |
def wrapper(func, *args, **kwargs): | |
def wrapped(): | |
return func(*args, **kwargs) | |
return wrapped | |
def read_shapefile(shpfile, projtransform=None): | |
with fiona.open(shpfile, "r") as SHP: | |
if projtransform is not None: | |
return [transform(projtransform, sgeom.shape(shp["geometry"])) for shp in SHP] | |
else: | |
return [sgeom.shape(shp["geometry"]) for shp in SHP] | |
shpfile = "usa/usa.shp" | |
# Map Projection Information | |
parms = {'datum': 'NAD83', 'proj': 'lcc', 'lat_1': 33, 'lat_2': 45, | |
'lat_0': 39., 'lon_0': -96.0, 'x_0': 0, 'y_0': 0, | |
'rsphere': (6378137.0, 298.257222101)} | |
pp = pyproj.Proj(parms) | |
reproject = partial(pyproj.transform, pyproj.Proj(init='epsg:4326'), pp) | |
f_noproj = wrapper(read_shapefile, shpfile) | |
f_withproj = wrapper(read_shapefile, shpfile, reproject) | |
noproj = timeit.timeit(f_noproj, number=1) | |
withproj = timeit.timeit(f_withproj, number=1) | |
print(f"No Projection: {noproj}") | |
print(f"With Projection: {withproj}") | |
print(f"Slowdown of: {withproj/noproj}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment