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.
Solved! Go to Solution.
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.
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!
@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
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!
User | Count |
---|---|
19 | |
14 | |
13 | |
9 | |
8 |