Skip to content

Instantly share code, notes, and snippets.

@micahcochran
Created September 17, 2015 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micahcochran/7826e025aa1f0f53e45b to your computer and use it in GitHub Desktop.
Save micahcochran/7826e025aa1f0f53e45b to your computer and use it in GitHub Desktop.
Geopandas from_feature Feature & FeatureCollection test
# This is a test for from_features function, which
# in geopandas reads the __geo_interface__ from other libraries.
# This test currently fails.
# 2015-09-17 I'm using a recent development version of geopandas
import geopandas as gpd
class geoEmptyClass:
pass
global_cities = geoEmptyClass()
global_cities.__geo_interface__ = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
2.3508,
48.8567
]
},
"properties": {
"name": "Paris"
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
114.2,
22.3
]
},
"properties": {
"name": "Hong Kong"
}
}
]
}
london_gi = geoEmptyClass()
london_gi.__geo_interface__ = {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-0.1275,
51.507222
]
},
"properties": {
"name": "London"
}
}
if __name__ == "__main__":
# this works fine
df_london = gpd.GeoDataFrame.from_features([london_gi])
# from_features currently fails because geopandas doesn't currently
# support reading FeatureCollections from the __geo_interface__
df_cities = gpd.GeoDataFrame.from_features([global_cities])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment