⚠️ Our 0.1 release refactored several early-development functions for long-term stability, to update your code see here. ⚠️
Future changes will come with deprecation warnings! 🙂

Open/save a vector

Open/save a vector#

This example demonstrates the instantiation of a vector through geoutils.Vector and saving with save().

import geoutils as gu

We open an example vector.

filename_vect = gu.examples.get_path("everest_rgi_outlines")
vect = gu.Vector(filename_vect)
vect
Vector(
  ds=             RGIId  ...                                           geometry
       0   RGI60-15.03410  ...  POLYGON ((86.92842 27.92877, 86.92866 27.92930...
       1   RGI60-15.03411  ...  POLYGON ((86.94077 27.92375, 86.94059 27.92295...
       2   RGI60-15.03412  ...  POLYGON ((86.85344 27.94752, 86.85340 27.94752...
       3   RGI60-15.03413  ...  POLYGON ((86.84776 27.94845, 86.84776 27.94849...
       4   RGI60-15.03414  ...  POLYGON ((86.84567 27.96906, 86.84567 27.96910...
       ..             ...  ...                                                ...
       81  RGI60-15.10070  ...  POLYGON ((86.94112 28.11455, 86.94129 28.11452...
       82  RGI60-15.10075  ...  POLYGON ((86.95861 28.04669, 86.95847 28.04701...
       83  RGI60-15.10077  ...  POLYGON ((86.96454 28.07843, 86.96445 28.07814...
       84  RGI60-15.10078  ...  POLYGON ((86.96302 28.04915, 86.96304 28.04920...
       85  RGI60-15.10079  ...  POLYGON ((86.97074 28.09496, 86.97039 28.09488...

       [86 rows x 23 columns]
  crs=EPSG:4326
  bounds=BoundingBox(left=86.70393205700003, bottom=27.847778695000045, right=87.11409458600008, top=28.14549759700003))


A vector is composed of a single main attribute: a ds geodataframe. All other attributes are inherited from Shapely and GeoPandas. See also The georeferenced vector (Vector).

Note

A vector can also be instantiated with a geopandas.GeoDataFrame, see From/to GeoPandas.

We can print more info on the vector.

"Filename:           /home/docs/checkouts/readthedocs.org/user_builds/geoutils/checkouts/stable/examples/data/Everest_Landsat/15_rgi60_glacier_outlines.gpkg \nCoordinate System:  EPSG:4326\nExtent:             [86.70393205700003, 27.847778695000045, 87.11409458600008, 28.14549759700003] \nNumber of features: 86 \nAttributes:         ['RGIId', 'GLIMSId', 'BgnDate', 'EndDate', 'CenLon', 'CenLat', 'O1Region', 'O2Region', 'Area', 'Zmin', 'Zmax', 'Zmed', 'Slope', 'Aspect', 'Lmax', 'Status', 'Connect', 'Form', 'TermType', 'Surging', 'Linkages', 'Name', 'geometry']"

Let’s plot by vector area

vect.plot(column="Area", cbar_title="Area (km²)")
read vector

Finally, a vector is saved using save().

vect.save("myvector.gpkg")

Total running time of the script: (0 minutes 0.268 seconds)

Gallery generated by Sphinx-Gallery