wradlib.io.gdal.VectorSource#

class wradlib.io.gdal.VectorSource(data=None, trg_crs=None, name='layer', source=0, **kwargs)[source]#

Bases: object

DataSource class for handling ogr/gdal vector data

DataSource handles creates in-memory (vector) ogr DataSource object with one layer for point or polygon geometries.

Parameters:
  • data (sequence or str) – sequence of source points (shape Nx2) or polygons (shape NxMx2) or Vector File (GDAL/OGR) filename containing source points/polygons

  • trg_crs (osgeo.osr.SpatialReference) – GDAL OSR SRS describing target CRS the source data should be projected to

Keyword Arguments:
  • name (str) – Layer Name, defaults to “layer”.

  • source (int) – Number of layer to load, if multiple layers in source shape file.

  • mode (str) – Return type of class access functions/properties. Can be either of “numpy”, “geo” and “ogr”, defaults to “numpy”.

  • src_crs (osgeo.osr.SpatialReference) – GDAL OGR SRS describing projection source in which data is provided in.

Warning

Writing shapefiles with the wrong locale settings can have impact on the type of the decimal. If problem arise use LC_NUMERIC=C in your environment.

Examples

See Vector Source.

close()[source]#
property mode#
property ds#

Returns VectorSource

property extent#
property crs#
property data#

Returns VectorSource geometries as numpy arrays

Note

This may be slow, because it extracts all source polygons

property geo#

Returns VectorSource geometries as GeoPandas Dataframe

get_data_by_idx(idx, *, mode=None)[source]#

Returns DataSource geometries from given index

Parameters:
  • idx (sequence) – sequence of int indices

  • mode (str, optional) – return type (“numpy”, “geo”, “ogr”), defaults to “numpy”

get_data_by_att(attr=None, value=None, mode=None)[source]#

Returns DataSource geometries filtered by given attribute/value

Keyword Arguments:
  • attr (str) – attribute name

  • value (str) – attribute value

  • mode (str) – return type (“numpy”, “geo”, “ogr”), defaults to “numpy”

get_data_by_geom(geom=None, mode=None)[source]#

Returns DataSource geometries filtered by given geometry

Keyword Arguments:
  • geom (osgeo.ogr.Geometry | geopandas.GeoDataFrame) – OGR.Geometry object or geopandas.GeoDataFrame containing the Geometry

  • mode (str) – return type (“numpy”, “geo”, “ogr”), defaults to “numpy”

dump_vector(filename, *, driver='ESRI Shapefile', remove=True)[source]#

Output layer to OGR Vector File

Parameters:
  • filename (str) – path to shape-filename

  • driver (str, optional) – driver string, defaults to “ESRI SHapefile”

  • remove (bool, optional) – if True removes existing output file, defaults to True

load_vector(filename, *, source=0, driver='ESRI Shapefile')[source]#

Read Layer from OGR Vector File

Parameters:
  • filename (str) – path to shape-filename

  • source (int or str, optional) – number or name of wanted layer, defaults to 0

  • driver (str, optional) – driver string, defaults to “ESRI Shapefile”

dump_raster(filename, *, driver='GTiff', attr=None, pixel_size=1.0, **kwargs)[source]#

Output layer to GDAL Rasterfile

Parameters:
  • filename (str) – path to shape-filename

  • driver (str, optional) – GDAL Raster Driver, defaults to “GTiff”.

  • attr (str, optional) – attribute to burn into raster, defaults to None.

  • pixel_size (float, optional) – pixel Size in source units

Keyword Arguments:
  • remove (bool, optional) – if True removes existing output file. Defaults to True.

  • silent (bool, optional) – If True no ProgressBar is shown. Defaults to False.

set_attribute(name, values, *, reset_filter=False)[source]#

Add/Set given Attribute with given values

Parameters:
  • name (str) – Attribute Name

  • values (numpy.ndarray) – Values to fill in attributes.

  • reset_filter (bool, optional) – reset any layer filter (spatial/attribute), defaults to False.

get_attributes(attrs, *, filt=None)[source]#

Return attributes

Parameters:
  • attrs (list) – Attribute Names to retrieve

  • filt (tuple, optional) – (attname, value) for Attribute Filter, defaults to None

get_geom_properties(props, *, filt=None)[source]#

Return geometry properties

Parameters:
  • props (list) – Property Names to retrieve

  • filt (tuple, optional) – (attname, value) for Attribute Filter, defaults to None.

get_attrs_and_props(*, attrs=None, props=None, filt=None)[source]#

Return properties and attributes

Keyword Arguments:
  • attrs (list) – Attribute Names to retrieve

  • props (list) – Property Names to retrieve

  • filt (tuple) – (attname, value) for Attribute Filter

close()

dump_raster(filename, *[, driver, attr, ...])

Output layer to GDAL Rasterfile

dump_vector(filename, *[, driver, remove])

Output layer to OGR Vector File

get_attributes(attrs, *[, filt])

Return attributes

get_attrs_and_props(*[, attrs, props, filt])

Return properties and attributes

get_data_by_att([attr, value, mode])

Returns DataSource geometries filtered by given attribute/value

get_data_by_geom([geom, mode])

Returns DataSource geometries filtered by given geometry

get_data_by_idx(idx, *[, mode])

Returns DataSource geometries from given index

get_geom_properties(props, *[, filt])

Return geometry properties

load_vector(filename, *[, source, driver])

Read Layer from OGR Vector File

set_attribute(name, values, *[, reset_filter])

Add/Set given Attribute with given values

crs

data

Returns VectorSource geometries as numpy arrays

ds

Returns VectorSource

extent

geo

Returns VectorSource geometries as GeoPandas Dataframe

mode