61 cartoee scalebar
In [1]:
Copied!
import ee
import geemap
from geemap import cartoee
import matplotlib.pyplot as plt
import ee
import geemap
from geemap import cartoee
import matplotlib.pyplot as plt
cartopy is not installed. Please see https://scitools.org.uk/cartopy/docs/latest/installing.html#installing for instructions on how to install cartopy. The easiest way to install cartopy is using conda: conda install -c conda-forge cartopy
In [2]:
Copied!
geemap.ee_initialize()
geemap.ee_initialize()
In [3]:
Copied!
# Get image
lon = -115.1585
lat = 36.1500
start_year = 1984
end_year = 2011
point = ee.Geometry.Point(lon, lat)
years = ee.List.sequence(start_year, end_year)
def get_best_image(year):
start_date = ee.Date.fromYMD(year, 1, 1)
end_date = ee.Date.fromYMD(year, 12, 31)
image = (
ee.ImageCollection("LANDSAT/LT05/C01/T1_SR")
.filterBounds(point)
.filterDate(start_date, end_date)
.sort("CLOUD_COVER")
.first()
)
return ee.Image(image)
collection = ee.ImageCollection(years.map(get_best_image))
vis_params = {"bands": ['B4', 'B3', 'B2'], "min": 0, "max": 5000}
image = ee.Image(collection.first())
# Get image
lon = -115.1585
lat = 36.1500
start_year = 1984
end_year = 2011
point = ee.Geometry.Point(lon, lat)
years = ee.List.sequence(start_year, end_year)
def get_best_image(year):
start_date = ee.Date.fromYMD(year, 1, 1)
end_date = ee.Date.fromYMD(year, 12, 31)
image = (
ee.ImageCollection("LANDSAT/LT05/C01/T1_SR")
.filterBounds(point)
.filterDate(start_date, end_date)
.sort("CLOUD_COVER")
.first()
)
return ee.Image(image)
collection = ee.ImageCollection(years.map(get_best_image))
vis_params = {"bands": ['B4', 'B3', 'B2'], "min": 0, "max": 5000}
image = ee.Image(collection.first())
In [4]:
Copied!
w = 0.4
h = 0.3
region = [lon + w, lat - h, lon - w, lat + h]
fig = plt.figure(figsize=(10, 8))
# use cartoee to get a map
ax = cartoee.get_map(image, region=region, vis_params=vis_params)
# add gridlines to the map at a specified interval
cartoee.add_gridlines(ax, interval=[0.2, 0.2], linestyle=":")
# add north arrow
north_arrow_dict = {
"text": "N",
"xy": (0.10, 0.36),
"arrow_length": 0.15,
"text_color": "white",
"arrow_color": "white",
"fontsize": 20,
"width": 5,
"headwidth": 15,
"ha": "center",
"va": "center",
}
cartoee.add_north_arrow(ax, **north_arrow_dict)
# add scale bar
scale_bar_dict = {
'metric_distance': 4,
'unit': "km",
'at_x': (0.05, 0.2),
'at_y': (0.08, 0.11),
'max_stripes': 5,
'ytick_label_margins': 0.25,
'fontsize': 8,
'font_weight': "bold",
'rotation': 0,
'zorder': 999,
'paddings': {"xmin": 0.05, "xmax": 0.05, "ymin": 1.5, "ymax": 0.5},
}
cartoee.add_scale_bar(ax, **scale_bar_dict)
ax.set_title(label='Las Vegas, NV', fontsize=15)
plt.show()
w = 0.4
h = 0.3
region = [lon + w, lat - h, lon - w, lat + h]
fig = plt.figure(figsize=(10, 8))
# use cartoee to get a map
ax = cartoee.get_map(image, region=region, vis_params=vis_params)
# add gridlines to the map at a specified interval
cartoee.add_gridlines(ax, interval=[0.2, 0.2], linestyle=":")
# add north arrow
north_arrow_dict = {
"text": "N",
"xy": (0.10, 0.36),
"arrow_length": 0.15,
"text_color": "white",
"arrow_color": "white",
"fontsize": 20,
"width": 5,
"headwidth": 15,
"ha": "center",
"va": "center",
}
cartoee.add_north_arrow(ax, **north_arrow_dict)
# add scale bar
scale_bar_dict = {
'metric_distance': 4,
'unit': "km",
'at_x': (0.05, 0.2),
'at_y': (0.08, 0.11),
'max_stripes': 5,
'ytick_label_margins': 0.25,
'fontsize': 8,
'font_weight': "bold",
'rotation': 0,
'zorder': 999,
'paddings': {"xmin": 0.05, "xmax": 0.05, "ymin": 1.5, "ymax": 0.5},
}
cartoee.add_scale_bar(ax, **scale_bar_dict)
ax.set_title(label='Las Vegas, NV', fontsize=15)
plt.show()
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Input In [4], in <cell line: 9>() 6 fig = plt.figure(figsize=(10, 8)) 8 # use cartoee to get a map ----> 9 ax = cartoee.get_map(image, region=region, vis_params=vis_params) 11 # add gridlines to the map at a specified interval 12 cartoee.add_gridlines(ax, interval=[0.2, 0.2], linestyle=":") File ~/.local/lib/python3.9/site-packages/geemap/cartoee.py:150, in get_map(ee_object, proj, **kwargs) 147 ee_object = ee_object.mosaic() 149 if proj is None: --> 150 proj = ccrs.PlateCarree() 152 if "style" in kwargs: 153 del kwargs["style"] NameError: name 'ccrs' is not defined
<Figure size 720x576 with 0 Axes>
Last update:
2022-03-14