1

I want to calculate protected areas in a region. My procedure was to convert the WDPA data set into an image and then calculate the area using the reducer.sum function. My problem is that my pixel value from Germany_PA is: constant: 0, so I could not use the reducer.sum function.

Is there a way to change the pixelvalue or is there another function to calculate the area?

Here is my code:

Map.setCenter(11.57, 50.88, 5);

var dataset = ee.FeatureCollection('WCMC/WDPA/current/polygons');
// WDPA Polygone filter
var target_values = ee.Filter.inList('DESIG', [ 'Nationalpark' ]);
  
var Nationalpark = dataset.filter(ee.Filter.and(
  (target_values),
  ee.Filter.eq('MARINE', '0')))
  
var gaul = ee.FeatureCollection("FAO/GAUL_SIMPLIFIED_500m/2015/level1")
var Germany = gaul.filter(
  ee.Filter.eq('ADM0_NAME', 'Germany'))
  
var PA = ee.Image().float().paint(Nationalpark)

// Nationalpark in Germany
var Germany_PA = PA.clip(Germany)

Map.addLayer(Germany_PA,{palette: ['00FF00']} , 'Germany_PA')

1 Answer 1

0

It doesn't matter. Calculation of ee.Image.pixelArea() can be forced to consider only the masked area with value equal 0 by using 'mask(ee.Image(PA).eq(0)' method. An example looks as follows:

var area = ee.Image.pixelArea().mask(ee.Image(PA).eq(0)).reduceRegion({
    reducer: ee.Reducer.sum(),
    geometry: Nationalpark_GE,
    scale: 500,
    maxPixels: 1e13
    
});

Modifying your code for also including Germany area calculation (for comparison purpose) I got:

Map.setCenter(11.57, 50.88, 5);

var dataset = ee.FeatureCollection('WCMC/WDPA/current/polygons');

// WDPA Polygone filter
var target_values = ee.Filter.inList('DESIG', [ 'Nationalpark' ]);
  
var Nationalpark = dataset.filter(ee.Filter.and(
  (target_values),
  ee.Filter.eq('MARINE', '0')));
  
print("Nationalpark", Nationalpark);

var gaul = ee.FeatureCollection("FAO/GAUL_SIMPLIFIED_500m/2015/level1");

var Germany = gaul.filter(
  ee.Filter.eq('ADM0_NAME', 'Germany'));

var Nationalpark_GE = ee.FeatureCollection(Nationalpark).filterBounds(Germany);

print("Nationalpark_GE", Nationalpark_GE);
  
var PA = ee.Image().float().paint(Nationalpark);

// Nationalpark in Germany
var Germany_PA = ee.Image(PA).clip(Germany);

var area = ee.Image.pixelArea().reduceRegion({
    reducer: ee.Reducer.sum(),
    geometry: Germany,
    scale: 500,
    maxPixels: 1e13
    
});

print("Germany Area", area.get('area'));

var area = ee.Image.pixelArea().mask(ee.Image(PA).eq(0)).reduceRegion({
    reducer: ee.Reducer.sum(),
    geometry: Nationalpark_GE,
    scale: 500,
    maxPixels: 1e13
    
});

print("National Parks Germany Area", area.get('area'));

Map.addLayer(Germany_PA, {palette: ['red']} , 'Germany_PA');
Map.addLayer(Nationalpark_GE, {color: 'blue'} , 'Nationalpark_GE');

Running above lines in GEE code editor, I got the result of following picture where the area of the parks (blue color) is considerably smaller than that of Germany.

enter image description here

2
  • Thank you so much fo help!! :) Is there a particular reason that you chose a scale of 500? Jun 30 at 12:28
  • You're welcome. On the other hand, there isn't any particular reason for choosing that scale. I used it only for speed up the calculation. You can choose your own scale.
    – xunilk
    Jun 30 at 14:19

Your Answer

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

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