|
POST
|
I get "False" when I added the print(arcpy.Exists(workspace)).
... View more
07-14-2021
09:40 AM
|
0
|
1
|
4897
|
|
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
|
4904
|
|
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
|
5236
|
|
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
|
4257
|
|
POST
|
Where are you defining 'altfields', 'updateAddress' and 'subdivisions'?
... View more
07-07-2021
08:42 AM
|
0
|
1
|
1189
|
|
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
|
1190
|
|
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
|
4374
|
|
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
|
4393
|
|
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
|
4402
|
|
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
|
4402
|
|
POST
|
I have over 20 layers that I need to spatially join, doing separate arcpy.SpatialJoin_analysis for each one would be time consuming. fc1 is the layer I want to multi batch the other layers in the database to. I have tried the following but it only spatially joins the first layer in the database. Is it possible to do a multi batch spatial joins? I am going about it the wrong way? import arcpy, os
from arcpy import env
from datetime import datetime as d
startTime = d.now()
arcpy.env.workspace = r"C:\Temp\Default2.gdb"
fc1 = r"C:\Temp\Default2.gdb\Parcels"
arcpy.env.overwriteOutput = True
fcs = arcpy.ListFeatureClasses() #gets the feature classes
for fc in fcs:
print(fc)
arcpy.SpatialJoin_analysis(fc1,fc, "SP_Test", "JOIN_ONE_TO_ONE", "KEEP_ALL", "", "INTERSECT", "", "")
print ('(Elapsed time: ' + str(d.now() - startTime)[:-3] + ')') fc1
... View more
06-30-2021
03:35 PM
|
0
|
15
|
5679
|
|
POST
|
Thank you for the replies, after looking at the data a little I was wrong, I was working with the wrong data sorry about that. So the Source table has OBJECTID_1(not sure way but this is how I get the data) and the target has OBJECTID. So the InsurtCur 'Cannot find field 'OBJECTID_1'. The Source OBJECTID_1 should go into the targets OBJECTID but as I said it can't find it. Maybe I am still over thinking it... If I use append would the ObjectID vs ObjectID_1 be an issue? I was trying use understand search and insert cursors to understand them better.
... View more
06-23-2021
09:29 AM
|
0
|
1
|
2836
|
|
POST
|
I guess I was completely over thinking it. dsc = arcpy.Describe(Source)
fields = dsc.fields
#out_fields = [dsc.OIDFieldName]
fieldnames = [field.name for field in fields]
lstFields = [field.name for field in fields]
with arcpy.da.SearchCursor(Source,fieldnames) as sCur:
with arcpy.da.InsertCursor(Target,lstFields) as iCur:
for row in sCur:
iCur.insertRow(row)
... View more
06-22-2021
08:15 AM
|
0
|
3
|
2849
|
|
POST
|
So can Field1A be skipped/not included when you pass the InsertCurosr, if so how?
... View more
06-21-2021
03:50 PM
|
0
|
5
|
2864
|
|
POST
|
The field Field1A doesn't exist in the source table only in the target. I guess I was thinking that line 12& 13 would take care of that issue for both the Source SearchCuror and the Target InsertCursor.
... View more
06-21-2021
01:33 PM
|
0
|
8
|
2879
|
| 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 |
07-14-2025
07:49 AM
|