calvinmetcalf / shapefile-js

Convert a Shapefile to GeoJSON. Not many caveats.
http://calvinmetcalf.github.io/shapefile-js/
MIT License
735 stars 230 forks source link

Generate geoJSON object from .shp file #43

Closed migelct1983 closed 7 years ago

migelct1983 commented 9 years ago

Is it possible to generate the geoJSON object from the .shp file?

I think currently it's only possible to generate an array of geometries from the .shp file using: shp.parseShp(). It would be helpful to have a method that return the geoJSON object directly. It could be similar to the combine function but the .dbf file shouldn't be mandatory.

shp.combine = function(arr) {
    var out = {};
    out.type = 'FeatureCollection';
    out.features = [];
    var i = 0;
    var len = arr[0].length;
    while (i < len) {
        out.features.push({
            'type': 'Feature',
            'geometry': arr[0][i],
//          'properties': arr[1][i] <- it shouldn't be mandatory
        });
        i++;
    }
    return out;
};
calvinmetcalf commented 9 years ago

can't you just take the array of geometries and turn that into your quasi geojson feature collection yourself ?

sidloki commented 8 years ago

You can use an empty array: shp.combine([shp.parseShp(shpBuffer), []]);