Created
October 7, 2014 18:16
-
-
Save jdherman/dbbe3e16d488450515ac to your computer and use it in GitHub Desktop.
Extract raster data value at a point
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
from __future__ import division | |
from osgeo import gdal | |
from geopy.geocoders import Nominatim | |
def get_value_at_point(rasterfile, pos): | |
gdata = gdal.Open(rasterfile) | |
gt = gdata.GetGeoTransform() | |
data = gdata.ReadAsArray().astype(np.float) | |
gdata = None | |
x = int((pos[0] - gt[0])/gt[1]) | |
y = int((pos[1] - gt[3])/gt[5]) | |
return data[y, x] | |
city = 'Ithaca, NY' | |
g = Nominatim().geocode(city, timeout=5) | |
p = (g.longitude,g.latitude) | |
print get_value_at_point('path/to/my/raster/file', p) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment