[gdal-dev] geojson to shp and vice versa

Kristijan Cindrić kcindric at gmail.com
Sun Dec 1 00:23:53 PST 2019


Thanks Richard,

in the end I opted for a client side solution (
https://github.com/calvinmetcalf/shapefile-js) which handles geometry
collections with multiple geometry types great.

Chtis

ned, 1. pro 2019. u 03:36 Richard Greenwood <richard.greenwood at gmail.com>
napisao je:

> I don't know anything about iterating thru a .zip file, but just in case
> you aren't already familiar with it, ogr2ogr has -sql and -where options
> that can be used to filter geometry types. So if you have different
> geometry type in a single source file you can use for example:
>    -where "OGR_GEOMETRY='MULTIPOLYGON' OR OGR_GEOMETRY='POLYGON'"
> If you have geometry collections with multiple geometry types it gets
> harder. Personally, I'd pump it thru PostGIS in that case.
>
> Rich
>
> On Fri, Nov 29, 2019 at 1:42 AM Kristijan Cindrić <kcindric at gmail.com>
> wrote:
>
>> Thanks for the prompt answers! Ok, it's clear now on what's the problem
>> here.
>> Is there a way I can iterate through a .zip file containing individual
>> .shp files, each file with its own geometry type (point, line, polygon),
>> using ogre.adc4gis.com API? I could then append each feature to a
>> geojson feature class and show it to the user. If ogre.adc4gis.com
>> doesn't work I can try to run ogr2ogr in my app so suggestions in that way
>> are helpful also.
>>
>> Thanks,
>>
>> Chris
>>
>> pet, 29. stu 2019. u 09:28 jratike80 <jukka.rahkonen at maanmittauslaitos.fi>
>> napisao je:
>>
>>> Hi,
>>>
>>> You just can't save lines and polygons into same shapefile. Read
>>> https://www.esri.com/library/whitepapers/pdfs/shapefile.pdf "All the
>>> non-Null shapes in a shapefile are required to be of the same shape
>>> type."
>>>
>>>
>>> -Jukka Rahkonen-
>>>
>>>
>>> Kristijan Cindrić wrote
>>> > Dear all,
>>> >
>>> > I have a headache inducing problem. Whenever I try to convert a GeoJSON
>>> > feature collection which contains multiple different geometry shapes
>>> (i.e.
>>> > polygon, linestring and point) I get this type of error:
>>> >
>>> > "ERROR 1: Attempt to write non-polygon (LINESTRING) geometry to POLYGON
>>> > type shapefile.\nERROR 1: Unable to write feature 1 from layer
>>> > OGRGeoJSON.\nERROR 1: Terminating translation prematurely after
>>> > failed\ntranslation of layer OGRGeoJSON (use -skipfailures to skip
>>> > errors)\n"
>>> >
>>> > This is the sample GeoJSON I'm trying to convert:
>>> >
>>> > {
>>> >     "type": "FeatureCollection",
>>> >     "features": [{
>>> >         "type": "Feature",
>>> >         "properties": {},
>>> >         "geometry": {
>>> >             "type": "Polygon",
>>> >             "coordinates": [
>>> >                 [
>>> >                     [31.816406250000004, 55.27911529201564],
>>> >                     [34.27734375000001, 51.944264879028765],
>>> >                     [43.94531250000001, 51.944264879028765],
>>> >                     [46.93359375000001, 58.35563036280967],
>>> >                     [40.42968750000001, 60.1524422143808],
>>> >                     [34.45312500000001, 59.085738569819505],
>>> >                     [31.816406250000004, 55.27911529201564]
>>> >                 ]
>>> >             ]
>>> >         }
>>> >     }, {
>>> >         "type": "Feature",
>>> >         "properties": {},
>>> >         "geometry": {
>>> >             "type": "LineString",
>>> >             "coordinates": [
>>> >                 [0.5273437500000001, 21.289374355860424],
>>> >                 [30.585937500000004, 20.632784250388028]
>>> >             ]
>>> >         }
>>> >     }, {
>>> >         "type": "Feature",
>>> >         "properties": {},
>>> >         "geometry": {
>>> >             "type": "Point",
>>> >             "coordinates": [14.062500000000002, 50.064191736659104]
>>> >         }
>>> >     }]
>>> > }
>>> >
>>> >
>>> > I validated the GeoJSON on geojsonlint <http://geojsonlint.com/>
>>> and
>>> > it's
>>> > all good. It happens every time I have a stack of different geometry
>>> > types.
>>> > It happens using ogre.adc4gis.com or ogr2ogr. It happens in the
>>> opposite
>>> > way also and when I use the skipfailure option I just get the first
>>> > feature
>>> > in my shapefile.
>>> >
>>> > Any ideas what's going on?
>>> >
>>> >
>>> > Thanks!
>>> >
>>> >
>>> > Chris
>>> >
>>> > _______________________________________________
>>> > gdal-dev mailing list
>>>
>>> > gdal-dev at .osgeo
>>>
>>> > https://lists.osgeo.org/mailman/listinfo/gdal-dev
>>>
>>>
>>>
>>>
>>>
>>> --
>>> Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
>>> _______________________________________________
>>> gdal-dev mailing list
>>> gdal-dev at lists.osgeo.org
>>> https://lists.osgeo.org/mailman/listinfo/gdal-dev
>>
>> _______________________________________________
>> gdal-dev mailing list
>> gdal-dev at lists.osgeo.org
>> https://lists.osgeo.org/mailman/listinfo/gdal-dev
>
>
>
> --
> Richard W. Greenwood, PLS
> www.greenwoodmap.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20191201/4e9c9c9d/attachment-0001.html>


More information about the gdal-dev mailing list