Below, I have clipped the same region from 2 google earth images. However, the two clips are at different projections (the crs
argument in reproject
determines the projection). The reason I am reprojecting is to decrease the resolution of the images, via the scale
argument, so that they can be imported with sampleRectangle
. How would I clip the images at the same projection such that they overlap?
import ee
import matplotlib.pyplot as plt
from matplotlib.pyplot import imshow
import numpy as np
# Load images
pH = ee.Image("OpenLandMap/SOL/SOL_PH-H2O_USDA-4C1A2A_M/v02")
AAFC = ee.ImageCollection('AAFC/ACI')
AAFC = AAFC.filter(ee.Filter.date('2016-01-01', '2016-12-31')).first()
# Get geometry/polygon of interest
geometry = CAR.getInfo()['features'][15]['geometry']['coordinates']
region = ee.Geometry.Polygon(geometry)
# Clip AAFC and plot
AAFC_crs = AAFC.clip(region).projection().wkt()
AAFC_region = AAFC.clip(region)
AAFC_region = AAFC_region.resample('bilinear').reproject(crs=AAFC_crs, scale=1000)
AAFC_img = AAFC_region.sampleRectangle(defaultValue=0)
AAFC_img = np.array(AAFC_img.getInfo()['properties']['landcover'])
AAFC_img = AAFC_img.reshape(len(AAFC_img), -1)
plt.imshow(AAFC_img)
plt.colorbar()
plt.show()
# Clip pH and plot
pH_crs = pH.clip(region).projection().wkt()
pH_region = pH.clip(region)
pH_region = pH_region.resample('bilinear').reproject(crs=pH_crs, scale=1000)
pH_img = pH_region.sampleRectangle(defaultValue=0)
pH_img = np.array(pH_img.getInfo()['properties']['b30'])
pH_img = pH_img.reshape(len(pH_img), -1)
plt.imshow(pH_img)
plt.colorbar()
plt.show()