bugra9 / gdal3.js

Convert raster and vector geospatial data to various formats and coordinate systems entirely in the browser.
https://gdal3.js.org
GNU Lesser General Public License v2.1
300 stars 45 forks source link

ogr2ogr: Shapefile outputs multiple files #45

Closed disarticulate closed 7 months ago

disarticulate commented 1 year ago

Everyone hates shapefiles: it generates multiple files: https://gdal.org/drivers/vector/shapefile.html

Currently, only the obvious *.shp file is presented as filePath. It should be generating at least three (four typically) files: .shp, .shx, and .dbf

to allow the ogr2ogr api seems it seems two options:

  1. return an array of filepaths to each file
  2. return a directory (ogr2ogr will use directories if they're passed in; and can output to a folder)

it looks like these files are being generated:

//const files = await gdal.getOutputFiles()
0: {path: '/output/design-features.shp', size: 14500}
1: {path: '/output/design-features.shx', size: 476}
2: {path: '/output/design-features.dbf', size: 1696}
3: {path: '/output/design-features.prj', size: 597}

so a initial work around would be to get output files instead of relying on the return value of ogr2ogr, but that would requiree knowing what these files are in advance (writing a special shaprefile only converter), which is difficult because of https://github.com/bugra9/gdal3.js/issues/44 as processing can't dictate the output filename, so no general purpose function seems reliable

to support shapefiles (or others?), I'd propose returning an array from ogr2ogr if multiple files are created or documenting this behavior and implementing a fix for https://github.com/bugra9/gdal3.js/issues/44

bugra9 commented 7 months ago

Hi @disarticulate,

I added the "all" attribute that lists all generated files in the ogr2ogr, gdal_translate, gdalwarp and gdal_rasterize outputs. https://gdal3.js.org/docs/TypeDefs.html#.FilePath

Will it work?