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

[ZIP] Missing Features when exporting FeatureCollection of Feature<Polygon> and Feature<MultiPolygon> #121

Open
juliolopeztorres opened this issue Mar 19, 2024 · 1 comment

Comments

@juliolopeztorres
Copy link

Hi there!

First of all, thank you for your library and for sharing the code. I am trying to export a given geojson coming from Turf JS in to a Shapefile project as a zip.

I am facing a problem when comparing results in QGis. The thing is that, as far as I can see in the code, POLYGON and MULTIPOLYGON collapse to the same Type, so the final file per type written into the temporary zip object shares its name (path), overwriting its content if some other file would have been generated previously with the same type (i. e.: Polygon and MultiPolygon).

An example of a geojson I am plugging in to the zip() method:

GeoJson example
{
  "type": "FeatureCollection",
    "features": [
    {
      "type": "Feature",
      "properties": {
        "region": "Europe",
      },
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              -5.25705141,
              35.964
            ],
            [
              -5.25,
              35.964
            ],
            [
              -5.25,
              36.02001499
            ],
            [
              -5.25705141,
              36.018782780352815
            ],
            [
              -5.25705141,
              35.964
            ]
          ]
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {
        "region": "Europe",
      },
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              -5.32906581,
              35.89872500745445
            ],
            [
              -5.3283905,
              35.89872015
            ],
            [
              -5.32839013,
              35.89871978
            ],
            [
              -5.32752954,
              35.89788818
            ],
            [
              -5.3267498,
              35.89788818
            ],
            [
              -5.32674976,
              35.89788815
            ],
            [
              -5.32674951,
              35.89788815
            ],
            [
              -5.32632062,
              35.89749971
            ],
            [
              -5.32589023,
              35.89711014
            ],
            [
              -5.32561911,
              35.89710003
            ],
            [
              -5.32505989,
              35.89707947
            ],
            [
              -5.32505957,
              35.89707915
            ],
            [
              -5.3250595,
              35.89707915
            ],
            [
              -5.32491102,
              35.89693043
            ],
            [
              -5.3238101,
              35.89582825
            ],
            [
              -5.32378006,
              35.89496994
            ],
            [
              -5.32211018,
              35.89336014
            ],
            [
              -5.32215371,
              35.89289092
            ],
            [
              -5.3221895,
              35.89250215
            ],
            [
              -5.32178242,
              35.89216103
            ],
            [
              -5.3217204,
              35.89210915
            ],
            [
              -5.32092496,
              35.8920943
            ],
            [
              -5.32005978,
              35.8920784
            ],
            [
              -5.32005954,
              35.89207815
            ],
            [
              -5.3200595,
              35.89207815
            ],
            [
              -5.319985811834431,
              35.892
            ],
            [
              -5.315118920724042,
              35.892
            ],
            [
              -5.3150605,
              35.89205915
            ],
            [
              -5.31506031,
              35.89205915
            ],
            [
              -5.31506014,
              35.89205933
            ],
            [
              -5.31166983,
              35.89205933
            ],
            [
              -5.31002998,
              35.89374924
            ],
            [
              -5.30991324,
              35.893745
            ],
            [
              -5.3091895,
              35.89371915
            ],
            [
              -5.3079705,
              35.89500015
            ],
            [
              -5.3079705,
              35.89580915
            ],
            [
              -5.30743964,
              35.89634808
            ],
            [
              -5.30671978,
              35.89707947
            ],
            [
              -5.3062013,
              35.89709926
            ],
            [
              -5.3059205,
              35.89711015
            ],
            [
              -5.30460978,
              35.8983309
            ],
            [
              -5.30463982,
              35.90164185
            ],
            [
              -5.3046395,
              35.90164215
            ],
            [
              -5.30332994,
              35.90291977
            ],
            [
              -5.30332989,
              35.90291977
            ],
            [
              -5.3033295,
              35.90292015
            ],
            [
              -5.30270023,
              35.90289482
            ],
            [
              -5.30255985,
              35.90288925
            ],
            [
              -5.30085993,
              35.90457916
            ],
            [
              -5.3000005,
              35.90457916
            ],
            [
              -5.2991905,
              35.90541815
            ],
            [
              -5.29919028,
              35.90541815
            ],
            [
              -5.29919004,
              35.9054184
            ],
            [
              -5.29750037,
              35.90544128
            ],
            [
              -5.29713854,
              35.90579353
            ],
            [
              -5.29666996,
              35.90625
            ],
            [
              -5.29666966,
              35.90624999
            ],
            [
              -5.2966695,
              35.90625015
            ],
            [
              -5.29615852,
              35.90624031
            ],
            [
              -5.29506015,
              35.90621948
            ],
            [
              -5.2941695,
              35.90705915
            ],
            [
              -5.29240879,
              35.90709436
            ],
            [
              -5.29171991,
              35.90710831
            ],
            [
              -5.29171977,
              35.90710814
            ],
            [
              -5.29171951,
              35.90710815
            ],
            [
              -5.2909395,
              35.90625015
            ],
            [
              -5.29038709,
              35.90624019
            ],
            [
              -5.28921986,
              35.90621948
            ],
            [
              -5.28921952,
              35.90621915
            ],
            [
              -5.28874029,
              35.90573954
            ],
            [
              -5.28800011,
              35.90499878
            ],
            [
              -5.28797007,
              35.90419006
            ],
            [
              -5.28716939,
              35.90341601
            ],
            [
              -5.2871095,
              35.90335815
            ],
            [
              -5.2871395,
              35.90250015
            ],
            [
              -5.28696236,
              35.90232695
            ],
            [
              -5.28669023,
              35.90206146
            ],
            [
              -5.28255987,
              35.90206146
            ],
            [
              -5.2825595,
              35.90206115
            ],
            [
              -5.2825543,
              35.9020566
            ],
            [
              -5.28211021,
              35.90166855
            ],
            [
              -5.28211021,
              35.89916992
            ],
            [
              -5.2829395,
              35.8983311
            ],
            [
              -5.2829195,
              35.89746815
            ],
            [
              -5.28463951,
              35.89582815
            ],
            [
              -5.2846695,
              35.89497015
            ],
            [
              -5.2850795,
              35.89458115
            ],
            [
              -5.28507963,
              35.89458115
            ],
            [
              -5.28507996,
              35.89458084
            ],
            [
              -5.28755981,
              35.89458084
            ],
            [
              -5.29014065774866,
              35.892
            ],
            [
              -5.25705141,
              35.892
            ],
            [
              -5.25705141,
              35.964
            ],
            [
              -5.32906581,
              35.964
            ],
            [
              -5.32906581,
              35.89872500745445
            ]
          ]
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {
        "region": "Europe",
      },
      "geometry": {
        "type": "MultiPolygon",
        "coordinates": [
          [
            [
              [
                -5.32906581,
                35.84148820946186
              ],
              [
                -5.3233965,
                35.84125315
              ],
              [
                -5.3079765,
                35.83853015
              ],
              [
                -5.2923065,
                35.83543815
              ],
              [
                -5.2869755,
                35.83187215
              ],
              [
                -5.2756285,
                35.82661915
              ],
              [
                -5.2727085,
                35.82515815
              ],
              [
                -5.263613494906775,
                35.82
              ],
              [
                -5.25705141,
                35.82
              ],
              [
                -5.25705141,
                35.892
              ],
              [
                -5.29014065774866,
                35.892
              ],
              [
                -5.29089051,
                35.89125015
              ],
              [
                -5.2923741,
                35.89122381
              ],
              [
                -5.29258013,
                35.89122009
              ],
              [
                -5.29317058,
                35.8906568
              ],
              [
                -5.29341951,
                35.89041915
              ],
              [
                -5.2934197,
                35.89041914
              ],
              [
                -5.29341984,
                35.89041901
              ],
              [
                -5.29365992,
                35.89041018
              ],
              [
                -5.29425035,
                35.89038815
              ],
              [
                -5.29508018,
                35.88957977
              ],
              [
                -5.29870738,
                35.889602
              ],
              [
                -5.3000595,
                35.88961015
              ],
              [
                -5.3008895,
                35.88872115
              ],
              [
                -5.3024995,
                35.88874815
              ],
              [
                -5.3035228,
                35.88774329
              ],
              [
                -5.3042202,
                35.88705826
              ],
              [
                -5.30422039,
                35.88705826
              ],
              [
                -5.3042205,
                35.88705815
              ],
              [
                -5.30589008,
                35.88708114
              ],
              [
                -5.30623128,
                35.88671407
              ],
              [
                -5.3067195,
                35.88618815
              ],
              [
                -5.30793271,
                35.88621149
              ],
              [
                -5.30833006,
                35.88621903
              ],
              [
                -5.30921984,
                35.88542175
              ],
              [
                -5.31168985,
                35.88542175
              ],
              [
                -5.31170936,
                35.885401
              ],
              [
                -5.3124995,
                35.88455915
              ],
              [
                -5.3150605,
                35.88460915
              ],
              [
                -5.31559188,
                35.8850929
              ],
              [
                -5.3159198,
                35.88539117
              ],
              [
                -5.31603599,
                35.88539871
              ],
              [
                -5.31668997,
                35.88544083
              ],
              [
                -5.31841993,
                35.88708115
              ],
              [
                -5.32250023,
                35.88711166
              ],
              [
                -5.32339001,
                35.88621903
              ],
              [
                -5.32422018,
                35.88621903
              ],
              [
                -5.32499566,
                35.88550035
              ],
              [
                -5.3250595,
                35.88544115
              ],
              [
                -5.32505954,
                35.88544115
              ],
              [
                -5.32505989,
                35.88544083
              ],
              [
                -5.32589006,
                35.88544083
              ],
              [
                -5.32788045,
                35.88344015
              ],
              [
                -5.32906581,
                35.88224820415134
              ],
              [
                -5.32906581,
                35.84148820946186
              ]
            ]
          ],
          [
            [
              [
                -5.319985811834431,
                35.892
              ],
              [
                -5.31998353,
                35.89199758
              ],
              [
                -5.31925016,
                35.89122015
              ],
              [
                -5.3188608,
                35.8912236
              ],
              [
                -5.31585979,
                35.89125061
              ],
              [
                -5.31522392,
                35.89189369
              ],
              [
                -5.315118920724042,
                35.892
              ],
              [
                -5.319985811834431,
                35.892
              ]
            ]
          ]
        ]
      }
    },
  ]
}

