|
POST
|
I still could not get it to work despite my efforts. Oddly enough I did find an abstract workaround that behaves similarly. What I had to do was intersect the two multipoint features then subtract the intersected feature from both multipoint features to get something similar. This definitely seems like a bug that I'll have to let someone at Esri know about. But so far that seems to work for some reason. Also, it works with both operators and functions in that regards.
... View more
05-17-2023
02:18 PM
|
0
|
0
|
1920
|
|
POST
|
Hi, I have a script that is designed to quickly analyze thousands of points to determine if there are any intersecting points. If there are any intersecting points, run the geometry analysis to get all of the intersecting points. Use the symmetrical difference analysis to get all points that do not intersect. InFeatureMPoint, RefFeatureMPoint = arcpy.Multipoint(arcpy.Array([arcpy.Point(*x) for x in ListACoords])), arcpy.Multipoint(arcpy.Array([arcpy.Point(*x) for x in ListBCoords]))
UnMatched = InFeatureMPoint^RefFeatureMPoint When I run the symmetrical difference analysis; I keep getting and error stating: return convertArcObjectToPythonObject(self._arc_object.symmetricdifference(other._arc_object))
ValueError: <geoprocessing describe geometry object object at 0x000002D08952E1E0> I don't know what the issue could be. I assume it might have something to do with the number of records but it is hard to say. Any help on this would be greatly appreciated.
... View more
05-17-2023
08:42 AM
|
0
|
2
|
1954
|
|
POST
|
Hi @kumarprince8071, Typically using where clauses in any cursor can be a bit of a hassle to deal with. It is better to use the search cursor without the where clause and specify all requirements for each row. Another unique and simple cursor trick is to create a dictionary of fields and row values for each row, which in turn makes it easier to specify the fields and values exactly. Also, two things: First: the search cursor fieldname/fieldnames need to be in brackets unless those are fieldnames a list of fieldnames Second: I am not following what the keys are in the subtype name. I assume those are either coded values with descriptions or something else. In either case you can modify the example to use however you need it. assetgroup = {}
assettype = {}
Fieldname_s = ['ASSETGROUP', 'x', 'y']
if searchfield == True:
with arcpy.da.SearchCursor(fc,Fieldname_s) as cursor:
for row in cursor:
FieldValueDict = dict(zip(Fieldname_s, row))
AssetGroup = FieldValueDict['ASSETGROUP']
FieldA = 'x'
FieldB = 'y'
if AssetGroup == 'High Voltage Transformer':
if all([ FieldValueDict[FieldA] in subtypename, subtypename[FieldValueDict[FieldA]] in assetgroup ]):
assetgroup[subtypename[FieldValueDict[FieldA]]] +=1
else: assetgroup[subtypename[FieldValueDict[FieldA]]] =1
if all([ FieldValueDict[FieldB] in codedvalue, codedvalue[FieldValueDict[FieldB]] in assettype ]):
assettype[codedvalue[FieldValueDict[FieldB]]] +=1
else: assetgroup[codedvalue[FieldValueDict[FieldB]]] =1
... View more
05-17-2023
07:53 AM
|
0
|
0
|
2639
|
|
POST
|
Thanks @DavidPike for the help. My other goal was to run a script without needing to create another feature to either search through or reference to get the information. So far both solutions seem to work, option 2 is faster than the other, but I was looking to see if there were other options out there that are similar and run even faster than the solutions I came up with. The first solution takes 7-8 seconds and the other 2-3 seconds. I just thought to reach out and see if there were other solutions that I had not thought of.
... View more
04-10-2023
09:55 AM
|
0
|
0
|
3406
|
|
POST
|
Thank you very much @dslamb2022 for the example. I was trying to test a third option to see if it would run faster than the first two. I tried using numpy but could not get it to work. I forgot to mention, when both tests were ran, the first option ran in between 7-8 seconds and the second option ran between 2-3 seconds. Both options gave me the result that I needed, but I wanted to reach out to see if there were any other possibilities that I did not think of that could also work.
... View more
04-10-2023
08:46 AM
|
0
|
0
|
3412
|
|
POST
|
Hi, I have several options that I discovered that can analyze thousands of point locations and return a list of ones that did not match and a dictionary of IDs where the points fell within a certain radius. However, I wanted to know if there are other alternatives that could be slightly faster. I have tried several other options, but I can't seem to find one that could potentially be faster. Any help on this would be greatly appreciated. # ________________________________________ Import modules ______________________________________________
import arcpy, os, datetime, numpy
from arcpy import ListFields, CreateFileGDB_management as CreateGDB, Point, Sort_management as Sorting
from arcpy.da import Editor as Editing, SearchCursor as Searching, InsertCursor as Inserting, UpdateCursor as Updating, Walk
from arcpy.management import CopyFeatures as ReplicateFeature, CreateFeatureDataset as MakeDataset, CreateRelationshipClass as MakeRelation, CreateTable, AddField, TruncateTable as EmptyFeature
from arcpy.conversion import ExportTable as ReplicateTable
from datetime import datetime, timedelta
from os import chdir as SetDirectory, mkdir as CreateDirectory
from os.path import basename as RootName, join as Combine, exists as Existing, dirname as ParentDirectory
import numpy as np
# ______________________________________ Define functions ______________________________________________
# Get list of items that exist in the database
def GetDatabaseItems(InputDatabase):return [Combine(root, filename) for root, directory, filenames in Walk(InputDatabase) for filename in filenames]
# Get current timestamp
def TimeStamp(*args):
GetStamp = {x: time.strftime(y) for x,y in zip(['Year','Month','Day','Date','Time'], ["%Y","%B","%A","%B %d, %Y",'%I:%M:%S %p'])}
DT, Values = None, [GetStamp[arg] for arg in args if arg in GetStamp]
if all(Values): DT = Values
elif any(Values): DT = GetStamp[Values[0]]
return DT
# Get point distance
def Distance(PointA, PointB): return (pow(PointA[0]-PointB[0], 2) + pow(PointA[1]-PointB[1], 2))**(1/2)
# Get matching point features
def SpatialIdentification(InFeatureCoords, RefFeatureCoords):
SortedInFeature, SortedRefFeature = sorted(InFeatureCoords, key=lambda x: x[0]), sorted(RefFeatureCoords, key=lambda x: x[0])
All = SortedInFeature + SortedRefFeature
n = 1
Matching = {}
NonMatching = []
InCheck, RefCheck = [], []
while SortedInFeature:
for A, B in zip(SortedInFeature, SortedRefFeature):
Ax, Ay, Bx, By = list(A) + list(B)
if Distance(A,B) <= n:
Matching[InFeatureCoords[A]] = RefFeatureCoords[B]
if A in SortedInFeature: SortedInFeature.remove(A)
if B in SortedRefFeature: SortedRefFeature.remove(B)
elif Distance(A,B) > n:
if Ax < Bx:
if InCheck:
for X in InCheck:
if Distance(X,B) <= n:
Matching[InFeatureCoords[A]] = RefFeatureCoords[B]
SortedRefFeature.remove(B)
InCheck.remove(X)
NonMatching.remove(X)
NonMatching.append(A)
InCheck.append(A)
SortedInFeature.remove(A)
SortedInFeature = sorted(SortedInFeature, key=lambda x: x[0])
break
elif Ax > Bx:
if RefCheck:
for Y in RefCheck:
if Distance(A,Y) <= n:
Matching[InFeatureCoords[A]] = RefFeatureCoords[Y]
SortedInFeature.remove(A)
RefCheck.remove(Y)
NonMatching.remove(Y)
NonMatching.append(B)
RefCheck.append(B)
SortedRefFeature.remove(B)
SortedRefFeature = sorted(SortedRefFeature, key=lambda x: x[0])
break
if SortedRefFeature: NonMatching + SortedRefFeature
return Matching, NonMatching
# Get time lapse
def LapsedTime(start, end):
hours, rem = divmod(end-start, 3600)
minutes, seconds = divmod(rem, 60)
lapse_time = ("{:0>2}:{:0>2}:{:05.2f}".format(int(hours),int(minutes),seconds))
return lapse_time
# ______________________________________ Important Variables ___________________________________________
# Get specific featureclasses and tables and all the fields from each
# Hydrant feature service (hosted)
HydrantFeatureService = r'*'
# Hydrant featureclass from water database
RefFeature = r'*'
# Create subfolders, geodatabases, etc for data to be copied over
MainFolder = r'*'
# __________________________________________ Main Script _______________________________________________
date, start, end, year, month, day, timestamp = ['Date','Start','End','Year','Month','Day','Time']
# Create a new filegeodatabase if it does not exist
DatabaseName = 'StagingDatabase' + '.gdb'
LocalDatabase = Combine(MainFolder, DatabaseName)
if not Existing(LocalDatabase): LocalDatabase = CreateDirectory(LocalDatabase)
# Get list of items in the database
DatabaseItems = GetDatabaseItems(LocalDatabase)
# Copy data from one database to another database in a newly created dataset
# Featureclass
Name = 'Test'
InFeature = Combine(LocalDatabase, Name)
if InFeature not in DatabaseItems: ReplicateFeature(HydrantFeatureService, InFeature)
# Create costants to test various options
Fields = ['OID@', 'SHAPE@XY']
InFeatureIDShape = {row[-1]:row[0] for row in Searching(InFeature, Fields)}
RefFeatureIDShape = {row[-1]: row[0] for row in Searching(RefFeature, Fields)}
SortedInFeature, SortedRefFeature = sorted(InFeatureIDShape, key=lambda x: x[0]), sorted(RefFeatureIDShape, key=lambda x: x[0])#sorted(RefFeatureIDShape)
n = 25
# First Option
print ('Option 1')
start = TimeStamp('Time')[0]
print (start)
start = time.time()
i = 0
Matched, UnMatched = SpatialIdentification(InFeatureIDShape, RefFeatureIDShape)
if Matched or UnMatched: print (f'{len(Matched)} matched features | {len(UnMatched)} unmatched features')
for A in sorted(Matched):
if i < n:
print (A, Matched[A])
i += 1
for Point in sorted(UnMatched):
print (Point)
end = TimeStamp('Time')[0]
print (end)
end = time.time()
lapse = LapsedTime(start, end)
print (lapse)
print ('\n')
# Second option
print ('Option 2')
start = TimeStamp('Time')[0]
print (start)
start = time.time()
i = 0
InFeatureMPoint, RefFeatureMPoint = arcpy.Multipoint(arcpy.Array([arcpy.Point(*x) for x in SortedInFeature])), arcpy.Multipoint(arcpy.Array([arcpy.Point(*x) for x in SortedRefFeature]))
UnMatched = [(Point.X, Point.Y) for Point in list(InFeatureMPoint - RefFeatureMPoint) + list(RefFeatureMPoint - InFeatureMPoint)]
UnMatched = sorted(UnMatched, key=lambda x: x[0])
Matched = dict(zip([InFeatureIDShape[x] for x in SortedInFeature if x not in UnMatched], [RefFeatureIDShape[x] for x in SortedRefFeature if x not in UnMatched]))
if Matched or UnMatched: print (f'{len(Matched)} matched features | {len(UnMatched)} unmatched features')
for A in sorted(Matched):
if i < n:
print (A, Matched[A])
i += 1
for Point in UnMatched:
print (Point)
end = TimeStamp('Time')[0]
print (end)
end = time.time()
lapse = LapsedTime(start, end)
print (lapse)
print ('\n')
... View more
04-10-2023
05:27 AM
|
0
|
4
|
3448
|
|
POST
|
Did you try selecting the legend item in contents pane and moving it to the desired column?
... View more
02-21-2023
08:43 AM
|
0
|
0
|
13086
|
|
POST
|
Thanks @JoshuaBixby. I didn't even realize that I had replicated an existing function. I knew of the itertools, but from examples I have seen online, I thought it might be limited, or there were other ways to achieve the same thing without importing another module. I will research more into these and other python modules to see if some of the code that I have written can be simplified using an existing module.
... View more
01-31-2023
09:00 AM
|
0
|
0
|
2638
|
|
POST
|
Thanks @JoshuaBixby, I thought of it as a fun exercise to see if I could utilize it for smaller scripts since it gave me the opportunity to try and test what I can do. I was not aware of the performance issues regarding how the code is written, so I will have a to run a few test scripts to see how significant the difference is.
... View more
01-31-2023
07:35 AM
|
0
|
2
|
2644
|
|
POST
|
Thanks @Anonymous User, The code itself was to see if there was a way to create a list of lists with combinations of values that were the same length and order as the fields. I was also trying to do it with the fewest lines of code possible to see if it could be done. I know the code itself is not that pretty, beautiful, or easy to read/understand, but my goal was to see if I could achieve a complex task with the fewest lines of code.
... View more
01-31-2023
05:43 AM
|
0
|
4
|
2647
|
|
POST
|
Hi, I wanted to see if anyone could help with figuring out if there is a simpler way to code what I have below. What I have below works fine but I wanted to see if there was a simpler way to write the code. Fields, Grps = ['FieldA','FieldB','FieldC'], ['GroupA','GroupB','GroupC']
Main = [['DOG','CAT','HORSE'], ['HOUSE','BARN'], ['FIELDS', 'YARD'],['MOUSE','SNAKE','LIZARD','OTHER'],['AQUARIUM','GLASS TANK','SMALL CAGE'],
['HOUSE','APARTMENT','PET STORE'],['COW','PIG', 'SHEEP'], ['FIELDS','PASTURES'], ['BARN','FARM HOUSE','OTHER']]
MainDict = dict(zip([chr(i) for i in range(ord('A'),ord('A')+len(Main))], Main))
EstVOrder = [[i for i in [chr(i) for i in range(ord('A')+n,ord('A')+n+len(Fields))]] for n in range(0,len(Main),len(Main)//len(Fields))]
Main = dict(zip(Grps,[[[x,y,z] for x in MainDict[a] for y in MainDict[b] for z in MainDict[c]] for a,b,c in EstVOrder]))
print (Main) I would also like to know if the code above is properly written.
... View more
01-30-2023
01:53 PM
|
0
|
6
|
2698
|
|
IDEA
|
Hi @BrettFrahm, I saw that you pushed my idea to Arcgis Online and wanted to let you know that there is a work around that I've implemented that works. I'm hoping that Esri can implement the idea of filtering using Arcade Expressions. The solution/work around that I currently use is a script that updates another field based on certain dates and then setting the filter widget to filter by those/other fields. I can share it if you would like. It can work for both hosted and enterprise feature services.
... View more
01-15-2023
10:00 AM
|
0
|
0
|
5574
|
|
POST
|
Here is some documentation that will allow for you to export any file information regarding the database. Get file information via python os.path.getatime(path) Return the time of last access of path. The return value is a floating point number giving the number of seconds since the epoch (see the time module). Raise OSError if the file does not exist or is inaccessible. os.path.getmtime(path) Return the time of last modification of path. The return value is a floating point number giving the number of seconds since the epoch (see the time module). Raise OSError if the file does not exist or is inaccessible. Changed in version 3.6: Accepts a path-like object. os.path.getctime(path) Return the system’s ctime which, on some systems (like Unix) is the time of the last metadata change, and, on others (like Windows), is the creation time for path. The return value is a number giving the number of seconds since the epoch (see the time module). Raise OSError if the file does not exist or is inaccessible. Changed in version 3.6: Accepts a path-like object. os.path.getsize(path) Return the size, in bytes, of path. Raise OSError if the file does not exist or is inaccessible. Changed in version 3.6: Accepts a path-like object.
... View more
12-30-2022
10:51 AM
|
0
|
0
|
965
|
|
POST
|
Hi, I came across this issue when trying to figure out the closest set of multiples for a given length of items in a list. The code below works but I wanted to see if anyone else had a better solution than the one below. n = 12
ranges = [chr(i) for i in range(65, 65+n)]
print (ranges)
v = [i+1 for i in range(len(ranges))]
print (v)
testlist = [[x,y] for x in v for y in v if all([len(v) in [x*y, y*x], x%y > y%x])][-1]
print (testlist)
... View more
12-27-2022
01:42 PM
|
0
|
1
|
1374
|
|
POST
|
Hi, I have some questions regarding geometries in python. I am currently working on a script to read/write the geometry of one feature class and analyzing the contains method to determine if the center of a line is contained by the input polygon geometry. A question that I have is, what is the difference between making a new geometry object vs reading and utilizing the existing geometry object? Ex: ['SHAPE@'] field to read the geometry vs Polygon (inputs, {spatial_reference}, {has_z}, {has_m}) to make a new geometry object. The other question is can this be utilized with the contains method or will I need to create a whole new object in order to do so? Any help on this would be greatly appreciated.
... View more
12-13-2022
06:04 AM
|
0
|
1
|
1485
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | a week ago | |
| 1 | 05-07-2026 01:36 PM | |
| 1 | 02-10-2026 06:09 AM | |
| 1 | 03-04-2026 01:08 PM | |
| 1 | 02-24-2026 12:59 PM |
| Online Status |
Offline
|
| Date Last Visited |
Monday
|