1

I'm trying to import a very basic OpenStreetMap multipolygon made out of two outer lines into Shapely:

import json
from shapely.ops import transform
from shapely.geometry import mapping,shape
from shapely.geometry.polygon import Polygon

way = """
{
   "features":[
      {
         "geometry":{
            "coordinates":[
               [
                  [
                     [
                        143.1305688,
                        72.1178189
                     ],
                     [
                        142.884063,
                        72.1186622
                     ],
                     [
                        142.8833764,
                        72.1820139
                     ],
                     [
                        142.8833764,
                        72.1820139
                     ],
                     [
                        143.122329,
                        72.1818038
                     ],
                     [
                        143.1305688,
                        72.1178189
                     ]
                  ]
               ]
            ],
            "type":"MultiPolygon"
         },
         "properties":{
            "type":"multipolygon"
         },
         "type":"Feature"
      }
   ],
   "type":"FeatureCollection"
}
"""

json = json.loads(way)

print(json['features'][0]['geometry'])

linestring = shape(json['features'][0]['geometry'])
geom = Polygon(linestring)

Which leads me to the error

Multi-part geometries do not themselves provide the array interface

If I only use geom = Polygon(shape(json)) I'm getting Unknown geometry type: featurecollection, which I don't understand – shouldn't it be "FeatureCollection"?

Do I first have to convert to Multipolygon in a Polygon (still in a FeatureCollection) with https://gist.github.com/mapmeld/8742ae89c6d687171d00 ?

  • 1
    Hi, is that the entirety of your code? What are you trying to accomplish? Have you tried geom = MultiPolygon(linestring) ? Note you would need to import multipolygon as well. Also, which lines produce which errors? – user1269942 Sep 16 '18 at 2:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.