mapbox / shp-write

create and write to shapefiles in pure javascript
BSD 3-Clause "New" or "Revised" License
290 stars 186 forks source link

two LineString will happen [Mismatched .dbf and .shp record count -- possible data loss.] in mapshaper.org #110

Closed HNQX closed 8 months ago

HNQX commented 8 months ago

This is a strange thing that i happened to find out: when there is more than one LineString Feature in geojson, after generating from shpWrite.zip(geojson,option), the mapshaper.org will notice [Mismatched .dbf and .shp record count -- possible data loss.] and muntip Polygon and Point wouldn't

The result will be ok If you delete the second LineString in the geojson and last only one. But two, will not

Can this can be solved?

const geojson = {
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "geometry": {
                "type": "Point",
                "coordinates": [102.0, 0.5]
            },
            "properties": {
                "prop0": "value0"
            }
        },
        {
            "type": "Feature",
            "geometry": {
                "type": "LineString",
                "coordinates": [
                    [102.0, 0.0],
                    [103.0, 1.0],
                    [104.0, 0.0],
                    [105.0, 1.0]
                ]
            },
            "properties": {
                "prop0": "value0",
                "prop1": 0.0
            }
        },
        {
            "type": "Feature",
            "geometry": {
                "type": "LineString",
                "coordinates": [
                    [102.0, 1.0],
                    [103.0, 2.0],
                    [104.0, 1.0],
                    [105.0, 2.0]
                ]
            },
            "properties": {
                "prop0": "value0",
                "prop1": 0.0
            }
        }, {
            "type": "Feature",
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [100.0, 1.0],
                        [101.0, 2.0],
                        [101.0, 2.0],
                        [100.0, 2.0],
                        [100.0, 1.0]
                    ]
                ]
            },
            "properties": {
                "prop0": "value0",
                "prop1": {
                    "this": "that"
                }
            }
        }, {
            "type": "Feature",
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [100.0, 0.0],
                        [101.0, 0.0],
                        [101.0, 1.0],
                        [100.0, 1.0],
                        [100.0, 0.0]
                    ]
                ]
            },
            "properties": {
                "prop0": "value0",
                "prop1": {
                    "this": "that"
                }
            }
        }]
}

const options = { folder: "my_folder", filename: "zip_name", outputType: "blob", compression: "DEFLATE", types: { point: "mypoints", polygon: "mypolygons", polyline: "mylines", } }
const zipData = shpwrite.zip(geojson, options)
zipData.then(r => {
    let url = window.URL.createObjectURL(r)
    let a = document.createElement("a")
    a.style.display = "none"
    a.href = url
    a.download = "shapefile"
    document.body.appendChild(a)
    a.click()
    document.body.removeChild(a)
    window.URL.revokeObjectURL(url)
})

image

abrman commented 7 months ago

@HNQX How did you resolve this? I'm facing the same problem while importing into an AutoCAD application :(

2023-11-10 13_01_36-AutoCAD Map Warning