read#
- read(vector: str | CloudPath | Path | GeoDataFrame | GeoSeries | None = None, crs: Any | None = None, archive_regex: str | None = None, window: Any | None = None, **kwargs) GeoDataFrame[source]#
Read any vector:
if KML/KMZ: sets correctly the drivers and open layered KML (you may need
ogr2ogrto make it work !)if archive (only zip or tar), use a regex to look for the vector inside the archive. You can use this site to build your regex.
if GML: manages the empty errors
Handles a lot of exceptions and have fallback mechanisms with
ogr2ogr(if inPATH)Handles both on disk and cloud-stored vectors.
Adds two attributes to your vector:
path: File pathname: File name
If vector object is passed:
in case of
geopandas.GeoSeries: Ageopandas.GeoDataFrameis created from itin case of
geopandas.GeoDataFrame: returned as is
- Parameters:
vector (AnyVectorType | gpd.GeoSeries) – Path to vector to read or vector itself. In case of archive, path to the archive.
crs – Wanted CRS of the vector. If None, using naive or origin CRS.
archive_regex (str) – [Archive only] Regex for the wanted vector inside the archive
window (Any) – Anything that can be returned as a bbox (i.e. path, gpd.GeoPandas, Iterable, …). In case of an iterable, assumption is made it corresponds to geographic bounds. Mimics
rasters.read(..., window=). If given,bboxis ignored.**kwargs – Additional arguments used in gpd.read_file. You can also give
file_list, the list of files of the archive to get the vector from, as this operation is expensive when done with large archives stored on the cloud. You can also setcompute_sindex=Falseto avoid computing the spatial index of the vector.
- Returns:
Read vector as a GeoDataFrame
- Return type:
gpd.GeoDataFrame
Examples
>>> # Usual >>> path = 'D:/path/to/vector.geojson' >>> vec = vectors.read(path, crs=WGS84) Name ... geometry 0 Sentinel-1 Image Overlay ... POLYGON ((0.85336 42.24660, -2.32032 42.65493,... >>> >>> # Attributes >>> vec.attrs["path"] 'D:/path/to/vector.geojson' >>> >>> vec.attrs["name"] 'vector.geojson'
>>> # Archive >>> arch_path = 'D:/path/to/zip.zip' >>> vectors.read(arch_path, archive_regex=r".*map-overlay.kml") Name ... geometry 0 Sentinel-1 Image Overlay ... POLYGON ((0.85336 42.24660, -2.32032 42.65493,...