Exemple #1
0
def dumps(ob, hex=False, srid=None, **kw):
    """Dump a WKB representation of a geometry to a byte string, or a
    hex-encoded string if ``hex=True``.
    
    Parameters
    ----------
    ob : geometry
        The geometry to export to well-known binary (WKB) representation
    hex : bool
        If true, export the WKB as a hexidecimal string. The default is to
        return a binary string/bytes object.
    srid : int
        Spatial reference system ID to include in the output. The default value
        means no SRID is included.
    **kw : kwargs
        See available keyword output settings in ``shapely.geos.WKBWriter``."""
    if srid is not None:
        # clone the object and set the SRID before dumping
        geom = lgeos.GEOSGeom_clone(ob._geom)
        lgeos.GEOSSetSRID(geom, srid)
        ob = geom_factory(geom)
        kw["include_srid"] = True
    writer = WKBWriter(lgeos, **kw)
    if hex:
        return writer.write_hex(ob)
    else:
        return writer.write(ob)
Exemple #2
0
def dumps(ob, hex=False, srid=None, **kw):
    """Dump a WKB representation of a geometry to a byte string, or a
    hex-encoded string if ``hex=True``.
    
    Parameters
    ----------
    ob : geometry
        The geometry to export to well-known binary (WKB) representation
    hex : bool
        If true, export the WKB as a hexidecimal string. The default is to
        return a binary string/bytes object.
    srid : int
        Spatial reference system ID to include in the output. The default value
        means no SRID is included.
    **kw : kwargs
        See available keyword output settings in ``shapely.geos.WKBWriter``."""
    if srid is not None:
        # clone the object and set the SRID before dumping
        geom = lgeos.GEOSGeom_clone(ob._geom)
        lgeos.GEOSSetSRID(geom, srid)
        ob = geom_factory(geom)
        kw["include_srid"] = True
    writer = WKBWriter(lgeos, **kw)
    if hex:
        return writer.write_hex(ob)
    else:
        return writer.write(ob)
Exemple #3
0
        def _to_wkb():
            # Create a closure that:
            # - Adds a not-null check. This allows the returned function to
            #   be used directly with apply, unlike `shapely.wkb.dumps`.
            # - Avoid extra work done by `shapely.wkb.dumps` that we don't need.
            # - Caches the WKBWriter (and write method lookup :) )
            # - Avoids adding WKBWriter, lgeos, and notnull to the module namespace.
            from shapely.geos import WKBWriter, lgeos

            write = WKBWriter(lgeos).write
            notnull = pandas.notnull

            def _to_wkb(v):
                return write(v) if notnull(v) else v

            return _to_wkb
Exemple #4
0
 def wkb_hex(self):
     """WKB hex representation of the geometry"""
     return WKBWriter(lgeos).write_hex(self)
Exemple #5
0
 def wkb(self):
     """WKB representation of the geometry"""
     return WKBWriter(lgeos).write(self)