1

This is using ArcGIS10 arcpy with spatial analyst.

I need to call Viewshed, but with an observer height set. I have tried using a Z-aware point feature set, but that only throws an error. I am feeding an arcpy.PointGeometry object with a Raster object of a dem for my inputs. e.g.

viewshed = arcpy.sa.Viewshed(dem, source_point)

I am using dynamically generated points as the source for my observer points for the viewshed. Feature classes have to be built in memory.

I have tried several ways to build an in-memory feature class with an OFFSETA field, but so far it has not worked.

Anyone have any idea how to use the Viewshed OFFSETA, or another way to set observer height when calling Viewshed inside python using an in memory feature class?


Here is the solution I came up with, using Matthew Snape's advice. dem, source_point, offseta, and offsetb are all inputs to function this is contained in:

   # Construct viewshed input
   arcpy.CreateFeatureclass_management("in_memory", "viewshedinput", "POINT")
   arcpy.AddField_management("in_memory\\viewshedinput", "OFFSETA", "FLOAT")
   arcpy.AddField_management("in_memory\\viewshedinput", "OFFSETB", "FLOAT")
   rows = arcpy.InsertCursor("in_memory\\viewshedinput")
   row = rows.newRow()
   row.shape = source_point
   row.OFFSETA = offseta
   row.OFFSETB = offsetb
   rows.insertRow(row)
   del rows, row
   # Calculate viewshed for source point
   viewshed = arcpy.sa.Viewshed(dem, "in_memory\\viewshedinput")
2

The viewshed tool uses feature layers to define observers. The OFFSETA and other parameters are specified using a field.

Create your point as a feature layer and then use arcpy.AddField_management and arcpy.CalculateField_management to create and set the field.

  • I have tried to build an in-memory feature class with AddField and CalculateField, but AddField does not seem to work on an in-memory feature class. – blord-castillo Sep 27 '11 at 22:08
  • Not sure what I was doing wrong before, but it works now! – blord-castillo Sep 30 '11 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.