ronnyhdez / reclaimed_sites_ab

https://ronnyhdez.github.io/reclaimed_sites_ab/
0 stars 0 forks source link

Exporting asset with negative buffer returns an error #114

Closed ronnyhdez closed 2 months ago

ronnyhdez commented 2 months ago

Error: Unable to export features with empty geometry. (Error code: 3)

Something happens with the negative buffer that I can't establish the new geometry.

Nonetheless, when checking some characteristics, I get basically the same results from the original asset and the negative buffer one:

Feature collection size: 81609
Dilated abandoned wells size: 81609
Collection bounds: {'geodesic': False, 'type': 'Polygon', 'coordinates': [[[-119.9997149059532, 48.997530594452044], [-110.00502850665308, 48.997530594452044], [-110.00502850665308, 59.98992565497423], [-119.9997149059532, 59.98992565497423], [-119.9997149059532, 48.997530594452044]]]}
Dilated abandoned wells bounds: {'geodesic': False, 'type': 'Polygon', 'coordinates': [[[-119.99922291476737, 48.99781344938099], [-110.00546871639538, 48.99781344938099], [-110.00546871639538, 59.989654557557216], [-119.99922291476737, 59.989654557557216], [-119.99922291476737, 48.99781344938099]]]}
ronnyhdez commented 2 months ago

Another guess is that some features are returning no values in geometries after the negative buffer, such as this cases:

image

This is not whats happening because they were filtered out by dates in the firs filters

ronnyhdez commented 2 months ago

Also, checking what's happening in GEE console, when I print the original sampled feature collection, in geometries I have:

image

In the dilated feature collection:

image

The coordinates list have 2 elements

ronnyhdez commented 2 months ago

But with the python API this doesn't seem to happen.

ronnyhdez commented 2 months ago

Using just one test case, I got the following:

var smallPolygon = ee.Geometry.Polygon([
  [
    [-122.263, 37.872],
    [-122.263, 37.873],
    [-122.262, 37.873],
    [-122.262, 37.872],
    [-122.263, 37.872]
  ]
]);

// Create a feature collection from this polygon
var featureCollection = ee.FeatureCollection([ee.Feature(smallPolygon)]);

var applyInwardBuffer = function(feature) {
  var bufferedFeature = feature.buffer(-30, 1);
  return bufferedFeature;
};

var bufferedCollection = featureCollection.map(applyInwardBuffer);

print(bufferedCollection);

Map.addLayer(featureCollection, {color: 'blue'}, 'Original FeatureCollection');
Map.addLayer(bufferedCollection, {color: 'red'}, 'Buffered FeatureCollection');

var check = bufferedCollection.geometry().coordinates().size()

print(check)

image

If I expand the negative buffer to -300, I will obtain the following:

image

So, probably to solve the error of empty geometries, I can use the size to filter out those.

ronnyhdez commented 2 months ago

In the notebook, I use the following to flag which polygons ended up with no coordinates after the negative buffer:

def check_empty_coordinates(feature):
    coordinates = feature.geometry().coordinates()
    is_empty = coordinates.size().eq(0)
    return feature.set('empty_buffer', is_empty)

check_empty_dilated = dilated_abandoned_wells.map(check_empty_coordinates)
results = check_empty_dilated.limit(2).getInfo()
print(json.dumps(results, indent = 2))

After that, I was able to filter and check a couple of those:

run_filter = check_empty_dilated.filter(ee.Filter.eq('empty_buffer', 1))
# total = run_filter.size()
# print(total) 
results = run_filter.limit(2).getInfo()
print(json.dumps(results, indent = 2))

That one worked!

ronnyhdez commented 2 months ago

Finally, with those filtering steps to avoid empty geometries, I can create the asset in GEE

image

ronnyhdez commented 2 months ago

Well, I had to join the v2 asset with the pixel count and it works:

// Check newly created merged asset to compare with v2
var v2 = ee.FeatureCollection("projects/ee-ronnyale/assets/intersecting_wells_flags_v2");
var merged = ee.FeatureCollection("projects/ee-ronnyale/assets/intersecting_wells_flags_v3_with_pixel_count_join");

Map.centerObject(v2, 10);
Map.addLayer(v2, {color: 'blue'}, 'Original FeatureCollection');
Map.addLayer(merged, {color: 'red'}, 'Buffered FeatureCollection');

image

ronnyhdez commented 2 months ago

Ref #117