Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polygons not supported #66

Open
naveenjaiswal opened this issue Mar 25, 2018 · 6 comments · Fixed by cyclomedia/shp-write#1
Open

Polygons not supported #66

naveenjaiswal opened this issue Mar 25, 2018 · 6 comments · Fixed by cyclomedia/shp-write#1

Comments

@naveenjaiswal
Copy link

For a Geojson file which contains 4 features , it converts eveything as a multipolygon instead of 4 feature each contains polygon. Do i miss any settings or config or its a bug.Please let me know how can i achieve this.

@maxel-inc
Copy link

Same problem

@vishyapps
Copy link

Had the same problem. I changed the script to work for my specific requirement - separate shapeFiles for each polygon in a FeatureCollection (geoJson). The shapeFiles are to be named using properties.fileName of each feature in the geoJson.

Change made in code corresponding to zip.js

if(l.type === "POLYGON" && l.properties.length > 1 && l.properties.length == l.geometries[0].length)
          {
            for(var i=0; i<l.properties.length; i++){
              var myProps = [l.properties[i]];
              var myGeoms = [[l.geometries[0][i]]];
              write(
                // field definitions
                myProps,
                // geometry type
                l.type,
                // geometries
                myGeoms,
                function(err, files) {
                    var fileName = myProps[0].fileName;//custom filename in each feature's properties
                    //var fileName = options && options.types[l.type.toLowerCase()] ? options.types[l.type.toLowerCase()] : l.type;
                    layers.file(fileName + '.shp', files.shp.buffer, { binary: true });
                    layers.file(fileName + '.shx', files.shx.buffer, { binary: true });
                    layers.file(fileName + '.dbf', files.dbf.buffer, { binary: true });
                    layers.file(fileName + '.prj', prj);
              });
            }
          }

@vishyapps
Copy link

Another requirement is to get all polygons as individual records in a single shape file.
I made the following changes to get this:

  1. pass l.geometries[0] to the write function (instead of l.geometries).
  2. pass [[coordinates]] to parts function in poly.js( instead of [coordinates] - note two enveloping arrays)

Tested the generated shape files on mapshaper.org. They worked fine without errors.
I'm no expert at this, but if any one is interested, I'd be happy to discuss.

@ionara
Copy link

ionara commented May 31, 2018

I created a loop to create the object list for features. It works for multiple records (in this case polygons) and it works fine for polygons with donuts

            var objectlist = []
                for (i = 0; i < myFeatureLayer.getSelectedFeatures().length; i++) {
                    var gra = new Graphic()
                    gra = myFeatureLayer.getSelectedFeatures()[i]
                    var geographicGeometry = webMercatorUtils.webMercatorToGeographic(gra.geometry);
                    properties = gra.attributes
                    var poly = new Polygon(geographicGeometry)
                    polyrings = poly.rings
                    var singleobject = {}
                    var singlegeometry = {}
                    singlegeometry['type'] = "Polygon"
                    singlegeometry['coordinates'] = [[[polyrings]]]
                    singleobject ['type'] = 'Feature';
                    singleobject['geometry'] = singlegeometry
                    singleobject['properties'] = properties
                    objectlist.push(singleobject)
                }

                shpwrite.download({
                    type: 'FeatureCollection',
                    features: objectlist
                }, options);

@Renaud009
Copy link

Is there any way to archeive creating a single shapefile containing multiple polygons instead of a single multipolygon? Any help will be appreciated.

@newmanw
Copy link

newmanw commented Oct 26, 2018

I believe #65 will fix your problem. Hoping this will be accepted and released.

jmmluna added a commit to jmmluna/shp-write that referenced this issue Jun 14, 2019
Solved issue mapbox#66 (mapbox#66), and customizable zip filename.
jessyst added a commit to jessyst/shp-write that referenced this issue Nov 5, 2019
Added fix mapbox#66, enhanced calculation of shplength and index for z-point
This was referenced Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants