How to use the geomet.wkt function in geomet

To help you get started, we’ve selected a few geomet examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sentinelsat / sentinelsat / sentinelsat / sentinel.py View on Github external
def to_geojson(products):
        """Return the products from a query response as a GeoJSON with the values in their
        appropriate Python types.
        """
        feature_list = []
        for i, (product_id, props) in enumerate(products.items()):
            props = props.copy()
            props["id"] = product_id
            poly = geomet.wkt.loads(props["footprint"])
            del props["footprint"]
            del props["gmlfootprint"]
            # Fix "'datetime' is not JSON serializable"
            for k, v in props.items():
                if isinstance(v, (date, datetime)):
                    props[k] = v.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
            feature_list.append(geojson.Feature(geometry=poly, id=i, properties=props))
        return geojson.FeatureCollection(feature_list)
github achapkowski / pygeopackage / src / geopackage / _geopackage.py View on Github external
def _update(self):
        """updates the current row"""
        txts = []
        values = []
        for k,v in self._values.items():
            if k.lower() != "objectid" and \
               k.lower() != 'shape':
                txts.append("%s=?" % k)
                values.append(v)
            elif k.lower() == 'shape':
                if isinstance(v, dict) and "coordinates" not in v:
                    v = self._header + dumps(v, False)
                elif isinstance(v, dict) and "coordinates" in v:
                    v = self._gpheader + geometwkb.dumps(obj=v)
                elif isinstance(v, str):
                    gj = geometwkt.loads(v)
                    v = self._gpheader + geometwkb.dumps(obj=gj)
                elif isinstance(v, (bytes, bytearray)):
                    if isinstance(v, (bytearray)):
                        v = bytes(v)
                    if len(v) > 2 and \
                       v[:2] != b'GB':
                        v = self._gpheader + v
                elif v is None:
                    v = self._gpheader + b'0x000000000000f87f'
                else:
                    raise ValueError(("Shape column must be Esri JSON dictionary, "
                                      "WKT, GeoJSON dictionary, or WKB (bytes)"))
                txts.append("%s=?" % k)
                values.append(v)
        sql = '''UPDATE {table} SET {values} WHERE OBJECTID={oid}'''.format(
            table=self._table_name,
github datastax / python-driver / cassandra / util.py View on Github external
def from_wkt(s):
        """
        Parse a Polygon geometry from a wkt string and return a new Polygon object.
        """
        if not _HAS_GEOMET:
            raise DriverException("Geomet is required to deserialize a wkt geometry.")

        try:
            geom = wkt.loads(s)
        except ValueError:
            raise ValueError("Invalid WKT geometry: '{0}'".format(s))

        if geom['type'] != 'Polygon':
            raise ValueError("Invalid WKT geometry type. Expected 'Polygon', got '{0}': '{1}'".format(geom['type'], s))

        coords = geom['coordinates']
        exterior = coords[0] if len(coords) > 0 else tuple()
        interiors = coords[1:] if len(coords) > 1 else None

        return Polygon(exterior=exterior, interiors=interiors)

geomet

Pure Python conversion library for common geospatial data formats

Apache-2.0
Latest version published 9 months ago

Package Health Score

71 / 100
Full package analysis