POST
|
I have the layer open in ArcMap. I then select features from it, and open the toolbox. I input the layer that has selected features "LASGridU" and run the script, but it does not honor the selection. It is actually just a regular Toolbox, but I have added a script written in Python to it. Sorry for the misnomer.
... View more
02-23-2016
11:59 AM
|
0
|
1
|
1567
|
POST
|
Freddie, the cursor is called on the user-inputted polygon feature class, which would have features selected. This is the variable is "LASGridU" which as you can see the SearchCursor is called on. I have tried selecting features, and then running the script in the toolbox, but it doesn't work.
... View more
02-23-2016
11:58 AM
|
0
|
0
|
1567
|
POST
|
Hi folks, I posted a similar question back in October that has remained unanswered, and have seen this question before on Stack Exchange (arcpy - How to pass only selected features in python toolbox - Geographic Information Systems Stack Exchange) but found that the answer did not work. I've created a toolbox that will allow a user to select certain polygon features (in this case, grid squares from a LiDAR survey). The selection *should* then be then used to get the selected .LAS files (based on the name, extracted from the polygon feature) from a specified folder, and create an LAS Dataset. I have found that despite my best efforts, the script still does not recognize the user selection and tries to put ALL of the features in the polygon feature class into the LAS Dataset. From what I've read, if a user has selected features from a feature class, a Search Cursor should just recognize that and will run on solely those features that were selected. For some reason this does not seem to be working for me. Any help appreciated. Also for what it's worth, I've tried doing the syntax highlighting for Python about 5 times and it refuses to post with it, so I apologize for that. Not sure what the deal is. try : import arcpy, sys, traceback, os.path from arcpy.sa import * arcpy.env.overwriteOutput = 1 arcpy.env.workspace = r "C:\Users\Kate\GIS" # NEED TO TURN THIS INTO A TOOLBOX SO THAT THE SELECTION IS HONORED. # User define input SHP (LASGRID FILE) LASGridU = sys.argv[ 1 ] # User define location of LAS tiles to be used LASLocationU = sys.argv[ 2 ] # User define output location of output LAS dataset LASDname = sys.argv[ 3 ] # User define spatial reference (not optional) spatialRefU = sys.argv[ 4 ] count = 0 # Create new feature class from selected features in LASGrid (apparently only way) #arcpy.CopyFeatures_management(LASGridU,selGrid) # Create the search cursor sCursor = arcpy.SearchCursor(LASGridU) # Create list to hold names of selected LAS files LASList = [] finalLAS = [] for row in sCursor: LASList.append( str (row.getValue( "LAS_File" ))) count + = 1 for las in LASList: finalLAS.append(os.path.join(LASLocationU + "/" + las)) arcpy.AddMessage(LASList) arcpy.AddMessage(finalLAS) # create LAS Dataset with the selected features in the index arcpy.CreateLasDataset_management(finalLAS, LASDname," "," ",spatialRefU," COMPUTE_STATS "," RELATIVE_PATHS") print count del row, sCursor except : tb = sys.exc_info()[ 2 ] tbinfo = traceback.format_tb(tb)[ 0 ] pymsg = tbinfo + "\n" + str (sys.exc_type) + ": " + str (sys.exc_value) arcpy.AddError(pymsg) arcpy.AddError(arcpy.GetMessages( 2 ))
... View more
02-23-2016
07:31 AM
|
1
|
5
|
4805
|
POST
|
Thanks to you both for some great insight! Owen, your suggestion of adding both original fields to the DBF motivated me to look at the documentation for arcpy.Statistics_analysis(), which is what I was using originally to create it, and gave me the answer! A second look at the documentation shows that you can actually use a combination of fields to create unique values for the case field on which to summarize. The code I was using originally was this: arcpy.Statistics_analysis(outputPoly, outputDBFTable, [["LithPerc", "SUM"]], "ConcatField") The code I ended up using that worked was this: arcpy.Statistics_analysis(outputPoly, outputDBFTable, [["LithPerc", "SUM"]], ["ROCKTYPE1","ROCKTYPE2"]) This allows you to summarize unique values but also maintain the original, separate fields. Cool!
... View more
12-09-2014
01:53 PM
|
1
|
0
|
1061
|
POST
|
I have searched extensively but can't really find any good documentation on using the TextToColumns method within Excel using win32com. The VB developer help gives the following example, but translating the parameters into Python has been a challenge. VBA: Worksheets("Sheet1").Activate
ActiveSheet.Paste
Selection.TextToColumns DataType:=xlDelimited, _
ConsecutiveDelimiter:=True, Space:=True The code I currently have takes 2 fields in a shapefile and concatenates them together with a "_" for unique identifier summarizing purposes while in ArcGIS, i.e., exRock = "!ROCKTYPE1!+'_'+!ROCKTYPE2!" Once the tables are exported to DBF and then converted to an XLS file, I want to separate the fields again based on the "_". If there is an easier way to do this without Excel any insights would be appreciated! I have tried using the .partition() method and csv files/strings however I can't get that to work correctly either.
... View more
12-09-2014
07:53 AM
|
0
|
3
|
4242
|
Title | Kudos | Posted |
---|---|---|
1 | 02-23-2016 07:31 AM | |
1 | 12-09-2014 01:53 PM |
Online Status |
Offline
|
Date Last Visited |
09-10-2021
12:55 PM
|