Vectors Sources Using GDAL (OGR)¶
- Dataset.open_vector(key, path, layer=None, driver='ESRI Shapefile', options=(), mode='r')[source]¶
Open a vector file within this Dataset under key. Only metadata are kept in memory.
>>> help(GDALFileVector)
Parameters
- key: hashable (like a string)
File identifier within Dataset
To avoid using a key, you may use
aopen_vector()
- path: string
- layer: None or int or string
- driver: string
ogr driver to use when opening the file http://www.gdal.org/ogr_formats.html
- options: sequence of str
options for ogr
- mode: one of {‘r’, ‘w’}
Returns
- source: GDALFileVector
Example
>>> ds.open_vector('trees', '/path/to.shp') >>> feature_count = len(ds.trees)
>>> ds.open_vector('roofs', '/path/to.json', driver='GeoJSON', mode='w') >>> fields_list = ds.roofs.fields
See Also
Dataset.aopen_vector()
: To skip the key assigmentbuzzard.open_vector()
: To skip the key assigment and the explicit Dataset instanciation
- Dataset.aopen_vector(path, layer=None, driver='ESRI Shapefile', options=(), mode='r')[source]¶
Open a vector file anonymously within this Dataset. Only metadata are kept in memory.
See
open_vector()
Example
>>> trees = ds.aopen_vector('/path/to.shp') >>> features_bounds = trees.bounds
See Also
Dataset.open_vector()
: To assign a key to this source within the Datasetbuzzard.open_vector()
: To skip the key assigment and the explicit Dataset instanciation
- Dataset.create_vector(key, path, type, fields=(), layer=None, driver='ESRI Shapefile', options=(), sr=None, ow=False)[source]¶
Create an empty vector file and register it under key within this Dataset. Only metadata are kept in memory.
>>> help(GDALFileVector) >>> help(GDALMemoryVector)
Parameters
- key: hashable (like a string)
File identifier within Dataset
To avoid using a key, you may use
acreate_vector()
- path: string
Anything that makes sense to GDAL:
A path to a file
An empty string when using driver=Memory
- type: string
name of a wkb geometry type, without the wkb prefix. For example: “Point”, “Polygon”, “LineString”.
full list: https://gdal.org/doxygen/ogr__core_8h.html#a800236a0d460ef66e687b7b65610f12a
- fields: sequence of dict
Attributes of fields, one dict per field. (see Field Attributes below)
- layer: None or string
- driver: string
ogr driver to use when opening the file http://www.gdal.org/ogr_formats.html
- options: sequence of str
options for ogr
- sr: string or None
Spatial reference of the new file
In order not to set a spatial reference, use None.
In order to set a spatial reference, use a string that can be converted to WKT by GDAL.
- ow: bool
Overwrite. Whether or not to erase the existing files.
Returns
- source: GDALFileVector or GDALMemoryVector
The type depends on the driver parameter
Example
>>> ds.create_vector('lines', '/path/to.shp', 'linestring') >>> geometry_type = ds.lines.type >>> ds.lines.insert_data([[0, 0], [1, 1], [1, 2]])
>>> fields = [ {'name': 'name', 'type': str}, {'name': 'count', 'type': 'int32'}, {'name': 'area', 'type': np.float64, 'width': 5, precision: 18}, {'name': 'when', 'type': np.datetime64}, ] >>> ds.create_vector('zones', '/path/to.shp', 'polygon', fields) >>> field0_type = ds.zones.fields[0]['type'] >>> ds.zones.insert_data(shapely.geometry.box(10, 10, 15, 15))
Field Attributes
Attributes:
“name”: string
“type”: string (see Field Types below)
“precision”: int
“width”: int
“nullable”: bool
“default”: same as type
An attribute missing or None is kept to default value.
Field Types
Type
Type names
Binary
“binary”, bytes, np.bytes_, aliases of np.bytes_
Date
“date”
DateTime
“datetime”, datetime.datetime, np.datetime64, aliases of np.datetime64
Time
“time”
Integer
“integer” np.int32, aliases of np.int32
Integer64
“integer64”, int, np.int64, aliases of np.int64
Real
“real”, float, np.float64, aliases of np.float64
String
“string”, str, np.str_, aliases of np.str_
Integer64List
“integer64list”, “int list”
IntegerList
“integerlist”
RealList
“reallist”, “float list”
See Also
Dataset.acreate_vector()
: To skip the key assigmentbuzzard.create_vector()
: To skip the key assigment and the explicit Dataset instanciation
- Dataset.acreate_vector(path, type, fields=(), layer=None, driver='ESRI Shapefile', options=(), sr=None, ow=False)[source]¶
Create a vector file anonymously within this Dataset. Only metadata are kept in memory.
See
create_vector()
Example
>>> lines = ds.acreate_vector('/path/to.shp', 'linestring') >>> file_proj4 = lines.proj4_stored
See Also
Dataset.create_vector()
: To assign a key to this source within the Datasetbuzzard.create_vector()
: To skip the key assigment and the explicit Dataset instanciation