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
{
"type": "FeatureCollection",
"name": "test_lines",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { "fid": 183521, "uuid": "{2c66f90e-befb-49d5-8083-c5642194be06}" }, "geometry": { "type": "LineString", "coordinates": [ [ -9.146176034327512, 2.172296541854189 ], [ -9.146450423923667, 2.172488614571499 ], [ -9.146649356380882, 2.172845321046502 ], [ -9.146697374560208, 2.172989375584485 ], [ -9.146834569358287, 2.173099131422947 ], [ -9.146944325196749, 2.173380380759008 ], [ -9.146951184936654, 2.17349013659747 ], [ -9.146923745977038, 2.173757666453723 ], [ -9.146717953779921, 2.174196689807574 ], [ -9.146621917421266, 2.174395622264787 ], [ -9.146553320022226, 2.174553396282577 ], [ -9.146436704443861, 2.174704310560464 ], [ -9.146004540829914, 2.175074736515274 ], [ -9.145572377215966, 2.17541772351047 ], [ -9.145270548660195, 2.175644094927299 ] ] } },
{ "type": "Feature", "properties": { "fid": 183518, "uuid": "{a84f6b24-082c-4e78-a39d-46f2d96582e4}" }, "geometry": { "type": "LineString", "coordinates": [ [ -9.148784450425975, 2.175074736515274 ], [ -9.148949084183668, 2.174889523537869 ], [ -9.149120577681266, 2.174807206659022 ], [ -9.149381247797615, 2.174642572901328 ], [ -9.149614478954348, 2.174457359923922 ], [ -9.149827130891369, 2.174299585906132 ], [ -9.150026063348584, 2.173936019691225 ], [ -9.150190697106277, 2.17349013659747 ], [ -9.150348471124067, 2.172996235324388 ], [ -9.150417068523106, 2.172783583387367 ], [ -9.150458226962529, 2.172399437952748 ], [ -9.15054740358128, 2.171994713298417 ], [ -9.150595421760608, 2.17175462240178 ], [ -9.150588562020706, 2.171617427603702 ], [ -9.150691458119262, 2.171349897747449 ], [ -9.150753195778398, 2.17112352633062 ] ] } },
{ "type": "Feature", "properties": { "fid": 183519, "uuid": "{be89730e-95de-4744-a18c-406730800b73}" }, "geometry": { "type": "LineString", "coordinates": [ [ -9.147330185566345, 2.175877326084033 ], [ -9.147583995942789, 2.17557549752826 ], [ -9.147782928400003, 2.175355985851335 ], [ -9.147940702417793, 2.175198211833545 ], [ -9.148180793314429, 2.175019858596043 ], [ -9.148324847852413, 2.174834645618637 ], [ -9.148448323170683, 2.174670011860944 ], [ -9.148647255627896, 2.174532817062865 ], [ -9.148784450425975, 2.174340744345556 ], [ -9.148866767304822, 2.174100653448919 ], [ -9.148921645224053, 2.173977178130648 ], [ -9.149072559501938, 2.173750806713819 ], [ -9.14912743742117, 2.173558733996509 ], [ -9.149182315340401, 2.173195167781602 ], [ -9.149168595860594, 2.172982515844581 ], [ -9.149141156900978, 2.172824741826791 ], [ -9.14928521143896, 2.172673827548905 ], [ -9.149394967277424, 2.172612089889769 ], [ -9.149504723115886, 2.17257779119025 ] ] } },
{ "type": "Feature", "properties": { "fid": 183517, "uuid": "{e02bf433-920a-4edd-a869-8bfabc832149}" }, "geometry": { "type": "LineString", "coordinates": [ [ -9.150869811356765, 2.174711170300367 ], [ -9.151041304854362, 2.174594554722001 ], [ -9.15117849965244, 2.174464219663826 ], [ -9.151267676271191, 2.174347604085459 ], [ -9.151329413930327, 2.174182970327766 ], [ -9.151349993150038, 2.174011476830168 ], [ -9.151281395750999, 2.173689069054684 ], [ -9.151226517831768, 2.173476417117663 ], [ -9.151130481473112, 2.173222606741218 ], [ -9.151048164594268, 2.173009954804196 ], [ -9.151034445114458, 2.17270126650852 ], [ -9.15105502433417, 2.172433736652267 ], [ -9.151164780172632, 2.172269102894574 ], [ -9.151205938612057, 2.172166206796015 ], [ -9.151233377571671, 2.171898676939762 ], [ -9.151247097051479, 2.171672305522933 ], [ -9.151315694450519, 2.171473373065719 ], [ -9.151391151589461, 2.171240141908986 ], [ -9.151446029508692, 2.171075508151293 ] ] } },
{ "type": "Feature", "properties": { "fid": 183522, "uuid": "{662d526c-0ef9-4aab-b533-7ac0a64ee014}" }, "geometry": { "type": "LineString", "coordinates": [ [ -9.146133160953113, 2.172913918445542 ], [ -9.146194898612247, 2.173037393763812 ], [ -9.146332093410326, 2.173154009342179 ], [ -9.146421270029077, 2.17324318596093 ], [ -9.146441849248788, 2.17340095997872 ], [ -9.146359532369942, 2.173558733996509 ], [ -9.146284075230998, 2.173689069054684 ], [ -9.146105721993496, 2.174073214489303 ], [ -9.146043984334362, 2.174230988507093 ], [ -9.146043984334362, 2.174272146946516 ] ] } },
{ "type": "Feature", "properties": { "fid": 183523, "uuid": "{d54434ff-2013-4897-bb9c-856468743b13}" }, "geometry": { "type": "LineString", "coordinates": [ [ -9.14416441560069, 2.172234804195054 ], [ -9.144377067537711, 2.172529773010922 ], [ -9.144438805196845, 2.172708126248424 ], [ -9.144589719474732, 2.172955076884965 ], [ -9.144651457133866, 2.173133430122467 ], [ -9.144802371411753, 2.173133430122467 ], [ -9.145008163608871, 2.173119710642659 ], [ -9.145138498667045, 2.17308541194314 ] ] } },
{ "type": "Feature", "properties": { "fid": 183520, "uuid": "{8bfc07f0-8550-479b-9682-741a3c3b1c75}" }, "geometry": { "type": "LineString", "coordinates": [ [ -9.148954228988597, 2.171761482141684 ], [ -9.148981667948213, 2.172090749657072 ], [ -9.148967948468405, 2.172344560033517 ], [ -9.148871912109751, 2.172625809369577 ], [ -9.148576943293881, 2.172797302867175 ], [ -9.148350571877053, 2.173044253503716 ], [ -9.148336852397245, 2.17317458856189 ], [ -9.148398590056379, 2.173298063880161 ], [ -9.148357431616956, 2.17352443529699 ], [ -9.148206517339069, 2.173572453476317 ], [ -9.147987005662147, 2.174025196309976 ], [ -9.147808652424644, 2.174340744345556 ], [ -9.147630299187142, 2.174615133941712 ], [ -9.147417647250119, 2.174923822237389 ], [ -9.147150117393867, 2.1752942481922 ], [ -9.146868868057807, 2.175589217008068 ] ] } }
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment