|
POST
|
I wrote some python code a while back to publish REST services to our ArcGIS server and as far as I could tell I could only secure the service after the publish (UploadServiceDefinition) was complete. This was fairly simple to do by sending a series of requests via the Add Permissions REST API. First I looped on the roles that I wanted to give access to ({'principal': <role_name>, 'isAllowed': True}), then I sent a request to disable the public access ({'principal': 'esriEveryone', 'isAllowed': False}) I didn't enable WMS so maybe there is an issue there that I didn't have to deal with. I'm curious is somebody has a better way so that my "secure" endpoint doesn't have to be exposed publicly - even if it is only for a couple of seconds
... View more
10-06-2021
07:42 AM
|
0
|
0
|
2681
|
|
POST
|
I do something similar to this. Since I have a relationship defined between the attachment table and the feature class, there is a field in the attachment table that holds the GUID of the associated feature. So my script reads this field in (along with 'DATA', 'ATT_NAME', 'ATTACHMENTID') then looks up the feature to get the desired value ('MapID') in your case.
... View more
09-28-2021
10:52 AM
|
1
|
0
|
3778
|
|
POST
|
Your code worked OK for me when I ran it against a feature class with a spatial reference whose unit of measure was degrees (NAD 1983). At least the polygon that it generated looks correct.
... View more
09-28-2021
10:37 AM
|
0
|
0
|
2951
|
|
POST
|
I do something similar with the code below to add a layer to the map that is currently open in ArcGIS Pro. My code runs from a python toolbox - not sure if it applies to what your are doing aprx = arcpy.mp.ArcGISProject('CURRENT')
current_map = aprx.activeMap
current_map.addDataFromPath(<path to feature class>)
... View more
09-20-2021
03:13 PM
|
3
|
3
|
2997
|
|
POST
|
It looks to me list you need to add another loop - to process the list of layouts that your get from the call to listLayouts. Like this for lyts in aprx.listLayouts("Layout 1"):
for lyt in lyts:
for elm in lyt.listElements("TEXT_ELEMENT"):
if elm.name == "Text":
elm.text = wl
... View more
09-19-2021
05:23 AM
|
1
|
0
|
2934
|
|
POST
|
I was able to get it to work by changing the data type of the input variable from GPLayer to GPString. I have no idea why, but this is typical with toolbox programming in that you just have to keep trying things until you find something that works. I guess in a way it makes sense since you really are just setting it to a string and not a layer object. On line 28 you also have to initialize the variable (eg poly_list = []). Good luck on your tool, the fun is just beginning 😉
... View more
09-17-2021
02:48 PM
|
1
|
1
|
4612
|
|
POST
|
I am working with a team to develop a HUB site and we are finding it difficult to manage all of the AGOL items that created. One aspect in particular is understanding relationships between items and finding obsolete/unreferenced items. I wrote a python script that prints a report listing the relationships and wanted to share it - not sure if this is the right place since it isn't really a question but I couldn't figure out how to create a blog entry. You have to update lines 6 and 7 before running to customize it with your credentials and to query your items. from arcgis.gis import GIS
import re
import json
# UPDATE THESE 2 STATEMENTS BEFORE RUNNING
AGOL = GIS(username=MY_USER_ID, password=MY_PASSWORD)
CONTENT_QUERY = MY_CONTENT_QUERY # eg "owner: %s" % 'MY_USER_ID'
REGEX = '"[0-9a-f]{32}"'
def run ():
# Build dicts of all agol items and all item descriptions (indexed by item id)
all_items = { i.id: i for i in AGOL.content.search(query = "%s" % CONTENT_QUERY, max_items=5000)}
all_item_descs = { i: "%s: %s" % (all_items[i].id, all_items[i].title) for i in all_items.keys()}
# Find the foward references for each item
item_types = set()
item_id_to_forward_refs = {lst: set() for lst in all_items.keys()}
for item_id in all_items.keys():
item_types.add(all_items[item_id].type)
try:
item_id_to_forward_refs[item_id].update([d[1:-1] for d in list(set(re.findall(REGEX, json.dumps(all_items[item_id].get_data(True)))))])
except:
pass
for rel_type in ['Map2Service', 'WMA2Code', 'Map2FeatureCollection', 'MobileApp2Code', 'Service2Data', 'Service2Service']:
item_id_to_forward_refs[item_id].update([i.id for i in all_items[item_id].related_items(rel_type, 'forward')])
# Find the backward references for each item
item_id_to_backward_refs = {lst: [] for lst in all_items.keys()}
for item_id in all_items.keys():
for i in all_items.keys():
if i in item_id_to_forward_refs[item_id]:
item_id_to_backward_refs[i].append(item_id)
# Print out the results
for item_type in item_types:
print ("\n\n========================%ss================================" % (item_type))
print ("Unreferenced")
unreferenced_item_ids = [i for i in item_id_to_backward_refs.keys() if all_items[i].type == item_type and len(item_id_to_backward_refs[i]) == 0]
print ('\n'.join( [all_item_descs[i] for i in unreferenced_item_ids] ))
print ("\n--------------------------------------------------------------------" )
print ("Referenced")
referenced_item_ids = [i for i in item_id_to_backward_refs.keys() if all_items[i].type == item_type and len(item_id_to_backward_refs[i]) > 0]
for referenced_item_id in referenced_item_ids:
print ("%s" % all_item_descs[referenced_item_id])
print ('\t' + '\n\t'.join( [all_item_descs[r] for r in item_id_to_backward_refs[referenced_item_id]] ))
if __name__ == '__main__':
run()
... View more
09-06-2021
05:29 AM
|
2
|
3
|
4029
|
|
POST
|
You are correct - I just checked the help documentation again and saw this note which indicates that I had omitted a step: When you save a service definition, the cache must be built manually after the web tile layer is published. I poked around the AGOL item settings and stumbled on the "Build Tiles" buttons and clicking that did trick. Thanks so much - I wasn't even aware that the cache existed or it was something I had to deal with until you pointed it out.
... View more
07-12-2021
05:15 AM
|
1
|
0
|
2853
|
|
POST
|
I actually don't see how in Python to set the tiling scheme when creating the service. In any case, it appears that the default " ArcGIS Online/Bing Maps/Google Maps" scheme was used since there are 24 256x256 levels in the AGOL tile layer description. When I access the tile layer using this URL https://tiles.arcgis.com/tiles/dJOijx2lWTlGQBDJ/arcgis/rest/services/TEST_TIF_1/MapServer and view the map, I do not see the image . There is no base map in this case so case so I think the problem is not related to a mismatch. When I make the tile layer a basemap, I get the same results. This is my first experience with tile layers so I really appreciate your suggestions. Backing up a bit, my goal is to come up with a python script/tool that takes a .tif (perhaps other raster formats also) file and makes it available in ArcGIS Online for users to add into their maps. Perhaps there is some other way to do it than how I'm going about it?
... View more
07-11-2021
04:07 PM
|
0
|
2
|
2865
|
|
POST
|
I have a map in my ArcGIS Pro project that has a single layer created from a .tif file and I want to use python to publish that as a "tile layer" in ArcGIS Online (see the code below). Everything seems to be OK but when I view the tile layer in the ArcGIS Online map viewer I don't see any of the image - although the layer shows up in the legend correctly (and the thumbnail is correct). In the browser trace I can see the map viewer sending requests for the tiles as I zoom in and out, but some come back with "Error 422: "No tile available for the specified boundary." and the rest throw a 404 error. Any ideas on what might be wrong? I am able to see the image in the map viewer when I do what I think is the equivalent process manually from ArcGIS Pro (Share -> Web Layer -> Share Web Layer) import os
import arcpy
SERVICE_NAME = 'TEST_TIF_1'
PROJECT_FN = r'E:\CW_Hub\temp\TEST_PROJECT.aprx'
SD_DRAFT_FN = os.path.join(arcpy.env.scratchFolder, SERVICE_NAME + ".sddraft")
SD_FN = os.path.join(arcpy.env.scratchFolder, SERVICE_NAME + ".sd")
def test_tif ():
if os.path.exists(SD_DRAFT_FN):
os.remove(SD_DRAFT_FN)
if os.path.exists(SD_FN):
os.remove(SD_FN)
aprx = arcpy.mp.ArcGISProject(PROJECT_FN)
aprx_map = aprx.listMaps()[0]
sharing_draft = aprx_map.getWebLayerSharingDraft("HOSTING_SERVER", "TILE", SERVICE_NAME)
sharing_draft.serviceName = SERVICE_NAME
sharing_draft.summary = SERVICE_NAME
sharing_draft.tags = 'test'
sharing_draft.description = SERVICE_NAME
sharing_draft.portalFolder = None
sharing_draft.overwriteExistingService = True
sharing_draft.exportToSDDraft(SD_DRAFT_FN)
print ('Staging service to %s' % (SD_FN))
arcpy.StageService_server(SD_DRAFT_FN, SD_FN)
print ('Uploading service')
arcpy.UploadServiceDefinition_server(SD_FN, "HOSTING_SERVER")
return
if __name__ == '__main__':
test_tif() ArcGIS Pro 2.6.1
... View more
07-11-2021
12:54 PM
|
0
|
4
|
2939
|
|
POST
|
I've run into the same problem - very simple scenario and there seems to be nothing I can do in my python script to delete the aprx file that I've finished with. Restarting the python process gets rid of the file but that isn't really an option in my workflow.
... View more
04-13-2021
05:10 PM
|
0
|
0
|
4905
|
|
POST
|
No - I got moved back to a 10.6 server where the problem doesn't seem to occur. Once that server moves to 10.8 (any day now I hope) and I can recreate it I plan to open a problem report. But I don't have high hopes of getting a quick resolution. As you mentioned, it happens in the most trivial case so I don't expect there is anything I can do to work around it. I'll post the problem report number here if I get one.
... View more
04-07-2021
04:55 PM
|
0
|
0
|
4330
|
|
POST
|
We used ArcPro tasks to implement a workflow where the task user interface lead the user through running a sequence of custom and built-in tools. I'm not sure if that works for you, but we did not have to change the existing tools at all.
... View more
03-14-2021
11:53 AM
|
0
|
0
|
1249
|
|
POST
|
We recently upgraded our ArcGIS server from 10.6 to 10.8.1 and I later noticed that after publishing a geoprocessing tool, the REST service returns an error when accessed: ERROR 000816: The tool is not valid. The problem appears to be caused by an unresolved import. The import used to work but now I believe it is failing. I was able to recreate the error with the default toolbox - adding the lines below to the .pyt file sys.path.append(r'C:\Git_Repository\ROW\DEV\ROW_as_habitat\row\consolidation')
import empty The tool runs on ArcGIS Pro OK and publishes OK. But the geoprocessing REST service fails. When I copy the import file to the toolkit directory, there is no problem. The problem only happens when python has to find it outside of the current directory. That tells me that the problem has something to do with how the consolidation is handled. I assume I'll have to report this to ESRI - has anybody else had this problem? I'm running this on Windows, ArcPro 2.6.1, and ArcGIS Server 10.8.1
... View more
03-14-2021
11:47 AM
|
1
|
10
|
5040
|
|
POST
|
I decide to just work around this be creating a list of "sanitized" items for my multivalue parameter - basically replacing double quotes, single quotes, and semicolons with a harmless back tick (`) character. Of course I have to keep track of the mapping between the alias and the real value and hope the mapping remains one to one so I can make sense of the selections. For instance the list below would be a problem..... ["a", "b", "don's c", "don;s c", "d"] It would be converted to ["a", "b", "don`s c", "don`s c", "d"]
... View more
01-28-2021
01:18 PM
|
0
|
1
|
5572
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 11-18-2025 03:42 PM | |
| 1 | 11-19-2025 02:36 PM | |
| 1 | 08-11-2025 09:19 PM | |
| 2 | 08-07-2025 11:47 AM | |
| 1 | 01-18-2022 07:15 AM |
| Online Status |
Offline
|
| Date Last Visited |
11-28-2025
04:52 AM
|