[GIS] How to load mapinfo mid/mif into GeoPandas

geopandasmapinfopython

I suspect this is a trivial question to answer but how do I load mapinfo mid/mif files into GeoPandas?

While it's trivial to load and manipulate .shp files, I can't work out what code to use:

Here's a few examples of the data I'm trying to play with: http://www.stoke.gov.uk/ccm/content/business/general/open-geospatial-consortium-data-catalogue.en

    cylpaths = geopandas.GeoDataFrame.from_file(path)  

I tried to test the geometry, which shows:

   cylpaths.crs

    Out[15]:
   {u'ellps': u'airy',
    u'k': 0.9996012717,
   u'lat_0': 49,
   u'lon_0': -2,
   u'no_defs': True,
   u'proj': u'tmerc',
   u'towgs84': u'375,-111,431,-0,-0,-0,0',
   u'units': u'm',
   u'x_0': 400000,
   u'y_0': -100000}

But when I try to preview the data, I get an empty dataframe:

    cylpaths

    Out[16]:
    Int64Index([], dtype='int64')   Empty GeoDataFrame

I'm a bit lost in working out what I need to do next.

Best Answer

I think you were doing things just fine, I'm wondering if it's just the dataset. I'm thinking you were trying to open the Cycleways dataset, yes (based on your variable name of cylpaths)? I first tried the "Car Parks" dataset on that site, and it worked with your code:

>>> from geopandas import GeoDataFrame
>>> df = GeoDataFrame.from_file("CARPARKS.mid")
>>> df
<class 'geopandas.geodataframe.GeoDataFrame'>
Int64Index: 81 entries, 0 to 80
Data columns (total 9 columns):
CARPARKNAME    81  non-null values
CODE           81  non-null values
FEATURECODE    81  non-null values
MI_PRINX       81  non-null values
MI_STYLE       81  non-null values
ORIGIN_X       81  non-null values
ORIGIN_Y       81  non-null values
UPRN           81  non-null values
geometry       81  non-null values
dtypes: float64(5), object(4)

I then tried the "Cycleways" dataset, and got the same thing as you, nothing:

>>> cyc = GeoDataFrame.from_file("CYCLEWAYS.mid")
>>> cyc
Empty GeoDataFrame
Columns: [geometry]
Index: []
>>> cyc["geometry"]
Series([], dtype: float64)

Finally, I tried to open the "Existing Shopping Areas" dataset, and it worked fine as well:

>>> shops = GeoDataFrame.from_file("EXISTINGSHOPPINGAREA.mid")
>>> shops
<class 'geopandas.geodataframe.GeoDataFrame'>
Int64Index: 6 entries, 0 to 5
Data columns (total 23 columns):
ADDRESS      6  non-null values
CODE         6  non-null values
...
TAG          6  non-null values
UNIQUE_ID    6  non-null values
UPRN         6  non-null values
geometry     6  non-null values
dtypes: float64(2), object(21)
>>> shops["geometry"]
0    POLYGON ((391004.768 343418.116, 391043.64 343...
1    POLYGON ((388249.762 347724.09, 388246.163 347...
2    POLYGON ((387592.015 345241.407, 387621.012 34...
3    POLYGON ((386842.681 349747.805, 386825.301 34...
4    POLYGON ((386823.752 349815.999, 386822.978 34...
5    POLYGON ((385983.258 351384.922, 385981.446 35...
Name: geometry, dtype: object
>>>

So, maybe it's just the original Mapinfo files perhaps?