Points Within a view

1264
5
06-06-2012 12:38 PM
WilliamIde
New Contributor II
I am fairly new to python.  But I have been asked to write a tool that will allow the user to pan to a specific location and hit a button that creates a PDF of the view as well as showing the attribute values from a layer
in the view.  I can create the PDF of the view no problem.  I am have difficulty with selecting and outputting the points from the layer.
newinputfile ="mypointfile"

arcpy.env.overwriteOutput = true

definput = arcpy.GetParameterAsText(0)

if definput == '#" or not definput":
 definput = newinputfile;
 env.workspace = "d:/Myprojects/DefWorkspace/projdata.gdb"

arcpy.AddMessage("starting")

mxd = arcpy.mapping.MapDocument("CURRENT")

layers = arcpy.mapping.ListLayers(mxd)

for layer in layers:
 if layer.longName == newinputfile:
 arcpy.addMessage("found layer")
# here is where I lose it
 arcpy.SelectLayerByLocation_management( ???, ???  


arcpy.mapping.ExportToPDF(mxd,"outputPDF")

# somehow add the selected point attributes the PDF

#Done.



Thanks  for looking
Tags (2)
0 Kudos
5 Replies
NobbirAhmed
Esri Regular Contributor
Could you please show the full statement for this line?

arcpy.SelectLayerByLocation_management( ???, ???  ....)


Another question, what do you mean by 'point attributes' when you say
".... add the selected point attributes to the PDF.."?


Assuming, by "attributes" you mean the point features themselves, I suggest use these steps before exporting to PDF:

# assuming you have only one data frame
df = arcpy.mapping.ListDataFrames(mxd)[0]

df.zoomToSelectedFeatures()

# clear selection - otherwise, the PDF will contain selection color 
arcpy.SelectLayerByAttribute_management("state_centroids", "CLEAR_SELECTION")
0 Kudos
WilliamIde
New Contributor II
That's just it. I don't know what parameters to use in the SelectByLocation.

I will try the df code and get back to you.
0 Kudos
WilliamIde
New Contributor II
I added the:

df = arcpy.mapping.ListDataFrames(mxd) [0]

statement.  That completed.  The
df.zoomToSelectedFeatures()

Failed it said that df didn't have zoom.... attribute.

The clear selection completed but did not alter the arcmap display. I assume because I didn't do an update.

What I am trying to accomplish is to find all of the points in the current view of the map.  Select then and then export each point as a table to a PDF.
0 Kudos
JimCousins
MVP Regular Contributor
The SelectLayerByLocation_management is looking for another feature layer, just as though you used the menu items SELECT>>SELECT BY LOCATION. There is no choice for "view extent".
It seems to me that you need to get a pointer to the dataframe ie: df = arcpy.mappinglListDataFrames(mxd)[0] , then use df.extent to return the current extent.
Next, you could get a cursor on the point features, and iterate through the rows, checking if the point.x and point.y values are within the dataframe extents, and adding them to the selectionset if they are.
Adding the selected attributes to the layout is a different problem. Do you need to show the entire attribute table, or just a few columns of information?
Regards,
Jim
0 Kudos
WilliamIde
New Contributor II
Just a few compared to the 20K or so records in the point featureclass.  I expect that the number of records will be between 30 and 60.  So I will interrogate the dr and come up with my map extent. Then as you say find the ones inside the extent.

From other posts I have seen that outputing to a PDF has probelems using 10.0.  ( I am using 10.0 SP2 )  There are goofy workarounds suggested.  Which I will try once I get the list of selected points.
0 Kudos