|
POST
|
yes i can do it on pro, i am trying to do it in a python script. I have the following to start with but i am not quite here but my approach may not be the correct one. BD = str('BUFF_DIST')
array = arcpy.Array()
with arcpy.da.SearchCursor(lyr, BD) as rows:
for r in rows:
for part in r[0]:
array.append(part)
poly = arcpy.Polygon(array, sr)
arcpy.management.CopyFeatures(poly, r'in_memory\multipart_poly_merge')
... View more
01-09-2020
11:06 AM
|
0
|
9
|
6066
|
|
POST
|
I have a feature class that can have many features within it i would like to merge all the features in this feature class into just one based on the "BUFF_DIST" like you would in ArcMap when you start editing, select all the features and go to edit, merge and you get the popup "Chose the feature with which other features will be merged:" i am trying to avoid creating a new feature class. Anyone done this or have an example of some python code?
... View more
01-09-2020
08:35 AM
|
0
|
20
|
10491
|
|
POST
|
I don't, which is why i was looking into trying to do it with python.
... View more
12-16-2019
01:02 PM
|
0
|
1
|
1374
|
|
POST
|
I have a feature class of polylines that are duplicate, one on top of the other and i would like to delete all except for 1 and it doesn't matter witch one just as long as there is one left. I would like this to be done in arcmap. I have the following that identifies the duplicates but i am not sure on how to delete duplicates in the set. import itertools, arcpy
arcpy.env.overwriteOutput = True
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
lyr = arcpy.mapping.ListLayers(mxd, "Parcel_Lines1")[0]
dsc = arcpy.Describe(lyr)
sr = dsc.spatialReference
oid_field_name = dsc.oidFieldName
# get a cursor on the input features
rows1 = arcpy.SearchCursor(lyr)
# exclude features already compared once
exclude = []
# iterate through the first coursor
for row1 in rows1:
oid1 = row1.getValue(oid_field_name)
shp1 = row1.shape
# get a second cursor on the same input features
rows2 = arcpy.SearchCursor(lyr)
# add the feature to be compared to exclude list
exclude.append(oid1)
# create a set to hold duplicate features
group = set()
# iterate through the second cursor
for row2 in rows2:
oid2 = row2.getValue(oid_field_name)
shp2 = row2.shape
# ignore features already compared
if oid2 in exclude:
continue
# test equality
if shp1.equals(shp2):
# add both feature ids to the set of identical features
group.add(oid1)
group.add(oid2)
# add the feature just compared to the exclude list
exclude.append(oid2)
if group: # if the group is not empty
print group
... View more
12-16-2019
11:39 AM
|
0
|
4
|
1461
|
|
POST
|
Thanks everyone that replied. I was able to come with the following code that works for me. fyi, Michael Boyce your code did work by the way. import arcpy
from datetime import datetime as d
startTime = d.now()
start_time = time.time()
arcpy.env.overwriteOutput = True
arcpy.env.workspace = "C:/Temp/blah.gdb"
fc1 = "C:/Temp/blah.gdb/Parcels"
arcpy.MakeFeatureLayer_management(fc1, "fc1Lyr")
CITY = "C:/Temp/blah.gdb/City_Limits"
arcpy.MakeFeatureLayer_management(CITY, "CityLyr")
with arcpy.da.SearchCursor("CityLyr", ["SHAPE@"]) as cursor:
for row in cursor:
#SELECT PROPERTIES BY CITYLIMITS
selection = arcpy.SelectLayerByLocation_management("fc1Lyr","HAVE_THEIR_CENTER_IN", "CityLyr")
result = int(arcpy.GetCount_management("fc1Lyr").getOutput(0))
with arcpy.da.UpdateCursor(selection, ['field1','field2','field3', 'field4']) as cursor:
for row in cursor:
# Select all parcels within the city limits layer
row[0] = "IN CITY"
row[1] = "IN CITY"
row[2] = "IN CITY"
row[3] = "IN CITY"
cursor.updateRow(row)
del row, cursor
try:
print ('(Elapsed time: ' + str(d.now() - startTime)[:-3] + ')')
print ('Number of features processed: ' + str(result))
except Exception as e:
# If an error occurred, print line number and error message
import traceback, sys
tb = sys.exc_info()[2]
print ("Line %i" % tb.tb_lineno)
print (e.message)
... View more
12-12-2019
09:16 AM
|
1
|
1
|
1042
|
|
POST
|
The data is in file database i didn't think i need to start an edit session.
... View more
12-11-2019
03:29 PM
|
0
|
1
|
3247
|
|
POST
|
I tried the following nothing happens, no error and the fields don't get updated. import arcpy
from datetime import datetime as d
startTime = d.now()
start_time = time.time()
arcpy.env.overwriteOutput = True
arcpy.env.workspace = "C:/Temp/blah.gdb"
fc1 = "C:/Temp/blah.gdb/Parcels"
arcpy.MakeFeatureLayer_management(fc1, "fc1tLyr")
CITY = "C:/Temp/blah.gdb/City_Limits"
arcpy.MakeFeatureLayer_management(CITY, "CityLyr")
with arcpy.da.UpdateCursor(fc1, ['field1','field2','field3', 'field4']) as cursor:
for row in cursor:
#Select all parcels within the city limits layer
arcpy.SelectLayerByLocation_management("fc1tLyr","HAVE_THEIR_CENTER_IN", "CityLyr")
result = arcpy.GetCount_management("fc1tLyr")
row [0] = "IN CITY"
row [1] = "IN CITY"
row [2] = "IN CITY"
row [3] = "IN CITY"
cursor.updateRow(row)
del row, cursor
print('Done')
try:
print ('(Elapsed time: ' + str(d.now() - startTime)[:-3] + ')')
except Exception as e:
# If an error occurred, print line number and error message
import traceback, sys
tb = sys.exc_info()[2]
print ("Line %i" % tb.tb_lineno)
print (e.message)
... View more
12-11-2019
03:12 PM
|
0
|
3
|
3247
|
|
POST
|
I am trying to do a select by location and then update the selected features, seems easy enough but i am see to get it figured out. Basically i want to update only the parcels that are within the City limits layer and update the 4 fields. I have tried different variations but i can't seem to get to work. I don't get any errors and also doesn't stop. I would appreciate any help. Here is what i have. import arcpy
from datetime import datetime as d
startTime = d.now()
start_time = time.time()
arcpy.env.overwriteOutput = True
arcpy.env.workspace = "C:/Temp/blah.gdb"
fc1 = "C:/Temp/blah.gdb/Parcels"
CITY = "C:/Temp/blah.gdb/City_Limits"
with arcpy.da.UpdateCursor(fc1, ['field1','field2','field3', 'field4']) as cursor:
for row in cursor:
#Select all parcels within the city limits layer
arcpy.SelectLayerByLocation_management(fc1,"HAVE_THEIR_CENTER_IN", CITY)
result = arcpy.GetCount_management(fc1)
row [0] = "IN CITY"
row [1] = "IN CITY"
row [2] = "IN CITY"
row [3] = "IN CITY"
cursor.updateRow(row)
del row, cursor
print('Done')
try:
print ('(Elapsed time: ' + str(d.now() - startTime)[:-3] + ')')
except Exception as e:
# If an error occurred, print line number and error message
import traceback, sys
tb = sys.exc_info()[2]
print ("Line %i" % tb.tb_lineno)
print (e.message)
... View more
12-11-2019
12:05 PM
|
0
|
17
|
4491
|
|
POST
|
Jake, I get error on in TableToExcel raise e ExecuteError: ERROR 000814: Invalid file type Failed to execute (TableToExcel) with " .xlsx " If i change the output to ".xls" get "RuntimeError: Cannot find field ''. I need this to run in side python in Arcmap not in a stand alone script. This will be made into a tool script. import arcpy
arcpy.env.overwriteOutput = True
mxd = arcpy.mapping.MapDocument("CURRENT")
lyr = arcpy.mapping.ListLayers(mxd, "Export_Output")[0]
# Create a fieldinfo object
fieldInfo = arcpy.FieldInfo()
# Fields to Hide
hiddenFields = ('FID', 'Shape', 'OBJECTID', 'Shape_Leng', 'Shape_Area')
# Get the fields from the input
fields= arcpy.ListFields(lyr)
for field in fields:
if field.name not in hiddenFields:
fieldInfo.addField(field.name, field.name, "VISIBLE", "")
else:
fieldInfo.addField(field.name, field.name, "HIDDEN", "")
# Create table view
arcpy.MakeTableView_management(lyr, "Notif_view", "", "", fieldInfo)
# Export to Excel
arcpy.conversion.TableToExcel("Notif_view", r"C:\temp\Notif_view.xlsx")
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
... View more
11-18-2019
02:21 PM
|
0
|
0
|
1028
|
|
POST
|
I have attached a sample of the data. Thanks for your help!
... View more
11-15-2019
10:11 AM
|
0
|
2
|
2815
|
|
POST
|
I tried this again but i am not getting an error. The Export_Output layer is a shapefile and the fields that are in the layer that i don't need are Shape*, OBJECTID, Shape_Leng & Shape_Area Traceback (most recent call last): File "c:\program files (x86)\arcgis\desktop10.6\ArcToolbox\Scripts\TableToExcel.py", line 224, in <module> arcpy.GetParameter(3)) File "c:\program files (x86)\arcgis\desktop10.6\ArcToolbox\Scripts\TableToExcel.py", line 194, in table_to_excel for row in cursor: RuntimeError: Cannot find field '' Failed to execute (TableToExcel). import arcpy
arcpy.env.overwriteOutput = True
mxd = arcpy.mapping.MapDocument("CURRENT")
lyr = arcpy.mapping.ListLayers(mxd, "Export_Output")[0]
#Exports NotifiedLots tabel to excel table
intable = lyr
# Create a fieldinfo object
fieldInfo = arcpy.FieldInfo()
# Get the fields from the input
fields= arcpy.ListFields(intable)
for field in fields:
if field.type != 'OID' and field.type != 'Shape':
fieldInfo.addField(field.name, field.name, "VISIBLE", "")
if field.type == 'OID':
fieldInfo.addField(field.name, field.name, "HIDDEN", "")
# Create table view
arcpy.MakeTableView_management(intable, "Notif_view", "", "", fieldInfo)
# Export to Excel
arcpy.conversion.TableToExcel("Notif_view", r"C:\TEMP\Notif_view.xls")
... View more
11-15-2019
09:51 AM
|
0
|
4
|
2815
|
|
POST
|
I am still have the the FID, Shape_Lenth & Shape_Area fields after the export to Excel after using what you posted
... View more
11-01-2019
02:24 PM
|
0
|
6
|
2815
|
|
POST
|
Ya I agree i could just open the excel spreadsheet and delete them if i were only doing it so often. I usually run this process about 10 times a week. So i was trying to make it as stream lined as possible.
... View more
11-01-2019
02:14 PM
|
1
|
0
|
1028
|
|
POST
|
Jake, Thanks for the recommendation but I would have thought that just dropping or removing the fields would be easier. I didn't want to do the field mapping.
... View more
11-01-2019
11:21 AM
|
0
|
10
|
2815
|
|
POST
|
I need to export attributes from a certain layer in Arcmap but without the OID & Geometry fields to excel. I've tried the following bet i am getting error ("AttributeError: DescribeData: Method areaFieldName does not exist") on line 15. I would appreciate any help with the code, thanks. import arcpy
import os
arcpy.env.overwriteOutput = True
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
lyr = arcpy.mapping.ListLayers(mxd, "Notified")[0]
arcpy.env.workspace = os.path.dirname(mxd.filePath)
wp = os.path.dirname(mxd.filePath)
fc = "Notified"
desc = arcpy.Describe(fc)
f = desc.fields
fields = [f.name for f in f if f.name != desc.OIDFieldName and f.type != 'Geometry' and f.name != desc.areaFieldName and f.name != desc.lengthFieldName]
for fld in fields:
fields.remove(fields)
arcpy.MakeQueryTable_management(fc, "tmp_table", "NO_KEY_FIELD")
arcpy.TableToExcel_conversion("tmp_table", Notified_xls)
... View more
11-01-2019
09:57 AM
|
0
|
14
|
4061
|
| 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
|