How do you read/write a FeatureCollection from/to a json file?

المشرف العام

Administrator
طاقم الإدارة
I am trying to read in a json FeatureCollection Python (2.7), add some properties, and write it back out to a json file (or string).

I can read the file, and modify the properties, but I end up with 2 nested FeatureCollection objects:

{ "type": "FeatureCollection", "features": { "type": "FeatureCollection", "features": [ { "geometry": { "type": "Polygon", "coordinates": [ [ ] ] }, "type": "Feature", "properties": { "gval": 1.0, "hectares": 0.218681933167, "xid": 0, "id": 1.0, "area": 2186.81933167 } } ] }}And I think I've worked out that I creating my FeatureCollection incorrectly:

path=r'd:\temp\test.json'with open(path) as data_file: data = json.load(data_file)print datafeature_collection = FeatureCollection(data)print feature_collectionThe feature_collection ends with nested features, which is probably why the resulting geojson.dumps has the nested FeatureCollection
{"features": {"features": [{"geometry":

I can think of a number of ways to hack it, but what is the correct way to create that FeatureCollection? Modify feature attribtues, and then write it back out to a file?



أكثر...
 
أعلى