Пример #1
0
    def _from_legacy(cls, uri, backend=None):
        """Instantiate this class from a legacy URL"""
        luri = uri.lower()
        for head in (
            "epsg:",
            "http://www.opengis.net/def/crs/epsg/0/",
            "http://www.opengis.net/gml/srs/epsg.xml#",
        ):
            if luri.startswith(head):
                crsid = luri[len(head) :]
                try:
                    srid = int(crsid)
                except ValueError:
                    raise SyntaxError(
                        f"CRS URI [{uri}] should contain a numeric SRID value."
                    ) from None

                crs = cls(
                    domain="ogc",
                    authority="EPSG",
                    version="",
                    crsid=crsid,
                    srid=srid,
                    backend=backend,
                )
                crs.__dict__["origin"] = uri
                return crs

        raise ExternalValueError(f"Unknown CRS URI [{uri}] specified")
Пример #2
0
    def _from_urn(cls, urn, backend=None):  # noqa: C901
        """Instantiate this class using an URN format."""
        urn_match = CRS_URN_REGEX.match(urn)
        if not urn_match:
            raise ExternalValueError(
                f"Unknown CRS URN [{urn}] specified: {CRS_URN_REGEX.pattern}"
            )

        domain = urn_match.group("domain")
        authority = urn_match.group("authority").upper()

        if domain not in ("ogc", "opengis"):
            raise ExternalValueError(
                f"CRS URI [{urn}] contains unknown domain [{domain}]"
            )

        if authority == "EPSG":
            crsid = urn_match.group("id")
            try:
                srid = int(crsid)
            except ValueError:
                raise SyntaxError(
                    f"CRS URI [{urn}] should contain a numeric SRID value."
                ) from None
        elif authority == "OGC":
            crsid = urn_match.group("id").upper()
            if crsid != "CRS84":
                raise ExternalValueError(
                    f"OGC CRS URI from [{urn}] contains unknown id [{id}]"
                )
            srid = 4326
        else:
            raise ExternalValueError(
                f"CRS URI [{urn}] contains unknown authority [{authority}]"
            )

        crs = cls(
            domain=domain,
            authority=authority,
            version=urn_match.group(3),
            crsid=crsid,
            srid=srid,
            backend=backend,
        )
        crs.__dict__["origin"] = urn
        return crs
Пример #3
0
    def resolve_element(self, xpath: str) -> XPathMatch:
        """Resolve the element, and the matching object.
        Internally, this method caches results.
        """
        nodes = self._cached_resolver(xpath)  # calls _inner_resolve_element
        if nodes is None:
            raise ExternalValueError(f"Field '{xpath}' does not exist.")

        return XPathMatch(self, nodes, query=xpath)
Пример #4
0
    def __post_init__(self):
        try:
            self.type_name, self.id = self.rid.rsplit(".", 1)
        except ValueError:
            if conf.GISSERVER_WFS_STRICT_STANDARD:
                raise ExternalValueError(
                    "Expected typename.id format") from None

            # This should end in a 404 instead.
            self.type_name = None
            self.id = None
Пример #5
0
    def resolve_element(self, xpath: str) -> XPathMatch:
        """Resolve the element, and the matching object.

        This is used to convert XPath references in requests
        to the actual elements and model attributes for queries.

        Internally, this method caches results.
        """
        nodes = self._cached_resolver(xpath)  # calls _inner_resolve_element
        if nodes is None:
            raise ExternalValueError(f"Field '{xpath}' does not exist.")

        return XPathMatch(self, nodes, query=xpath)