@@ -217,19 +217,16 @@ def _autozoom(self):
217
217
# remove the following with new Folium release
218
218
# rough approximation, assuming max_zoom is 18
219
219
import math
220
- try :
221
- lat_diff = bounds ['max_lat' ] - bounds ['min_lat' ]
222
- lon_diff = bounds ['max_lon' ] - bounds ['min_lon' ]
223
- area , max_area = lat_diff * lon_diff , 180 * 360
224
- if area :
225
- factor = 1 + max (0 , 1 - self ._width / 1000 )/ 2 + max (0 , 1 - area ** 0.5 )/ 2
226
- zoom = math .log (area / max_area )/ - factor
227
- else :
228
- zoom = self ._default_zoom
229
- zoom = max (1 , min (18 , round (zoom )))
230
- attrs ['zoom_start' ] = zoom
231
- except ValueError as e :
232
- raise Exception ('Check that your locations are lat-lon pairs' , e )
220
+ lat_diff = bounds ['max_lat' ] - bounds ['min_lat' ]
221
+ lon_diff = bounds ['max_lon' ] - bounds ['min_lon' ]
222
+ area , max_area = lat_diff * lon_diff , 180 * 360
223
+ if area :
224
+ factor = 1 + max (0 , 1 - self ._width / 1000 )/ 2 + max (0 , 1 - area ** 0.5 )/ 2
225
+ zoom = math .log (area / max_area )/ - factor
226
+ else :
227
+ zoom = self ._default_zoom
228
+ zoom = max (1 , min (18 , round (zoom )))
229
+ attrs ['zoom_start' ] = zoom
233
230
234
231
return attrs
235
232
@@ -395,20 +392,21 @@ def read_geojson(cls, path_or_json_or_string_or_url):
395
392
data = None
396
393
if isinstance (path_or_json_or_string_or_url , (dict , list )):
397
394
data = path_or_json_or_string_or_url
398
- try :
399
- data = json .loads (path_or_json_or_string_or_url )
400
- except ValueError :
401
- pass
402
- try :
403
- path = path_or_json_or_string_or_url
404
- if path .endswith ('.gz' ) or path .endswith ('.gzip' ):
405
- import gzip
406
- contents = gzip .open (path , 'r' ).read ().decode ('utf-8' )
407
- else :
408
- contents = open (path , 'r' ).read ()
409
- data = json .loads (contents )
410
- except FileNotFoundError :
411
- pass
395
+ else :
396
+ try :
397
+ data = json .loads (path_or_json_or_string_or_url )
398
+ except ValueError :
399
+ pass
400
+ try :
401
+ path = path_or_json_or_string_or_url
402
+ if path .endswith ('.gz' ) or path .endswith ('.gzip' ):
403
+ import gzip
404
+ contents = gzip .open (path , 'r' ).read ().decode ('utf-8' )
405
+ else :
406
+ contents = open (path , 'r' ).read ()
407
+ data = json .loads (contents )
408
+ except FileNotFoundError :
409
+ pass
412
410
if not data :
413
411
import urllib .request
414
412
with urllib .request .urlopen (path_or_json_or_string_or_url ) as url :
@@ -425,7 +423,7 @@ def _read_geojson_features(data, features=None, prefix=""):
425
423
key = feature .get ('id' , prefix + str (i ))
426
424
feature_type = feature ['geometry' ]['type' ]
427
425
if feature_type == 'FeatureCollection' :
428
- _read_geojson_features (feature , features , prefix + '.' + key )
426
+ value = Map . _read_geojson_features (feature [ 'geometry' ] , features , prefix + '.' + key )
429
427
elif feature_type == 'Point' :
430
428
value = Circle ._convert_point (feature )
431
429
elif feature_type in ['Polygon' , 'MultiPolygon' ]:
@@ -575,7 +573,7 @@ def _convert_point(cls, feature):
575
573
"""Convert a GeoJSON point to a Marker."""
576
574
lon , lat = feature ['geometry' ]['coordinates' ]
577
575
popup = feature ['properties' ].get ('name' , '' )
578
- return cls (lat , lon )
576
+ return cls (lat , lon , popup = popup )
579
577
580
578
@classmethod
581
579
def map (cls , latitudes , longitudes , labels = None , colors = None , areas = None , other_attrs = None , clustered_marker = False , ** kwargs ):
@@ -855,7 +853,7 @@ def polygons(self):
855
853
"""
856
854
if self .type == 'Polygon' :
857
855
polygons = [self ._geojson ['geometry' ]['coordinates' ]]
858
- elif self .type == ' MultiPolygon' :
856
+ else : # self.type == " MultiPolygon"
859
857
polygons = self ._geojson ['geometry' ]['coordinates' ]
860
858
return [ [ [_lat_lons_from_geojson (s ) for
861
859
s in ring ] for
@@ -979,11 +977,7 @@ def get_coordinates(table, replace_columns=False, remove_nans=False):
979
977
table = table .with_columns ("lat" , lat , "lon" , lon )
980
978
table = table .drop (index_name )
981
979
if replace_columns :
982
- for label in ["county" , "city" , "zip code" , "state" ]:
983
- try :
984
- table = table .drop (label )
985
- except KeyError :
986
- pass
980
+ table = table .drop (["county" , "city" , "zip code" , "state" ])
987
981
if remove_nans :
988
982
table = table .where ("lat" , are .below (float ("inf" ))) # NaNs are not considered to be smaller than infinity
989
983
return table
0 commit comments