|
POST
|
Pretty new to cursors here - trying to write a script that will remove any hard 'returns'/newlines/carriages from any text values in a feature class. For example, a user might enter: What I need is: Can someone clarify why I'm getting the error TypeError: sequence size must match size of the row. import arcpy
import os
import time
# Start the clock
startTime = time.time()
# Input geodatabase with feature classes to update
inputGDB = r'C:\data\test.gdb'
# Set workspace to input GDB
arcpy.env.workspace = inputGDB
eolchar = ""
# Get a list of feature datasets
datasets = arcpy.ListDatasets(feature_type='feature')
datasets = [''] + datasets if datasets is not None else []
# Loop through all feature classes (including ones in feature datasets)
print('Reading Feature Classes...')
for ds in datasets:
for fc in arcpy.ListFeatureClasses(feature_dataset=ds):
# Get the name of the feature class
path = os.path.join(arcpy.env.workspace, fc)
desc = arcpy.Describe(path)
fcName = desc.name
print('Cleaning feature class: {}'.format(fcName))
# Build a list of all TEXT/String Fields
fieldList = [i.name for i in arcpy.ListFields(fc) if i.type == 'String']
fieldList = ['OID@'] + fieldList
# Iterate through each row and execute the clean
# row = [i.replace(chr(10), eolchar).replace(chr(13), eolchar) if i is not None else i for i in row]
with arcpy.da.UpdateCursor(fc, fieldList) as cursor:
for row in cursor:
for i in row:
if i is not None:
if chr(10) in str(i) or chr(13) in str(i):
print('\nHard Return found in feature class: {}'.format(fc))
print('Object ID: {}'.format(row[0]))
print('There is a newline in {}'.format(i))
# print ('Field is {}'.format(fieldList))
row = i.replace(chr(10), eolchar).replace(chr(13), eolchar)
cursor.updateRow(row)
print('Finished cleaning.')
print('Completed.') If I use the following below, it works. # row = [i.replace(chr(10), eolchar).replace(chr(13), eolchar) if i is not None else i for i in row] But I'm trying the print the Feature Class name, OID, and Field Name if/where any changes are made. Using the code above, how can I extract the field name where hard returns/carriages are removed?
... View more
03-03-2022
06:50 PM
|
0
|
5
|
1724
|
|
POST
|
I am trying to write a script that will take different permutations of the word Null and convert them to true database Nulls. I have users populate 'Null', 'NULL' or similar, and I need to convert these to true Nulls. I have a list of the different permutations and a geodatabase with several feature classes. I'm trying to loop through my list and compare against all string values in all feature class. If there is a match, convert the string to the true Null. I am getting an invalid syntax error on line 26: row = [None if i in nullList else pass for i in row] If I replace pass with print ('Test') it changes every value to Null. Any ideas? import arcpy
import os
import time
inputGDB = r'C:\Test_null.gdb'
# Set workspace to input GDB
arcpy.env.workspace = inputGDB
nullList = ['', ' ', ' ', ' ', '-', '--', '---', '<Null>', '<NULL>', 'Null', 'NULL', '”Null”', '”NULL”']
datasets = arcpy.ListDatasets(feature_type='feature')
datasets = [''] + datasets if datasets is not None else []
# Loop through all feature classes
print('Reading Feature Classes...')
for ds in datasets:
for fc in arcpy.ListFeatureClasses(feature_dataset=ds):
# Build a list of all TEXT/String Fields where NULL values are allowed
fieldList = [i.name for i in arcpy.ListFields(fc) if i.type == 'String' and i.isNullable is True]
# Iterate through each row and execute the clean
with arcpy.da.UpdateCursor(fc, fieldList) as cursor:
for row in cursor:
row = [None if i in nullList else pass for i in row]
cursor.updateRow(row)
print('Done.')
... View more
02-23-2022
04:15 PM
|
0
|
2
|
2604
|
|
POST
|
Solved by silently uninstalling the Data Store and Server pieces. That removed the remnants/ghost files and allowed me to proceed with the Enterprise Builder install. How To: Silently uninstall ArcGIS products (esri.com)
... View more
01-20-2022
11:02 AM
|
1
|
0
|
1298
|
|
POST
|
I am trying to install ArcGIS Enterprise 10.9.1 on a Windows AWS machine using Enterprise Builder. This machine previously had 10.8.1 installed manually without Enterprise Builder. I have followed this guidance here to uninstall all components of 10.8.1: How To: Perform a clean uninstallation of ArcGIS Enterprise base deployment components (esri.com) When I try to run the Enterprise Builder installer I get this error: The ArcGIS Server, Portal, Data Store and 2 Web Adaptors have been uninstalled and I verified there are no windows services running for any of those pieces. Any other common places to check for 'ghost' files?
... View more
01-19-2022
11:06 AM
|
0
|
1
|
1374
|
|
POST
|
Running ArcGIS Pro 2.8 and ArcGIS Enterprise 10.9 This script should retrieve a token from an active Portal connection in ArcGIS Pro. from arcgis.gis import GIS
# Get a Token
portalURL = arcpy.GetActivePortalURL()
token = arcpy.GetSigninToken()
if token is not None:
token = (token['token'])
gis = GIS(portalURL, token = token, verify_cert=False)
print(token)
else:
print('Fail.') Line 8 fails with an invalid Token error. I can print the token and confirm it's valid. Any idea how I can use the token to connect to the GIS? Exception: Invalid token.
(Error Code: 498)
... View more
12-13-2021
02:12 PM
|
0
|
1
|
2416
|
|
POST
|
Good catch. I've found, in general, it's best practice to publish services with all fields on/visible, then hide them on the front end from the map viewer or else where.
... View more
12-01-2021
12:05 PM
|
1
|
1
|
10561
|
|
POST
|
I cant say for sure, since I left my previous org where I had this working. But I think these were the steps 1. Create a new WAB app using WAB Dev 2. Create a new website on my IIS and get DNS configured - website should have a URL like https://mywebsite.com/appname 3. Deploy WAB app to the new website 4. Add a web application item in your Portal/AGOL with the URL of your locally deployed app. This item will function as a placeholder for your locally deployed app 5. Go into the just registered app's settings and click Register at the bottom to generate an AppId 7. Copy the appId into your locally deployed app's config.json in the appId property 6. Set the redirect URI(s) to your app. In my case it was https://mywebsite.com/appname The redirect URLs should not be your federated or standalone GIS Server, if that's what you're trying.
... View more
11-23-2021
01:16 PM
|
0
|
2
|
1439
|
|
POST
|
Also see: Solved: Create Time Enabled Layer from CSV in AGOL or Port... - Esri Community As a last ditch effort, you may have to modify your CSV then re-upload it to AGO.
... View more
11-20-2021
02:49 PM
|
0
|
1
|
2802
|
|
POST
|
Open a fresh ArcGIS Pro session. Sign out and sign back into your AGO, then set it as the active Portal. Does your map have layers?
... View more
11-20-2021
02:46 PM
|
0
|
2
|
2802
|
|
POST
|
Are you signed into your AGO in Pro and have you set it as the active Portal? Do you have publishing permissions?
... View more
11-20-2021
02:20 PM
|
0
|
4
|
2822
|
|
POST
|
Thanks for the tip, got me going in the right direction. I added a snippet to get everything from the root folder and move it to a specified folder. Kind of a hacky solution that makes the assumption that the root folder is empty by default, but it does the job for now. arcpy.UploadServiceDefinition_server(sdOutFileName, gisServer)
myUser = gis.users.get(parameters[1].valueAsText)
rootfolder = myUser.items()
for item in rootfolder:
item.move(parameters[5].valueAsText)
... View more
11-18-2021
02:10 PM
|
0
|
0
|
1690
|
|
POST
|
I am using the example here to publish map image layers with associated feature layers from an EGDB to ArcGIS Enterprise. https://pro.arcgis.com/en/pro-app/2.9/arcpy/sharing/mapimagesharingdraft-class.htm#GUID-98B8320E-3561-4E46-AECF-70B0553AE4FF I have set the portalFolder property in line 87 to an existing folder in my Portal but the services get placed in my root Portal Folder. How do I publish my services to the specified Portal Folder rather than the root folder? import arcpy
import os
import xml.dom.minidom as DOM
def configure_featureserver_capabilities(sddraftPath, capabilities):
"""Function to configure FeatureServer properties"""
# Read the .sddraft file
doc = DOM.parse(sddraftPath)
# Find all elements named TypeName
# This is where the additional layers and capabilities are defined
typeNames = doc.getElementsByTagName('TypeName')
for typeName in typeNames:
# Get the TypeName to enable
if typeName.firstChild.data == "FeatureServer":
extension = typeName.parentNode
for extElement in extension.childNodes:
if extElement.tagName == 'Info':
for propSet in extElement.childNodes:
for prop in propSet.childNodes:
for prop1 in prop.childNodes:
if prop1.tagName == "Key":
if prop1.firstChild.data == 'WebCapabilities':
if prop1.nextSibling.hasChildNodes():
prop1.nextSibling.firstChild.data = capabilities
else:
txt = doc.createTextNode(capabilities)
prop1.nextSibling.appendChild(txt)
# Write to the .sddraft file
f = open(sddraftPath, 'w')
doc.writexml(f)
f.close()
def configure_mapserver_capabilities(sddraftPath, capabilities):
"""Function to configure MapServer properties"""
# Read the .sddraft file
doc = DOM.parse(sddraftPath)
# Find all elements named TypeName
# This is where the additional layers and capabilities are defined
typeNames = doc.getElementsByTagName('TypeName')
for typeName in typeNames:
# Get the TypeName to enable
if typeName.firstChild.data == "MapServer":
extension = typeName.parentNode
for extElement in extension.childNodes:
if extElement.tagName == 'Definition':
for propArray in extElement.childNodes:
if propArray.tagName == 'Info':
for propSet in propArray.childNodes:
for prop in propSet.childNodes:
for prop1 in prop.childNodes:
if prop1.tagName == "Key":
if prop1.firstChild.data == 'WebCapabilities':
if prop1.nextSibling.hasChildNodes():
prop1.nextSibling.firstChild.data = capabilities
else:
txt = doc.createTextNode(capabilities)
prop1.nextSibling.appendChild(txt)
# Write to the .sddraft file
f = open(sddraftPath, 'w')
doc.writexml(f)
f.close()
if __name__ == "__main__":
# Sign in to portal
arcpy.SignInToPortal("https://www.portal.domain.com/webadaptor", "MyUserName", "MyPassword")
# Set output file names
outdir = r"C:\Project\Output"
service_name = "MapImageSharingDraftExample"
sddraft_filename = service_name + ".sddraft"
sddraft_output_filename = os.path.join(outdir, sddraft_filename)
sd_filename = service_name + ".sd"
sd_output_filename = os.path.join(outdir, sd_filename)
# Reference map to publish
aprx = arcpy.mp.ArcGISProject(r"C:\Project\World.aprx")
m = aprx.listMaps('World')[0]
# Create MapImageSharingDraft and set copyDataToServer property to False to reference registered data
server_type = "FEDERATED_SERVER"
federated_server_url = "https://MyFederatedServer.esri.com/server"
sddraft = m.getWebLayerSharingDraft(server_type, "MAP_IMAGE", service_name)
sddraft.federatedServerUrl = federated_server_url
sddraft.copyDataToServer = False
sddraft.portalFolder = 'Test_Folder'
# Create Service Definition Draft file
sddraft.exportToSDDraft(sddraft_output_filename)
"""Modify the .sddraft file to include a feature layer and set map image layer and feature layer properties"""
# Modify the .sddraft file to change map image layer properties
# Defaults are Map,Query,Data
# Comment out the line below if you do not want to modify map image layer properties
configure_mapserver_capabilities(sddraft_output_filename, "Map,Data")
# Modify the .sddraft file to include a feature layer
# Read the file
doc = DOM.parse(sddraft_output_filename)
# Find all elements named TypeName
# This is where the extensions are defined
typeNames = doc.getElementsByTagName('TypeName')
for typeName in typeNames:
# Get the TypeName to enable
if typeName.firstChild.data == "FeatureServer":
extension = typeName.parentNode
for extElement in extension.childNodes:
# Include a feature layer
if extElement.tagName == 'Enabled':
extElement.firstChild.data = 'true'
# Write to new .sddraft file
sddraft_mod_xml = service_name + '_mod_xml' + '.sddraft'
sddraft_mod_xml_file = os.path.join(outdir, sddraft_mod_xml)
f = open(sddraft_mod_xml_file, 'w')
doc.writexml(f)
f.close()
# Modify the .sddraft file to change feature layer properties
# Defaults are Query,Create,Update,Delete,Uploads,Editing
# Comment out the line below if you don't want to modify feature layer properties
configure_featureserver_capabilities(sddraft_mod_xml_file, "Create,Sync,Query")
# Stage Service
print("Start Staging")
arcpy.StageService_server(sddraft_mod_xml_file, sd_output_filename)
# Share to portal
print("Start Uploading")
arcpy.UploadServiceDefinition_server(sd_output_filename, federated_server_url)
print("Finish Publishing")
... View more
11-16-2021
01:09 PM
|
0
|
2
|
1779
|
|
POST
|
Following this doc here: Managing your GIS servers | ArcGIS Developer I am trying to build a list of all GIS Servers federated to my Portal. Running Enterprise 1081. from arcgis.gis import GIS
gis = GIS("http://siteurl.mysite.com/portal", "username")
gis_servers = gis.admin.servers.list()
gis_servers Gives me this: [<Server at https://pythonapi.playground.esri.com/server/admin>, <Server at https://python-ga.playground.esri.com/server/admin>, <Server at https://python-ra.playground.esri.com/arcgis/admin>] What I need is the URL for the Server, not the admin endpoint. Looks like the list() method does not provide this. Looking in https://portal.domain.com/arcgis/portaladmin/federation/servers/servername I can see the URL attribute. Can I get the server URLs using the arcgis python api?
... View more
11-11-2021
06:15 PM
|
0
|
3
|
2015
|
| Title | Kudos | Posted |
|---|---|---|
| 2 | 07-16-2022 08:54 AM | |
| 1 | 11-09-2021 04:14 PM | |
| 1 | 04-13-2022 08:10 AM | |
| 1 | 11-13-2024 05:02 PM | |
| 1 | 05-06-2021 06:48 PM |
| Online Status |
Offline
|
| Date Last Visited |
3 weeks ago
|