예제 #1
0
 def __init__(
     self,
     name: str = "undefined",
     datum: Any = "urn:ogc:def:datum:EPSG::6326",
     ellipsoidal_cs: Any = None,
 ) -> None:
     """
     Parameters
     ----------
     name: str, optional
         Name of the CRS. Default is undefined.
     datum: Any, optional
         Anything accepted by :meth:`pyproj.crs.Datum.from_user_input` or
         a :class:`pyproj.crs.datum.CustomDatum`.
     ellipsoidal_cs: Any, optional
         Input to create an Ellipsoidal Coordinate System.
         Anything accepted by :meth:`pyproj.crs.CoordinateSystem.from_user_input`
         or an Ellipsoidal Coordinate System created from :ref:`coordinate_system`.
     """
     geographic_crs_json = {
         "$schema":
         "https://proj.org/schemas/v0.2/projjson.schema.json",
         "type":
         "GeographicCRS",
         "name":
         name,
         "datum":
         Datum.from_user_input(datum).to_json_dict(),
         "coordinate_system":
         CoordinateSystem.from_user_input(
             ellipsoidal_cs or Ellipsoidal2DCS()).to_json_dict(),
     }
     super().__init__(geographic_crs_json)
예제 #2
0
    def __init__(self,
                 name,
                 datum,
                 vertical_cs=VerticalCS(),
                 geoid_model=None):
        """
        Parameters
        ----------
        name: str
            The name of the Vertical CRS (e.g. NAVD88 height).
        datum: Any
            Anything accepted by :meth:`pyproj.crs.Datum.from_user_input`
        vertical_cs: Any, optional
            Input to create a Vertical Coordinate System accepted by
            :meth:`pyproj.crs.CoordinateSystem.from_user_input`
            or :class:`pyproj.crs.coordinate_system.VerticalCS`
        geoid_model: str, optional
            The name of the GEOID Model (e.g. GEOID12B).
        """
        vert_crs_json = {
            "$schema":
            "https://proj.org/schemas/v0.2/projjson.schema.json",
            "type":
            "VerticalCRS",
            "name":
            name,
            "datum":
            Datum.from_user_input(datum).to_json_dict(),
            "coordinate_system":
            CoordinateSystem.from_user_input(vertical_cs).to_json_dict(),
        }
        if geoid_model is not None:
            vert_crs_json["geoid_model"] = {"name": geoid_model}

        super().__init__(vert_crs_json)
예제 #3
0
 def __init__(
     self, base_crs, conversion, ellipsoidal_cs=Ellipsoidal2DCS(), name="undefined",
 ):
     """
     Parameters
     ----------
     base_crs: Any
         Input to create the Geodetic CRS, a :class:`GeographicCRS` or
         anything accepted by :meth:`pyproj.crs.CRS.from_user_input`.
     conversion: Any
         Anything accepted by :meth:`pyproj.crs.CoordinateSystem.from_user_input`
         or a conversion from :ref:`coordinate_operation`.
     ellipsoidal_cs: Any, optional
         Input to create an Ellipsoidal Coordinate System.
         Anything accepted by :meth:`pyproj.crs.CoordinateSystem.from_user_input`
         or an Ellipsoidal Coordinate System created from :ref:`coordinate_system`.
     name: str, optional
         Name of the CRS. Default is undefined.
     """
     derived_geographic_crs_json = {
         "$schema": "https://proj.org/schemas/v0.2/projjson.schema.json",
         "type": "DerivedGeographicCRS",
         "name": name,
         "base_crs": CRS.from_user_input(base_crs).to_json_dict(),
         "conversion": CoordinateOperation.from_user_input(
             conversion
         ).to_json_dict(),
         "coordinate_system": CoordinateSystem.from_user_input(
             ellipsoidal_cs
         ).to_json_dict(),
     }
     super().__init__(derived_geographic_crs_json)
예제 #4
0
 def __init__(
     self,
     conversion: Any,
     name: str = "undefined",
     cartesian_cs: Any = None,
     geodetic_crs: Any = None,
 ) -> None:
     """
     Parameters
     ----------
     conversion: Any
         Anything accepted by :meth:`pyproj.crs.CoordinateSystem.from_user_input`
         or a conversion from :ref:`coordinate_operation`.
     name: str, optional
         The name of the Projected CRS. Default is undefined.
     cartesian_cs: Any, optional
         Input to create a Cartesian Coordinate System.
         Anything accepted by :meth:`pyproj.crs.CoordinateSystem.from_user_input`
         or :class:`pyproj.crs.coordinate_system.Cartesian2DCS`.
     geodetic_crs: Any, optional
         Input to create the Geodetic CRS, a :class:`GeographicCRS` or
         anything accepted by :meth:`pyproj.crs.CRS.from_user_input`.
     """
     proj_crs_json = {
         "$schema":
         "https://proj.org/schemas/v0.2/projjson.schema.json",
         "type":
         "ProjectedCRS",
         "name":
         name,
         "base_crs":
         CRS.from_user_input(geodetic_crs
                             or GeographicCRS()).to_json_dict(),
         "conversion":
         CoordinateOperation.from_user_input(conversion).to_json_dict(),
         "coordinate_system":
         CoordinateSystem.from_user_input(
             cartesian_cs or Cartesian2DCS()).to_json_dict(),
     }
     super().__init__(proj_crs_json)
