Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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")
share|improve this question

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer
    
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

According to the help files on viewshed, the OFFSETA field must exist within the feature class table to be use. Check the details within the help topic.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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