Vector basics

The Vector class builds upon the great functionalities of GeoPandas, with the aim to bridge the gap between vector and raster files. It uses geopandas.GeoDataFrame as a base driver, accessible through Vector.ds.

Opening a Vector file

import geoutils as gu

filename = gu.datasets.get_path("glacier_outlines")

outlines = gu.Vector(filename)

Printing the Vector shows the underlying GeoDataFrame and some extra statistics:

print(outlines)
Filename:           /home/docs/checkouts/readthedocs.org/user_builds/geoutils-erikm/envs/latest/lib/python3.7/site-packages/geoutils/datasets/glacier_outlines.gpkg 
Coordinate System:  EPSG:4326
Number of features: 86 
Extent:             [86.70393205700003, 27.847778695000045, 87.11409458600008, 28.14549759700003] 
Attributes:         ['RGIId', 'GLIMSId', 'BgnDate', 'EndDate', 'CenLon', 'CenLat', 'O1Region', 'O2Region', 'Area', 'Zmin', 'Zmax', 'Zmed', 'Slope', 'Aspect', 'Lmax', 'Status', 'Connect', 'Form', 'TermType', 'Surging', 'Linkages', 'Name', 'geometry'] 
             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]

Masks can easily be generated for use with Rasters:

# Load an example Landsat image
filename = gu.datasets.get_path("landsat_B4")
image = gu.Raster(filename)

# Generate a boolean mask from the glacier outlines.
mask = outlines.create_mask(image)

We can prove that glaciers are bright (who could have known!?) by masking the values outside and inside of the glaciers:

print(f"Inside: {image.data[mask].mean():.1f}, outside: {image.data[~mask].mean():.1f}")
Inside: 172.7, outside: 110.5

TODO: Add rasterize text.