Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load mapinfo file into geopandas

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.

like image 626
elksie5000 Avatar asked Jan 26 '26 00:01

elksie5000


1 Answers

At the time I'm writing this answer, the original question is 7 years old, but it might make sense to address.

The current version of GeoPandas does include out-of-the-box support for MapInfo files. This is actually handled by the Fiona library. Check the snippet of code below:

import fiona

# Checks if GeoPandas can read MapInfo files
print('MapInfo File' in fiona.supported_drivers)

The code above should print out True. If so, it means that your setup is ready to read MapInfo files. If not, you might have to reinstall Fiona.

In case your setup is MapInfo-ready, you can use the code chunk below to read in this sample data.

import geopandas as gpd

tab_file = 'US_CNTY.TAB'

tab_data = gpd.read_file(tab_file)

At this point, tab_data is an easy-to-manipulate GeoDataFrame.

I hope this answers things!

like image 195
Felipe D. Avatar answered Jan 27 '26 13:01

Felipe D.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!