1

I have two layers: one which contains few seperated polygons, and one which has raster which I have uploaded (type feature collection). In addition, I have draw one for test (geometry).

My goal:

I want each polygon to get information based on its' location regard: how many pixels are in its' region that their value is lower than 0.2, between 0.2-0.4 ect.

What I have done: I have used code that I had and tried to do this iteration for each polygon.

The result: when running this with the GEE manual drawn polygon. calculation was done, but I got in the end imagecollection which contains this data in each feature properties. Also when I run this on my geometry (sometimes get error: geometry.geometry is not a function).

Code:

  var c0204 = image.gt(0.2).lt(0.4).selfMask().reduceRegion({
    reducer: ee.Reducer.count(),
    geometry: geometry,
    crs: 'EPSG:4326',
    //maxPixels:1310361348,
    scale: 20,
  }).values().get(0);

This is a link to my code, let me know if the imports are unavilable.

https://code.earthengine.google.com/24f5e8f9ef310b96d632ef89454c00eb

My end goal: To have the count pixels data in table so I can know for each polygon how many pixels were found in each count category. or at least to have it as featurecollection and not as imagecollection

2 Answers 2

1

Use the .and() logical function to find the intersection of two conditionals:

var c0204 = image.gt(0.2).and(image.lt(0.4)).selfMask()
var c0406 = image.gt(0.4).and(image.lt(0.6)).selfMask()
0

It doesn't work as you use 1) different scales (I set every scale to 20m), 2) you expressions for the values in between are wrong.

If you apply this function image.gt(0.2) all pixel values will become 0 (for below 0.2) and 1 (for above 0.2). If you then use .lt(0.4) on that image, all pixels which where 1 from your previous calculations will be 1 again (because 1 is higher than 0.4, off course).

Therefore, use for example this statement:

  image.gt(0.2).add(image.lte(0.4)).eq(2).selfMask()

link code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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