Point layer

725
5
03-20-2014 09:07 PM
MaherAL_ZUHAIRI
New Contributor
Excuse me, help me
this code does not work when I make it as a script tool also it does not show to any error but no results
??????????????????


import arcpy
arcpy.env.workspace="C:\\test"
arcpy.env.overwriteOutput = True
inX = arcpy.GetParameterAsText(0)
inY = arcpy.GetParameterAsText(1)
pnt=arcpy.Point()
pnt.X=float(inX)
pnt.Y=float(inY)
p=arcpy.PointGeometry(pnt)
newl=arcpy.CopyFeatures_management(p)
OUTp= arcpy.SetParameterAsText(2, newl)
Tags (2)
0 Kudos
5 Replies
XanderBakker
Esri Esteemed Contributor
A few pointers:

  • You can define in your tool a parameter type "Point". This will provide two input boxes to specify the X and Y coordinates. The result (when read as text) is a string containing "Xvalue Yvalue"

  • When I tested a snippet of code I received an error indicating that the input feature falls outside the output geometry domain. So an spatial reference is probably required. Define a second parameter with type "Spatial Reference"

  • The third parameter in this case will be output featureclass. Set the direction to output.

  • In the line where you use the "arcpy.CopyFeatures_management" you have to provide an output featureclass as second parameter

Se below the code for this tool:

import arcpy
arcpy.env.overwriteOutput = True

# Point, input
pnt_in = arcpy.GetParameterAsText(0)
arcpy.AddMessage("Input pnt_in: {0}".format(pnt_in))

# Spatial Reference, input
sr = arcpy.GetParameter(1)
arcpy.AddMessage("Input sr: {0}".format(sr))

# Featureclass, output
fc = arcpy.GetParameter(2)
arcpy.AddMessage("Input fc: {0}".format(fc))

# split the XY coordinates text into a list
lst = pnt_in.split()
arcpy.AddMessage("lst: {0}".format(lst))

# create a point object from the X and Y values in the list
pnt = arcpy.Point(lst[0], lst[1])
arcpy.AddMessage("pnt: X={0}  Y={1}".format(pnt.X, pnt.Y))

# create a point geometry object point object and apply the spatial reference
pnt_geom = arcpy.PointGeometry(pnt, sr)
arcpy.AddMessage("pnt_geom: X={0}  Y={1}".format(pnt_geom.firstPoint.X, pnt_geom.firstPoint.Y))

# create the output featureclass, 
arcpy.CopyFeatures_management(pnt_geom, fc)
arcpy.AddMessage(arcpy.GetMessages())

# your third parameter is already set in the dialog, no need to use the "arcpy.SetParameterAsText"


Hope this helps you.

Kind regards,

Xander
0 Kudos
MaherAL_ZUHAIRI
New Contributor
[ATTACH=CONFIG]32387[/ATTACH]


Hello,
I have tried to apply your notes and the code that you have written to me, however, the same problem happened to me the picture above show the state when I apply the tool this process stay in progress until I click cancel and nothing happen when I click also no error message.
I dont no the problem with me, please help me with your knowledge. or is it possible to make it as a toolbox and send it to me


Thanks with regards
0 Kudos
XanderBakker
Esri Esteemed Contributor
Hi Maher,

I don't think that the problem you are facing has anything to do with the underlying Python code. However, I did attach a zip with the toolbox, and this toolbox worked for me specifying X=4 and Y=5 using WGS84.

If this doesn't work for you, you will have to provide some more details on what you specify in the dialog, version of ArcGIS, write privileges on output location, etc. If you use a tool from the standard ArcGIS toolboxes and write to an output featureclass (same location as in the provided tool), does that work?

Kind regards,

Xander
0 Kudos
MaherAL_ZUHAIRI
New Contributor
Sorry I am bothering you, thank you for your helping the toolbox works correctly, but on last question I want to use this toolbox in model builder so I need to specify the X and Y value from calculate value (tool)  output value.
How can I do this?


Thanks
0 Kudos
XanderBakker
Esri Esteemed Contributor
The Calculate Value tool requires an expression, and an output type (which could be variant) and an optional expression. If you create a string as result, which combines the X and Y like this "{0} {1}".format(X, Y), then you can connect it to the coordinates input of the tool (which you can just drag to your model). You should define some of the tool parameters as model parameters.

Now, it might be better to take the calculation you are planning inside the tool, but in order to judge that, I would have to know what type of calculation you are planning to perform and what the input data will be.

Kind regards,

Xander
0 Kudos