GDALMemoryVector¶
-
class
buzzard.
ASource
(<implementation detail>)[source] Base abstract class defining the common behavior of all sources opened in the Dataset.
Features Defined
Has a stored spatial reference
Has a virtual spatial reference that is influenced by the Dataset’s opening mode
Can be closed
-
property
wkt_stored
The spatial reference that can be found in the metadata of a source, in wkt format.
string or None
-
property
proj4_stored
The spatial reference that can be found in the metadata of a source, in proj4 format.
string or None
-
property
wkt_virtual
The spatial reference considered to be written in the metadata of a source, in wkt format.
string or None
-
property
proj4_virtual
The spatial reference considered to be written in the metadata of a source, in proj4 format.
string or None
-
get_keys
()[source] Get the list of keys under which this source is registered to in the Dataset
-
property
close
Close a source with a call or a context management. The close attribute returns an object that can be both called and used in a with statement
Examples
>>> ds.dem.close() >>> with ds.dem.close: # code... >>> with ds.acreate_raster('result.tif', fp, float, 1).close as result: # code... >>> with ds.acreate_vector('results.shp', 'linestring').close as roofs: # code...
-
__del__
()[source]
-
class
buzzard.
ASourceVector
(<implementation detail>)[source] Base abstract class defining the common behavior of all vectors.
Features Defined
Has a type that defines the type of geometry (like “Polygon”)
Has fields that define the type of informations that is paired with each geometries
Has a stored extent that allows to retrieve the current extent of all the geometries
Has a length that indicates how many geometries this source contains.
Has several read functions (like iter_data) to retrieve geometries in their current state to shapely objects
-
property
type
Geometry type
-
property
fields
Fields definition
-
property
extent
Get the vector’s extent in work spatial reference. (x then y)
Example
>>> minx, maxx, miny, maxy = ds.roofs.extent
-
property
extent_stored
Get the vector’s extent in stored spatial reference. (minx, miny, maxx, maxy)
-
property
bounds
Get the vector’s bounds in work spatial reference. (min then max)
Example
>>> minx, miny, maxx, maxy = ds.roofs.extent
-
property
bounds_stored
Get the vector’s bounds in stored spatial reference. (min then max)
-
__len__
()[source] Return the number of features in vector
-
iter_data
(fields=None, geom_type='shapely', mask=None, clip=False, slicing=slice(0, None, 1))[source] Create an iterator over vector’s features
Parameters
- fields: None or string or -1 or sequence of string/int
Which fields to include in iteration
if None, empty sequence or empty string: No fields included
if -1: All fields included
if string: Name of fields to include (separated by comma or space)
if sequence: List of indices / names to include
- geom_type: {‘shapely’, ‘coordinates’}
Returned geometry type
- mask: None or Footprint or shapely geometry or (nbr, nbr, nbr, nbr)
Add a spatial filter to iteration, only geometries not disjoint with mask will be included.
if None: No spatial filter
if Footprint or shapely polygon: Polygon
if (nbr, nbr, nbr, nbr): Extent (minx, maxx, miny, maxy)
- clip: bool
Returns intersection of geometries and mask. Caveat: A clipped geometry might not be of the same type as the original geometry. e.g: polygon might be clipped to might be converted to one of those:
polygon
line
point
multipolygon
multiline
multipoint
geometrycollection
- slicing: slice
Slice of the iteration to return. It is applied after spatial filtering
Yields
- feature: geometry or (geometry,) or (geometry, *fields)
If geom_type is ‘shapely’: geometry is a shapely geometry.
If geom_type is coordinates: geometry is a nested lists of numpy arrays.
If fields is not a sequence: feature is geometry or (geometry, *fields), depending on the number of fields to yield.
If fields is a sequence or a string: feature is (geometry,) or (geometry, *fields). Use fields=[-1] to get a monad containing all fields.
Examples
>>> for polygon, volume, stock_type in ds.stocks.iter_data('volume,type'): print('area:{}m**2, volume:{}m**3'.format(polygon.area, volume))
>>> for polygon, in ds.stocks.iter_data([]): print('area:{}m**2'.format(polygon.area))
>>> for polygon in ds.stocks.iter_data(): print('area:{}m**2'.format(polygon.area))
-
get_data
(index, fields=-1, geom_type='shapely', mask=None, clip=False)[source] Fetch a single feature in vector. See ASourceVector.iter_data
-
iter_geojson
(mask=None, clip=False, slicing=slice(0, None, 1))[source] Create an iterator over vector’s features
Parameters
- mask: None or Footprint or shapely geometry or (nbr, nbr, nbr, nbr)
Add a spatial filter to iteration, only geometries not disjoint with mask will be included.
if None: No spatial filter
if Footprint or shapely polygon: Polygon
if (nbr, nbr, nbr, nbr): Extent (minx, maxx, miny, maxy)
- clip: bool
Returns intersection of geometries and mask. Caveat: A clipped geometry might not be of the same type as the original geometry. e.g: polygon might be clipped to might be converted to one of those:
polygon
line
point
multipolygon
multiline
multipoint
geometrycollection
- slicing: slice
Slice of the iteration to return. It is applied after spatial filtering
Returns
iterable of geojson feature (dict)
Example
>>> for geojson in ds.stocks.iter_geojson(): print('exterior-point-count:{}, volume:{}m**3'.format( len(geojson['geometry']['coordinates'][0]), geojson['properties']['volume'] ))
-
get_geojson
(index, mask=None, clip=False)[source] Fetch a single feature in vector. See ASourceVector.iter_geojson
-
extent_origin
Descriptor object to manage deprecation
-
class
buzzard.
AStored
(<implementation detail>)[source] Base abstract class defining the common behavior of all sources that are stored somewhere (like RAM or disk).
Features Defined
Has an opening mode
-
property
mode
Open mode, one of {‘r’, ‘w’}
-
class
buzzard.
AStoredVector
(<implementation detail>)[source] Base abstract class defining the common behavior of all vectors that are stored somewhere (like RAM or disk).
Features Defined
Has an insert_data method that allows to write geometries to storage
-
insert_data
(geom, fields=(), index=-1)[source] Insert a feature in vector.
This method is not thread-safe.
Parameters
- geom: shapely.base.BaseGeometry or nested sequence of coordinates
- fields: sequence or dict
Feature’s fields, missing or None fields are defaulted.
if empty sequence: Keep all fields defaulted
if sequence of length len(self.fields): Fields to be set, same order as self.fields
if dict: Mapping of fields to be set
- index: int
if -1: append feature
else: insert feature at index (if applicable)
Example
>>> poly = shapely.geometry.box(10, 10, 42, 43) >>> fields = {'volume': 42.24} >>> ds.stocks.insert_data(poly, fields)
Caveat
When using a Vector backed by a driver (like an OGR driver), the data might be flushed to disk only after the garbage collection of the driver object. To be absolutely sure that the driver cache is flushed to disk, call .close or .deactivate on this Vector.
-
class
buzzard.
AEmissary
(<implementation detail>)[source] Base abstract class defining the common behavior of all sources that are backed by a driver.
Features Defined
Has a driver (like “GTiff” for GDAL’s geotiff driver)
Has open_options
Has a path (if the driver supports it)
Can be deleted (if the driver supports it)
-
property
driver
Get the driver name, such as ‘GTiff’ or ‘GeoJSON’
-
property
open_options
Get the list of options used for opening
-
property
path
Get the file system path of this source, may be the empty string if not applicable
-
property
delete
Delete a source with a call or a context management. May raise an exception if not applicable or if mode = ‘r’ The delete attribute returns an object that can be both called and used in a with statement
Example
>>> ds.dem.delete() >>> with ds.dem.delete: # code... >>> with ds.acreate_raster('/tmp/tmp.tif', fp, float, 1).delete as tmp: # code... >>> with ds.acreate_vector('/tmp/tmp.shp', 'polygon').delete as tmp: # code...
-
property
remove
Delete a source with a call or a context management. May raise an exception if not applicable or if mode = ‘r’ The delete attribute returns an object that can be both called and used in a with statement
Example
>>> ds.dem.delete() >>> with ds.dem.delete: # code... >>> with ds.acreate_raster('/tmp/tmp.tif', fp, float, 1).delete as tmp: # code... >>> with ds.acreate_vector('/tmp/tmp.shp', 'polygon').delete as tmp: # code...
-
class
buzzard.
AEmissaryVector
(<implementation detail>)[source] Base abstract class defining the common behavior of all vectors that are backed by a driver.
Features Defined
Has a layer (if the driver supports it)
-
property
layer
-
class
buzzard.
GDALMemoryVector
(<implementation detail>)[source] Concrete class defining the behavior of a GDAL raster using the “Memory” driver
>>> help(Dataset.create_vector)
Features Defined
None