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)


# 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)


enter image description here


You should be able to set a common crs in both reproject() calls. Since I don't know where exactly your study area is you can use a global coordinate reference system like WGS84 with the EPSG Code 4326.

Alternatively you can look up the UTM Zone of your study area and get a more local EPSG code.

# Clip AAFC and plot
AAFC_region = AAFC.clip(region)
AAFC_region = AAFC_region.resample('bilinear').reproject(crs='EPSG:4326', scale=1000)

# Clip pH and plot

pH_region = pH.clip(region)
pH_region = pH_region.resample('bilinear').reproject(crs='EPSG:4326', scale=1000)
  • I actually receive a an error of "EEException: Image.sampleRectangle: Sampling region is unbounded." – PiccolMan May 6 at 15:49
  • Then you should give it a geometry as a sample region, but that's another question not immediately connected to reprojecting. If you have more issues with that you can post another question – JonasV May 6 at 18:45
  • 1
    But just in case, you would do it something like this: pH_region.sampleRectangle(region=geometry, defaultValue=0) – JonasV May 6 at 18:56
  • It worked! Thank you so much @JonasV. – PiccolMan May 6 at 20:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.