Question

Convert JSON API response to a polygon

  • 24 October 2022
  • 1 reply
  • 2 views

I get a response from an API GET request in JSON and it contains the coordinates for a polygon.

{"authenticationResultCode":"ValidCredentials","brandLogoUri":"http:\/\/dev.virtualearth.net\/Branding\/logo_powered_by.png","copyright":"Copyright © 2022 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.","resourceSets":[{"estimatedTotal":1,"resources":[{"__type":"IsochroneResponse:http:\/\/schemas.microsoft.com\/search\/local\/ws\/rest\/v1","dataSourcesUsed":[5],"origin":{"latitude":-34.021682824034,"longitude":18.4837339189645},"polygons":[{"coordinates":[[[-34.0224675816069,18.47607560705454],[-34.021900339603782,18.476424942466956],[-34.021834632851942,18.47667223294113],[-34.021763236949283,18.4766453367028],[-34.02119900085917,18.477001621671914],[-34.021216553524575,18.477231713278478],[-34.020956999043712,18.477130968901353],[-34.020613182625453,18.477165228610041],[-34.020460500759683,18.47738177759841],[-34.020197274110672,18.477411260748216],[-34.020028031581866,18.477656322794978],[-34.019802103094847,18.477680432421995],[-34.019580702909352,18.477998187715652],[-34.019601606286329,18.478280685384213],[-34.019283631607479,18.478160238254329],[-34.018940023376381,18.478197389117021],[-34.018722648397407,18.47851010213002],[-34.018528104661172,18.478413958150266],[-34.01820967392387,18.478573394162236],[-34.01813108338073,18.478802746305377],[-34.018099714056845,18.47879072486916],[-34.018099677466253,18.478790863849508],[-34.018099330523377,18.47879218163267],[-34.017970372857704,18.479281993021754],[-34.017639074467681,18.479154360387163],[-34.017072945763594,18.479506272203515],[-34.0170920692713,18.47977598441711],[-34.016793995381306,18.479663696106591],[-34.016669161449684,18.479677428124653],[-34.016573522458877,18.479580334717131],[-34.016006999468921,18.479931326036215],[-34.015912278815946,18.480290824496546],[-34.015834692088688,18.480261149155183],[-34.0154909990064,18.480297151390484],[-34.01537047750454,18.480469549052184],[-34.0150520008598,18.480483053639635],[-34.014891245234551,18.480690232564069],[-34.014580191498766,18.480550872376835],[-34.014006360267977,18.480854633150074],[-34.014240674132253,18.481553169575861],[-34.014917772678047,18.481918272714221],[-34.014944781118892,18.481918616811349],[-34.014966418962409,18.481940321058904],[-34.014981010804057,18.481945853677598],[-34.014821986407462,18.482189951276819],[-34.015126562853268,18.482855585954933],[-34.015437923088477,18.482968524449607],[-34.015308968541127,18.483155129847685],[-34.015340905001729,18.483567656598783],[-34.015581183949571,18.483807116203618],[-34.015542747650215,18.483857201467881],[-34.01580779728463,18.48455141641228],[-34.01689449527273,18.485044021956572],[-34.0169231541725,18.485042336320952],[-34.021184554353411,18.486918063330727],[-34.021192929046379,18.486926897273868],[-34.021669844780483,18.48713483418943],[-34.021681195787274,18.487267644578697],[-34.021929685696385,18.487528684644019],[-34.025207993561445,18.488951158754297],[-34.025548806145046,18.488933010843251],[-34.025624141281114,18.488835949374547],[-34.025894926614114,18.488810963573119],[-34.0260995406635,18.488093399742848],[-34.025882985623319,18.487857532099572],[-34.025971214585958,18.48777024410462],[-34.026685957869965,18.48804046705963],[-34.0266868438813,18.488040803352717],[-34.026687323991638,18.488040983554118],[-34.026697057307004,18.488003502684709],[-34.026822573541146,18.488065540915475],[-34.027141005087628,18.487906092431633],[-34.027246695005537,18.487597627270418],[-34.027363296672711,18.487657098280618],[-34.027967051385232,18.487324502040963],[-34.028073171360539,18.486926280959285],[-34.028526131863913,18.487098807818242],[-34.029091286639357,18.486744600394335],[-34.028796370887747,18.48606580630863],[-34.028346243706125,18.485894364071445],[-34.028457452663879,18.485471149615019],[-34.028127541736993,18.484778819328689],[-34.027794171201627,18.484687275441306],[-34.027947856947556,18.484466742407083],[-34.027652802915249,18.483788044087579],[-34.027338902897689,18.483668591029684],[-34.027460271376796,18.483190892391391],[-34.0271634230525,18.482514611812586],[-34.027065202404287,18.482525286226121],[-34.027087320528523,18.48249364581288],[-34.02679312704953,18.481814415637444],[-34.026502839766117,18.48170336061084],[-34.026633173274639,18.481516033468804],[-34.026602402199465,18.481103324353395],[-34.026475166370844,18.480975629426688],[-34.026479007465724,18.480961216729682],[-34.026451353816888,18.480548191188376],[-34.026194129638355,18.480285239303104],[-34.026179936050973,18.480099599983987],[-34.025914698298529,18.47983462787905],[-34.025612204207377,18.4797207516613],[-34.025750122150541,18.479530791543453],[-34.025466556825819,18.478845082473086],[-34.025442160079578,18.478835137255512],[-34.025502294177549,18.478605759011014],[-34.025209211723123,18.477925848905244],[-34.024643105574825,18.478277842637151],[-34.024582356733106,18.478509565998916],[-34.024530160100589,18.478491292639347],[-34.0239720216991,18.478861182861376],[-34.023995024268551,18.479107858623088],[-34.023711110040232,18.478999560985887],[-34.02369685843221,18.47878958296112],[-34.023511032424771,18.478600044901057],[-34.023484039584922,18.478256056805524],[-34.023218274307013,18.477991856465636],[-34.022925210673833,18.4778824656244],[-34.023056825350132,18.477689710614595],[-34.022756105751128,18.477014647618418],[-34.022695843317315,18.476992520407869],[-34.022758460142889,18.476756859198957],[-34.0224675816069,18.47607560705454]]]}]}]}],"statusCode":200,"statusDescription":"OK","traceId":"5828fe21e6f141b2a49cc0b8d0ad6760|DU0000276C|0.0.0.0|DU000005EB,DU00001F72"}

Is there a way for me to extract the polygon definition from the JSON and (a) write it to a shapefile and (b) use it as a spatial filter?

 

Thanks,

 

tC/.


1 reply

Userlevel 6
Badge +33

I do not think this is a standard json geometry structure, like Esri JSON or GeoJSON. But you can always extract the coordinates using a JSONFragmenter , create the points using a VertexCreator and build a polygon using a LineBuilder. Attached a workspace demonstrating this.

 

result 

Reply