Code references:

Type mapping
File name setting

My question is:

  • Is this a bug or is it the way the library is supposed to work?

I would expect as a result of executing zip() just one set of files (.dbf, .prj, .shp, .shx) inside a .zip.

Checking the library code, multiple sets of files (.dbf, .prj, .shp, .shx) would be generated depending on the geojson feature types, effectively dividing its content. I think that this behavior is a bit weird.

  • Could you please confirm or assist on how I can get just one set of files (.dbf, .prj, .shp, .shx) in a .zip representing the entire geojson original content?

In a GeoServer instance using WFS\GetFeature, that is what is returned (.dbf contains all features properties).

Example on TS
zip<'blob'>(geojson, {outputType: 'blob', compression: 'STORE'})
  .then((blob) => {
    const anchor = document.createElement('a')
    document.body.appendChild(anchor)
    anchor.style.display = 'none'
    anchor.href = URL.createObjectURL(blob)
    anchor.download = `exampleGeoJsonToShapefile.zip`
    anchor.click()
    document.body.removeChild(anchor)
  })
  .catch((error) => console.log('error', error))
@juliolopeztorres juliolopeztorres changed the title [ZIP] Missing Feature when exporting FeatureCollection of Feature<Polygon> and Feature<MultiPolygon> [ZIP] Missing Features when exporting FeatureCollection of Feature<Polygon> and Feature<MultiPolygon> Mar 19, 2024
@stenon-olivier
Copy link

Maintainers, any comment on this issue? I see the same problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants