#!/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/giswqs/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/giswqs/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/giswqs/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/giswqs/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[ ]: Map = geemap.Map(center=[0, 0], zoom=2) in_shp = '../data/countries.shp' Map.add_shapefile(in_shp, layer_name="Countries") Map # In[ ]: Map = geemap.Map() in_kml = '../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/giswqs/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 = '../data/countries.shp' in_geojson = '../data/us-states.json' in_kml = '../data/us-states.kml' # 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