POST
|
Syntax CreateFeatureclass_management (out_path, out_name, {geometry_type}, {template}, {has_m}, {has_z}, {spatial_reference}, {config_keyword}, {spatial_grid_1}, {spatial_grid_2}, {spatial_grid_3}) the MDB seems to be working
... View more
02-06-2017
11:43 AM
|
0
|
0
|
192
|
POST
|
f = open(iFile, 'r')# input text file C:\Scripts\Lab 7 Data\NorthAmericaWildfires_2007275.txt in "read" mode lstFires = f.readlines() # Read the first lines of file print (lstFires[0]) print (lstFires[0].strip().split(',')) This gives me : Latitude,Longitude,Confidence ['Latitude', 'Longitude', 'Confidence'] But how can I access the Confidence string only, to be used later in arcpy.AddField_management
... View more
02-06-2017
09:59 AM
|
0
|
2
|
1280
|
POST
|
conField = [] for line in f: conField = line.split(',')[2] field = ["SHAPE@", conField] # represents the field names for each row in the feature class # Process: Create Feature Class arcpy.CreateFeatureclass_management(work, output, "POINT") arcpy.AddField_management(output, conField, "FLOAT") Traceback (most recent call last): File "C:\Program Files (x86)\Wing IDE 101 4.1\src\debug\tserver\_sandbox.py", line 25, in <module> File "C:\Program Files (x86)\ArcGIS\Desktop10.3\arcpy\arcpy\management.py", line 3246, in AddField raise e RuntimeError: Object: Error in executing tool
... View more
02-06-2017
09:16 AM
|
0
|
0
|
1280
|
POST
|
conField = [] for line in f: conField = line.split(',')[2] field = ["SHAPE@", conField] # represents the field names for each row in the feature class # Process: Create Feature Class arcpy.CreateFeatureclass_management(work, output, "POINT") arcpy.AddField_management(output, conField, "FLOAT") Traceback (most recent call last): File "C:\Program Files (x86)\Wing IDE 101 4.1\src\debug\tserver\_sandbox.py", line 25, in <module> File "C:\Program Files (x86)\ArcGIS\Desktop10.3\arcpy\arcpy\management.py", line 3246, in AddField raise e RuntimeError: Object: Error in executing tool
... View more
02-06-2017
09:16 AM
|
0
|
1
|
1280
|
POST
|
I am attempting to write a script so that instead of hardcoding the name of the new field as "CONFIVALUE" for the confidence value, I want to use the name of the third column in the header of the input text file. For example, let's say that the first line of the input text file looks like this: Latitude,Longitude,Confidence In this case the field name should be "Confidence". If the first line looked like this: Latitude,Longitude,ConfidValue Then the field name should be "ConfidValue". The error if i have conField indexed as conField[2]: Traceback (most recent call last): File "C:\Users\Aleah\Desktop\PythonScripts\Lab7_Q5.py", line 22, in <module> IndexError: list index out of range The error i am receiving if i remove the index is: Traceback (most recent call last): File "C:\Program Files (x86)\Wing IDE 101 4.1\src\debug\tserver\_sandbox.py", line 27, in <module> File "C:\Program Files (x86)\ArcGIS\Desktop10.3\arcpy\arcpy\management.py", line 3246, in AddField raise e RuntimeError: Object: Error in executing tool import arcpy work = "C:\Scripts\Lab 7 Data\WildlandFires.mdb" arcpy.env.workspace = work # Set the workspace to the geodatabase arcpy.env.overwriteOutput = True iFile = "C:\Scripts\Lab 7 Data\NorthAmericaWildfires_2007275.txt" output = "NewFires.shp" threshold = 99 f = open(iFile, 'r')# input text file C:\Scripts\Lab 7 Data\NorthAmericaWildfires_2007275.txt in "read" mode lstFires = f.readlines() # Read the lines of fire conField = [] for line in f: comma = line.split(',') conField = comma print conField[2] field = ["SHAPE@", conField[2]] # represents the field names for each row in the feature class # Process: Create Feature Class arcpy.CreateFeatureclass_management(work, output, "POINT") arcpy.AddField_management(output, conField[2], "FLOAT") cursor_new = arcpy.da.InsertCursor(output, field)# add the new points that you will create to the "NewFires" feature class f.close() # close the file del cursor_new # release the cursor lock on the feature class
... View more
02-05-2017
11:59 AM
|
0
|
12
|
3059
|
POST
|
Corrected Working Code: import arcpy try: work = arcpy.env.workspace = raw_input("Enter the full workspace path: ") sType = "JUNIOR HIGH" outFile = "output.shp" arcpy.env.overwriteOutput = True def selectSchools(work,sType, outFile): fc = "Schools.shp" arcpy.MakeFeatureLayer_management(fc, "schoolslyr") query = "\"FACILITY\" = '{0}'".format(sType) arcpy.Select_analysis(fc, outFile, query) with arcpy.da.UpdateCursor(outFile, ['VERIFIED', 'NAME']) as uCursor: for row in uCursor: if row[0] != 'y': print ("The following schools have not been verified: "), row[1] if (row[0] != 'y'): uCursor.deleteRow() selectSchools(work,sType,outFile) except Exception as e: print "ERROR IN FUNCTION 'selectSchools' " + str("") # Prints Python-related errors print arcpy.GetMessages() # Prints ArcPy-related errors arcpy.AddError(e) # Adds errors to ArcGIS custom tool
... View more
02-01-2017
10:00 AM
|
1
|
0
|
1863
|
POST
|
My updated code is now printing out the names of the facilities that do not equal "y" which is good. But when I try to delete those same names from my rows, it deletes all of my records.
... View more
02-01-2017
08:43 AM
|
0
|
1
|
1863
|
POST
|
Is there a way to write this in a 'for' or 'while' loop using either update cursor or deleteRow()?
... View more
02-01-2017
06:13 AM
|
0
|
3
|
1863
|
POST
|
In my program: -I am selecting only schools of the specified type based on the "FACILITY" field and creating new feature class of the result. - Deleting records from the resulting feature class from "Select" where the "Verified" field does not equal "Y" (I need to use: Update cursor and deleteRow method) - While deleting records, print the name of each deleted school My code is not deleting the features that are not equal to "Y". And I am not sure how to print out the values that do not equal "Y". import arcpy work = arcpy.env.workspace = "c:\Scripts\Lab 6 Data" sType = "JUNIOR HIGH" outFile = "output.shp" arcpy.env.overwriteOutput = True def selectSchools(work,sType, outFile): fc = "Schools.shp" arcpy.MakeFeatureLayer_management(fc, "schoolslyr") query = "\"FACILITY\" = '{0}'".format(sType) arcpy.Select_analysis(fc, outFile, query) arcpy.AddMessage("Select_Analysis layer tool completed!") where_c = "\"VERIFIED\" = 'y%'" update = arcpy.UpdateCursor(outFile, where_c) row = update.next() for row in update: update.setValue(where_c) update.updateRow(row) print("The uppdate row was sucessful!") print ("The following schools have not been verefied: ") selectSchools(work,sType,outFile)) Updated Code: import arcpy work = arcpy.env.workspace = "c:\Scripts\Lab 6 Data" sType = "JUNIOR HIGH" outFile = "output.shp" arcpy.env.overwriteOutput = True def selectSchools(work,sType, outFile): fc = "Schools.shp" arcpy.MakeFeatureLayer_management(fc, "schoolslyr") query = "\"FACILITY\" = '{0}'".format(sType) arcpy.Select_analysis(fc, outFile, query) arcpy.AddMessage("Select_Analysis layer tool completed!") with arcpy.da.UpdateCursor(outFile, ['VERIFIED', 'NAME']) as uCursor: for row in uCursor: if row[0].upper() != 'y%': print row[1] if (row[0].upper() != 'y%'): uCursor.deleteRow() selectSchools(work,sType,outFile)
... View more
01-31-2017
06:06 PM
|
1
|
5
|
2908
|
POST
|
The sTyp will be converted into a raw_input statement. It is just hard-coded here for convenience. Instead of select layer by attribute, is there a way to get to the field "Facility" the value 'High School' by using SearchCursor()?
... View more
01-31-2017
01:07 PM
|
0
|
2
|
2043
|
POST
|
Sorry, I do not need to return the names of the schools just the count. I works fine when I hard-coded it but I do not know how to change the sTyp to High School or Elementary School and return the correct output. I am required to use Search Cursors to write my code. using arcpy or arcpy.da
... View more
01-31-2017
11:04 AM
|
0
|
0
|
2043
|
POST
|
I have this attribute table where I am supposed to access the Field "Facility" and based on what type of facility the user enters, my code is supposed to return the names and count of that facility type. For example: I enter High School as my facility type. My code needs to return the names of the high schools, as well as how many high schools there are. Oh and this is supposed to operate as a function. import arcpy arcpy.env.workspace = raw_input("Enter the workspace path: ")# c:\Scripts\Lab 6 Data shapefile = "Schools.shp" work = arcpy.env.workspace sTyp = "HIGH SCHOOL" def numSchools(work, shapefile, sTyp): sc = arcpy.SearchCursor(work, shapefile) field = "FACILITY" for row in sc: if row.getValue(field)== sTyp return row.getValue("NAME") numSchools(work, shapefile, sTyp)
... View more
01-31-2017
10:02 AM
|
0
|
6
|
2958
|
Title | Kudos | Posted |
---|---|---|
1 | 02-01-2017 10:00 AM | |
1 | 01-31-2017 06:06 PM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:25 AM
|