1

I have JSON structure gotten from the Tracker:

{
    "16bec99d-a13e-4a21-a761-f673631b6060": {
    "ImageName": "chp/chp08.png",
    "Fill": 844168280,
    "Line": -11469736,
    "ID": "16bec99d-a13e-4a21-a761-f673631b6060",
    "ParentID": "94021e84-2a1e-440d-9f37-b349fa2cd0d8",
    "Name": "198008",
    "IsPolygon": true,
    "R": 0,
    "Lat": [
    58.496235,
    58.496299,
    58.49533,
    58.495213
    ],
    "Lng": [
    103.794173,
    103.797618,
    103.797715,
    103.796126
    ],
    "Holes": null
    },
    "8dc91f95-666e-4137-b29b-b12dbbddbdbe": {
    "ImageName": "chp/chp08.png",
    "Fill": 844168280,
    "Line": -11469736,
    "ID": "8dc91f95-666e-4137-b29b-b12dbbddbdbe",
    "ParentID": "94021e84-2a1e-440d-9f37-b349fa2cd0d8",
    "Name": "198005",
    "IsPolygon": true,
    "R": 0,
    "Lat": [
    58.484494,
    58.484392,
    58.483932,
    58.484163
    ],
    "Lng": [
    103.625914,
    103.626353,
    103.625889,
    103.625286
    ],
    "Holes": null
    }
}

I am intended to do it like this:

{
  "features": [
    {
      "geometry": {
        "rings": [
          [
            [103.794173,58.496235],
            [103.797618,58.496299],
            [103.797715,58.49533],
            [103.796126,58.495213]
          ]
        ],
      },
      "attributes": {
        "Name": "123456",
        "ID": "16bec99d-a13e-4a21-a761-f673631b6060",
        "Fill": 844168280,
        "Line": -11469736
      }
    },
    {
      "geometry": {
        "rings": [
          [
            [103.625914,58.484494],
            [103.626353,58.484392],
            [103.625889,58.483932],
            [103.625286,58.484163]
          ]
        ],
      },
      "attributes": {
        "Name": "689651",
        "ID": "8dc91f95-666e-4137-b29b-b12dbbddbdbe",
        "Fill": 844168280,
        "Line": -11469736
      }
    }
  ]
}

I tried to use json module in Python (in jupyter notebook) for loading JSON file and get a dictionary. Here is my code:

import json 
data = json.load(tracker_data)
arc_json = {
      "features": [
    {
      "geometry": {
        "rings": [x,y]

      },
        "attributes": data[d]
    } for x,y in zip(data[d]['Lng'],data[d]['Lat'])
  ]
}

The output isn't a thing I can be proud of.

1 Answer 1

0

Finally, I have achieved my aim and in case someone is looking for smth similar, here is my solution:

import json
#loading json object to our script
#after it's loaded, it's being in dictionary format
with open (path_to_your_json_file) as data_file:
json_data = json.load(data_file)

#script gets started in here
    arc_json={}
    geoAtr_lst=[]
    for d in json_data:
            feats={}
            feats['geometry']={}
            feats['geometry']['rings']=[list(map(list,zip(json_data[d]['Lng'],json_data[d]['Lat'])))]
            feats['attributes']={}
            feats['attributes']['Name']=json_data[d]['Name']
            feats['attributes']['ID']=json_data[d]['ID']
            feats['attributes']['Fill']=json_data[d]['Fill']
            feats['attributes']['Line']=json_data[d]['Line']
            geoAtr_lst.append(feats)
            arc_json['features']=geoAtr_lst

So, our result in arc_json variable: enter image description here

Kind regards, Sibdar

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.