Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.
Free Trial

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Parsing JSON for spatial objects with holes in them?

Ali_288-1
6 - Meteoroid

Hello,

I've created a macro that'll download a spatial dataset from AGOL (as a JSON) and parse it to Alteryx format. However - I'm finding that this workflow doesn't treat polygons with holes in them correctly. It's not cutting holes out, so I'm ending up with objects overlapping, as attached. 

 

So my question is - should it be possible to correctly parse holes from JSON? e.g., using the poly-build tool? 

 

If so... how? (I'm not sure how to post my workflow without proprietary data, so I've attached a screenshot)

 

EDIT: I've found out why this happens - the JSON for a multipolygon is: 

 

{

  "type": "MultiPolygon",

  "coordinates": [

    [

      {polygon},

      {hole},

      {hole},

      {hole}

    ]

  ]

}

 

So since Alteryx is parsing each row of the JSON one at a time, it's treating the holes as separate objects. There doesn't seem to be a way to automatically parse the following rows as holes. 

4 REPLIES 4
DataNath
17 - Castor
17 - Castor

Hey @Ali_288-1, funnily enough this was actually a weekly challenge once!

 

https://community.alteryx.com/t5/Weekly-Challenge/Challenge-60-Fill-in-the-Spatial-Object/td-p/48852

 

Does something like this help? Each of your polygons will need an identifier, so if you don't have one already then you can just add a Record ID tool to start.

 

DataNath_0-1655372843647.png

 

Ali_288-1
6 - Meteoroid

Ah thanks a lot for pulling this up so fast! I think I have almost the opposite problem, in that I know that the holes are defined in the JSON, but seem to get filled in/dropped at some point between me downloading, parsing, and building the objects. I'll attach my workflow in case that shines a light!

DataNath
17 - Castor
17 - Castor

@Ali_288-1 if each group of objects has a unique identifier, you could try splitting the objects off into two streams (polygon & holes), combine the holes (Summarize > spatial) and then rejoin on the unique identifier. After that, you could perhaps use the spatial process tool to create an inverse intersection and cut out the ‘holes’ from the polygons. Just a quick thought I had on the fly as I’m not 100% sure without seeing the data.

 

https://help.alteryx.com/20221/designer/spatial-process-tool

Ali_288-1
6 - Meteoroid

Thanks a lot - yes, this works! I hadn't twigged what the 'inverse intersection' does. 

 

So, I realised that the objects within multipolygons are numbered, starting from 0. So, the first object in the multipolygon will always be numbered 0, then any subsequent objects (holes and islands) will be numbered 1+. I added a filter to split out records with an object number greater than 0; then combined those at the feature ID level; which is then matched back with the 'core' objects (which have the object number of 0). The inverse intersection then adds any islands to that core object, and cuts out any holes. Perfect! 

 

Ali_2881_1-1655900464866.png

 

 

Labels
Top Solution Authors