Skip to content

Instantly share code, notes, and snippets.

@micahcochran
Created September 17, 2015 19:48
Show Gist options
  • Select an option

  • Save micahcochran/7826e025aa1f0f53e45b to your computer and use it in GitHub Desktop.

Select an option

Save micahcochran/7826e025aa1f0f53e45b to your computer and use it in GitHub Desktop.

Revisions

  1. micahcochran created this gist Sep 17, 2015.
    66 changes: 66 additions & 0 deletions geopandas_from_features_test.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,66 @@
    # 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])