AnsweredAssumed Answered

Using 'projectAs()' Point Geometry Function Via Python Function in Command Prompt

Question asked by bz89 on Jul 3, 2019
Latest reply on Jul 11, 2019 by rvburton

So, i have a python function defined that projects coordinates using the 'projectAs()' point geometry function. When i call this function in a script from a toolbox it gives different results vs calling it in a python command prompt window. See below python function below:

def ProjectCoordinates(x,y,inputcrs,outputcrs):
     import arcpy
     point = arcpy.PointGeometry(arcpy.Point(x,y),inputcrs)
     projectedpoint = point.projectAs(outputcrs)
     projectedcoordinates = [projectedpoint.firstPoint.X,projectedpoint.firstPoint.Y]
     
     return projectedcoordinates

Full Toolbox Script:

def ProjectCoordinates(x,y,inputcrs,outputcrs):
     import arcpy
     point = arcpy.PointGeometry(arcpy.Point(x,y),inputcrs)
     projectedpoint = point.projectAs(outputcrs)
     projectedcoordinates = [projectedpoint.firstPoint.X,projectedpoint.firstPoint.Y]
     
     return projectedcoordinates

import arcpy

xin = arcpy.GetParameterAsText(0)
yin = arcpy.GetParameterAsText(1)

srin = arcpy.GetParameter(2)
srout = arcpy.GetParameter(3)

xout,yout = ProjectCoordinates(xin,yin,srin,srout)

arcpy.AddMessage(srin.name)
arcpy.AddMessage(srout.name)
arcpy.AddMessage(str(xout) + " ," + str(yout))

Results of Each:

Can anyone replicate this? Does anyone have any ideas why this is happening?

 

Also, if it helps, I know from surveyed data that the toolbox script output is correct and the command prompt output is incorrect.

Outcomes