def create_domain_crs(self) -> CRS: proj = self.get_proj_kwargs() if proj is None: raise UserError('Incomplete projection definition') map_proj = proj['map_proj'] if map_proj == 'lambert': if self.center_lat.is_valid(): origin_lat = self.center_lat.value() else: origin_lat = 0 crs = CRS.create_lambert(proj['truelat1'], proj['truelat2'], LonLat(proj['stand_lon'], origin_lat)) elif map_proj == 'polar': crs = CRS.create_polar(proj['truelat1'], proj['stand_lon']) elif map_proj == 'mercator': if self.center_lon.is_valid(): origin_lon = self.center_lon.value() else: origin_lon = 0 crs = CRS.create_mercator(proj['truelat1'], origin_lon) elif map_proj == 'lat-lon': crs = CRS.create_lonlat() else: assert False, 'unknown proj: ' + map_proj return crs
def test_projection_origin(crs_name: str): origin_lonlat = LonLat(lon=4, lat=0) if crs_name == 'lambert': crs = CRS.create_lambert(truelat1=3.5, truelat2=7, origin=origin_lonlat) elif crs_name == 'mercator': crs = CRS.create_mercator(truelat1=3.5, origin_lon=origin_lonlat.lon) elif crs_name == 'polar': origin_lonlat = LonLat(lon=origin_lonlat.lon, lat=90) crs = CRS.create_polar(truelat1=3.5, origin_lon=origin_lonlat.lon) elif crs_name == 'albers_nad83': crs = CRS.create_albers_nad83(truelat1=3.5, truelat2=7, origin=origin_lonlat) origin_xy = crs.to_xy(origin_lonlat) assert origin_xy.x == pytest.approx(0) assert origin_xy.y == pytest.approx(0, abs=1e-9)
def create_domain_crs(self) -> CRS: proj = self.get_proj_kwargs() if proj is None: raise ValueError('Incomplete projection definition') origin_valid = all( map(lambda w: w.is_valid(), [self.center_lat, self.center_lon])) if origin_valid: origin = LonLat(self.center_lon.value(), self.center_lat.value()) else: origin = LonLat(0, 0) if proj['map_proj'] == 'lambert': crs = CRS.create_lambert(proj['truelat1'], proj['truelat2'], origin) elif proj['map_proj'] == 'lat-lon': crs = CRS.create_lonlat() else: raise NotImplementedError('unknown proj: ' + proj['map_proj']) return crs
def test_geo_roundtrip(crs_name: str): if crs_name == 'lonlat': crs = CRS.create_lonlat() elif crs_name == 'lambert': crs = CRS.create_lambert(truelat1=3.5, truelat2=7, origin=LonLat(lon=4, lat=0)) elif crs_name == 'mercator': crs = CRS.create_mercator(truelat1=3.5, origin_lon=4) elif crs_name == 'polar': crs = CRS.create_polar(truelat1=3.5, origin_lon=4) elif crs_name == 'albers_nad83': crs = CRS.create_albers_nad83(truelat1=3.5, truelat2=7, origin=LonLat(lon=4, lat=0)) lonlat = LonLat(lon=10, lat=30) xy = crs.to_xy(lonlat) lonlat2 = crs.to_lonlat(xy) assert lonlat.lon == pytest.approx(lonlat2.lon) assert lonlat.lat == pytest.approx(lonlat2.lat)