0

I have a featureCollection of pixels (called "Pixel_values")from using sampleRegions and a feature collection of lineStrings (called "Hydro"), some of which intersect the pixels. I want to add a column/property to "Pixel_values" that returns true or false for if a pixel intersects with "Hydro". Every time I've succesfully exported a csv, every pixel returns a "FALSE" value.

Here is the code for generating "Pixel_values":

// REGION
var region = ee.FeatureCollection([
    ee.Feature(geometry2, {id: 1, Dam: 'no'}),
    ee.Feature(geometry3, {id: 2, Dam: 'yes'}),
    ee.Feature(geometry4, {id: 3, Dam: 'no'}),
    ee.Feature(geometry5, {id: 4, Dam: 'yes'}),
    ee.Feature(geometry6, {id: 5, Dam: 'yes'})
]);

// NAIP

var NAIP_add_NDVI_NDWI = function(image) {
    var ndvi = image.normalizedDifference(['N','R']).rename('NDVI_N');
    var ndwi = image.normalizedDifference(['G', 'N']).rename('NDWI_N');
return image.addBands(ndvi).addBands(ndwi)
};

var NAIP_Filter = NAIP.filterDate(startDate,endDate).filterBounds(region);

// apply ndvi to NAIP collection
var NAIP_Indices = NAIP_Filter.map(NAIP_add_NDVI_NDWI);
var NAIP_NDVI_NDWI = NAIP_Indices.select('NDVI_N')
var NAIP_IndicesClipped = NAIP_NDVI_NDWI.mean().clip(region);


// Generate pixel values of NDVI
var Pixel_values = NAIP_IndicesClipped.sampleRegions({
    collection: region, // area to take pixel values from
    properties: ['id','Dam'], // what properties to retain from area
    scale: 6 // how many pixels .6 is highest resolution
});

I then used the intersect function, and tried with multiple types of data to represent the hydrology that intersects the pixels. First, I imported a shapefile of a featureCollection of lineString. Then, I drew a line geometry that intersects the points. It didn't work for either.

// Define a function to check if a feature overlaps with any feature in the river collection
var checkIntersection = function(feature) {
    var Intersect_check = feature
        .geometry()
        .intersects(Hydro.geometry(), ee.ErrorMargin(1));
return feature.set('Intersects', Intersect_check);
};

// Map the checkIntersection function over the region feature collection

var Intersect_practice = Pixel_values.map(checkIntersection);

// // Export the data to a CSV file

Export.table.toDrive({
description: "Add_Intersect_Feature_Test6",
collection: regionWithOverlap,
fileFormat: "CSV",
folder: "Pixel_test",
fileNamePrefix: "Add_Intersect_Feature_Test6" 
}); 

Finally, I tried to run a union on "Hydro" to make it a single feature, but that didn't work.

Here is the link to the Hydrology data (Streams Chapter 93 Designated Use) used: https://www.pasda.psu.edu/uci/SearchResults.aspx?Keyword=streams

1 Answer 1

1

Once you've extracted pixels to a table, they're no longer represented by an area, but by an infinitely small point location. In order to test intersection against the original area, you will have to either:

  • buffer+bounds the point geometry to turn it back into a rectangular area before testing the intersection,

or, if you can, it'd be better to

  • paint the lines into a raster before you sample and just sample that raster too.
2
  • Thank you Noel. Are you familiar with a process for the painting? I've attempted buffering an area around each point, but it doesn't seem to create a new feature (doesn't appear when I map it.
    – Hutch T
    Commented Apr 25, 2023 at 19:37
  • Something like: ee.Image().paint(collection, 0) Commented Apr 26, 2023 at 15:45

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.