|
sgsPy
structurally guided sampling
|
This class represents a spatial vector, and is used as an input to many sgs functions. More...
Public Member Functions | |
| __init__ (self, str|GDALVectorWrapper image) | |
| print_info (self, str layer_name, dict layer_info) | |
| info (self, Optional[int|str] layer=None) | |
| samples_as_wkt (self) | |
| plot (self, str geomtype, Optional[matplotlib.axes.Axes] ax=None, Optional[int|str] layer=None, **kwargs) | |
| from_geopandas (cls, obj, str layer_name=None) | |
| to_geopandas (self) | |
Public Attributes | |
| cpp_vector = GDALVectorWrapper(image, PROJDB_PATH) | |
| layers = self.cpp_vector.get_layer_names() | |
This class represents a spatial vector, and is used as an input to many sgs functions.
It has a number of additional uses, including displaying info about the vector, converting to a GDAL or GeoPandas object.
Accessing vector info:
vector metadata can be displayed using the info() function. All layers are displayed unless a specific layer is specified. The per-layer info includes: name, number of features, number of fields, geomtype, and bounds.
layer_names : list[str]
a list of layer names
info()
takes an optional argument specify the band, and prints vector metadata to console
| sgspy.utils.vector.SpatialVector.__init__ | ( | self, | |
| str | GDALVectorWrapper | image ) |
Constructing method for the SpatialVector class. Has one required parameter to specify a gdal dataset. The following attributes are populated: self.cpp_vector self.layer_names Parameters -------------------- image: str | GDALVectorWrapper specifies a path to a vector file or the C++ class object itself
| sgspy.utils.vector.SpatialVector.from_geopandas | ( | cls, | |
| obj, | |||
| str | layer_name = None ) |
This function is used to convert a geopandas object into an sgspy.SpatialVector. The geopandas object
may either by of type GeoDataFrame or GeoSeries.
If a particular layer name is desired, it can be passed as a parameter.
Examples:
gdf = gpd.read_file("access.shp")
access = sgspy.SpatialVector.from_geopandas(gdf)
gs = gpd['geometry'] #geometry column is a geoseries
access = sgspy.SpatialVector.from_geopandas(gs)
gdf = gpd.read_file("access.shp")
gdf = gdf[gdf == "LineString"]
access = sgspy.SpatialVector.from_geopandas(gdf)
| sgspy.utils.vector.SpatialVector.info | ( | self, | |
| Optional[int | str] | layer = None ) |
calls self.print_info depending on layer parameter. If no layer is given,
print all layers. A layer may be specified by either a str or an int.
Parameters
--------------------
layer : str or int
specifies the layer to print information on
| sgspy.utils.vector.SpatialVector.plot | ( | self, | |
| str | geomtype, | ||
| Optional[matplotlib.axes.Axes] | ax = None, | ||
| Optional[int | str] | layer = None, | ||
| ** | kwargs ) |
Calls plot_vector on self.
Paramters
--------------------
ax : matplotlib.axes.Axes
axes to plot the raster on
geomtype : str
the geometry type to try to print
layer : None | int | str
specification of which layer to print
**kwargs
any parameter which may be passed ot matplotlib.pyplot.plot
| sgspy.utils.vector.SpatialVector.print_info | ( | self, | |
| str | layer_name, | ||
| dict | layer_info ) |
prints layer information using the layer_info from self.cpp_vector.
This is an internal function not meant to be used by the end user.
Parameters
--------------------
name : str
str containing the layer name
layer_info : dict
dict containing 'feature_count', 'field_count', 'geometry_type', 'xmax', 'xmin', 'ymax', and 'ymin' items
| sgspy.utils.vector.SpatialVector.samples_as_wkt | ( | self | ) |
Calls get_wkt_points on the underlying cpp class, to return the samples as wkt strings. This function requires that there be a layer named 'samples' which is comprised entirely of Points or MultiPoints. These conditions will be satisfied if this SpatialVector is the output of one of the sampling functions in the sgs package.
| sgspy.utils.vector.SpatialVector.to_geopandas | ( | self | ) |
This function is used to convert an sgspy.SpatialVector into a geopandas geodataframe.
Examples:
access = sgspy.SpatialVector("access.shp")
gdf = access.to_geopandas()
| sgspy.utils.vector.SpatialVector.cpp_vector = GDALVectorWrapper(image, PROJDB_PATH) |
| sgspy.utils.vector.SpatialVector.layers = self.cpp_vector.get_layer_names() |