Using python cursors in gpk

05-09-2016 10:44 PM
Esri Regular Contributor


I created a tool based on python script and pack it into gpk.

When I try to run it from RT SDK for .net as local service it does not work.

After the line "p = row[0]" I get the error that p is not defined.

I am trying to read the coordinate of a layer that was created in the tool.

I tried both "old" cursors and the da cursor.

Is this a known limitation? How can I get the value of some records in the results (I would like to return it as a string).


0 Kudos
3 Replies
Esri Frequent Contributor


Please can you share your Python script?



0 Kudos
Esri Regular Contributor

Hi Mike

Thanks for the response; I was hoping to get your attention

My code do basic Viewshed operation but later on I will add more functionality to intersect with some polyline/polygon and determine the overlap area.

In my code I need to get the point coordinate to set the extent (works much quicker).

You can see the code that does not work in comment and the work around I found.

Even with this workaround it still does not work. It gives me error message about Desktop 10.2 that was installed once on my machine but now I have 10.3.1

I wonder if the cursor should work.


import arcpy
obs = arcpy.GetParameterAsText(0)
rad = arcpy.GetParameter(1)
# constants
arcpy.env.overwriteOutput = True
dtm = r"C:\demos\RtGp\dem_itm.tif"
# temporary names
outRaster = arcpy.env.scratchFolder + r"\visRas.tif"
outVector = r"in_memory\visVec"
# set extent of operation
#with arcpy.da.SearchCursor(obs, "SHAPE@XY") as cursor:
#    for row in cursor:
#        p = row[0]
desc = arcpy.Describe(obs)
arcpy.env.extent = "%s %s %s %s" % (desc.extent.XMin - rad,desc.extent.YMin - rad,desc.extent.XMin + rad,desc.extent.YMin + rad)
#arcpy.env.extent = "%s %s %s %s" % (p[0] - rad,p[1] - rad,p[0] + rad,p[1] + rad)
# prepare observer
arcpy.CalculateField_management(obs,"OFFSETA",7, "PYTHON_9.3")
arcpy.CalculateField_management(obs,"RADIUS2",3000 , "PYTHON_9.3")
# start process - visibility
0 Kudos
Esri Regular Contributor

Solved it

The python script did not get the input point for the observer so the layer was empty and the cursor retun nothing but did not fail.

When I translate everything to web mercator it all works.

I think you should write a paper about using local projection, this is needed in many local application that does not use AGOL.