0

I have 2 feature collections. One of the "departamentos" of Argentina, and another of the "provincias".

These are internal political boundaries. The "departamentos" each belong to only one "provincia".

I want to subset the "departamentos" so that I work with only the ones in a "provincia".

When I try to filter them by bounds. The result is the intersection. (which annoyingly always includes the neighbouring departamentos). See the example here.

var departamentos = ee.FeatureCollection("users/JASPR/Geography/AR/Departamentos"),
    provincias = ee.FeatureCollection("users/JASPR/Geography/AR/Provincias");


var myProvincia = provincias.filterMetadata("NAM","equals","Buenos Aires")

print(myProvincia)


// Buffer inwards, so that we don't include departamentos of other
// provinces.

var myProvinciaBN = myProvincia //.geometry().buffer(-10) // Commented so that it works with Buenos Aires.

//print(myProvinciaBN)

var myDepartamentos = departamentos.filterBounds(myProvinciaBN)

myDepartamentos = myDepartamentos.filterMetadata("NAM","not_equals", "Antártida Argentina")

// create empty list to pass as argument to the function
var first = ee.List([])


// Function that receives the feature, and a list of previous info
// returns list to itself through the feature collection.
var getNAM = function (f,list){
  var theName = f.get("NAM")
  return ee.List(list).add(theName)

}


// Create list that is a result of every "NAM" property in the
// feature collection
var allNAM = ee.List(myDepartamentos.iterate(getNAM,first));

print(allNAM)

Map.centerObject(myProvincia)
Map.addLayer(myProvincia)

Map.addLayer(myDepartamentos)

For internal provinces with regular borders, I have solved this by simply buffering the provincia borders inwards by 10M so that they don't intersect with the neighbours. However, this solution doesn't work for any provinces with coastlines, or rivers as borders. (the fractal nature of the buffering makes it fail.)

I have tried to use the ee.Filter.isContained() filter, but have so far failed to find a working example that I can leverage off.

1

Using the center of each departamento would work in this case to find out which departamento is contained in your provincia.

Adding this as a property to each departamento and then filter on that property should work.

Here is how I would do it:

// use the centroid of each department to check if it's inside your province of interest
var inMyProvincia = departamentos.map(function(departamento){
  var center = departamento.centroid();
  var insideMyProvincia = myProvincia.contains(center, 1);
  return departamento.set('containedIn', insideMyProvincia);
});

// filter the departementos on metadata 
var departamentoInProvincia = inMyProvincia.filter(ee.Filter.eq("containedIn", true));

Link to script

  • It worked perfectly. Important to point out that your link works well. Adding your code in the box, doesn't because the result of the line selecting the line at the top of the script needs to be cast to a feature from a feature collection. (as you did in your link). Otherwise it won't work. – Sean Roulet Jan 9 at 19:28
  • Would you know how to modify it so that a departamento is included if the majority of its area is in the provincia? If you look at the Province of Chaco, it has a departamento whose centroid is in the neighbouring province.... – Sean Roulet Jan 9 at 20:09
  • Yes I was afraid the center could cause some problems with some departementos. I also tried something with buffer and intersects/intersection, but computation timed out easily. I would recommend to export the table of departementos to your asset with a property attached in which province the departemento is using centroid and then manually name the few departementos which have are wrongly named. Or maybe easier, ask the data provider to attach a property to each department naming the province? – Kuik Jan 10 at 9:45
  • I believe manually changing the ones that are problematic will probably be the better and faster solution. The list is short. (So far only 1). Thanks. – Sean Roulet Jan 10 at 13:06

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.