Skip to content

Instantly share code, notes, and snippets.

@ValerieAnne563
Created April 17, 2019 15:13
Show Gist options
  • Select an option

  • Save ValerieAnne563/46015fba18247c103966f31045f60ee6 to your computer and use it in GitHub Desktop.

Select an option

Save ValerieAnne563/46015fba18247c103966f31045f60ee6 to your computer and use it in GitHub Desktop.
# Demonstrates the ability to open a Fiona collection through VSI bindings
# Based on the following example but with the correct source URL:
# https://gis.stackexchange.com/questions/225586/reading-raw-data-into-geopandas
import fiona
import gdal
import requests
import uuid
import geopandas as gpd
request = requests.get('https://raw.githubusercontent.com/OSGeo/gdal/master/autotest/ogr/data/poly.zip')
vsiz = '/vsimem/{}.zip'.format(uuid.uuid4().hex) #gdal/ogr requires a .zip extension
gdal.FileFromMemBuffer(vsiz,bytes(request.content))
with fiona.Collection(vsiz, vsi='zip', layer ='poly') as f:
gdf = gpd.GeoDataFrame.from_features(f, crs=f.crs)
print(gdf.head())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment