HI all
I am puzzled by a simple problem. I don't know how to access a point object's x and y coordinate from a arctoolbox in python script.
It can be accessed this way:
pnt=arcpy.GetParameterAsText(0).split() # c1 is a point object in arctoolbox interface
x=float(pnt[0])
y=float(pnt[1])
It's not ideal because the code will fail when the x and y are inputed in different decimal seperator, say ',' format.
So I use:
pnt=arcpy.GetParamete(0)
But what's the method to get pnt.X and pnt.Y?
Have a look at this help description: http://pro.arcgis.com/en/pro-app/arcpy/classes/point.htm
Then to read the geometry:
point = arcpy.GetParameter(0)
ptGeometry = arcpy.PointGeometry(point)
x = ptGeometry.X
y = ptGeometry.Y
Thank you Basson. Line 2 return: RuntimeError: Object: CreateObject cannot create geometry from inputs.
arcpy.AddMessage(type(point)) show: <type 'geoprocessing value object'>
It leaves the question of how your point object is defined? Is it a string? Please provide more information on the tool.
point = arcpy.GetParameter(0)
coords = str(point).split(' ')
x = coords[0]
y = coords[1]
arcpy.AddMessage(x)
arcpy.AddMessage(y)
The x and y will be used as float, so decimal seperator problem still exists.
Your decimals should be in point notation (12.3456) and not comma notation (12,3456), then the Python code works.
Than you Basson, but I am tring to write a tool not only for myself.
So your issue is with the regional settings of the OS for decimal number notation. You can detect what format the user's OS is showing floats with
locale.localeconv()['decimal_point']