GeoTIFF / geoblaze

Blazing Fast JavaScript Raster Processing Engine
http://geoblaze.io
MIT License
181 stars 28 forks source link

Can't get stats within a geojson geometry #210

Closed lukecoursey closed 1 year ago

lukecoursey commented 1 year ago

Hello. I'm having trouble getting any stats back from geoblaze when providing a geojson geometry. I have this problem whatever geoblaze method i'm trying to use (get, mean, stats etc...).

This is my raster result from .parse(arrayBuffer) - works as expected.

{ _blob_is_available: true, _data: ArrayBuffer { byteLength: 129983082 }, _url_is_available: true, _web_worker_is_available: true, height: 4556, maxs: Array(4) [ 253, 253, 253, … ], mins: Array(4) [ 30, 1, 1, … ], noDataValue: null, numberOfRasters: 4, pixelHeight: 25, pixelWidth: 25, projection: 6933, ranges: Array(4) [ 223, 252, 252, … ], rasterType: "geotiff", sourceType: "ArrayBuffer", toCanvas: function toCanvas(e5), values: Array(4) [ (4556) […], (4556) […], (4556) […], … ], width: 7131, xmax: -5999500, xmin: -6177775, ymax: -420875, ymin: -534775 }

If I provide an extent like so const stats = await geoblaze.mean(raster, [-6177775, -534775, -6170000, -530000]);

Then it works fine and I get a value for each of the 4 bands in the raster: [ 74.85047389774583, 168.05213716940793, 109.55458662312083, 255 ]

However if I provide an extent using a geojson polygon const stats = await geoblaze.mean(raster, { "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": {}, "geometry": { "coordinates": [ [ [ -63.275656127929466, -3.968733782247085 ], [ -63.275999450683614, -3.9844886066915137 ], [ -63.25471343994157, -3.985173592221443 ], [ -63.25883331298806, -3.968391282720958 ], [ -63.275656127929466, -3.968733782247085 ] ] ], "type": "Polygon" } } ] });

I get "No Values were found in the given geometry"

And if I instead use turf to bbox the above geojson geometry: const stats = await geoblaze.mean(raster, turf.bbox(geometry));

I get an array of NaN as the output: [ NaN, NaN, NaN, NaN ]

What could be going wrong here? The geometry i'm providing is within the bounds of the raster (they both plot where I expect with mapbox gl, using a raster and polygon layer respectively).

lukecoursey commented 1 year ago

I think this is actually a projection issue, I will confirm if I manage to resolve it

lukecoursey commented 1 year ago

Was being daft. A reprojection using gdalwarp solved my issue