|
DOC
|
@ChrisJRoss13 it could be a permissions issue for the scratch directory. You can change this to another directory by updating line 43. For example, change the below: gdb = arcpy.CreateFileGDB_management(arcpy.env.scratchFolder, gdbId)[0] to something such as: gdb = arcpy.CreateFileGDB_management(r"C:\temp", gdbId)[0]
... View more
01-29-2024
05:31 AM
|
0
|
0
|
17663
|
|
POST
|
Hi @FawazAmjad35, Here is a workflow you could do: 1. Create a separate table of only the school campus address 2. Geocode the school campus address 3. Buffer the result by 120 miles 4. Geocode the attribute table that contains all 575 records 5. Perform a Select by Location to select the addresses that do not intersect the 120 mile buffer
... View more
01-25-2024
06:12 AM
|
1
|
0
|
1972
|
|
DOC
|
@A_Schwab after a quick test, I too am receiving this error. I would recommend logging a case with Tech Support as I suspect this may be an issue with ArcGIS Online. Try the following script as an alternative.
... View more
01-22-2024
05:54 AM
|
0
|
0
|
17803
|
|
DOC
|
Previously, I wrote an document on how to overwrite an ArcGIS Online feature service by referencing a feature class and using a truncate/append method. I received a lot of feedback from this document, with some users encountering limitations such as attachments not being supported, and updating services containing multiple layers. This solution is aimed to address these limitations. Below is a script to overwrite an ArcGIS Online feature service by referencing an ArcGIS Pro project, and a video on how to use the script. Please comment below if there are any issues or questions. import arcpy, os, time, requests, json
from arcgis.gis import GIS
from arcgis.features import FeatureLayerCollection
# Variables
prjPath = r"C:\Projects\GeoNET\GeoNET.aprx" # Path to Pro Project
map = 'State Parks' # Name of map in Pro Project
serviceDefID = '3fa1620c47dc490db43b9370e8cf5df8' # Item ID of Service Definition
featureServiceID = 'fb42ef7b43154f95b8b6ad7357b7f663' # Item ID of Feature Service
portal = "https://www.arcgis.com" # AGOL
user = "jskinner_rats" # AGOL username
password = "********" # AGOL password
preserveEditorTracking = True # True/False to preserve editor tracking from feature class
unregisterReplicas = True # True/False to unregister existing replicas
# Set Environment Variables
arcpy.env.overwriteOutput = 1
# Disable warnings
requests.packages.urllib3.disable_warnings()
# Start Timer
startTime = time.time()
print(f"Connecting to AGOL")
gis = GIS(portal, user, password)
arcpy.SignInToPortal(portal, user, password)
# Local paths to create temporary content
sddraft = os.path.join(arcpy.env.scratchFolder, "WebUpdate.sddraft")
sd = os.path.join(arcpy.env.scratchFolder, "WebUpdate.sd")
sdItem = gis.content.get(serviceDefID)
# Create a new SDDraft and stage to SD
print("Creating SD file")
arcpy.env.overwriteOutput = True
prj = arcpy.mp.ArcGISProject(prjPath)
mp = prj.listMaps(map)[0]
serviceDefName = sdItem.title
arcpy.mp.CreateWebLayerSDDraft(mp, sddraft, serviceDefName, 'MY_HOSTED_SERVICES',
'FEATURE_ACCESS', '', True, True)
arcpy.StageService_server(sddraft, sd)
# Reference existing feature service to get properties
fsItem = gis.content.get(featureServiceID)
flyrCollection = FeatureLayerCollection.fromitem(fsItem)
properties = fsItem.get_data()
capabilities = flyrCollection.manager.properties
# Get thumbnail and metadata
thumbnail_file = fsItem.download_thumbnail(arcpy.env.scratchFolder)
metadata_file = fsItem.download_metadata(arcpy.env.scratchFolder)
# Unregister existing replicas
enableSync = False
if unregisterReplicas:
if flyrCollection.properties.syncEnabled:
enableSync = True
print("Unregister existing replicas")
for replica in flyrCollection.replicas.get_list():
replicaID = replica['replicaID']
flyrCollection.replicas.unregister(replicaID)
# Overwrite feature service
sdItem.update(data=sd)
print("Overwriting existing feature service")
if preserveEditorTracking:
pub_params = {"editorTrackingInfo" : {"preserveEditUsersAndTimestamps":'true'}}
fs = sdItem.publish(overwrite=True, publish_parameters=pub_params)
else:
fs = sdItem.publish(overwrite=True)
# Update service with previous properties
print("Updating service properties")
item_properties = {"text": json.dumps(properties)}
fs.update(item_properties=item_properties)
flyrCollection.manager.update_definition(capabilities)
# Update thumbnail and metadata
print("Updating thumbnail and metadata")
fs.update(thumbnail=thumbnail_file, metadata=metadata_file)
print("Clearing scratch directory")
arcpy.env.workspace = arcpy.env.scratchFolder
for file in arcpy.ListFiles():
if file.split(".")[-1] in ('sd', 'sddraft', 'png', 'xml'):
arcpy.Delete_management(file)
endTime = time.time()
elapsedTime = round((endTime - startTime) / 60, 2)
print(f"Script completed in {elapsedTime} minutes") Updates Update 2/2/24: Added the option to unregister existing replicas Update 12/2/24: Sync is re-enabled if it was previously enabled
... View more
01-17-2024
12:38 PM
|
5
|
46
|
26604
|
|
DOC
|
@Gisbert61 thank you for bringing this to my attention. I went ahead and updated the script to remove commas when writing to the CSV file. You can re-download the tool and it should work correctly now.
... View more
01-16-2024
06:55 AM
|
0
|
0
|
30574
|
|
DOC
|
@ashleyf_lcpud @MelissaJohnson @BrantSollis2 I'm having trouble reproducing this behavior. Can anyone share a sample dataset with me in an AGOL group? You can invite my account (jskinner_rats).
... View more
01-10-2024
07:05 AM
|
0
|
0
|
25146
|
|
POST
|
Hi @Nicole_Ueberschär, can you post the script you are using?
... View more
01-09-2024
06:01 AM
|
0
|
1
|
1790
|
|
POST
|
Hi @julian3930, With SAML authentication, you won't be able to authenticate without user interaction. One thing you could try is to create an Application in ArcGIS Online by going to New Item > Application: Specify Other Application and then specify a name: In the Application details, this will create a Client ID and Client Secret: Using these two, you can generate a token to authenticate with AGOL: import requests, json
from arcgis.gis import GIS
# Variables
clientId = 'Gl2890aGas'
clientSecret = '123kl0987234jajfw9087f123r'
# Generate Token
params = {
'client_id': clientId,
'client_secret': clientSecret,
'grant_type': "client_credentials",
}
request = requests.get('https://www.arcgis.com/sharing/oauth2/token', params=params)
response = request.json()
token = response["access_token"]
# Connect to GIS
gis = GIS('https://www.arcgis.com', token=token) However, you have very limited functionality when authenticating this way.
... View more
01-08-2024
06:57 AM
|
1
|
1
|
2613
|
|
DOC
|
@GeobilityCo thanks for pointing out this issue. I went ahead and updated the code so that the web map is no longer being reported as a dependency of itself.
... View more
01-02-2024
12:08 PM
|
0
|
0
|
30902
|
|
DOC
|
It's always a good practice to have a DEV/STAGING environment along with a PRODUCTION environment for ArcGIS Enterprise. I frequently get asked how to migrate content from one to the other. Hosted services can be straight forward, and can easily be scripted (expect an update later to this toolset for this functionality), but referenced services can be rather difficult. For example, there are numerous prerequisites that are required for a service to be published from an Enterprise Geodatabase, such as: does the ArcGIS Service Account have necessary privileges is the geodatabase registered with the ArcGIS Server instance does the feature class in fact exist within the new geodatabase etc These tools pick up once your services have been published to the other environment and you would like to begin migrating web maps, apps, and dashboards. Take a look at the video below on how to execute these tools. These tools should only be used to migrate web maps/apps where the environments are the same version (i.e. 11.1). Migrating content between two ArcGIS Online organizations is also supported. Currently, these tools have only been tested in ArcGIS Enterprise 11.1 and ArcGIS Online. If there are any issues, please report in the comment section below. Migrating Referenced Services: Updates 1/16/24: Added tools to copy hosted feature services and file based items. 1/29/24: Added option to run when portal has Windows Authentication enabled. Also, updated the Copy Dashboard tool to specify stand-alone layers. 2/12/24: Web Map item IDs now update 3/28/24: Added tool to copy Story Maps 6/30/24: Group layers and tables are now supported when copying web maps 7/10/24: Experience Builder Templates are now supported 5/1/25: Web Scenes are now supported 6/14/25: Updated for ArcGIS API 2.4.1 10/6/25: Referenced services are now supported 10/28/25: Hosted Views and Surveys are now supported Known Issues If hosted feature services exist in Enterprise, they will not successfully overwrite when executing the Copy Hosted Feature Services tool. Will successfully overwrite in AGOL. Possible bug with ArcGIS API for Python After Story Map is copied to Enterprise, the Story Map must first be opened in Edit mode and published before it can be successfully viewed. This is not the case for AGOL. Possible bug with ArcGIS API for Python
... View more
01-02-2024
09:36 AM
|
29
|
171
|
87530
|
|
DOC
|
@MarkGambordella, yes you can update the where statement on line 87:
... View more
12-20-2023
07:17 AM
|
0
|
0
|
6660
|
|
DOC
|
@MarcoMob, Write to file: https://www.w3schools.com/python/python_file_write.asp Script Execution time: https://www.tutorialspoint.com/how-to-check-the-execution-time-of-python-script#:~:text=Using%20the%20time%20Module,of%20the%20given%20code%20block. Get File Size on Disk https://stackoverflow.com/questions/2104080/how-do-i-check-file-size-in-python
... View more
12-15-2023
05:28 AM
|
0
|
0
|
32580
|
|
DOC
|
@MarcoMob the WebGISDR tool output file did not become available until 11.1, so you would need to code the information you're looking for. For example, you could update the python script to output the total time it took to execute, and the size of the file created on disk, to a txt file.
... View more
12-14-2023
05:47 AM
|
0
|
0
|
32636
|
|
DOC
|
@MelissaJohnson I downloaded the OpenGov feature serivce, and then re-published to my Org. The below code work for me to update each layer in the feature service. import arcpy, os, time, uuid
from zipfile import ZipFile
from arcgis.gis import GIS
import arcgis.features
# Overwrite Output
arcpy.env.overwriteOutput = True
# Variables
username = "jskinner_rats"
password = "*******"
fc1 = r"c:\projects\GeoNET\GeoNET.gdb\AddressPoints"
fc2 = r"C:\projects\GeoNET\GeoNET.gdb\Streets"
fc3 = r"c:\projects\GeoNET\GeoNET.gdb\Parcels"
fc4 = r"c:\projects\GeoNET\GeoNET.gdb\UrbanBoundaryParcels"
fc5 = r"c:\projects\GeoNET\GeoNET.gdb\WaterDistricts"
fc6 = r"c:\projects\GeoNET\GeoNET.gdb\CityLimits"
fc7 = r"c:\projects\GeoNET\GeoNET.gdb\FireDistricts"
fc8 = r"c:\projects\GeoNET\GeoNET.gdb\SanitarySewerBasinsJC"
fc9 = r"c:\projects\GeoNET\GeoNET.gdb\FloodZones"
fsItemId = "1fe9a4e285af4c9385bb1071660a8d0c"
featureService = True
hostedTable = False
layerIndex1 = 0
layerIndex2 = 1
layerIndex3 = 2
layerIndex4 = 3
layerIndex5 = 4
layerIndex6 = 5
layerIndex7 = 6
layerIndex8 = 7
layerIndex9 = 8
disableSync = True
updateSchema = True
# Start Timer
startTime = time.time()
# Create dictionary
dataDict = {}
dataDict[fc1] = layerIndex1
dataDict[fc2] = layerIndex2
dataDict[fc3] = layerIndex3
dataDict[fc4] = layerIndex4
dataDict[fc5] = layerIndex5
dataDict[fc6] = layerIndex6
dataDict[fc7] = layerIndex7
dataDict[fc8] = layerIndex8
dataDict[fc9] = layerIndex9
# Function to Zip FGD
def zipDir(dirPath, zipPath):
'''Zip File Geodatabase'''
zipf = ZipFile(zipPath , mode='w')
gdb = os.path.basename(dirPath)
for root, _ , files in os.walk(dirPath):
for file in files:
if 'lock' not in file:
filePath = os.path.join(root, file)
zipf.write(filePath , os.path.join(gdb, file))
zipf.close()
# Create GIS object
print("Connecting to AGOL")
gis = GIS("https://www.arcgis.com", username, password)
for fc, layerIndex in dataDict.items():
# Create UUID variable for GDB
gdbId = str(uuid.uuid1())
print("\n=========================\nCreating temporary File Geodatabase")
gdb = arcpy.CreateFileGDB_management(arcpy.env.scratchFolder, gdbId)[0]
# Export featureService classes to temporary File Geodatabase
fcName = os.path.basename(fc)
fcName = fcName.split('.')[-1]
print(f"Exporting {fcName} to temp FGD")
if featureService == True:
arcpy.conversion.FeatureClassToFeatureClass(fc, gdb, fcName)
elif hostedTable == True:
arcpy.conversion.TableToTable(fc, gdb, fcName)
# Zip temp FGD
print("Zipping temp FGD")
zipDir(gdb, gdb + ".zip")
# Upload zipped File Geodatabase
print("Uploading File Geodatabase")
fgd_properties={'title':gdbId, 'tags':'temp file geodatabase', 'type':'File Geodatabase'}
fgd_item = gis.content.add(item_properties=fgd_properties, data=gdb + ".zip")
# Get featureService/hostedTable layer
serviceLayer = gis.content.get(fsItemId)
if featureService == True:
fLyr = serviceLayer.layers[layerIndex]
elif hostedTable == True:
fLyr = serviceLayer.tables[layerIndex]
# Truncate Feature Service
# If views exist, or disableSync = False use delete_features. OBJECTIDs will not reset
flc = arcgis.features.FeatureLayerCollection(serviceLayer.url, gis)
try:
if flc.properties.hasViews == True:
print("Feature Service has view(s)")
hasViews = True
except:
hasViews = False
if hasViews == True or disableSync == False:
# Get Min OBJECTID
minOID = fLyr.query(out_statistics=[{"statisticType": "MIN", "onStatisticField": "OBJECTID", "outStatisticFieldName": "MINOID"}])
minOBJECTID = minOID.features[0].attributes['MINOID']
# Get Max OBJECTID
maxOID = fLyr.query(out_statistics=[{"statisticType": "MAX", "onStatisticField": "OBJECTID", "outStatisticFieldName": "MAXOID"}])
maxOBJECTID = maxOID.features[0].attributes['MAXOID']
# If more than 2,000 features, delete in 2000 increments
print("Deleting features")
if (maxOBJECTID - minOBJECTID) > 2000:
x = minOBJECTID
y = x + 1999
while x < maxOBJECTID:
query = f"OBJECTID >= {x} AND OBJECTID <= {y}"
fLyr.delete_features(where=query)
x += 2000
y += 2000
# Else if less than 2,000 features, delete all
else:
print("Deleting features")
fLyr.delete_features(where="1=1")
# If no views and disableSync is True: disable Sync, truncate, and then re-enable Sync. OBJECTIDs will reset
elif hasViews == False and disableSync == True:
if flc.properties.syncEnabled == True:
print("Disabling Sync")
properties = flc.properties.capabilities
updateDict = {"capabilities": "Query", "syncEnabled": False}
flc.manager.update_definition(updateDict)
print("Truncating Feature Service")
fLyr.manager.truncate()
print("Enabling Sync")
updateDict = {"capabilities": properties, "syncEnabled": True}
flc.manager.update_definition(updateDict)
else:
print("Truncating Feature Service")
fLyr.manager.truncate()
# Schema Sync
if updateSchema == True:
# Get feature service fields
print("Get feature service fields")
featureServiceFields = {}
for field in fLyr.manager.properties.fields:
if field.type != 'esriFieldTypeOID' and 'Shape_' not in field.name:
featureServiceFields[field.name] = field.type
# Get feature class/table fields
print("Get feature class/table fields")
featureClassFields = {}
arcpy.env.workspace = gdb
if hostedTable == True:
for field in arcpy.ListFields(gdbTable):
if field.type != 'OID' and field.type != 'Geometry':
featureClassFields[field.name] = field.type
else:
for field in arcpy.ListFields(fc):
if field.type != 'OID' and field.type != 'Geometry' and 'Shape_' not in field.name:
featureClassFields[field.name] = field.type
minusSchemaDiff = set(featureServiceFields) - set(featureClassFields)
addSchemaDiff = set(featureClassFields) - set(featureServiceFields)
# Delete removed fields
if len(minusSchemaDiff) > 0:
print("Deleting removed fields")
for key in minusSchemaDiff:
print(f"\tDeleting field {key}")
remove_field = {
"name": key,
"type": featureServiceFields[key]
}
update_dict = {"fields": [remove_field]}
fLyr.manager.delete_from_definition(update_dict)
# Create additional fields
fieldTypeDict = {}
fieldTypeDict['Date'] = 'esriFieldTypeDate'
fieldTypeDict['Double'] = 'esriFieldTypeDouble'
fieldTypeDict['Integer'] = 'esriFieldTypeInteger'
fieldTypeDict['String'] = 'esriFieldTypeString'
if len(addSchemaDiff) > 0:
print("Adding additional fields")
for key in addSchemaDiff:
print(f"\tAdding field {key}")
if fieldTypeDict[featureClassFields[key]] == 'esriFieldTypeString':
new_field = {
"name": key,
"type": fieldTypeDict[featureClassFields[key]],
"length": [field.length for field in arcpy.ListFields(fc, key)][0]
}
else:
new_field = {
"name": key,
"type": fieldTypeDict[featureClassFields[key]]
}
update_dict = {"fields": [new_field]}
fLyr.manager.add_to_definition(update_dict)
# Append features from featureService class/hostedTable
print("Appending features")
fLyr.append(item_id=fgd_item.id, upload_format="filegdb", upsert=False, field_mappings=[])
# Delete Uploaded File Geodatabase
print("Deleting uploaded File Geodatabase")
fgd_item.delete()
# Delete temporary File Geodatabase and zip file
print("Deleting temporary FGD and zip file")
try:
arcpy.Delete_management(gdb)
except Exception as e:
print(e)
pass
try:
os.remove(gdb + ".zip")
except Exception as e:
print(e)
endTime = time.time()
elapsedTime = round((endTime - startTime) / 60, 2)
print("Script finished in {0} minutes".format(elapsedTime))
... View more
12-14-2023
05:41 AM
|
0
|
0
|
25920
|
|
DOC
|
@SFM_TravisBott I believe only basic HTML formatting is supported (i.e. bold, italics, etc). I tested an e-mail trying to send a hyperlink, and it failed.
... View more
12-14-2023
05:39 AM
|
0
|
0
|
10456
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 4 weeks ago | |
| 4 | 05-07-2020 05:14 PM | |
| 1 | 03-25-2026 04:16 AM | |
| 1 | 03-16-2026 01:00 PM | |
| 1 | 12-22-2025 10:39 AM |
| Online Status |
Offline
|
| Date Last Visited |
yesterday
|