MCPcopy
hub / github.com/python-visualization/folium / process_data

Method process_data

folium/features.py:754–780  ·  view source on GitHub ↗

Convert an unknown data input into a geojson dictionary.

(self, data: Any)

Source from the content-addressed store, hash-verified

752 self.add_child(popup)
753
754 def process_data(self, data: Any) -> dict:
755 """Convert an unknown data input into a geojson dictionary."""
756 if isinstance(data, dict):
757 self.embed = True
758 return data
759 elif isinstance(data, str):
760 if data.lower().startswith(("http:", "ftp:", "https:")):
761 if not self.embed:
762 self.embed_link = data
763 return self.get_geojson_from_web(data)
764 elif data.lstrip()[0] in "[{": # This is a GeoJSON inline string
765 self.embed = True
766 return json.loads(data)
767 else: # This is a filename
768 if not self.embed:
769 self.embed_link = data
770 with open(data) as f:
771 return json.loads(f.read())
772 elif hasattr(data, "__geo_interface__"):
773 self.embed = True
774 if hasattr(data, "to_crs"):
775 data = data.to_crs("EPSG:4326")
776 return json.loads(json.dumps(data.__geo_interface__))
777 else:
778 raise ValueError(
779 "Cannot render objects with any missing geometries" f": {data!r}"
780 )
781
782 def get_geojson_from_web(self, url: str) -> dict:
783 return requests.get(url).json()

Callers 2

__init__Method · 0.95
__init__Method · 0.80

Calls 1

get_geojson_from_webMethod · 0.95

Tested by

no test coverage detected