Skip to content

Commit

Permalink
Add elevations to any shapely geom
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Barron committed Feb 4, 2020
1 parent 27a4def commit 3789ed3
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions code/data_source/usgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from geopandas import GeoDataFrame as GDF
from geopandas.tools import sjoin
from shapely.geometry import LineString, Polygon
from shapely.ops import transform

from .base import DataSource

Expand Down Expand Up @@ -115,6 +116,24 @@ def extract(self):
cmd = ['unzip', '-o', zip_fname, img_name, '-d', out_dir]
run(cmd, check=True)

def query_geom(self, geometry, interp_kind=None):
"""Add elevations to Shapely geometry
Args:
- geometry: shapely geometry of any type
- interp_kind: kind of interpolation. Passed to
scipy.interpolate.interp2d. Can be [None, 'linear’, ‘cubic’,
‘quintic']
Returns:
geometry of same type with z values added
"""
dem_paths = self.files()
query = demquery.Query(dem_paths)
fn = lambda x, y, z=None: query.query_points([(x, y)],
interp_kind=interp_kind)
return transform(fn, geometry)

def query(self, coords, interp_kind=None):
"""Query elevation data for coordinates
Expand Down

0 comments on commit 3789ed3

Please sign in to comment.