def NormCoords(lista, NORM): # Recibe una lista de coordenadas from pyproj.aoi import AreaOfInterest from pyproj.database import query_utm_crs_info from pyproj import CRS from pyproj import Proj import math import numpy as np import pandas as pd Lat = np.array(lista)[:, 0] Long = np.array(lista)[:, 1] utm_crs_list = query_utm_crs_info( datum_name="WGS 84", area_of_interest=AreaOfInterest( west_lon_degree=Lat.mean(), south_lat_degree=Long.mean(), east_lon_degree=Lat.mean(), north_lat_degree=Long.mean(), ), ) utm_crs = CRS.from_epsg(utm_crs_list[0].code) myProj = Proj(utm_crs_list[0].name) UTMx, UTMy = myProj(Long, Lat, inverse=False) MxLon = UTMx.max() MnLon = UTMx.min() MxLat = UTMy.max() MnLat = UTMy.min() bx = (UTMx.max() - UTMx.min()) by = (UTMy.max() - UTMy.min()) NormLon = [] NormLat = [] for i in range(0, len(UTMx)): NormLon.append((UTMx[i] - MxLon) * NORM / bx + NORM) NormLat.append((UTMy[i] - MxLat) * NORM / by + NORM) Info = [] for i in range(0, len(NormLon)): Info.append([NormLon[i], NormLat[i]]) return (Info)
def estimate_utm_crs(self, datum_name="WGS 84"): """Returns the estimated UTM CRS based on the bounds of the dataset. .. versionadded:: 0.2 .. note:: Requires pyproj 3+ Parameters ---------- datum_name : str, optional The name of the datum to use in the query. Default is WGS 84. Returns ------- rasterio.crs.CRS """ # pylint: disable=import-outside-toplevel try: from pyproj.aoi import AreaOfInterest from pyproj.database import query_utm_crs_info except ImportError: raise RuntimeError( "pyproj 3+ required for estimate_utm_crs.") from None if self.crs is None: raise RuntimeError("crs must be set to estimate UTM CRS.") # ensure using geographic coordinates if self.crs.is_geographic: minx, miny, maxx, maxy = self.bounds(recalc=True) else: minx, miny, maxx, maxy = self.transform_bounds("EPSG:4326", recalc=True) x_center = np.mean([minx, maxx]) y_center = np.mean([miny, maxy]) utm_crs_list = query_utm_crs_info( datum_name=datum_name, area_of_interest=AreaOfInterest( west_lon_degree=x_center, south_lat_degree=y_center, east_lon_degree=x_center, north_lat_degree=y_center, ), ) try: return CRS.from_epsg(utm_crs_list[0].code) except IndexError: raise RuntimeError("Unable to determine UTM CRS") from None
def test_query_utm_crs_info__aoi_contains(): aoi = BBox(west=41, south=50, east=42, north=51) crs_info_list = query_utm_crs_info( area_of_interest=AreaOfInterest( west_lon_degree=aoi.west, south_lat_degree=aoi.south, east_lon_degree=aoi.east, north_lat_degree=aoi.north, ), contains=True, ) assert crs_info_list for crs_info in crs_info_list: assert BBox(*crs_info.area_of_use.bounds).contains(aoi) assert "UTM zone" in crs_info.name assert crs_info.auth_name == "EPSG" assert crs_info.type == PJType.PROJECTED_CRS assert not crs_info.deprecated
def test_query_utm_crs_info__aoi_datum_name(datum_name): aoi = BBox(west=-93.581543, south=42.032974, east=-93.581543, north=42.032974) crs_info_list = query_utm_crs_info( datum_name=datum_name, area_of_interest=AreaOfInterest( west_lon_degree=aoi.west, south_lat_degree=aoi.south, east_lon_degree=aoi.east, north_lat_degree=aoi.north, ), ) assert len(crs_info_list) == 1 crs_info = crs_info_list[0] bbox = BBox(*crs_info.area_of_use.bounds) assert bbox.intersects(aoi) assert "UTM zone" in crs_info.name assert datum_name.replace(" ", "") in crs_info.name.replace(" ", "") assert crs_info.auth_name == "EPSG" assert crs_info.type == PJType.PROJECTED_CRS assert not crs_info.deprecated
def estimate_utm_crs(self, datum_name="WGS 84"): """Returns the estimated UTM CRS based on the bounds of the dataset. .. versionadded:: 0.9 .. note:: Requires pyproj 3+ Parameters ---------- datum_name : str, optional The name of the datum to use in the query. Default is WGS 84. Returns ------- pyproj.CRS Examples -------- >>> world = geopandas.read_file( ... geopandas.datasets.get_path("naturalearth_lowres") ... ) >>> germany = world.loc[world.name == "Germany"] >>> germany.geometry.estimate_utm_crs() # doctest: +SKIP <Projected CRS: EPSG:32632> Name: WGS 84 / UTM zone 32N Axis Info [cartesian]: - E[east]: Easting (metre) - N[north]: Northing (metre) Area of Use: - name: World - N hemisphere - 6°E to 12°E - by country - bounds: (6.0, 0.0, 12.0, 84.0) Coordinate Operation: - name: UTM zone 32N - method: Transverse Mercator Datum: World Geodetic System 1984 - Ellipsoid: WGS 84 - Prime Meridian: Greenwich """ try: from pyproj.aoi import AreaOfInterest from pyproj.database import query_utm_crs_info except ImportError: raise RuntimeError("pyproj 3+ required for estimate_utm_crs.") if not self.crs: raise RuntimeError("crs must be set to estimate UTM CRS.") minx, miny, maxx, maxy = self.total_bounds # ensure using geographic coordinates if not self.crs.is_geographic: lon, lat = Transformer.from_crs(self.crs, "EPSG:4326", always_xy=True).transform( (minx, maxx, minx, maxx), (miny, miny, maxy, maxy)) x_center = np.mean(lon) y_center = np.mean(lat) else: x_center = np.mean([minx, maxx]) y_center = np.mean([miny, maxy]) utm_crs_list = query_utm_crs_info( datum_name=datum_name, area_of_interest=AreaOfInterest( west_lon_degree=x_center, south_lat_degree=y_center, east_lon_degree=x_center, north_lat_degree=y_center, ), ) try: return CRS.from_epsg(utm_crs_list[0].code) except IndexError: raise RuntimeError("Unable to determine UTM CRS")