Created
April 29, 2016 20:42
-
-
Save kapadia/57969d97d7ac50ac03a34aeae29abdc7 to your computer and use it in GitHub Desktop.
Transform from pixel-space to world-space.
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
#!/usr/bin/env python | |
import argparse | |
import rasterio as rio | |
import rasterio.warp | |
def get_coordinates(srcpath, pixel): | |
with rio.open(srcpath) as src: | |
print("Coordinate reference system %s" % src.crs['init']) | |
src_crs = src.crs | |
# Transform from pixel coordinates to world coordinates in the CRS of the image | |
xy = src.ul(*pixel) | |
# To transform to another coordinate reference system | |
# Note the need to use the image's CRS as an intermediary. There might | |
# be a way to skip this step. | |
dst_crs = {'init': 'epsg:4326'} | |
print rasterio.warp.transform(src_crs, dst_crs, *zip(xy)) | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser() | |
parser.add_argument("srcpath") | |
parser.add_argument("--pixel", nargs=2, type=int) | |
args = parser.parse_args() | |
get_coordinates(args.srcpath, args.pixel) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment