Skip to content

Instantly share code, notes, and snippets.

@AndrewAnnex
Created September 6, 2018 19:57
Show Gist options
  • Save AndrewAnnex/417dfe3f742ecbbf0976d3b4d59fee6a to your computer and use it in GitHub Desktop.
Save AndrewAnnex/417dfe3f742ecbbf0976d3b4d59fee6a to your computer and use it in GitHub Desktop.
Rasterio test case data for transform_geom #1446
src_crs = {'init': 'EPSG:4326'}
dst_crs = CRS({'proj': 'sinu', 'lon_0': 350.85607029556, 'x_0': 0, 'y_0': 0, 'a': 3396190, 'b': 3396190, 'units': 'm', 'no_defs': True})
dst_crs_wkt = 'PROJCS["unnamed",GEOGCS["unnamed ellipse",DATUM["unknown",SPHEROID["unnamed",3396190,0]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]],PROJECTION["Sinusoidal"],PARAMETER["longitude_of_center",350.85607029556],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["Meter",1],EXTENSION["PROJ4","+proj=sinu +lon_0=350.85607029556 +x_0=0 +y_0=0 +a=3396190 +b=3396190 +units=m +no_defs +wktext"]]'
import matplotlib.pyplot as plt
import fiona
import rasterio.warp
import rasterio as rio
import numpy as np
with fiona.open('./test_lines.geojson') as geoms:
src_crs = rio.crs.CRS({'init': 'EPSG:4326'})
dst_crs = rio.crs.CRS({'proj': 'sinu', 'lon_0': 350.85607029556, 'x_0': 0, 'y_0': 0, 'a': 3396190, 'b': 3396190, 'units': 'm', 'no_defs': True})
plt.subplot(1, 2, 1)
for g in geoms:
x = np.asarray(g['geometry']['coordinates']).T
plt.scatter(*x)
plt.plot(*x)
transformed_geoms = [rio.warp.transform_geom(src_crs, dst_crs, g['geometry']) for g in geoms]
plt.subplot(1, 2, 2)
for tg in transformed_geoms:
x = np.asarray(tg['coordinates']).T
plt.scatter(*x)
plt.plot(*x)
plt.tight_layout()
plt.show()
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment