Parsing JSON list to get coordinates that work with GMPLOT

Viewed 33

I am getting a json response of coordinates that look like this:

{
  "buildingId": "blda6fd0be6b35e",
  "footprint2d": {
    "coordinates": [
      [
        [
          [
            153.014281692,
            -27.423883671000002
          ],
          [
            153.014415275,
            -27.423897007
          ],
          [
            153.014401252,
            -27.424008856
          ],
          [
            153.01426766900002,
            -27.423995519
          ],
          [
            153.014281692,
            -27.423883671000002
          ]
        ]
      ]
    ],
    "type": "MultiPolygon"
  }
}

And I am trying to get into a form that would work with the GMPLOT polygon following this documentation: https://github.com/gmplot/gmplot/wiki/GoogleMapPlotter.polygon

import gmplot
apikey = '' # (your API key here)
gmap = gmplot.GoogleMapPlotter(37.766956, -122.448481, 14, apikey=apikey)

golden_gate_park = zip(*[
    (37.771269, -122.511015),
    (37.773495, -122.464830),
    (37.774797, -122.454538),
    (37.771988, -122.454018),
    (37.773646, -122.440979),
    (37.772742, -122.440797),
    (37.771096, -122.453889),
    (37.768669, -122.453518),
    (37.766227, -122.460213),
    (37.764028, -122.510347)
])

gmap.polygon(*golden_gate_park, face_color='pink', edge_color='cornflowerblue', edge_width=5)
gmap.draw('map.html')

The number of coordinate points changes (depending on the complexity of the shape) so I can't hardcode it, I'm still learning how to parse more advanced json files like this. Can someone help?

0 Answers
Related