Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polygonize & Output shapefile not working. #249

Open
james-berry opened this issue Nov 19, 2018 · 2 comments
Open

Polygonize & Output shapefile not working. #249

james-berry opened this issue Nov 19, 2018 · 2 comments

Comments

@james-berry
Copy link

james-berry commented Nov 19, 2018

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

@brandonreavis
Copy link
Member

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?

@MrSampii
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants