node-gdal
node-gdal copied to clipboard
Polygonize & Output shapefile not working.
Hi, when polygonize function finished it updates the empty shapefile in the same directory but doesnt add any features to the file.
const gdal = require("gdal");
const tif = gdal.open("raster.tif")
const tifBands = tif.bands;
let tifBandLayer
tifBands.forEach(layer => {
tifBandLayer = layer
});
const shapefile = gdal.open('empty_shapefile.shp', 'r+')
const shapefileLayers = shape.layers
let shapefileLayerDatasetLayers
shapefileLayers.forEach(element => {
shapefileLayerDatasetLayers = element
});
gdal.polygonize({
src: tifBandLayer,
dst: shapefileLayerDatasetLayers,
pixValField: 0,
useFloats: true,
})
Any assistance is muchly apprieicated, documentation is pretty lacking..
The tests are a good place to search for examples: https://github.com/naturalatlas/node-gdal/blob/master/test/api_algorithms.test.js#L194.
If empty_shapefile.shp
is a shapefile with an existing polygon layer, I think the main issue is that you're not closing the dataset so the changes are not getting flushed when the process exits. Does adding shapefile.close()
at the end fix the problem?
In addition to @brandonreavis answer, i would like to add that you have misspelling errors when accesing your shapefile.
const shapefile = gdal.open('empty_shapefile.shp', 'r+') const shapefileLayers = shapefile.layers
See https://mmomtchev.github.io/node-gdal-async/#contouroptions as an alternative fork, which it is currently mantained.