POST
|
Hello, I have a file geodatabase table with a field titled "min_value". Within this field there are values from -1000 to +1000. I am trying to search all of the rows in the table to select the row with the lowest absolute value within the "min_value" field (ie. value +/- closest to zero). I will then be using a value (shapefile name) within the same row (but different field) to identify which shapefile to use in the next processing step of the script. Any help is greatly appreciated! Thank-you!
... View more
08-08-2012
08:07 AM
|
0
|
5
|
311
|
POST
|
Hello NobbirAhmed, I am using ArcGIS 9.3. when I added the additional print message, and the try/except block this error occured: Executing: SelectLayerByLocation 11013_e.lyr INTERSECT 11013_vec.lyr # ADD_TO_SELECTION 11013_e.lyr Start Time: Tue Jun 12 14:18:24 2012 Failed to execute. Parameters are not valid. ERROR 000732: Input Feature Layer: Dataset 20041115011426_20041122011013_e.lyr does not exist or is not supported ERROR 000732: Selecting Features: Dataset 20041115011426_20041122011013_vec.lyr does not exist or is not supported Failed to execute (SelectLayerByLocation).
... View more
06-12-2012
10:23 AM
|
0
|
0
|
348
|
POST
|
I added the try and except statement around the select layers by location by did not get any error messages generated. This is what printed in the python shell: Feature Layers created. (suggesting that the feature layers were created) Selecting vectors that intersect the gate for:20041115011426_20041122011013 (this is the start of the select by location commands) (i'm not sure why this is occuring after the feature layers should have aExecuting: MakeFeatureLayer E:\temp\5464648_vec.shp vec_lyr # # "CP CP VISIBLE NONE;startX startX VISIBLE NONE;startY startY VISIBLE NONE;dispX dispX VISIBLE NONE;dispY dispY VISIBLE NONE;sLat sLat VISIBLE NONE;sLon sLon VISIBLE NONE;theta theta VISIBLE NONE;pCorr pCorr VISIBLE NONE;pkStr pkStr VISIBLE NONE;cCorr cCorr VISIBLE NONE;conf conf VISIBLE NONE;velX velX VISIBLE NONE;velY velY VISIBLE NONE;endX endX VISIBLE NONE;endY endY VISIBLE NONE;eLat eLat VISIBLE NONE;eLon eLon VISIBLE NONE" Start Time: Tue Jun 12 12:57:06 2012 Executed (MakeFeatureLayer) successfully. End Time: Tue Jun 12 12:57:06 2012 (Elapsed Time: 0.00 seconds) I know that the select by location should work because when I do it manually in ArcMap, i'm able to select several features through following the similar set of commands but the automation for this step doesn't seem to run.
# Variables...
tableName_e = tableName + str("_e.shp")
tableName_vec = tableName + str("_vec.shp")
tableName_e = tableName + str ("_e.shp")
tableName_sim = tableName + str("_sim.shp")
gate = r"E:\test\gate.shp"
end_lyr = tableName + str("_e.lyr")
vec_lyr = tableName + str("_vec.lyr")
# Make a layer from the feature class
gp.MakeFeatureLayer_management(gate, "gate_lyr")
gp.MakeFeatureLayer_management(tableName_e, "end_lyr")
gp.MakeFeatureLayer_management(tableName_vec, "vec_lyr")
print "Feature Layers created."
#Selecting the vectors that intersect the gate
print "Selecting vectors that intersect the gate for:" + str(tableName)
# Process: Select Layer By Location...
gp.SelectLayerByLocation_management(vec_lyr, "INTERSECT", gate_lyr, "", "NEW_SELECTION")
# Process: Select Layer By Location (2)...
gp.SelectLayerByLocation_management(end_lyr, "INTERSECT", vec_lyr, "", "ADD_TO_SELECTION")
# Process: Select Layer By Location (3)...
gp.SelectLayerByLocation_management(vec_lyr, "INTERSECT", gate_lyr, "", "REMOVE_FROM_SELECTION")
# Write the selected features to a new feature class
gp.CopyFeatures_management(end_lyr, tableName_sim, "", "0", "0", "0")
... View more
06-12-2012
09:03 AM
|
0
|
0
|
769
|
POST
|
It says that the search distance is optional so I have tried to set it as "None", "Null", "No_Value", "", " ", "0", as I do not want to create a buffer, but rather only select the points that intersect with the specified vector... I can't seem to find any other alternative placeholder to setting it as blank. You need to use the proper syntax. SelectLayerByLocation_management (in_layer, overlap_type, select_features, search_distance, selection_type) http://webhelp.esri.com/arcgisdesktop/9.3/body.cfm?id=1877&pid=1865&topicname=Select%20Layer%20By%20Location%20%28Data%20Management%29&tocVisable=0 You are trying to insert "ADD_TO_SELECITON" in the search distance parameter.
... View more
06-12-2012
07:13 AM
|
0
|
0
|
769
|
POST
|
# Make a layer from the feature class
gp.MakeFeatureLayer_management(gate, "gate_lyr")
gp.MakeFeatureLayer_management(tableName_e, "tableName_e_lyr")
gp.MakeFeatureLayer_management(tableName_vec, "tableName_vec_lyr")
print "Feature Layers created."
#Selecting the vectors that intersect the gate
gp.SelectLayerByLocation_management(tableName_vec_lyr, "intersect", gate_lyr)
# Add to selection, points that intersect with the previously selected vectors
gp.SelectLayerByLocation_management(tableName_e_lyr, "intersect", tableName_vec_lyr, "ADD_TO_SELECTION")
# Remove initial vector selection
gp.SelectLayerByLocation_management(tableName_vec_lyr, "intersect", gate_lyr, "REMOVE_FROM_SELECTION")
# Write the selected features to a new feature class
gp.CopyFeatures(tableName_e_lyr, tableName_sim) The feature layers are successfully created, and the first "select layer by location " works, but it doesn't seem to perform the 2 subsequent "select layer by location"'s.
... View more
06-12-2012
06:18 AM
|
0
|
0
|
769
|
POST
|
When creating the feature layer using the following code,
# Make a layer from the shapefiles
gp.MakeFeatureLayer("tableName_e.shp", "tableName_e_lyr")
gp.MakeFeatureLayer("tableName_vctor.shp", "tableName_vctor_lyr") I am trying to call on shapefiles that were made earlier in the code (the files in blue), yet I am getting this error: Failed to execute. Parameters are not valid. ERROR 000732: Input Features: Dataset tableName_e.shp does not exist or is not supported Failed to execute (MakeFeatureLayer).
... View more
06-12-2012
04:43 AM
|
0
|
0
|
769
|
POST
|
Hello, I am trying to select features by location from the "tableName_vctor" layer as defined (and highlighted in red), then export them to a new shapefile and am receiving the following errors (refer to the blue section): ERROR 000622: Failed to execute (Select Layer By Location). Parameters are not valid. ERROR 000628: Cannot set input into parameter search_distance. any insight as to how to fix these errors is much appreciated thank-you in advance! try:
# Iterates through each of the input text files
for v in list(table):
# Removes the file extension
tableName = os.path.splitext(v)[0]
# Variables
tableName_line = tableName + str("_line.shp")
tableName_vctor = tableName + str("_vctor.shp")
tableName_e = tableName + str ("_e.shp")
gate = r"C:\gis\gate.shp"
tableName_sim = tableName + str("_sim.shp")
# Creating vectors from xy coordinates
gp.Toolbox = r"C:\Program Files\ArcGIS\ArcToolbox\Toolboxes\Military Analyst Tools.tbx"
gp.TableToLine_ma(v, tableName_line, "Decimal Degrees", "sLat", "sLon", "eLat", "eLon", "False", "False")
gp.Project_management(tableName_line, tableName_vctor, "PROJCS['LCC']")
#Selecting vectors that intersect a line, then points that intersect the vector, then removing the initial selection
gp.SelectLayerByLocation(tableName_vctor, "intersect", gate, "NEW_SELECTION")
gp.SelectLayerByLocation(tableName_e, "intersect", tableName_vctor, "ADD_TO_SELECTION")
gp.SelectLayerByLocation(tableName_vctor, "intersect", gate, "REMOVE_FROM_SELECTION")
# Write the selected features to a new feature class in the folder
gp.CopyFeatures(tableName_sim, r"C:\gis\temp")
except:
#If an error occurred while running the script, then print the messages
print gp.GetMessages()
... View more
06-11-2012
11:17 AM
|
0
|
13
|
2156
|
POST
|
Thank-you Everyone! I've finally got it working now!
... View more
06-07-2012
10:57 AM
|
0
|
0
|
382
|
POST
|
Hello again, When I run the script, I recieved this error: Failed to execute. Parameters are not valid. ERROR 000732: Input Features: Dataset tableName_tmp1.shp does not exist or is not supported Failed to execute (CopyFeatures). I tried to solve it by adding the local variables (similar to the original model that was exported from Model Builder), but that didn't seem to work ... any suggestions as to where I am going wrong? Thanks! # List the .txt file input tables
table = gp.ListTables("*txt")
print table
try:
for t in list(table):
# Removes the file extension
tableName = os.path.splitext(t)[0]
# Reports which table is being processed
gp.addmessage("Processing table" + str(tableName))
# Local variables...
tableName_tmp = tableName + str("_tmp")
tableName_tmp1 = tableName + str("_tmp1")
tableName_e = tableName + str("_e.shp")
tableName_tmp1A = tableName + str("_tmp1A.shp")
tableName_s = tableName + str("_s.shp")
tableName_tmpA = tableName + str("_tmpA.shp")
# Process: Make XY Event Layer (endLatLon)...
gp.MakeXYEventLayer_management(t, "eLon", "eLat", tableName_tmp1, "GeographicCoordinates")
# Process: Copy Features (endLatLon)...
gp.CopyFeatures_management("tableName_tmp1.shp", tableName_tmp1A, "", "0", "0", "0")
# Process: Project (endLatLon)...
gp.Project_management("tableName_tmp1A.shp", tableName_e, "ProjectedCoordinates")
# Process: Add Field onto(endLatLon)...
gp.AddField_management("tableName_e.shp", "Vel_Value", "FLOAT", "6", "4", "", "", "NON_NULLABLE", "NON_REQUIRED", "")
# Process: Calculate Field onto (endLatLon)...
gp.CalculateField_management("tableName_e.shp", "Vel_Value", "x^2 ", "VB", "")
# Process: Make XY Event Layer (startLatLon)...
gp.MakeXYEventLayer_management(tableName, "sLon", "sLat", tableName_tmp, "GeographicCoordinates")
# Process: Copy Features (startLatLon)...
gp.CopyFeatures_management("tableName_tmp.shp", tableName_tmpA, "", "0", "0", "0")
# Process: Project (startLatLon)...
gp.Project_management("tableName_tmpA.shp", tableName_s, "ProjectedCoordinates")
except:
#If an error occurred while running the script, then print the messages
print gp.GetMessages()
... View more
06-07-2012
09:24 AM
|
0
|
0
|
382
|
POST
|
I changed the code as follows, now I am getting a tab/space error... I have de-dented all of the code, and re-indented it. I have even tried the untabify region with no success. Is there anything else could be causing this problem? Also, I am unsure as to how to name the output files at the individual steps within the for loop ... it seems that this might be the cause of the problem? # List the .txt file input tables
table = gp.ListTables("*txt")
print table
try:
for t in list(table):
# Removes the file extension
tableName = os.path.splitext(t)[0]
# Reports which table is being processed
gp.addmessage("Processing table" + str(tableName))
# Process: Make XY Event Layer (endLatLon)...
gp.MakeXYEventLayer_management(tableName, "eLon", "eLat", tableName + (str(_tmp1)), "Coordinate System")
# Process: Copy Features (endLatLon)...
gp.CopyFeatures_management(tableName_tmp1), tableName + (str(_tmp1a)), "", "0", "0", "0")
# Process: Project (endLatLon)...
gp.Project_management(tableName_tmp1a, tableName + (str(_e.shp)), "PROJCS['LCC')]")
# Process: Add Field onto(endLatLon)...
gp.AddField_management(tableName_e.shp), "Vari", "FLOAT", "3", "2", "", "", "NON_NULLABLE", "NON_REQUIRED", "")
# Process: Calculate Field onto (endLatLon)...
gp.CalculateField_management(tableName_e.shp, "Vari", "Sqr ( x^2 )", "VB", "")
# Process: Make XY Event Layer (startLatLon)...
gp.MakeXYEventLayer_management(tableName, "sLon", "sLat", tableName + (str(_tmp)), "Coordinate System")
# Process: Copy Features (startLatLon)...
gp.CopyFeatures_management(tableName_tmp), tableName + (str(_tmpa)), "", "0", "0", "0")
# Process: Project (startLatLon)...
gp.Project_management(tableName_tmpa.shp, tableName + (str(_s.shp)), "PROJCS['LCC')]")
except:
#If an error occurred while running the script, then print the messages
print gp.GetMessages()
... View more
06-07-2012
05:48 AM
|
0
|
0
|
382
|
POST
|
Hello, I created a model using model builder, and have exported it as a python script. What I am trying to do, by using the for loop, is have it run in batch mode for a series of .txt files that are tables. I am trying to have it so that the end result its 2 separate shape files, one that has been created for the starting latlon, and the other for the endlatlon (with the values all coming from 4 separate columns in the .txt file). I have run into a lot of difficulties trying to create a python script that will run in batch mode ... I am very new to python (as I'm sure you are able to tell by the code), and would appreciate any feedback as to how to use this model that has been exported from model builder by using python and running in batch mode. Thank-you # Import system modules import sys, string, os, arcgisscripting # Create the Geoprocessor object gp = arcgisscripting.create(9.3) # Load required toolboxes... gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx") # Allows geoprocessing tools to overwrite the output if it already exists. gp.OverWriteOutput = True # Set the Environment Variables gp.Workspace = r"C:\TST_Folder" # List the .txt file input tables table = gp.ListTables("*txt") try: # For each .txt table found in the Workspace, perform the following series of tasks for each .txt file for table in Workspace: # Removes the file extension tableName = table[:-4] # Reports which table is being processed gp.addmessage("Processing table" + str(tableName)) # Process: Make XY Event Layer (E_LATLON)...Save file as the tableName with tmp1 as the suffix gp.MakeXYEventLayer_management(tableName, "LON", "LAT", tableName + (str(tmp1)), "GEOGCS['GCS_WGS_1984',DATUM") # Process: Copy Features (E_LATLON)...Save file as the tableName with tmp1 as the suffix gp.CopyFeatures_management(tableName + (str(tmp1)), tableName + (str(tmp1.shp)), "", "0", "0", "0") # Process: Project (E_LATLON)...Save file as the tableName with _e as the suffix gp.Project_management(tableName + (str(tmp1.shp)), tableName + (str(_e.shp)), "PROJCS['LCC']) # Process: Add Field onto(E_LATLON)... gp.AddField_management(tableName + (str(_e.shp)), "Title", "FLOAT", "6", "4", "", "", "NON_NULLABLE", "NON_REQUIRED", "") # Process: Calculate Field onto (E_LATLON)... gp.CalculateField_management(tableName_e.shp, "Title", "Sqr ( X^2 )", "VB", "") # Process: Make XY Event Layer (S_LATLON)... Save file as the tableName with tmp as the suffix gp.MakeXYEventLayer_management(tableName, "sLon", "sLat", tableName_tmp, "GEOGCS['GCS_WGS_1984',DATUM") # Process: Copy Features (S_LATLON)... Save file as the tableName with tmp as the suffix gp.CopyFeatures_management(tableName + (str(tmp)), tableName + (str(tmp.shp)), "", "0", "0", "0") # Process: Project (S_LATLON)... Save file as the tableName with _s as the suffix gp.Project_management(tableName_tmp.shp, tableName + (str(_s.shp)), "PROJCS['LCC']) except: #If an error occurred while running the script, then print the messages print gp.GetMessages()
... View more
06-06-2012
03:52 PM
|
0
|
7
|
1323
|
POST
|
Hello, I am trying to import .txt files (tables) into a geodatabase (as a table) using the code below, but am getting the following error: Traceback (most recent call last): inTables = inTables + " ; " + tb TypeError: can only concatenate tuple (not "str") to tuple Does anyone know what might be causing this and how to fix it? Thank-you # Import system modules import sys, string, os, arcgisscripting # Create the Geoprocessor object gp = arcgisscripting.create() # Load required toolboxes... gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx") # To import the .txt tables into the geodatabase # the folder where the original table files are stored inFolder = "C:\\w\\x\\y\\z\\mnth" # the geodatabase where the tables will be imported to outGeodatabase = "C:\\w\\x\\test.gdb" inTables = ("*", "txt") gp.Workspace = inFolder tbs = gp.ListTables() tb = tbs.Next() while tb: if inTables: inTables = inTables + " ; " + tb else: inTables = tb tb = tbs.Next() # Put a try-except-look around the tool, in case an error occurs try: print "Importing the following tables: " + inTables gp.TableToGeodatabase(inTables, outGeodatabase) except: # If an error occurred, print the messages returned by the tool print gp.GetMessages() print "Completed: Table Added to Geodatabase"
... View more
06-01-2012
07:13 AM
|
0
|
2
|
406
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|