Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

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

GeoDataFrame generated in a Python Tool cannot be output to Alteryx

moemily
5 - Atom

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 :

moemily_0-1580399097798.jpeg

 

Appreciate any help.

 

 

 

6 REPLIES 6
CharlieS
17 - Castor
17 - Castor

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. 

TravisR
Alteryx Alumni (Retired)

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!

moemily
5 - Atom

Thank you.

 

I think converting it to a geojson format should work.

 

Will test it out as soon as I can.

 

 

moemily
5 - Atom

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

 

TravisR
Alteryx Alumni (Retired)

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

moemily
5 - Atom
Thanks for the reply and the link.

The link shows how to read in geodataframe in Python Tool.

What I am doing here is to write the geodataframe from Python Tool to the Alteryx workflow.

In Python Tool, I changed the SpatialObj to be a json datatype and send it over to the Alteryx workflow. There is no place for me to change it to V_WString.
Once in Alteryx workflow, I changed it to SpatialObj in Select Tool (first tool to receive the data coming out from Python Tool), but at that point, it's already truncated.

Thanks
Emily
Labels