I’m currently trying to crop out areas of a GeoTiff that contain points from a shp file I have. I’m finding however that a spatial ‘contains’ query on the bounds of the GeoTiff actually gives back points outside what I deem to be the bounds of the data.
For example the above image shows that I have points outside of the SAR data and in my code these are also returned, is there a way for to extract only the ‘populated’ areas of a GeoTiff as a polygon?
Sorry if this isn’t the best/right place to ask!
The problem is that the black area is part of your product bounds but has no data.
As the black area has a constant fill value I can imagine two things you can do.
Filter you exported data afterwards for occurrences of this value and remove those records
Set the fill value as no-data value to the band and also enable the usage of this no-data value.
After wards you can ask band.isPixelValid(x, y)
Is there a certain method which would do this in snappy? If I can fit it into the automated pipeline it’d be handy.
I feel like filtering for black on a greyscale image is kind of dangerous.
Normally the outside area has a dedicated value, outside of the valid value range. Should be mentioned in the product spec.
How to do it is written here:
You can set the valid pixel expression on the band
myBand.setValidPixelExpression(myBand < maxValue && myBand > minValue)
If you want to filter just a single value you can set the no-data value
Note that you have to enable the usage of the no-data value.
So within Python, would this be added as a param such as these:
params = HashMap()
Or is this something separate to these? Will this be persisted when saved as a GeoTiff?
The last parameter ist actually
outputImageScaleInDb and not outImageScaleInDb. At least if you use the “Calibration” operator.
No it is separate from the operator parameters.
If you have the final product and the band you can set:
I thought that you iterate over the pixel manually and export them. Here you can check if the pixel is valid.
For doing pixel extraction there is also the so called PixEx operator. Maybe this one is of any use for you.