calvinmetcalf / shapefile-js

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

problem when parsing shp file with mutiple polygon #219

Closed 850036165 closed 2 weeks ago

850036165 commented 3 weeks ago

when i parse a shp.zip file, if the file contant only one Polygon , i works good. but when the file looks like this, the data can't parse properly, it seems the data be parsed as MultiPolygon and the coords are lose.

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "coordinates": [
          [
            [
              95.9992492132618,
              5.248203435064326
            ],
            [
              95.9992492132618,
              -0.8764815860385653
            ],
            [
              104.52356749348485,
              -0.8764815860385653
            ],
            [
              104.52356749348485,
              5.248203435064326
            ],
            [
              95.9992492132618,
              5.248203435064326
            ]
          ]
        ],
        "type": "Polygon"
      }
    },
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "coordinates": [
          [
            [
              106.62599661671214,
              4.61735908288729
            ],
            [
              106.62599661671214,
              -0.674913025566596
            ],
            [
              111.4681807849588,
              -0.674913025566596
            ],
            [
              111.4681807849588,
              4.61735908288729
            ],
            [
              106.62599661671214,
              4.61735908288729
            ]
          ]
        ],
        "type": "Polygon"
      }
    }
  ]
}
{
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "geometry": {
                "bbox": [
                    95.9992492132618,
                    -0.8764815860385654,
                    111.4681807849588,
                    5.248203435064326
                ],
                "type": "MultiPolygon",
                "coordinates": []
            },
            "properties": {
                "stroke": "#243cd8",
                "stroke-width": 2,
                "stroke-opacity": 1,
                "fill": "#5370d8",
                "fill-opacity": 0.5,
                "name": "upload area"
            }
        }
    ],
    "fileName": "layers/POLYGON"
}
calvinmetcalf commented 2 weeks ago

can you share the shapefile you are having trouble parsing?

850036165 commented 2 weeks ago

thanks @calvinmetcalf ,i think it might be the problems of the shape file. 1, got this file in https://geojson.io/ , i draw 2 polygon and save as a ziped shapefile 2, use shp.js to parse it ,failed. 3, tried to open it in the https://mapshaper.org/ , it can be open 4, tried to open it in arcgis, failed. 5, looks like it is the problem of the file not the shp.js

image
calvinmetcalf commented 2 weeks ago

mapbox/geojson.io#847 looks to be the issue