Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add a scalebar using matplotlib-scalebar in geemap cartoee plot? #34

Open
GokulGeo opened this issue Dec 11, 2020 · 1 comment
Open

Comments

@GokulGeo
Copy link

Hi,
I am trying to add a scalebar using the sample scripts in geemap. But I am getting wrong results. The pixel size of the satellite imagery is 10m.The output is coming as

image

Which is wrong,

The script which I used is,

oi =m.draw_last_feature
geom = roi.geometry()
coords = geom.coordinates().getInfo()
zoom_region = [coords[0][0][0], coords[0][0][1], coords[0][2][0], coords[0][2][1]]

fig = plt.figure(figsize=(10,20))

vis = {
    "bands":["VV"],
    "min":-25,
    "max":0,
    "palette":['aqua', 'black']
}

# use cartoee to get a map
ax = cartoee.get_map(Sentinel_1,vis_params=vis,region=zoom_region)

# add gridlines to the map at a specified interval
cartoee.add_gridlines(ax,interval=[0.005,0.005],linestyle=":")

ax.set_title(
    label = 'Sentinel-1, October 5,2020 ',
    fontsize = 15
)

scalebar = ScaleBar(10) # 1 pixel = 0.2 meter
ax.add_artist(scalebar)
plt.show()

Kindly suggest ways to fix it.
Thank you.

@ppinard
Copy link
Owner

ppinard commented Jan 1, 2021

Based on the comment in your code snippet, "1 pixel = 0.2 meter", the dx argument should be 0.2:

scalebar = ScaleBar(0.2, "m")

Does this help? I don't know the cartoee package. Other users using geopandas had a similar issue, and the following note was added to the documentation:

Special notes for geospatial plots: If you are plotting geospatial coordinates (such as scatterplots of the location of structures, geopandas geodataframe plots, etc.), dx needs to be set differently depending on the coordinate system:

  • For UTM based coordinate system, where the X and Y are in meters, simply set dx = 1.
  • For WGS or NAD based coordinate system, where X and Y are in latitude (Y) and longitude (X), compute the distance between two points at the latitude (Y) you wish to have the scale represented and are also one full degree of longitude (X) apart, in meters. For example, dx = great_circle_distance((X, Y), (X + 1, Y))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants