|
POST
|
Hello, I try to find excactly identical points in a polygon feature class with the 10.4. basic license to search for polygon errors with python 2.7. The following script can't find end points in the row[1].lastPoint in line 18? I need to exclude start and end points. What's wrong or any ideas how to do better? import arcpy
infc = r"R:\XXX\LSG_Fehler.shp"
outfc = r"C:\temp2\GleicheKoord.shp"
CoordList = list()
arcpy.env.overwriteOutput = True
# Enter for loop for each feature
#
for row in arcpy.da.SearchCursor(infc, ["OID@", "SHAPE@"]):
# Print the current multipoint's ID
#
print("Feature {}:".format(row[0]))
partnum = 0
if row[1] == row[1].lastPoint:
print row[1].lastPoint
break
# Step through each part of the feature
else:
for part in row[1]:
# Print the part number
#
print("Part {}:".format(partnum))
# Step through each vertex in the feature
for pnt in part:
if pnt:
# print("{}, {}".format(pnt.X, pnt.Y))
CoordList.append("{};{}".format(pnt.X, pnt.Y))
else:
# If pnt is None, this represents an interior ring
#
print("Interior Ring:")
partnum += 1
# Find identical coordinates
output = set([x for x in CoordList if CoordList.count(x) > 1])
print(output)
spatial_reference = arcpy.SpatialReference(25832)
pt = arcpy.Point()
ptGeoms = []
for p in output:
coord = p.split(";")
pt.X = coord[0]
print(coord[0])
pt.Y = coord[1]
print(coord[1])
ptGeoms.append(arcpy.PointGeometry(pt, spatial_reference))
arcpy.CopyFeatures_management(ptGeoms, outfc)
arcpy.AddXY_management(outfc)
... View more
10-31-2019
05:49 AM
|
0
|
8
|
2290
|
|
POST
|
Could this help you: Performing Point Distance analysis using Basic level license of ArcGIS for Desktop? - Geographic Information Systems Sta…
... View more
10-25-2019
04:08 AM
|
0
|
0
|
1567
|
|
POST
|
while (int(result1.getOutput(0)) < 10):
old_value = int(result1.getOutput(0))
arcpy.SelectLayerByLocation_management (alk_sel_Layer, "INTERSECT", alk_sel_Layer)
result1 = arcpy.GetCount_management(alk_sel_Layer)
print(result1)
if int(result1.getOutput(0)) == old_value:
break This was the solution for me.
... View more
10-10-2019
12:41 AM
|
0
|
0
|
939
|
|
POST
|
Thank you, remains the question how to get out of the while loop if the result1 value didn't change.
... View more
10-09-2019
05:46 AM
|
0
|
1
|
939
|
|
POST
|
I would like to divide a shp in about 20-50 adjacent polygons. I have the following script but the while loop (line 54) becomes endless if there are less than 10 adjacent polygons to select. Any ideas for a better solution? # -*- coding: cp1252 -*-
import arcpy
arcpy.env.overwriteOutput = True
arcpy.env.workspace = "in_memory"
Alk_Sel = r"R:\Daten\sgb_Planungen\2013\Saalbachniederung\Eigentuemer\ALK_merge_E.shp"
alk_sel_Layer = "alk_sel_Layer"
InFile = r"C:\temp2\InFile.shp"
def SicFeature():
arcpy.CopyFeatures_management(Alk_Sel, InFile)
arcpy.MakeFeatureLayer_management(InFile, alk_sel_Layer)
def AddField():
arcpy.AddField_management(alk_sel_Layer, "Round", "LONG")
def selectMin():
sum = arcpy.GetCount_management(alk_sel_Layer)
print sum
i = 0
for i in range(1, int(sum.getOutput(0)), 10):
i += 1
Expression = """ "Round" = {} """.format(0)
arcpy.MakeFeatureLayer_management(InFile, alk_sel_Layer, Expression )
sum1 = arcpy.GetCount_management(alk_sel_Layer)
print('{} has a sum of {} records'.format(alk_sel_Layer, sum1[0]))
MyList = list()
cursor = arcpy.da.SearchCursor(alk_sel_Layer, "FID")
for row in cursor:
MyList.append(int(row[0]))
print 'Minimum: {0}'.format(min(MyList))
expression1 = min(MyList)
arcpy.SelectLayerByAttribute_management(alk_sel_Layer, "NEW_SELECTION", """ "FID" = {} """.format(expression1))
result1 = arcpy.GetCount_management(alk_sel_Layer)
while (int(result1.getOutput(0)) < 10):
arcpy.SelectLayerByLocation_management (alk_sel_Layer, "INTERSECT", alk_sel_Layer)
result1 = arcpy.GetCount_management(alk_sel_Layer)
print(result1)
arcpy.CalculateField_management(alk_sel_Layer, "Round", i)
OutFile = r"C:\temp2\OutFile_{}.shp".format(i)
arcpy.CopyFeatures_management(alk_sel_Layer, OutFile)
SicFeature()
AddField()
selectMin()
... View more
10-09-2019
12:25 AM
|
0
|
3
|
1000
|
|
POST
|
Why not creating two lines? One line with the full data, one erase line with the data without z information? Then erase the no data line area?
... View more
10-02-2019
04:53 AM
|
0
|
0
|
830
|
|
POST
|
Think it's not possible, but why not buffer your points again with a very small distance?
... View more
09-27-2019
06:26 AM
|
0
|
3
|
1199
|
|
POST
|
Yes OK. If I write it like this it overwrites all rows with the last value in MyList1. Don't really know how to get it to write exactly each row in the list into the right row in the table? def UpdateFields(self):
print MyList1
with arcpy.da.UpdateCursor(inTable,["File"]) as cursor:
for row in cursor:
for value in MyList1:
print value
cursor.updateRow([value])
... View more
09-20-2019
05:49 AM
|
0
|
2
|
2243
|
|
POST
|
If you use a array, how to fill a column in an array with a list? This doesn't work: def UpdateFields(self):
inArray = numpy.array([(MyList, MyList1, MyList2)],
numpy.dtype([('Path_File', '|S256'),
('File', '|S256'),
('h_not_used', numpy.int32)]))
arcpy.da.NumPyArrayToTable(inArray, outTable) Error message: line 63, in UpdateFields ('h_not_used', numpy.int32)])) ValueError: cannot set an array element with a sequence
... View more
09-20-2019
03:50 AM
|
0
|
1
|
2243
|
|
POST
|
Hello, I have problems to update two attribute fields with values created in the following code. The insert cursor works well but with the update cursor I get a error message. Are there any other ways to fill a table with values? Error message: line 60, in UpdateFields cursor.updateRow([row]) StopIteration: iteration not started # -*- coding: cp1252 -*-
import arcpy, os
arcpy.env.overwriteOutput = True
myPath = r"R:\Daten\geo_daten\Arten\Fledermaeuse\AltDaten"
out_path_table = r"C:\temp4\Geodatenbestand.mdb"
out_name_table = "Geodatenbestand"
template_table = r"C:\temp4\Geodatenbestand.mdb\Geodatenbestand_Template"
inTable = os.path.join(out_path_table, out_name_table)
inTableL = "Table_Layer"
MyList1 = list()
MyList2 = list()
# Encoding der Standardausgabe herausfinden
stdout_encoding = sys.stdout.encoding or sys.getfilesystemencoding()
class Geodatenbestand(object):
def __init__(self):
self.myPath = myPath
def SearchFiles(self):
SHPCounter = 0
for path, dirs, files in os.walk(myPath):
for file in files:
if file.lower().endswith('.shp'):
print path + "\\" + file
SHPCounter += 1
print SHPCounter
accessTime = os.path.getatime(os.path.join(path, file)) # last access time
actualTime = time.time()
hoursPassed = """{}""".format(int((actualTime - accessTime)/3600))
path1 = path.decode(stdout_encoding)
file1 = file.decode(stdout_encoding)
print file1
cursor = arcpy.da.InsertCursor(inTable, ['PathFile'])
cursor.insertRow([path1 + "\\" + file1])
MyList1.append(file1)
MyList2.append(hoursPassed)
def UpdateFields(self):
print MyList1
with arcpy.da.UpdateCursor(inTable,["File"]) as cursor:
for row in MyList1:
cursor.updateRow([row])
print MyList2
with arcpy.da.UpdateCursor(inTable,["h_not_used"]) as cursor:
for row in MyList2:
cursor.updateRow([row])
def CreateTable(self):
if arcpy.Exists(inTable):
arcpy.Delete_management(inTable)
arcpy.CreateTable_management(out_path_table, out_name_table, template_table)
if __name__ == '__main__':
MyClass = Geodatenbestand()
MyClass.CreateTable()
MyClass.SearchFiles()
MyClass.UpdateFields()
... View more
09-20-2019
12:24 AM
|
0
|
6
|
2592
|
|
POST
|
What if you put in a arcpy.AddMessage (f)
after line 20, does it throws something out?
I think your code needs to be "rebuilt", it's easier to do this with hard coded "parameters" rather than arcpy.GetParameterAsText(0)
... View more
09-16-2019
07:32 AM
|
0
|
0
|
4022
|
|
POST
|
Does arcpy.List () exists? I would start with this: Erstellen von Datenlisten—ArcPy Get Started | ArcGIS Desktop
... View more
09-16-2019
06:56 AM
|
0
|
1
|
4022
|
|
POST
|
Could you use code formatting? /blogs/dan_patterson/2016/08/14/script-formatting
... View more
09-16-2019
06:10 AM
|
0
|
1
|
4022
|
|
POST
|
Maybe you can try this, you have to change the path: import os
import arcpy
top_folder = r"your path"
for path, dirs, files in os.walk(top_folder):
for d in dirs:
if not d.endswith(".gdb"):
continue
gdb_path = os.path.join(path, d)
arcpy.env.workspace = gdb_path
featureclasses = arcpy.ListFeatureClasses()
for fc in featureclasses:
arcpy.Rename_management(fc, "{}_{}".format(d[:-4], fc))
... View more
09-10-2019
02:28 AM
|
1
|
1
|
5589
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 09-10-2025 08:08 AM | |
| 1 | 05-13-2025 05:05 AM | |
| 1 | 04-28-2025 03:40 AM | |
| 4 | 08-13-2024 10:49 PM | |
| 1 | 08-13-2024 09:52 PM |
| Online Status |
Offline
|
| Date Last Visited |
23 hours ago
|