VectorLayer¶
- class HSTB.kluster.gdal_helpers.VectorLayer(output_file, driver_name, input_crs, update, silent=True)¶
Bases:
objectConvert numpy arrays and metadata to OGR geometry to then generate OGR files. Includes methods for the common geometry types like polygons, lines and points. Would need to be expanded if there are types outside of these basic types.
ex:
>>> vl = VectorLayer(‘C:collabdasktestdata_dirSHAM_ERStst.shp’, ‘ESRI Shapefile’, 26917, False)Creating new file C:collabdasktestdata_dirSHAM_ERStst.shp>>> vl.write_to_layer(‘new_poly’, np.array([[1116651.439379124, 637392.6969887456], [1188804.0108498496, 652655.7409537067], [1226730.3625203592, 637392.6969887456], [1188804.0108498496, 622467.6640211721]]), ogr.wkbPolygon)Successfully generated 1 out of 1 features in layer new_poly>>> vl.close()Or write to virtual file system object (using gpkg driver for variety, is not driver specific) vl = VectorLayer(‘/vsimem/tst.gpkg’, ‘GPKG’, 26917, False)
Attributes Summary
Returns if the output_file is a gdal virtual file system path
Methods Summary
close()Close the dataset
delete_layer(layer_name)Delete the layer from the dataset
get_layer_by_name(layer_name)hide_layer(layer_name)show_layer(layer_name)write_to_layer(layer_name, coords_dset, ...)Build the requested geometry and write to layer_name.
Attributes Documentation
- is_virtual¶
Returns if the output_file is a gdal virtual file system path
Methods Documentation
- close()¶
Close the dataset
- delete_layer(layer_name)¶
Delete the layer from the dataset
- Parameters
layer_name (
str) – name of the dataset layer
- get_layer_by_name(layer_name)¶
- hide_layer(layer_name)¶
- show_layer(layer_name)¶
- write_to_layer(layer_name, coords_dset, geom_type)¶
Build the requested geometry and write to layer_name. If that layer exists, will update as long as the update switch is on.
- Parameters
layer_name (
str) – name of the dataset layercoords_dset (
ndarray) – either a numpy array of coords for the feature, or a list of numpy arrays if there are multiple features you are writing to the layergeom_type (
int) – The geometry type of the layer