google / Xee

An Xarray extension for Google Earth Engine
Apache License 2.0
240 stars 28 forks source link

Convert value outside of ee.Image boundary to NaN. #140

Closed dabhicusp closed 6 months ago

dabhicusp commented 6 months ago

Fixed: #131.

As mentioned in the #131, the current code returns 0 values for the external boundary of the clipped region. However, this is incorrect, and therefore, these values should be converted to the NaN values.

Approach: Create a global image with a constant value, and then blend this image with the actual image, ensuring that the original image data is preserved in the final image.

dabhicusp commented 6 months ago

The last 2 commit based on the below examples:

Ex:

point = ee.Geometry.Point(-40.2414893624401 ,105.48790177216375 )
distance = 311.5
scale = 5000
projection = ee.Projection("EPSG:4326", [1, 0, 0, 0, -1, 0]).atScale(scale)

geometry = point.buffer(distance, proj=projection).bounds(proj=projection)
geometry.getInfo()

Output:

{'geodesic': False,
 'crs': {'type': 'name', 'properties': {'name': 'EPSG:4326'}},
 'type': 'Polygon',
 'coordinates': [[[-54.232749912601655, 91.49664122200221],
   [-26.250228812278554, 91.49664122200221],
   [-26.250228812278554, 119.47916232232531],
   [-54.232749912601655, 119.47916232232531],
   [-54.232749912601655, 91.49664122200221]]]}

2.) geometry.bounds().getInfo()

{'geodesic': False,
 'type': 'Polygon',
 'coordinates': [[[-54.232749912601655, 91.49664122200221],
   [-26.250228812278554, 91.49664122200221],
   [-26.250228812278554, 91.49664122200221],
   [-54.232749912601655, 91.49664122200221],
   [-54.232749912601655, 91.49664122200221]]]}

So geometry.bounds() is not working properly on the above examples so I updated it with only geometry.