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

View extent in cartoee module switched up #1958

Closed
djcotto opened this issue Mar 29, 2024 · 4 comments
Closed

View extent in cartoee module switched up #1958

djcotto opened this issue Mar 29, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@djcotto
Copy link

djcotto commented Mar 29, 2024

Description

Hej all,

I tried to make a publication map via the cartoee module. In the end, the names of districts were constantly not in the centroid eventhough I just calculated them correctly and double checked correctness. I think I now located a slight switch-up of numbers in the cartoee module. If a region is specified as part of the add_layer() function the view_extent is set wrongly. Code is in line 232.

Instead of

view_extent = (region[2], region[0], region[1], region[3])

It should be

view_extent = (region[0], region[2], region[1], region[3])

Unsure if you need any further info. First bug report :)

@djcotto djcotto added the bug Something isn't working label Mar 29, 2024
@giswqs
Copy link
Member

giswqs commented Apr 3, 2024

Thank you for reporting. Would you like to submit a pull request to fix the issue?

@giswqs
Copy link
Member

giswqs commented Apr 7, 2024

I tested it. Changing it will resulting in incorrect extent. Can you share sample code that can reproduce the issue?

image

@djcotto
Copy link
Author

djcotto commented Apr 9, 2024

Basically what happens on my side is that the outline of the districts is mapped correctly. But as soon as I define a region /bounding box for my figure manually the coordinates for that figure on the x-axis are switched around. See the picture below where the intervalls on the x-axis define 1.2°W on the left and 1.8°W on the right, while for Kumasi it is the other way around.
This gets more clear when trying to place something on the figure according to the coordinates. Below you can see that the district names calculated to be in the centroid are not in the centroid of each district because of the interchanged view_extent that gets defined for the figure when a region is specified.

Happy to submit a pull request when agreed on the issue.

view_extent_Kumasi

import ee
import matplotlib.pyplot as plt
from geemap import cartoee

FAO_adm_lvl2 = ee.FeatureCollection("FAO/GAUL/2015/level2") 
filtered = FAO_adm_lvl2.filter(ee.Filter.And(ee.Filter.inList("ADM2_CODE", [190581, 190568, 190575, 190567, 16578, 16576, 190719, 190720]), 
                                        ee.Filter.eq("ADM0_NAME", "Ghana")))

style = {"color": "#000000", "width": 1, "fillColor": "#00000000"}

adm2_outline = ee.Image(filtered.style(**style))

region = [-1.95, 6.4, -1.2, 7.2]

specified_regions_with_centroids = filtered.map(lambda feature: feature.set('centroid', feature.geometry().centroid()))
specified_regions_list = specified_regions_with_centroids.toList(specified_regions_with_centroids.size())

# Iterate over the list to extract geometries and attributes
region_centroids = []
region_names = []
for i in range(specified_regions_list.size().getInfo()):
    feature = ee.Feature(specified_regions_list.get(i))
    region_centroids.append(dict(feature.get('centroid').getInfo())["coordinates"])
    region_names.append(feature.get('ADM2_NAME').getInfo())

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

ax = cartoee.get_map(adm2_outline, region=region) 
cartoee.add_gridlines(ax, interval=0.2, xtick_rotation=0, linestyle=":")

for name, centroid in zip(region_names, region_centroids):
    plt.annotate(text=name, xy=centroid, fontsize=8, color='red', ha='center')

plt.savefig("view_extent_Kumasi")

@giswqs
Copy link
Member

giswqs commented Apr 16, 2024

The region should be in the format of [E,S,W,N].

region = [-1.2, 6.4, -1.95, 7.2]

image

@giswqs giswqs closed this as completed Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants