node-gdal icon indicating copy to clipboard operation
node-gdal copied to clipboard

Polygonize & Output shapefile not working.

Open james-berry opened this issue 6 years ago • 2 comments

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..

james-berry avatar Nov 19 '18 17:11 james-berry

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?

brandonreavis avatar Nov 21 '18 18:11 brandonreavis

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.

MrSampii avatar Aug 11 '22 09:08 MrSampii