def test_wkt_to_osr(self): self.assertTrue( georef.wkt_to_osr(self.wgs84).IsSame( georef.get_default_projection())) self.assertTrue(georef.wkt_to_osr().IsSame( georef.get_default_projection()))
def test_wkt_to_osr(self): self.assertTrue(georef.wkt_to_osr('GEOGCS["WGS 84",DATUM["WGS_1984",' 'SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],' 'AUTHORITY["EPSG","6326"]],' 'PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],' 'UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],' 'AUTHORITY["EPSG","4326"]]').IsSame(georef.get_default_projection())) self.assertTrue(georef.wkt_to_osr().IsSame(georef.get_default_projection()))
def test_wkt_to_osr(self): self.assertTrue( georef.wkt_to_osr( 'GEOGCS["WGS 84",DATUM["WGS_1984",' 'SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],' 'AUTHORITY["EPSG","6326"]],' 'PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],' 'UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],' 'AUTHORITY["EPSG","4326"]]').IsSame( georef.get_default_projection())) self.assertTrue(georef.wkt_to_osr().IsSame( georef.get_default_projection()))
def test_spherical_to_polyvert(self): sph = georef.get_default_projection() polyvert = georef.spherical_to_polyvert(np.array([10000., 10100.]), np.array([45., 90.]), 0, (9., 48.), proj=sph) arr = np.asarray([[[9.05084865, 48.08224715, 6.], [9.05136309, 48.0830778, 6.], [9.1238846, 48.03435008, 6.], [9.12264494, 48.03400725, 6.], [9.05084865, 48.08224715, 6.]], [[9.05136309, 48.0830778, 6.], [9.05187756, 48.08390846, 6.], [9.12512428, 48.03469291, 6.], [9.1238846, 48.03435008, 6.], [9.05136309, 48.0830778, 6.]], [[9.12264494, 48.03400725, 6.], [9.1238846, 48.03435008, 6.], [9.05136309, 48.0830778, 6.], [9.05084865, 48.08224715, 6.], [9.12264494, 48.03400725, 6.]], [[9.1238846, 48.03435008, 6.], [9.12512428, 48.03469291, 6.], [9.05187756, 48.08390846, 6.], [9.05136309, 48.0830778, 6.], [9.1238846, 48.03435008, 6.]]]) self.assertTrue(np.allclose(polyvert, arr, rtol=1e-12))
def test_get_default_projection(self): self.assertEqual(georef.get_default_projection().ExportToWkt(), 'GEOGCS["WGS 84",DATUM["WGS_1984",' 'SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],' 'AUTHORITY["EPSG","6326"]],' 'PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],' 'UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],' 'AUTHORITY["EPSG","4326"]]')
def test_get_radar_projection(self): sitecoords = [5, 52, 90] p0 = georef.get_radar_projection(sitecoords) if gdal.VersionInfo()[0] >= "3": assert p0.GetName() == "Unknown Azimuthal Equidistant" assert p0.IsProjected() assert p0.IsSameGeogCS(georef.get_default_projection()) assert p0.GetNormProjParm("latitude_of_center") == sitecoords[1] assert p0.GetNormProjParm("longitude_of_center") == sitecoords[0]
def test_get_default_projection(self): self.assertEqual( georef.get_default_projection().ExportToWkt(), 'GEOGCS["WGS 84",DATUM["WGS_1984",' 'SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],' 'AUTHORITY["EPSG","6326"]],' 'PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],' 'UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],' 'AUTHORITY["EPSG","4326"]]')
def test_spherical_to_centroids(self): r = np.array([10000., 10100.]) az = np.array([45., 90.]) sitecoords = (9., 48., 0.) sph = georef.get_default_projection() centroids = georef.spherical_to_centroids(r, az, 0, sitecoords, proj=sph) arr = np.asarray([[[9.09439583, 48.06323717, 6.], [9.09534571, 48.06387232, 6.]], [[9.1333325, 47.99992262, 6.], [9.13467253, 47.99992106, 6.]]]) self.assertTrue(np.allclose(centroids, arr))
def test_spherical_to_polyvert(self): sph = georef.get_default_projection() polyvert = georef.spherical_to_polyvert(np.array([10000., 10100.]), np.array([45., 90.]), 0, (9., 48.), proj=sph) arr = np.asarray([[[9.05084865, 48.08224715, 6.], [9.05136309, 48.0830778, 6.], [9.1238846, 48.03435008, 6.], [9.12264494, 48.03400725, 6.], [9.05084865, 48.08224715, 6.]], [[9.05136309, 48.0830778, 6.], [9.05187756, 48.08390846, 6.], [9.12512428, 48.03469291, 6.], [9.1238846, 48.03435008, 6.], [9.05136309, 48.0830778, 6.]], [[9.12264494, 48.03400725, 6.], [9.1238846, 48.03435008, 6.], [9.05136309, 48.0830778, 6.], [9.05084865, 48.08224715, 6.], [9.12264494, 48.03400725, 6.]], [[9.1238846, 48.03435008, 6.], [9.12512428, 48.03469291, 6.], [9.05187756, 48.08390846, 6.], [9.05136309, 48.0830778, 6.], [9.1238846, 48.03435008, 6.]]]) np.testing.assert_array_almost_equal(polyvert, arr, decimal=3) polyvert, pr = georef.spherical_to_polyvert(np.array([10000., 10100.]), np.array([45., 90.]), 0, (9., 48.)) arr = np.asarray([[[3.7885640e+03, 9.1464023e+03, 6.], [3.8268320e+03, 9.2387900e+03, 6.], [9.2387900e+03, 3.8268323e+03, 6.], [9.1464023e+03, 3.7885645e+03, 6.], [3.7885640e+03, 9.1464023e+03, 6.]], [[3.8268320e+03, 9.2387900e+03, 6.], [3.8651003e+03, 9.3311777e+03, 6.], [9.3311777e+03, 3.8651006e+03, 6.], [9.2387900e+03, 3.8268323e+03, 6.], [3.8268320e+03, 9.2387900e+03, 6.]], [[9.1464023e+03, 3.7885645e+03, 6.], [9.2387900e+03, 3.8268323e+03, 6.], [3.8268320e+03, 9.2387900e+03, 6.], [3.7885640e+03, 9.1464023e+03, 6.], [9.1464023e+03, 3.7885645e+03, 6.]], [[9.2387900e+03, 3.8268323e+03, 6.], [9.3311777e+03, 3.8651006e+03, 6.], [3.8651003e+03, 9.3311777e+03, 6.], [3.8268320e+03, 9.2387900e+03, 6.], [9.2387900e+03, 3.8268323e+03, 6.]]]) np.testing.assert_array_almost_equal(polyvert, arr, decimal=3)
def test_spherical_to_polyvert(self): sph = georef.get_default_projection() polyvert = georef.spherical_to_polyvert(np.array([10000., 10100.]), np.array([45., 90.]), 0, (9., 48.), proj=sph) arr = np.asarray([[[9.05084865, 48.08224715, 6.], [9.05136309, 48.0830778, 6.], [9.1238846, 48.03435008, 6.], [9.12264494, 48.03400725, 6.], [9.05084865, 48.08224715, 6.]], [[9.05136309, 48.0830778, 6.], [9.05187756, 48.08390846, 6.], [9.12512428, 48.03469291, 6.], [9.1238846, 48.03435008, 6.], [9.05136309, 48.0830778, 6.]], [[9.12264494, 48.03400725, 6.], [9.1238846, 48.03435008, 6.], [9.05136309, 48.0830778, 6.], [9.05084865, 48.08224715, 6.], [9.12264494, 48.03400725, 6.]], [[9.1238846, 48.03435008, 6.], [9.12512428, 48.03469291, 6.], [9.05187756, 48.08390846, 6.], [9.05136309, 48.0830778, 6.], [9.1238846, 48.03435008, 6.]]]) np.testing.assert_array_almost_equal(polyvert, arr, decimal=3) polyvert, pr = georef.spherical_to_polyvert(np.array([10000., 10100.]), np.array([45., 90.]), 0, (9., 48.)) arr = np.asarray([[[3.7885640e+03, 9.1464023e+03, 6.], [3.8268320e+03, 9.2387900e+03, 6.], [9.2387900e+03, 3.8268323e+03, 6.], [9.1464023e+03, 3.7885645e+03, 6.], [3.7885640e+03, 9.1464023e+03, 6.]], [[3.8268320e+03, 9.2387900e+03, 6.], [3.8651003e+03, 9.3311777e+03, 6.], [9.3311777e+03, 3.8651006e+03, 6.], [9.2387900e+03, 3.8268323e+03, 6.], [3.8268320e+03, 9.2387900e+03, 6.]], [[9.1464023e+03, 3.7885645e+03, 6.], [9.2387900e+03, 3.8268323e+03, 6.], [3.8268320e+03, 9.2387900e+03, 6.], [3.7885640e+03, 9.1464023e+03, 6.], [9.1464023e+03, 3.7885645e+03, 6.]], [[9.2387900e+03, 3.8268323e+03, 6.], [9.3311777e+03, 3.8651006e+03, 6.], [3.8651003e+03, 9.3311777e+03, 6.], [3.8268320e+03, 9.2387900e+03, 6.], [9.2387900e+03, 3.8268323e+03, 6.]]]) np.testing.assert_array_almost_equal(polyvert, arr, decimal=3)
def setUp(self): f = 'gpm/2A-CS-151E24S154E30S.GPM.Ku.V7-20170308.20141206-S095002-E095137.004383.V05A.HDF5' # noqa gpm_file = util.get_wradlib_data_file(f) pr_data = read_generic_hdf5(gpm_file) pr_lon = pr_data['NS/Longitude']['data'] pr_lat = pr_data['NS/Latitude']['data'] zenith = pr_data['NS/PRE/localZenithAngle']['data'] wgs84 = georef.get_default_projection() a = wgs84.GetSemiMajor() b = wgs84.GetSemiMinor() rad = georef.proj4_to_osr( ('+proj=aeqd +lon_0={lon:f} ' + '+lat_0={lat:f} +a={a:f} +b={b:f}' + '').format(lon=pr_lon[68, 0], lat=pr_lat[68, 0], a=a, b=b)) pr_x, pr_y = georef.reproject(pr_lon, pr_lat, projection_source=wgs84, projection_target=rad) self.re = georef.get_earth_radius(pr_lat[68, 0], wgs84) * 4. / 3. self.pr_xy = np.dstack((pr_x, pr_y)) self.alpha = zenith self.zt = 407000. self.dr = 125. self.bw_pr = 0.71 self.nbin = 176 self.nray = pr_lon.shape[1] self.pr_out = np.array([[[[-58533.78453556, 124660.60390174], [-58501.33048429, 124677.58873852]], [[-53702.13393133, 127251.83656509], [-53670.98686161, 127268.11882882]]], [[[-56444.00788528, 120205.5374491], [-56411.55421163, 120222.52300741]], [[-51612.2360682, 122796.78620764], [-51581.08938314, 122813.06920719]]]]) self.r_out = np.array( [0., 125., 250., 375., 500., 625., 750., 875., 1000., 1125.]) self.z_out = np.array([ 0., 119.51255112, 239.02510224, 358.53765337, 478.05020449, 597.56275561, 717.07530673, 836.58785786, 956.10040898, 1075.6129601 ])
def test_spherical_to_centroids(self): r = np.array([10000., 10100.]) az = np.array([45., 90.]) sitecoords = (9., 48., 0.) sph = georef.get_default_projection() centroids = georef.spherical_to_centroids(r, az, 0, sitecoords, proj=sph) arr = np.asarray([[[9.09439583, 48.06323717, 6.], [9.09534571, 48.06387232, 6.]], [[9.1333325, 47.99992262, 6.], [9.13467253, 47.99992106, 6.]]]) np.testing.assert_array_almost_equal(centroids, arr, decimal=3) centroids, pr = georef.spherical_to_centroids(r, az, 0, sitecoords) arr = np.asarray([[[7.0357090e+03, 7.0357090e+03, 6.], [7.1064194e+03, 7.1064194e+03, 6.]], [[9.9499951e+03, 0., 6.], [1.0049995e+04, 0., 6.]]]) np.testing.assert_array_almost_equal(centroids, arr, decimal=3)
def test_spherical_to_centroids(self): r = np.array([10000., 10100.]) az = np.array([45., 90.]) sitecoords = (9., 48., 0.) sph = georef.get_default_projection() centroids = georef.spherical_to_centroids(r, az, 0, sitecoords, proj=sph) arr = np.asarray([[[9.09439583, 48.06323717, 6.], [9.09534571, 48.06387232, 6.]], [[9.1333325, 47.99992262, 6.], [9.13467253, 47.99992106, 6.]]]) np.testing.assert_array_almost_equal(centroids, arr, decimal=3) centroids, pr = georef.spherical_to_centroids(r, az, 0, sitecoords) arr = np.asarray([[[7.0357090e+03, 7.0357090e+03, 6.], [7.1064194e+03, 7.1064194e+03, 6.]], [[9.9499951e+03, 0., 6.], [1.0049995e+04, 0., 6.]]]) np.testing.assert_array_almost_equal(centroids, arr, decimal=3)
def setUp(self): f = 'gpm/2A-CS-151E24S154E30S.GPM.Ku.V7-20170308.20141206-S095002-E095137.004383.V05A.HDF5' # noqa gpm_file = util.get_wradlib_data_file(f) pr_data = read_generic_hdf5(gpm_file) pr_lon = pr_data['NS/Longitude']['data'] pr_lat = pr_data['NS/Latitude']['data'] zenith = pr_data['NS/PRE/localZenithAngle']['data'] wgs84 = georef.get_default_projection() a = wgs84.GetSemiMajor() b = wgs84.GetSemiMinor() rad = georef.proj4_to_osr(('+proj=aeqd +lon_0={lon:f} ' + '+lat_0={lat:f} +a={a:f} +b={b:f}' + '').format(lon=pr_lon[68, 0], lat=pr_lat[68, 0], a=a, b=b)) pr_x, pr_y = georef.reproject(pr_lon, pr_lat, projection_source=wgs84, projection_target=rad) self.re = georef.get_earth_radius(pr_lat[68, 0], wgs84) * 4. / 3. self.pr_xy = np.dstack((pr_x, pr_y)) self.alpha = zenith self.zt = 407000. self.dr = 125. self.bw_pr = 0.71 self.nbin = 176 self.nray = pr_lon.shape[1] self.pr_out = np.array([[[[-58533.78453556, 124660.60390174], [-58501.33048429, 124677.58873852]], [[-53702.13393133, 127251.83656509], [-53670.98686161, 127268.11882882]]], [[[-56444.00788528, 120205.5374491], [-56411.55421163, 120222.52300741]], [[-51612.2360682, 122796.78620764], [-51581.08938314, 122813.06920719]]]]) self.r_out = np.array([0., 125., 250., 375., 500., 625., 750., 875., 1000., 1125.]) self.z_out = np.array([0., 119.51255112, 239.02510224, 358.53765337, 478.05020449, 597.56275561, 717.07530673, 836.58785786, 956.10040898, 1075.6129601])
def setUp(self): self.proj = osr.SpatialReference() self.proj.ImportFromEPSG(31466) self.wgs84 = georef.get_default_projection() self.npobj = np.array([[2600000., 5630000.], [2600000., 5630100.], [2600100., 5630100.], [2600100., 5630000.], [2600000., 5630000.]]) self.lonlat = np.array([[7.41779154, 50.79679579], [7.41781875, 50.79769443], [7.4192367, 50.79767718], [7.41920947, 50.79677854], [7.41779154, 50.79679579]]) self.ogrobj = georef.numpy_to_ogr(self.npobj, 'Polygon') self.ogrobj.AssignSpatialReference(None) self.projobj = georef.numpy_to_ogr(self.npobj, 'Polygon') self.projobj.AssignSpatialReference(self.proj) filename = util.get_wradlib_data_file('shapefiles/agger/' 'agger_merge.shp') self.ds, self.layer = open_vector(filename)
def setUp(self): self.proj = osr.SpatialReference() self.proj.ImportFromEPSG(31466) self.wgs84 = georef.get_default_projection() self.npobj = np.array([[2600000., 5630000.], [2600000., 5630100.], [2600100., 5630100.], [2600100., 5630000.], [2600000., 5630000.]]) self.lonlat = np.array([[7.41779154, 50.79679579], [7.41781875, 50.79769443], [7.4192367, 50.79767718], [7.41920947, 50.79677854], [7.41779154, 50.79679579]]) self.ogrobj = georef.numpy_to_ogr(self.npobj, 'Polygon') self.ogrobj.AssignSpatialReference(None) self.projobj = georef.numpy_to_ogr(self.npobj, 'Polygon') self.projobj.AssignSpatialReference(self.proj) filename = util.get_wradlib_data_file('shapefiles/agger/' 'agger_merge.shp') self.ds, self.layer = open_vector(filename)
class TestSatellite: f = "gpm/2A-CS-151E24S154E30S.GPM.Ku.V7-20170308.20141206-S095002-E095137.004383.V05A.HDF5" # noqa gpm_file = util.get_wradlib_data_file(f) pr_data = wradlib.io.read_generic_hdf5(gpm_file) pr_lon = pr_data["NS/Longitude"]["data"] pr_lat = pr_data["NS/Latitude"]["data"] zenith = pr_data["NS/PRE/localZenithAngle"]["data"] wgs84 = georef.get_default_projection() a = wgs84.GetSemiMajor() b = wgs84.GetSemiMinor() rad = georef.proj4_to_osr( ("+proj=aeqd +lon_0={lon:f} " + "+lat_0={lat:f} +a={a:f} +b={b:f}" + "").format( lon=pr_lon[68, 0], lat=pr_lat[68, 0], a=a, b=b ) ) pr_x, pr_y = georef.reproject( pr_lon, pr_lat, projection_source=wgs84, projection_target=rad ) re = georef.get_earth_radius(pr_lat[68, 0], wgs84) * 4.0 / 3.0 pr_xy = np.dstack((pr_x, pr_y)) alpha = zenith zt = 407000.0 dr = 125.0 bw_pr = 0.71 nbin = 176 nray = pr_lon.shape[1] pr_out = np.array( [ [ [ [-58533.78453556, 124660.60390174], [-58501.33048429, 124677.58873852], ], [ [-53702.13393133, 127251.83656509], [-53670.98686161, 127268.11882882], ], ], [ [ [-56444.00788528, 120205.5374491], [-56411.55421163, 120222.52300741], ], [ [-51612.2360682, 122796.78620764], [-51581.08938314, 122813.06920719], ], ], ] ) r_out = np.array( [0.0, 125.0, 250.0, 375.0, 500.0, 625.0, 750.0, 875.0, 1000.0, 1125.0] ) z_out = np.array( [ 0.0, 119.51255112, 239.02510224, 358.53765337, 478.05020449, 597.56275561, 717.07530673, 836.58785786, 956.10040898, 1075.6129601, ] ) def test_correct_parallax(self): xy, r, z = georef.correct_parallax(self.pr_xy, self.nbin, self.dr, self.alpha) pr_out = np.array( [ [ [ [-16582.50734831, 35678.47219358], [-16547.94607589, 35696.40777009], ], [ [-11742.02016667, 38252.32622057], [-11708.84553319, 38269.52268457], ], ], [ [ [-14508.62005182, 31215.98689653], [-14474.05905935, 31233.92329553], ], [ [-9667.99183645, 33789.86576047], [-9634.81750708, 33807.06305397], ], ], ] ) r_out = np.array( [0.0, 125.0, 250.0, 375.0, 500.0, 625.0, 750.0, 875.0, 1000.0, 1125.0] ) z_out = np.array( [ 0.0, 118.78164113, 237.56328225, 356.34492338, 475.1265645, 593.90820563, 712.68984675, 831.47148788, 950.25312901, 1069.03477013, ] ) np.testing.assert_allclose(xy[60:62, 0:2, 0:2, :], pr_out, rtol=1e-12) np.testing.assert_allclose(r[0:10], r_out, rtol=1e-12) np.testing.assert_allclose(z[0, 0, 0:10], z_out, rtol=1e-10) def test_dist_from_orbit(self): beta = abs(-17.04 + np.arange(self.nray) * self.bw_pr) xy, r, z = georef.correct_parallax(self.pr_xy, self.nbin, self.dr, self.alpha) dists = georef.dist_from_orbit(self.zt, self.alpha, beta, r, re=self.re) bd = np.array( [ 426553.58667772, 426553.50342119, 426553.49658156, 426553.51025979, 426553.43461609, 426553.42515894, 426553.46559985, 426553.37020786, 426553.44407286, 426553.42173696, ] ) sd = np.array( [ 426553.58667772, 424895.63462839, 423322.25176564, 421825.47714885, 420405.9414294, 419062.44208923, 417796.86827302, 416606.91482435, 415490.82582636, 414444.11587979, ] ) np.testing.assert_allclose(dists[0:10, 0, 0], bd, rtol=1e-12) np.testing.assert_allclose(dists[0, 0:10, 0], sd, rtol=1e-12)
def test_get_default_projection(self): assert georef.get_default_projection().ExportToWkt() == self.wgs84
class TestVector: proj = osr.SpatialReference() proj.ImportFromEPSG(31466) wgs84 = georef.get_default_projection() npobj = np.array( [ [2600000.0, 5630000.0], [2600000.0, 5630100.0], [2600100.0, 5630100.0], [2600100.0, 5630000.0], [2600000.0, 5630000.0], ] ) lonlat = np.array( [ [7.41779154, 50.79679579], [7.41781875, 50.79769443], [7.4192367, 50.79767718], [7.41920947, 50.79677854], [7.41779154, 50.79679579], ] ) ogrobj = georef.numpy_to_ogr(npobj, "Polygon") ogrobj.AssignSpatialReference(None) projobj = georef.numpy_to_ogr(npobj, "Polygon") projobj.AssignSpatialReference(proj) filename = util.get_wradlib_data_file("shapefiles/agger/" "agger_merge.shp") ds, layer = wradlib.io.open_vector(filename) def test_ogr_create_layer(self): ds = wradlib.io.gdal_create_dataset("Memory", "test", gdal_type=gdal.OF_VECTOR) with pytest.raises(TypeError): georef.ogr_create_layer(ds, "test") lyr = georef.ogr_create_layer( ds, "test", geom_type=ogr.wkbPoint, fields=[("test", ogr.OFTReal)] ) assert isinstance(lyr, ogr.Layer) def test_ogr_to_numpy(self): np.testing.assert_allclose(georef.ogr_to_numpy(self.ogrobj), self.npobj) def test_get_vector_points(self): # this also tests equality with `ogr_to_numpy` x = np.array(list(georef.get_vector_points(self.ogrobj))[0]) y = georef.ogr_to_numpy(self.ogrobj) np.testing.assert_allclose(x, y) def test_get_vector_points_warning(self): point_wkt = "POINT (1198054.34 648493.09)" point = ogr.CreateGeometryFromWkt(point_wkt) with pytest.warns(UserWarning): list(georef.get_vector_points(point)) def test_get_vector_coordinates(self): # this also tests equality with `ogr_to_numpy` x, attrs = georef.get_vector_coordinates(self.layer, key="FID") assert attrs == list(range(13)) x, attrs = georef.get_vector_coordinates(self.layer) y = [] self.layer.ResetReading() for i in range(self.layer.GetFeatureCount()): feature = self.layer.GetNextFeature() if feature: geom = feature.GetGeometryRef() y.append(georef.ogr_to_numpy(geom)) y = np.array(y) for x1, y1 in zip(x, y): np.testing.assert_allclose(x1, y1) self.layer.ResetReading() x, attrs = georef.get_vector_coordinates( self.layer, source_srs=self.proj, dest_srs=self.wgs84 ) self.layer.ResetReading() x, attrs = georef.get_vector_coordinates(self.layer, dest_srs=self.wgs84) def test_transform_geometry(self): geom = georef.transform_geometry(self.projobj, dest_srs=self.wgs84) x = list(georef.get_vector_points(geom))[0] np.testing.assert_allclose(x, self.lonlat, rtol=1e-05) def test_transform_geometry_warning(self): with pytest.warns(UserWarning): georef.transform_geometry(self.ogrobj, dest_srs=self.wgs84) def test_ogr_copy_layer(self): ds = wradlib.io.gdal_create_dataset("Memory", "test", gdal_type=gdal.OF_VECTOR) georef.ogr_copy_layer(self.ds, 0, ds) assert isinstance(ds.GetLayer(), ogr.Layer) def test_ogr_copy_layer_by_name(self): ds = wradlib.io.gdal_create_dataset("Memory", "test", gdal_type=gdal.OF_VECTOR) georef.ogr_copy_layer_by_name(self.ds, "agger_merge", ds) assert isinstance(ds.GetLayer(), ogr.Layer) with pytest.raises(ValueError): georef.ogr_copy_layer_by_name(self.ds, "agger_merge1", ds) def test_ogr_add_feature(self): ds = wradlib.io.gdal_create_dataset("Memory", "test", gdal_type=gdal.OF_VECTOR) georef.ogr_create_layer( ds, "test", geom_type=ogr.wkbPoint, fields=[("index", ogr.OFTReal)] ) point = np.array([1198054.34, 648493.09]) parr = np.array([point, point, point]) georef.ogr_add_feature(ds, parr) georef.ogr_add_feature(ds, parr, name="test") def test_ogr_add_geometry(self): ds = wradlib.io.gdal_create_dataset("Memory", "test", gdal_type=gdal.OF_VECTOR) lyr = georef.ogr_create_layer( ds, "test", geom_type=ogr.wkbPoint, fields=[("test", ogr.OFTReal)] ) point = ogr.Geometry(ogr.wkbPoint) point.AddPoint(1198054.34, 648493.09) georef.ogr_add_geometry(lyr, point, [42.42]) def test_geocol_to_numpy(self): # Create a geometry collection geomcol = ogr.Geometry(ogr.wkbGeometryCollection) # Create polygon ring = ogr.Geometry(ogr.wkbLinearRing) ring.AddPoint(1179091.1646903288, 712782.8838459781) ring.AddPoint(1161053.0218226474, 667456.2684348812) ring.AddPoint(1214704.933941905, 641092.8288590391) ring.AddPoint(1228580.428455506, 682719.3123998424) ring.AddPoint(1218405.0658121984, 721108.1805541387) ring.AddPoint(1179091.1646903288, 712782.8838459781) poly = ogr.Geometry(ogr.wkbPolygon) poly.AddGeometry(ring) geomcol.AddGeometry(poly) # Add a point point = ogr.Geometry(ogr.wkbPoint) point.AddPoint(-122.23, 47.09) geomcol.AddGeometry(point) # Add a line line = ogr.Geometry(ogr.wkbLineString) line.AddPoint(-122.60, 47.14) line.AddPoint(-122.48, 47.23) geomcol.AddGeometry(line) arr = georef.ogr_geocol_to_numpy(geomcol)[..., 0:2] res = np.array( [ [1179091.1646903288, 712782.8838459781], [1161053.0218226474, 667456.2684348812], [1214704.933941905, 641092.8288590391], [1228580.428455506, 682719.3123998424], [1218405.0658121984, 721108.1805541387], [1179091.1646903288, 712782.8838459781], ] ) np.testing.assert_allclose(arr, res) def test_get_centroid(self): cent1 = georef.get_centroid(self.npobj) cent2 = georef.get_centroid(self.ogrobj) assert cent1 == (2600050.0, 5630050.0) assert cent2 == (2600050.0, 5630050.0)
def test_get_default_projection(self): self.assertEqual(georef.get_default_projection().ExportToWkt(), self.wgs84)