#!/usr/bin/env python # coding: utf-8 # Open in Colab # # Uncomment the following line to install [geemap](https://geemap.org) if needed. # In[ ]: # !pip install geemap # # How to add a shapefile, GeoJSON, and KML to the map # # ## For ipyleaflet # In[ ]: import geemap # In[ ]: # geemap.update_package() # In[ ]: Map = geemap.Map(center=[0, 0], zoom=2) in_geojson = "https://raw.githubusercontent.com/gee-community/geemap/master/examples/data/cable_geo.geojson" Map.add_geojson(in_geojson, layer_name="Cable lines") Map # In[ ]: Map = geemap.Map(center=[0, 0], zoom=2) url = "https://raw.githubusercontent.com/gee-community/geemap/master/examples/data/countries.geojson" Map.add_geojson( url, layer_name="Countries", fill_colors=["red", "yellow", "green", "orange"] ) Map # In[ ]: import random Map = geemap.Map(center=[0, 0], zoom=2) url = "https://raw.githubusercontent.com/gee-community/geemap/master/examples/data/countries.geojson" def random_color(feature): return { "color": "black", "fillColor": random.choice(["red", "yellow", "green", "orange"]), } Map.add_geojson(url, layer_name="Countries", style_callback=random_color) Map # In[ ]: Map = geemap.Map(center=[0, 0], zoom=2) url = "https://raw.githubusercontent.com/gee-community/geemap/master/examples/data/countries.geojson" style = { "stroke": True, "color": "#0000ff", "weight": 2, "opacity": 1, "fill": True, "fillColor": "#0000ff", "fillOpacity": 0.1, } hover_style = {"fillOpacity": 0.7} Map.add_geojson(url, layer_name="Countries", style=style, hover_style=hover_style) Map # In[ ]: url = "https://raw.githubusercontent.com/gee-community/geemap/master/examples/data/countries.zip" geemap.download_file(url) # Uncomment to install `PyCRS` as needed # In[ ]: # !pip install PyCRS # In[ ]: Map = geemap.Map(center=[0, 0], zoom=2) in_shp = "countries.shp" Map.add_shapefile(in_shp, layer_name="Countries") Map # In[ ]: Map = geemap.Map() in_kml = "https://raw.githubusercontent.com/gee-community/geemap/master/examples/data/us_states.kml" Map.add_kml(in_kml, layer_name="US States KML") Map # In[ ]: Map = geemap.Map(center=[0, 0], zoom=2) url = "https://raw.githubusercontent.com/gee-community/geemap/master/examples/data/countries.geojson" Map.add_vector( url, layer_name="Countries", fill_colors=["red", "yellow", "green", "orange"] ) Map # ## For folium # In[ ]: import geemap.foliumap as geemap # In[ ]: Map = geemap.Map() # In[ ]: in_shp = "countries.shp" in_geojson = "https://raw.githubusercontent.com/gee-community/geemap/master/examples/data/us_states.json" in_kml = "./us_states.kml" # the kml visualization above downloads this file # In[ ]: Map.add_shapefile(in_shp, layer_name="Shapefile") # In[ ]: Map.add_geojson(in_geojson, layer_name="GeoJSON") # In[ ]: Map.add_kml(in_kml, layer_name="KML") # In[ ]: Map