I am creating polygons in the Python Tool and want to output the GeoDataFrame to Alteryx to continue the analysis. The GeoDataFrame is created, but got an error in Alteryx. In Python Tool, the last few lines are :
gdf_5mw_df = pd.DataFrame(gdf_5mw)
gdf_5mw_df =gdf_5mw_df.astype({'the_geom': 'object'})
Alteryx.write(gdf_5mw_df, 1, {"the_geom": {"type": "SpatialObj"}})
There's no error when running Python Tool, but the Alteryx is unable to output the data :
Appreciate any help.
Solved! Go to Solution.
I may not be much help on the Python side, but if you can successfully output the spatial object in a text format (and share it here), I'm sure we can construct that into an Alteryx spatial object for you.
Hi @moemily
My information may be inaccurate these days - as it's been a while since I've worked with spatial data in the python tool - but to my knowledge the Python Tool cannot read/write Alteryx spatial object data.
However - there is a work around! Spatial Data in Alteryx is merely geojson. So to read Alteryx spatial data into Python Tool - you can simply use a select tool and covert the type into a string, read the data into the python tool as a string, then convert that string data back to geojson or your spatial data type of choice in python and proceed with your script. To write spatial data out of the Python Tool is the same process. Convert your spatial data to a geojson string, then write that string from the Python Tool, and then use a select tool to convert that string back to the Alteryx Spatial Object format.
Hope that helps!
Thank you.
I think converting it to a geojson format should work.
Will test it out as soon as I can.
Thanks for the advice.
Now I managed to convert the_geom into geojson format and successfully output it to Alteryx from a python tool.
In Alteryx, the output file (only one column - the_geom) which is in geojson format : {type : "Polygon", "coordinates" : [[-84.123456, 33.095679] [-84.123444, 33.095678]].....
But the output file truncates the long column the_geom and now with the Select Tool, it can't be converted to spatialobj correctly as it's truncated.
Wondering if there is another solution/workaround for it.
Thanks
Hi @moemily So I took a look to see what we could do in terms to changing the string length - and it looks like at some point support for Spatial data was added to the Python tool.
Check out the 'Working with Spatial Data' under Troubleshooting at the bottom of this page:
https://help.alteryx.com/current/Python.htm
If that doesn't solve it - then I would experiment with changing data types (maybe V_WStrng vs String) or extending data type sizes