Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Select features from layers and send to output tables...

$
0
0
I'm sure there is an easier way to do this so any help would be appreciated:

I have a shapefile with all valves (hydrant valves and main valves) included in it. I want to select all of the main valves in the currentview extent and output them to a table called "Main Valves" and select the hydrant valves in the current extent and output them to a table called "Hydrant Valves".

Code:

  for lyr in arcpy.mapping.ListLayers(mxd, "", df):
    if lyr.name == "Main Valves"
      extentPolygon = arcpy.Polygon(arcpy.Array([df.extent.lowerLeft,df.extent.lowerRight, df.extent.upperRight, df.extent.upperLeft]),df.spatialReference)
      arcpy.SelectLayerByLocation_management(lyr, "INTERSECT", extentPolygon, "", "NEW_SELECTION")
      arcpy.CopyRows_management("Main valves", tbl1)
      mainvalves_outputrows = arcpy.SearchCursor(tbl1,"","","Valve_ID; vDiameter; LOCATION_DATA","Valve_ID")
    elif lyr.name == "Hydrant Valves"
      extentPolygon = arcpy.Polygon(arcpy.Array([df.extent.lowerLeft,df.extent.lowerRight, df.extent.upperRight, df.extent.upperLeft]),df.spatialReference)
      arcpy.SelectLayerByLocation_management(lyr, "INTERSECT", extentPolygon, "", "NEW_SELECTION")
      arcpy.CopyRows_management("Hydrant valves", tbl2)
      hydrantvalves_outputrows = arcpy.SearchCursor(tbl2,"","","Valve_ID; vDiameter; LOCATION_DATA","Valve_ID")
    else:
       
  Clear all table text values
  tab1Col1Txt.text = " "; tab1Col2Txt.text = " "; tab1Col3Txt.text = " "
  tab1Col1Value = ""
  tab1Col2Value = ""
  tab1Col3Value = ""
  tab2Col1Txt.text = " "; tab2Col2Txt.text = " "; tab2Col3Txt.text = " "
  tab2Col1Value = ""
  tab2Col2Value = ""
  tab2Col3Value = ""
 
  for row in mainvalves_outputrows:
    tab1Col1Value += str(row.Valve_ID) + "\n"
    tab1Col2Value += str(row.vDiameter) + "\n"
    tab1Col3Value += str(row.LOCATION_DATA) + "\n"

  tab1Col1Txt.text = tab1Col1Value
  tab1Col2Txt.text = tab1Col2Value
  tab1Col3Txt.text = tab1Col3Value

  for row in hydrantvalves_outputrows:
    tab2Col1Value += str(row.Valve_ID) + "\n"
    tab2Col2Value += str(row.vDiameter) + "\n"
    tab2Col3Value += str(row.LOCATION_DATA) + "\n"

  tab2Col1Txt.text = tab2Col1Value
  tab2Col2Txt.text = tab2Col2Value
  tab2Col3Txt.text = tab2Col3Value


Viewing all articles
Browse latest Browse all 2485

Trending Articles