1

I want to make a feature in a react.js web application where I can export/download shapefiles from the dashboard. I have implemented shp-write which takes a GeoJSON input. It is working fine with textual data. I would like to add 3 attributes which should contain an image in the shapefile. I have saved the required Image in my local storage. There is no JavaScript NPM module to do so

My implementation

var shpwrite = require('shp-write');
var options = {
    folder: 'myshapes',
    types: {
        point: 'mypoints',
        polygon: 'mypolygons',
        line: 'mylines'
    }
}
// a GeoJSON input for features
shpwrite.download({
    type: 'FeatureCollection',
    features: [
        {
            type: 'Feature',
            geometry: {
                type: 'Point',
                coordinates: [0, 0]
            },
            properties: {
                name: 'Foo',
                image: 'C:\Users\DELL1\Downloads\Survey.png'
            }
        },
        {
            type: 'Feature',
            geometry: {
                type: 'Point',
                coordinates: [0, 10]
            },
            properties: {
                name: 'Bar',
                image: 'C:\Users\DELL1\Downloads\Survey.png' 

            }
        }
    ]
}, options);

The Current output has image path as a text type field. It doesn't contain image. Current result

My Expected output should contain the image itself. Expected output

What approach can I use in JavaScript to achieve this result.

  • You may have a problem finding a library, for example GDAL doesn't support writing binary field types ~ gdal.org/drivers/vector/shapefile.html. Wondering too, if you want to write a lot of images ,whether you'd hit an issue over shapefile size limit. Perhaps writing to GeoPackage might be better option – nmtoken Sep 17 at 9:51
  • Can you provide an example which shows working with exporting GeoPackage or shapefile(Ignoring shapefile size limit limitation) in javascript? Any source link will be a great help. – Simhadri Akaash Sep 17 at 10:01
  • 1
    dBase III+ doesn't support inline binary data, just the memo field, which isn't supported by shapefiles. Including a path in a 254-character limited string field is the best you can do, format-wise. It still shouldn't be difficult to add an image tag to the HTML. – Vince Sep 17 at 10:57
  • Thanks for the response. But I would like to view the image in any GIS software like ArcGIS, Qgis instead of a webpage. And this shapefile needs to be distributed easily along with the images. I suppose adding the path in a string field won't work. – Simhadri Akaash Sep 18 at 5:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.