Coder Social home page Coder Social logo

demquery's Introduction

demquery

Pypi Downloads Supported Python Versions

Wrapper around rasterio to query points on a Digital Elevation Model.

Features

  • Use multiple raster files without having to merge them into a new file
  • Query many points at once
  • Optional 2D interpolation (linear, cubic, or quintic)
  • Reasonably performant by reading the minimal data required from raster

Install

I recommend first installing dependencies with Conda, then installing demquery itself with pip.

conda install gdal rasterio numpy scipy -c conda-forge
pip install demquery

CLI Script

> demquery --help
Usage: demquery [OPTIONS] FEATURES...

  Assign elevations to GeoJSON

Options:
  -d, --dem PATH          Paths to DEM files.  [required]
  -g, --dem-glob TEXT     Glob expression for DEM paths if folder is provided.
  -b, --band INTEGER      Band of rasters to use  [default: 1]
  -i, --interp-kind TEXT  either None, "linear", "cubic", or "quintic". None
                          will do no interpolation and choose the value in the
                          DEM closest to the provided point. linear creates a
                          3x3 grid and runs linear interpolation; cubic
                          creates a 5x5 grid and runs cubic interpolation;
                          quintic creates a 7x7 grid and runs quintic
                          interpolation.
  --help                  Show this message and exit.
echo \
    '{"type":"Feature","properties":{"name": "Glacier Peak"},"geometry":{"type":"Point","coordinates":[-121.2436843,48.0163834]}}' \
    | demquery -d /path/to/dem/files

Outputs:

{"type": "FeatureCollection", "features": [{"type": "Feature", "geometry": {"type": "Point", "coordinates": [-121.243684, 48.016383, 1431.5755615234375]}, "properties": {"name": "Glacier Peak"}}]}

Documentation

from demquery import Query

dem_paths = ['dem1.tif', 'dem2.tif']
query = Query(dem_paths)

# Points must be in longitude, latitude order!
# These points are in Manhattan, not Antarctica
points = [(-73.985564, 40.757965), (-73.968520, 40.778912)]
elevations = query.query_points(points, interp_kind='linear')

Data Download

For a great visual tool to download worldwide SRTM data, check out these sites:

Releasing

To upload a new release to PyPI

python setup.py sdist
twine upload dist/demquery-0.3.0.tar.gz

demquery's People

Contributors

kylebarron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

demquery's Issues

AssertionError when trying to use Netherlands DEMs

  • demquery version: 0.3.1
  • Python version: 3.8.6
  • Operating System: Windows 10

Description

Trying to add elevation values to a map of Amsterdam using TIFs from pdok.nl. I'm confident that the TIF files actually cover all of the graph.

What I Did

Here is the code I ran:


dem_paths = glob.glob("../data/netherlands_dem_5m/*.tif")

graph = ox.graph.graph_from_place(name, network_type="walk")
test_elev = add_node_elevations_from_dem(graph.nodes, dem_paths, interp_kind="linear")
t = dict((k, test_elev[k]['elevation']) for k in test_elev.keys())
nx.set_node_attributes(graph, name="elevation", values=t)
ox.save_graphml(G=graph, filepath=f"../data/{name}.graphml")

And the error message:


  File "C:\Users\craig\Documents\Embarc\Coding\elevation_injector\src\netherlands_query.py", line 22, in <module>
    test_elev = add_node_elevations_from_dem(graph.nodes, dem_paths, interp_kind="linear")

  File "C:\Users\craig\Documents\Embarc\Coding\elevation_injector\src\dem_elevation.py", line 32, in add_node_elevations_from_dem
    elevations = query.query_points(points)

  File "C:\Users\craig\Anaconda3\envs\embarc\lib\site-packages\demquery\demquery.py", line 74, in query_points
    self._check_bounds(dem, points, num_buffer=num_buffer)

  File "C:\Users\craig\Anaconda3\envs\embarc\lib\site-packages\demquery\demquery.py", line 150, in _check_bounds
    assert maxrow <= dem.height

AssertionError

Add more tests

Add a couple tests with low resolution DEM data. Not sure what the lowest-resolution dem would be. An SRTM tile from here is 35MB zipped.

Something that size is probably a good size to download (and cache) for tests, but not to include in the repository.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.