|
POST
|
What you have to do is add in the arcgis module as well as arcpy. Then you can access AGOL tools which include the Geocoding Service. Or switch to the geocoding service direct from ArcGISPro. Thefunctions and parameters are different but it is the same service ultimately, and will also cost credits.
... View more
09-13-2022
10:22 PM
|
0
|
0
|
5614
|
|
POST
|
The GlobalID is readonly and out of our control. Make a new field and save the ID to a new GUID field that you do have ownership. Then make up a dictionary of oldID to newID and change the foreign key in the attachment to point to the new one. Phew!
... View more
09-13-2022
10:13 PM
|
0
|
0
|
1407
|
|
POST
|
I am trying to do the same. My hope was that you might be able to do this with Arcade from a parent/child relation. Maybe you can. However it will be quite complex because you will need to allow for multiple child records and you will need to use the last record. So turn on EditTracking. I have then found it would be possible to update the parent feature with the latest record using the Python API by offloading all the hard work to Pandas. Get a list of visit records and find the latest date for each GUID that is a foreign key to the GlobalID. Now you have a dataframe of these records to update the main layer with whatever you want to calculate into a status field ready to be symbolised. Note the magic one-liner at line 24. This script was in Pro, so there are a few changes to get a featureset in AGOL using fl.query_related_records() # excess WeedLocations fields joined when adding extra visit events will be cleaned up...
# dictionary of field mappings so far from Visits_Table to WeedLocations
visit_to_weed = {
'Guid_visits': 'GlobalID', # foreign key -> primary key
'EditDate_1':'DateVisitMadeFromLastVisit', # for latest date
"WeedVisitStatus":'StatusFromLastVisit', # as inspected
'DifficultyChild':'DifficultyFromLastVisit', # as inspected
'VisitStage':'LatestVisitStage', # as inspected
'Area':'LatestArea' # as inspected
}
# extract the data required from the database Visits_Table, don't even need a primary key eg GlobalID
# In the future we will put on a filter greater than the last update
filter = '' #"""EditDate_1 > date '{}'""".format('2022-07-01')
in_flds = list(visit_to_weed.keys()) # ['Guid_visits','EditDate_1','WeedVisitStatus','DifficultyChild','VisitStage','Area']
out_flds = list(visit_to_weed.values())
vdate =[row for row in arcpy.da.SearchCursor(visits,in_flds,filter)]
print('vdate:',len(vdate))
# put in a pandas dataframe
df = pd.DataFrame(vdate,columns=in_flds)
# find the record with max edit date by visit and keep the other details all in one line!
idx = df.groupby(['Guid_visits'])['EditDate_1'].transform(max) == df['EditDate_1']
# print(df[idx])
dVisit = df.set_index('Guid_visits').T.to_dict('list')
# print(dVisit.get('{08125D4D-4725-4A26-BAC9-98BE7EF0784C}',"Missing"))
# {08125D4D-4725-4A26-BAC9-98BE7EF0784C}, 2022-08-23 03:04:01.644000, None, None, None, NaN
# Count visits for each location
vguid = [row[0] for row in arcpy.da.SearchCursor(visits,['GUID_visits'], "GUID_visits is not NULL")]
# dict of counts by GlobalID for updating
vguid_counts = collections.Counter(vguid)
# put counts in new field VisitCount for now
if len(arcpy.ListFields(weeds,'VisitCount')) == 0:
arcpy.management.AddField(weeds,'VisitCount','LONG')
with arcpy.da.UpdateCursor(weeds, ['VisitCount'] + out_flds) as cur:
n = 0
for row in cur:
try:
row[1] = vguid_counts[row[0]]
if dVisit.get(row[0],None):
row[2] = dVisit.get(row[0],None)[0]
row[3] = dVisit.get(row[0],None)[1]
row[4] = dVisit.get(row[0],None)[2]
row[5] = dVisit.get(row[0],None)[3]
row[6] = dVisit.get(row[0],None)[4]
cur.updateRow(row)
n+=1
except Exception as e:
arcpy.AddMessage(row)
arcpy.AddMessage(e)
arcpy.AddMessage("Well Done, {} records updated".format(n))
... View more
09-13-2022
10:02 PM
|
0
|
0
|
652
|
|
POST
|
Yes you can! But as pointed out the performance is terrible and limited. So you have to precalculate it to be useful on a map. Even that is painful! I have the same problem. In my case the user wanted to move the visit records to a related child table and have the location table as the parent. But some records do not have a child. Since the foreign key (a horrible GUID) is the link to the GlobalID (a read-only GUID) I needed to add missing records in the location feature layer to the visit related layer. I did this in a prototype using relates in Pro, and then in an arcpy script using dictionaries. Because arcpy does not use relates (or the tools that do are not reliable). So it works a treat in Pro because you have da.Cursors, and georelational tables. But in AGOL you have a giant object that you have to query in single REST requests that have limits on the data returned. In my Pro example there is still some magic performed in Pandas. It finds the record with the latest date grouped by foreign key all ready to update the feature layer. My next strategy is to go to the Visit related table with a more direct query in AGOL.You can get all the Visit records slowly by the WeedLocation record using query_related_records(). It is slow and painful and the return is a json nested mess but Pandas can unpack it. This enables me to update the featurelayer attributes that are used for symbology. # add missing visits
# oh yeah, cannot use relates
# use keyfiles
# Creative Commons NZ 4.0 Kim Ollivier
# 10 Sept 2022
import os
import sys
import collections
import arcpy
try:
gdb = sys.argv[1]
except IndexError:
gdb = 'm:/project/econet/source9Sep/CAMS_weed.gdb'
if not arcpy.Exists(gdb):
raise IOError
arcpy.env.workspace = gdb
arcpy.env.overwriteOutput = True
arcpy.AddMessage(gdb)
# "Visits_Table", "GUID_visits" "WeedLocations", "ParentGuid" or "GlobalID"
vguid = [row[0] for row in arcpy.da.SearchCursor('Visits_Table',['GUID_visits'], "GUID_visits is not NULL")]
print('vguid:',len(vguid))
# dict of counts by GUID for inspection later
vguid_counts = collections.Counter(vguid)
sql = """GlobalID NOT IN {}""".format(tuple(vguid))
print(sql[0:60], ' ... ',sql[-42:])
arcpy.management.MakeFeatureLayer('Weedlocations','weed_no_visit_lay',sql) # use a fieldinfo to limit fields?
arcpy.management.CopyRows('weed_no_visit_lay','Visit_extra') # this adds in my name as an editor??
print("extras",arcpy.management.GetCount('Visit_extra'))
# maybe extract a dict and insert
#
# make a new visits table to allow repeated tests
arcpy.management.Merge(['Visits_Table','Visit_extra'], 'Visits_Table_new',add_source="ADD_SOURCE_INFO")
max_dates = {}
for key, value in {r[0]:r[1] for r in 'Visits_Table'}.items():
max_dates.setdefault(value, set()).add(key)
with arcpy.da.UpdateCursor('WeedLocations',['GlobalID','VisitCount']) as cur:
for row in cur:
row[1] = vguid_counts.get(row[0],None)
cur.updateRow(row)
... View more
09-13-2022
09:51 PM
|
0
|
0
|
4153
|
|
POST
|
The only workaround that I see often is to create a ParentGUID GUID field and copy the GlobalID first. Then you have to change the foreign key GUID to the new GlobalID with an update.Maybe a python script or the Python API. This has also been driving me mad. The GlobalID is like an OBJECTID - not yours, so the software decides if the feature is a new record
... View more
09-13-2022
09:33 PM
|
0
|
0
|
5307
|
|
POST
|
Sort of retired? Jack Dangermond hasn't! Covid lockdowns have made me virtually retired!
... View more
09-04-2022
04:01 AM
|
0
|
1
|
1465
|
|
POST
|
Here I am in 2022 with ArcGIS Pro 3.01 installed still looking to see why it does not work with a couple of simple file geodatabases!
... View more
09-04-2022
03:45 AM
|
1
|
0
|
4071
|
|
BLOG
|
A great supplement to the official documentation. I have been looking everywhere for an example just like this. I have one to many, so am looking forward to this simple change to see it working for me.
... View more
08-20-2022
10:33 PM
|
2
|
0
|
9047
|
|
POST
|
# zoom to selected features
import arcpy
p = arcpy.mp.ArcGISProject('CURRENT')
m = p.listMaps()[0]
mv = p.activeView
# part of trail selected
lay = m.listLayers('trail')[0]
extent = mv.getLayerExtent(lay, True, True)
mv.zoomToAllLayers(True,True) Maybe this function was not available in 2017, but it is now in 2021 in version 2.8 or earlier. The trick is to realise that the extents are available in the MapView of the active Map. While looking for this I tried out using Bookmarks which are also available, maybe a nice way to store the extent of selections.
... View more
09-17-2021
05:04 PM
|
0
|
0
|
2090
|
|
POST
|
"No answer was the stern reply" after a year, so I suppose sadly that there is no REST interface to webmaps, which is what I wanted to do to get a thumbnail using all the nice formatting in the webmap by someone else.
... View more
08-22-2021
04:50 PM
|
0
|
0
|
2043
|
|
IDEA
|
I note that the new 2.6 OLE interface is read-only, and presumably one cannot copy fgb tables or featureclasses into Access either. But there is a simple way using the Microsoft Access Drivers (64 bit) and the python module pyodbc. With these installed I am able to write a single page python script to translate tables between the two formats. With a bit of extra work I am able to export the shape field as WKT or WKB into the Access table and bring it back again in a lossless round trip. Not the same as joining tables inside ArcGISPro but it does provide a simple exchange.
... View more
07-27-2020
05:47 PM
|
1
|
0
|
3885
|
|
IDEA
|
I am very disappointed at the dropping of support for custom help tools. I used a proper help authoring tool to consolidate all the help for a project. I don't want to edit each tools "Metadata", I need proper help with images, diagrams, URLs and links to other parts of the help. Like we already have in ArcMap. Cmon Esri, the custom tools environment look really amateur now, a throwback to ARC/INFO of 20 years ago.
... View more
07-16-2020
10:07 PM
|
0
|
0
|
2231
|
|
POST
|
But the Anaconda version of Python is slightly different for some libraries. The sqlite3 implementation has been compiled to disallow extensions and has not included Rtrees, This makes it impossible to use sqlite3 for geometry tables. Great. Now I have to hack the installation to replace the sqlite3.dll with the standard build and the mod_spatialite extension. Note that the geopackage is only designed for data exchange, not faster efficient geoprocessing...
... View more
05-04-2020
03:19 PM
|
0
|
0
|
2550
|
|
IDEA
|
And now at 10.8 the sqlite functions are broken again. Is it because Esri are now using Anaconda compilation? Sqlite3.dll has been compiled without RTrees! Great, that means we cannot use spatial data in python. The solution is to hack the installation and replace the sqlite3.dll in the DLLs folder with the latest version from sqlite.org. While we are hacking, why not replace the spatialite400x.dll with a full replacement for mod_spatialite by downloading from spatialite.org the latest extension suite. Since there is now a Libs/sqlite3 folder in the standard install, pop them in there and add it to the system path.
... View more
05-04-2020
03:12 PM
|
1
|
0
|
8008
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 09-15-2024 10:32 PM | |
| 1 | 03-12-2026 01:10 AM | |
| 1 | 03-13-2026 08:30 PM | |
| 1 | 03-13-2026 05:17 PM | |
| 1 | 03-12-2026 05:14 PM |
| Online Status |
Offline
|
| Date Last Visited |
03-13-2026
05:04 PM
|