Python Toolbox Spatial Reference Input Parameter

743
3
Jump to solution
04-22-2022 02:32 PM
TylerTownes
New Contributor III

Hi,

The GPSpatialReference datatype within an input parameter invokes a nice user experience to select the sr...

TylerTownes_0-1650662759989.png

 

Accessing the GPSpatialReference parameter returns the following sample string:

 'GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]];-400 -400 1000000000;-100000 10000;-100000 10000;8.98315284119521E-09;0.001;0.001;IsHighPrecision'

However, my source code is using spatially enabled dataframes (SEDFs).  SEDFs deal better with WKIDs than the string above.

So, I see two potential options if I want to keep the gui sr selector:

1) change to another data type that uses the gui sr selector and assigs a WKID, or,

2) Convert that string above to a WKID or something an SEDF will ingest.

Any ideas how to convert that string to WKID, or know a better parameter data type?

Last resort:

1) change datatype to string and collect the WKID directly.  Not as end user friendly.

Thank you,

Tyler

 

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
Luke_Pinner
MVP Regular Contributor
  • Leave the parameter as  GPSpatialReference,
  • Access the SpatialReference object using parameters[N].value (not valueAsText)
  • Get the WKID using the SpatialReference.factoryCode property 

View solution in original post

3 Replies
TylerTownes
New Contributor III

I had a couple of thoughts:

1) Notice the behavior of both the GPSpatialReference and GPCoordinateSystem.  If you type in:

TylerTownes_0-1650721640263.png

...the field converts it to the string above.  That makes me wonder how to access the same conversion dictionary that the toobox module is using.

2) I posted a general Python topic question of how to best normalize this html table https://developers.arcgis.com/javascript/3/jshelp/gcs.html. 

See post at:

https://community.esri.com/t5/python-questions/pd-read-html-parameters-https-developers-arcgis/td-p/...

Reading html tables is a general topic I would like to get better at so the topic stands alone.  However, as it relates to the current situation, the idea would be to read it in and use it as a look up table.  The 4326 wkid matched the string exactly.  

Thx. 

Tyler

0 Kudos
Luke_Pinner
MVP Regular Contributor
  • Leave the parameter as  GPSpatialReference,
  • Access the SpatialReference object using parameters[N].value (not valueAsText)
  • Get the WKID using the SpatialReference.factoryCode property 
TylerTownes
New Contributor III

@Luke_Pinner 

Perfect.  Thank you!

0 Kudos