read

Contents

read#

read(vector_path: str | CloudPath | Path, 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 ogr2ogr to 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 in PATH)

Handles both on disk and cloud-stored vectors.

Adds two attributes to your vector:

  • path: File path

  • name: File name

Parameters:
  • vector_path (AnyPathStrType) – Path to vector to read. 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, bbox is ignored.

  • **kwargs – Additional arguments used in gpd.read_file

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,...