~pythonxy/pythonxy-upstream/python-folium

« back to all changes in this revision

Viewing changes to folium/features.py

  • Committer: Filipe
  • Date: 2015-12-15 21:04:18 UTC
  • mfrom: (143.1.1)
  • Revision ID: git-v1:7ec30b786e3447de9773b3f60d841c28c0714b55
Merge pull request #296 from BibMartin/geopandas

Enable GeoPandas drawing

Show diffs side-by-side

added added

removed removed

Lines of Context:
238
238
            else:  # This is a filename
239
239
                self.embed = False
240
240
                self.data = data
 
241
        elif data.__class__.__name__ in ['GeoDataFrame', 'GeoSeries']:
 
242
            self.embed = True
 
243
            if hasattr(data, '__geo_interface__'):
 
244
                # We have a GeoPandas 0.2 object
 
245
                self.data = json.loads(json.dumps(data.to_crs(epsg='4326').__geo_interface__))
 
246
            elif hasattr(data, 'columns'):
 
247
                # We have a GeoDataFrame 0.1
 
248
                self.data = json.loads(data.to_crs(epsg='4326').to_json())
 
249
            else:
 
250
                raise ValueError('Unable to transform this object to a GeoJSON.')
241
251
        else:
242
 
            raise ValueError('Unhandled data type.')
 
252
            raise ValueError('Unhandled object {!r}.'.format(data))
243
253
 
244
254
        if style_function is None:
245
255
            style_function = lambda x: {}