예제 #5
0
    def from_cf(
        in_cf: dict,
        ellipsoidal_cs: Any = None,
        cartesian_cs: Any = None,
        vertical_cs: Any = None,
        errcheck=False,
    ) -> "CRS":
        """
        .. versionadded:: 2.2.0

        .. versionadded:: 3.0.0 ellipsoidal_cs, cartesian_cs, vertical_cs

        This converts a Climate and Forecast (CF) Grid Mapping Version 1.8
        dict to a :obj:`pyproj.crs.CRS` object.

        :ref:`build_crs_cf`

        Parameters
        ----------
        in_cf: dict
            CF version of the projection.
        ellipsoidal_cs: Any, optional
            Input to create an Ellipsoidal Coordinate System.
            Anything accepted by :meth:`pyproj.crs.CoordinateSystem.from_user_input`
            or an Ellipsoidal Coordinate System created from :ref:`coordinate_system`.
        cartesian_cs: Any, optional
            Input to create a Cartesian Coordinate System.
            Anything accepted by :meth:`pyproj.crs.CoordinateSystem.from_user_input`
            or :class:`pyproj.crs.coordinate_system.Cartesian2DCS`.
        vertical_cs: Any, optional
            Input to create a Vertical Coordinate System accepted by
            :meth:`pyproj.crs.CoordinateSystem.from_user_input`
            or :class:`pyproj.crs.coordinate_system.VerticalCS`
        errcheck: bool, optional
            This parameter is for backwards compatibility with the old version.
            It currently does nothing when True or False.

        Returns
        -------
        CRS
        """
        unknown_names = ("unknown", "undefined")
        if "crs_wkt" in in_cf:
            return CRS(in_cf["crs_wkt"])
        elif "spatial_ref" in in_cf:  # for previous supported WKT key
            return CRS(in_cf["spatial_ref"])

        grid_mapping_name = in_cf.get("grid_mapping_name")
        if grid_mapping_name is None:
            raise CRSError(
                "CF projection parameters missing 'grid_mapping_name'")

        # build datum if possible
        datum = _horizontal_datum_from_params(in_cf)

        # build geographic CRS
        try:
            geographic_conversion_method = _GEOGRAPHIC_GRID_MAPPING_NAME_MAP[
                grid_mapping_name]  # type: Optional[Callable]
        except KeyError:
            geographic_conversion_method = None

        geographic_crs_name = in_cf.get("geographic_crs_name")
        if datum:
            geographic_crs = GeographicCRS(
                name=geographic_crs_name or "undefined",
                datum=datum,
                ellipsoidal_cs=ellipsoidal_cs,
            )  # type: CRS
        elif geographic_crs_name and geographic_crs_name not in unknown_names:
            geographic_crs = CRS(geographic_crs_name)
            if ellipsoidal_cs is not None:
                geographic_crs_json = geographic_crs.to_json_dict()
                geographic_crs_json[
                    "coordinate_system"] = CoordinateSystem.from_user_input(
                        ellipsoidal_cs).to_json_dict()
                geographic_crs = CRS(geographic_crs_json)
        else:
            geographic_crs = GeographicCRS(ellipsoidal_cs=ellipsoidal_cs)
        if grid_mapping_name == "latitude_longitude":
            return geographic_crs
        if geographic_conversion_method is not None:
            return DerivedGeographicCRS(
                base_crs=geographic_crs,
                conversion=geographic_conversion_method(in_cf),
                ellipsoidal_cs=ellipsoidal_cs,
            )

        # build projected CRS
        try:
            conversion_method = _GRID_MAPPING_NAME_MAP[grid_mapping_name]
        except KeyError:
            raise CRSError(
                f"Unsupported grid mapping name: {grid_mapping_name}")
        projected_crs = ProjectedCRS(
            name=in_cf.get("projected_crs_name", "undefined"),
            conversion=conversion_method(in_cf),
            geodetic_crs=geographic_crs,
            cartesian_cs=cartesian_cs,
        )

        # build bound CRS if exists
        bound_crs = None
        if "towgs84" in in_cf:
            bound_crs = BoundCRS(
                source_crs=projected_crs,
                target_crs="WGS 84",
                transformation=ToWGS84Transformation(
                    projected_crs.geodetic_crs,
                    *_try_list_if_string(in_cf["towgs84"])),
            )
        if "geopotential_datum_name" not in in_cf:
            return bound_crs or projected_crs

        # build Vertical CRS
        vertical_crs = VerticalCRS(
            name="undefined",
            datum=in_cf["geopotential_datum_name"],
            geoid_model=in_cf.get("geoid_name"),
            vertical_cs=vertical_cs,
        )

        # build compound CRS
        return CompoundCRS(
            name="undefined",
            components=[bound_crs or projected_crs, vertical_crs])