alekzvik / shapely-geojson

Set of classes to work better with GeoJson spec with Shapely classes.
MIT License
25 stars 1 forks source link

Can I read a MultiPolygon geojson with this library #2

Open uswoods opened 6 years ago

uswoods commented 6 years ago

Hi alex,

can I read a MultiPolygon geojson with this library?

import json
from shapely.geometry import mapping,shape
from shapely_geojson import FeatureCollection

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"
}
"""
shape = FeatureCollection(json.loads(way))
cmcaine commented 6 years ago

The entire library is one short file: https://github.com/alekzvik/shapely-geojson/blob/master/shapely_geojson.py

The JSON representation is one-way: shapely -> JSON, not the other way around.

cmcaine commented 6 years ago

GeoJSON is very similar to the __geo_interface__ format that shapely does accept in shapely.geometry.shape(), though, so it shouldn't be too difficult: just convert the json to a dictionary and give it to that function.