|
POST
|
I removed the try block. I get the following error, ERROR 000055: Cannot create a Query Table for this workspace Failed to execute (MakeQueryTable).
... View more
09-10-2021
11:04 AM
|
0
|
2
|
1916
|
|
POST
|
I need to be able to export the selected attributes from Arcmap. I have the following but I get an error on line 32. The first arcpy.Addmessage does print the OID's but not the second Addmessage. My guess is that it's not creating the temp_view. How can I get past this error? error on line 32 ERROR 000732: Input Table: Dataset tmp_view does not exist or is not supported Failed to execute (TableToExcel) selection = "NParcels"
try:
if int(arcpy.GetCount_management(selection).getOutput(0)) > 0:
arcpy.CopyRows_management(selection, "selct")
arcpy.MakeTableView_management("selct","selectionView")
fc = "selectionView"
desc = arcpy.Describe(fc)
oidList = [oid[0] for oid in arcpy.da.SearchCursor(fc,["OID@"])]
arcpy.AddMessage(oidList)
flds = [fld.name for fld in desc.fields]
flds_remove = [desc.OIDFieldName,
desc.shapeFieldName,
desc.areaFieldName,
desc.LengthFieldName]
for fld in flds_remove:
flds.remove(fld)
arcpy.MakeQueryTable_management(fc, "tmp_view", "NO_KEY_FIELD", "", flds)
oidList = [oid[0] for oid in arcpy.da.SearchCursor(fc,["OID@"])]
arcpy.AddMessage(oidList)
except:
pass
wp1 = "C:/Temp"
outputName = arcpy.GetParameterAsText(0)
outputDist = arcpy.GetParameterAsText(1)
OutputExt = ".xls"
#Result 'tmp_view'
arcpy.TableToExcel_conversion("tmp_view", wp1 +'\\'+ outputName + '_' + outputDist + '_' + 'Notification' + OutputExt) K
... View more
09-10-2021
08:37 AM
|
0
|
6
|
1929
|
|
POST
|
I need to spatial join only certain feature class with specific names but I am not sure how to pass the list of feature class on arcpy.ListFeatureClasses. There is about 10 feature classes in the geodatabase but like I said just need certain ones. import arcpy
from arcpy import env
env.workspace = r"C:\Temp\Default2.gdb"
env.overwriteOutput=True
#arcpy.CreateFileGDB_management(r"C:\Temp\Test", "test_6.gdb")
lst = ["Wetlands","Current_Panels"] # this is where I was trying to list the spcifice feature classes I need from the geodatabase.
fclist = arcpy.ListFeatureClasses(lst, "polygon")
for fc in fclist:
print (fc)
#fcdesc = arcpy.Describe(fc)
#print (fc)
#arcpy.Union_analysis(fc, "C:\Temp\Test\test_6.gdb")
... View more
08-12-2021
01:03 PM
|
0
|
5
|
2646
|
|
POST
|
I did try the following. workspace = r"C:\Users\***\AppData\Roaming\ESRI\Desktop10.8\ArcCatalog\***_***_***.sde"
fc1 = os.path.join("***.***.TEST","***.***.Test")
&
workspace = r"C:\Users\***\AppData\Roaming\ESRI\Desktop10.8\ArcCatalog\***_***_***.sde"
fc1 = "***.***.TEST","***.***.Test" But adding the workspace to the os.path.join is what allowed me to edit. workspace = r"C:\Users\***\AppData\Roaming\ESRI\Desktop10.8\ArcCatalog\***_***_***.sde"
fc1 = os.path.join(workspace,"***.***.TEST","***.***.Test") #adding workspace worked.
... View more
07-14-2021
10:15 AM
|
0
|
0
|
5413
|
|
POST
|
I get "False" when I added the print(arcpy.Exists(workspace)).
... View more
07-14-2021
09:40 AM
|
0
|
1
|
5446
|
|
POST
|
Thanks for the replay. I have being trying different workspace formats, with r and \\, / etc. Thanks for the recommendations. I made changes based on your recommendations and I still get the darn 'cannot open workspace' error. I am trying to see if inserCursor is faster then Append. In my current code the Append process just take to long so I thought I would try insertCursor.
... View more
07-14-2021
09:32 AM
|
0
|
1
|
5452
|
|
POST
|
Not sure what the issues is but I am trying to use arcpy.da.InsertCursor on a SDE feature class but keep getting the 'Can't open workspace' error.The feature-dateset is versioned. edit = arcpy.da.Editor(workspace) RuntimeError: cannot open workspace fc = r"C:\Users\***\AppData\Roaming\ESRI\Desktop10.8\ArcCatalog\***_***_***.sde\***.***.TEST\C***.***.Test"
workspace = os.path.dirname(fc)
#arcpy.env.workspace = r"C:\\Users\\***\\AppData\\Roaming\\Esri\\ArcGISPro\\Favorites\\Database Connections\\***_***.sde\\***.***.TEST"
#fc = "***.***.Test"
edit = arcpy.da.Editor(workspace)
# Edit session is started without an undo/redo stack for versioned data
# (for second argument, use False for unversioned data)
edit.startEditing(True)
# Start an edit operation
edit.startOperation()
dsc = arcpy.Describe(fc1)
fields = dsc.fields
# List all field names except the OID field
fieldnames = [field.name for field in fields]
# Create cursors and insert new rows
with arcpy.da.SearchCursor(fc1,fieldnames) as sCur:
with arcpy.da.InsertCursor(fc,fieldnames) as iCur:
for row in sCur:
iCur.insertRow(row)
del sCur
# Stop the edit operation.
edit.stopOperation()
# Stop the edit session and save the changes
edit.stopEditing(True)
... View more
07-14-2021
08:52 AM
|
0
|
10
|
5871
|
|
POST
|
I have tried to implement some field mapping to change some field names and it works on the first one but then errors. I am assuming that it is because it's is trying to change the field again? How can I by pass this on the second go around? Error line 33. FieldMappings: Error in getting field map from field mapping for GetFieldMap import arcpy, os
from arcpy import env
from datetime import datetime as d
startTime = d.now()
###Working 7/2/2021
arcpy.env.overwriteOutput = True
arcpy.env.workspace = r"C:\Temp\Default.gdb"
fc1 = r"C:\Temp\fc1.shp"
fcs = arcpy.ListFeatureClasses() #gets the feature class from database
counter = 1
for fc in fcs:
###Field Mapping
fieldmappings = arcpy.FieldMappings()
# Add all fields from inputs.
fieldmappings.addTable(fc1)
fieldmappings.addTable(fc)
# Name fields you want. Could get these names programmatically too.
keepers = ["Field1", "Field2", "Field3", "Field4","Field5", "Field6"] # etc.
# Remove all output fields you don't want.
for field in fieldmappings.fields:
if field.name not in keepers:
fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex(field.name))
# Rename fields
fieldmap = fieldmappings.getFieldMap(fieldmappings.findFieldMapIndex("DXF_LAYER"))
field.name = "Field1A"
field.type = 'Text'
#field.aliasName = "mean_city_pop"
fieldmap.outputField = field
#fieldmap.mergeRule = "Count"
fieldmappings.replaceFieldMap(fieldmappings.findFieldMapIndex("Field1"),fieldmap)
####
####
#print(fc)
out_fc = "SP_Test" + str(counter)
spjoin= arcpy.SpatialJoin_analysis(fc1,fc, out_fc, "JOIN_ONE_TO_ONE", "KEEP_ALL", fieldmappings, "INTERSECT", "", "")
counter += 1
fc1 = out_fc
print ('(Elapsed time: ' + str(d.now() - startTime)[:-3] + ')')
... View more
07-09-2021
07:39 AM
|
0
|
0
|
4861
|
|
POST
|
Where are you defining 'altfields', 'updateAddress' and 'subdivisions'?
... View more
07-07-2021
08:42 AM
|
0
|
1
|
1472
|
|
POST
|
To have one feature class with certain fields and rename some fields. I can keep certain fields with the following but I need to change some fields names and just the whole fieldmappings gives me a headache. fieldmappings = arcpy.FieldMappings()
# Add all fields from inputs.
fieldmappings.addTable(fc1)
fieldmappings.addTable(fc)
# Name fields you want. Could get these names programmatically too.
keepers = ["Field1", "Field2", "Field3", "Field4","Field5", "Field6"] # etc.
# Remove all output fields you don't want.
for field in fieldmappings.fields:
if field.name not in keepers:
fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex(field.name)) I need to be able to rename "Field1", "Field2", "Field3", "Field4","Field5", "Field6" to something else, "AFieldA", "BFieldB", "CFieldC", "DFieldD","EFieldE", "FFieldF". No specifically these names but to something else. I also need to use a merge rule and join delimiter to one layer in the database.
... View more
07-07-2021
08:39 AM
|
0
|
0
|
1473
|
|
POST
|
I guess I am confused about the who process. I was thinking./hoping I could do a spatial join all at once and spatial join would add the new fields from every feature class to the end of fc1. But it sounds like it will create a new feature class for every feature class in the database, maybe I am better off just doing individual spatial joins so I can do the field mapping. import arcpy, os
from arcpy import env
import traceback
from datetime import datetime as d
startTime = d.now()
arcpy.env.workspace = r"C:\Temp\Default2.gdb"
fc1 = r"C:\Temp\Taxparcels1.shp"
arcpy.env.overwriteOutput = True
fcs = arcpy.ListFeatureClasses() #gets the feature class names
# Creating a for loop to iterate over featureclasses
for i in range(0,len(fcs)):
fcs_s = fcs[i]
print (fcs_s)
arcpy.SpatialJoin_analysis(fc1,fcs_s, "SP_Test", "JOIN_ONE_TO_ONE", "KEEP_ALL", "", "INTERSECT", "", "")
... View more
07-01-2021
03:28 PM
|
0
|
2
|
4978
|
|
POST
|
ok, I see what the "Counter" is doing (SP_Test1, SP_Test2, SP_Test3). The Fc1 layer has 95K features after merging all there is 361,320k features in the merged layer. I must be missing something?
... View more
07-01-2021
08:22 AM
|
0
|
2
|
4997
|
|
POST
|
When you say 'all joins' do you meaning making 20+ separate spatial joins or arcpy.SpatialJoin_analysis(fc1,fc, "memory\SP_Test" + str(counter), "JOIN_ONE_TO_ONE", "KEEP_ALL", "", "INTERSECT", "", "")
... View more
07-01-2021
07:18 AM
|
0
|
0
|
5006
|
|
POST
|
If you don't mind sharing that would be great. I hate and think the way ESRI's traditional field mapping is so counterintuitive.
... View more
07-01-2021
07:11 AM
|
0
|
0
|
5006
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 08-01-2024 07:19 AM | |
| 1 | 07-26-2024 09:38 AM | |
| 1 | 01-08-2024 09:44 AM | |
| 1 | 03-07-2023 11:46 AM | |
| 1 | 11-02-2020 08:24 AM |
| Online Status |
Offline
|
| Date Last Visited |
02-12-2026
12:36 PM
|