AnsweredAssumed Answered

Convert JSON into FeatureCollection

Question asked by jamesfreddyc on Mar 30, 2017
Latest reply on Apr 3, 2017 by rvburton

I've been provided a JSON output in the sample below and tasked with getting this into a point feature class somehow.

 

[
{
  "Name": "w1",
  "Long": "-60.44",
  "Lat": "21.60",
  "table": [
   [
    "G310-P:",
    "84 cfs; Mar 2, 17"
   ],
   [
    "G251-P:",
    "0 cfs; Mar 2, 17"
   ]
  ],
  "Heading": "315"
},
{
  "Name": "w2",
  "Long": "-60.32",
  "Lat": "21.63",
  "table": [
   [
    "S362-P:",
    "136 cfs; Mar 2, 17"
   ]
  ],
  "Heading": "0"
},
{
  "Name": "w2",
  "Long": "-60.35",
  "Lat": "21.37",
  "table": [
   [
    "S10A-C:",
    "0 cfs; Mar 2, 17"
   ],
   [
    "S10C-C:",
    "0 cfs; Mar 2, 17"
   ],
   [
    "S10D-C:",
    "0 cfs; Mar 2, 17"
   ]
  ],
  "Heading": "20"
}
]

 

I have some existing processes that get close but hoped to run it by the community to see if someone spots the obvious solution before I dillydally down the wrong path for too long.  In the JSON sample above, I have Lat/Lon attributes that I would need to get into an array in order to use this def() to convert it to something closer to what I need.  My first thought is to create a new attribute called 'rings' so that it would just work with my geo_convert() def:

 

def geo_convert(ring_string):  
    from json import loads, dumps 
    
    rings = loads(ring_string) 
    feat_coll = {'type': 'FeatureCollection', 
                 'features':[]} 
    
    for ring in rings:
        feat_coll['features'].append( 
            {'type': 'Feature', 
             'geometry': { 
                'type': 'Point', 
                'coordinates': ring['rings'][0]
            }}) 
   
    return dumps(feat_coll) 

 

Any ideas on what I could do? 

Outcomes