|
POST
|
FWIW, this what the support techs came up with for a solution. It's basically borrowed from several other threads on GeoNet, but i've yet to get an answer about the need for the enumeration. I was able to modify their code to accommodate a loop to handle multiple layers [not included here; i suspect there are a number of redundancies which can be eliminated from my own solution]. Esri's code: from arcgis.gis import GIS
import copy
from json import dumps
from json import JSONDecoder
from arcgis.mapping import WebMap
gis = GIS("https://supt0010856.esri.com/portal", "siteadmin", "siteadmin1")
print("Logged in as: " + gis.properties.user.username)
#Retrieve NortheastFieldData web map
webMapSearch = gis.content.search("title: LynseyTest2",item_type = "Web Map")
sourceWebMap= webMapSearch[0]
webMapObject = WebMap(sourceWebMap)
#Create a copy of the web map with a new title
webmap_item_properties = {'title': 'TestCopyLynsey3', 'snippet':'testcopydis', 'tags':'Test'}
webMapObject.save(webmap_item_properties)
newWebMapSearch = gis.content.search("title: TestCopyLynsey3",item_type = "Web Map")
newWebMap = newWebMapSearch[0]
print (newWebMap)
for layer in WebMap(newWebMap).layers:
print(layer.title)
#Extract JSON from webmap
pubMapJson = newWebMap.get_data(try_json=True)
jsonCopy = copy.deepcopy(pubMapJson)
#print copy of webmap json
print (jsonCopy)
lyrFilter = "stringtest = '{0}'".format("test")
print (lyrFilter)
fldMapJsonCopy = copy.deepcopy(pubMapJson)
lyrT = [l for l in pubMapJson['operationalLayers'] if l['title']== 'APITest']
if len(lyrT) >0:
tZoneLyr = lyrT[0]
if 'layerDefinition' in tZoneLyr:
z = [[x, y] for x, y in enumerate(pubMapJson['operationalLayers']) if y['title'] == 'APITest'][0]
fldMapJsonCopy['operationalLayers'][z[0]]['layerDefinition']['definitionExpression'] = lyrFilter
final= newWebMap.update(item_properties={'text':dumps(fldMapJsonCopy)})
print (final)
Any one have any idea what the enumeration is doing here?
... View more
01-22-2020
11:26 AM
|
0
|
0
|
2663
|
|
POST
|
This is interesting to me because every other thread I've seen regarding this has a process by which you need to extract the JSON from the web map (deepcopy) modify it and then apply the full JSON back to the webmap. Obviously, your method is simpler. However, I cannot seem to the 'definitionExpression' key by your method. For example: json_key = 'layerDefinition'
for layer in webMapTest.layers:
if 'layerDefinition' in layer:
print(layer.title)
print(layer['layerDefinition']) returns the following for each layer: NortheastClientsCollector - NortheastLines
{'minScale': 80000, 'maxScale': 0, 'definitionExpression': "LVI_CODE = '0'"} however, if you try the following: json_key = 'layerDefinition'
for layer in webMapTest.layers:
if 'layerDefinition' in layer:
print(layer.title)
print(layer['definitionExpression']) you get a key error: KeyError: 'definitionExpression' printing webMapTest.definition, I can see that 'definitionExpression' is a child element of 'layerDefinition' : "layerDefinition": {
"definitionExpression": "LVI_CODE = '0'"
}, I don't know how to modify that child element. I'm adding another response to this thread for some additional clarity.
... View more
01-22-2020
11:23 AM
|
0
|
1
|
2663
|
|
POST
|
Very similar observations here. Has anyone from Esri responded about this issue!?
... View more
01-21-2020
06:31 AM
|
1
|
0
|
2653
|
|
POST
|
Thanks for the clarification and that makes sense given that you can publish a script tool created in Pro so there would have to be 3.x compatibility. What do you see as the advantages to using the Python API vs 'conventional' geoprocessing tools? Are there performance considerations? Ease of deployment?
... View more
12-13-2019
05:49 AM
|
0
|
0
|
2745
|
|
POST
|
Thanks for replying...this is the kind of discussion I was hoping people would have! I believe the Python API is really a label for the arcgis module, right? That's more or less how I see it too. Granted, one will still land in the Pleistocene world of Python 2.7 by default. But you can install arcpy in 3.6 with conda. That's a really great point since in terms of server-side processing all of Enterprise/Server still leverages python 2.7 I mean, in large part i'm using 3.x for any of the heavy-lifting type analysis I need to do to churn out things. But in terms of extending pre-canned tools to non-GIS users, I'm still sorta struggling to understand how the Python API fits in. Unless I stand up a Notebook server, I'll be more or less rolling up python scripts into GP Tools/services and Widgets. Within those, I would have the choice to use the API to have the analysis run on web services, but why bother when arcpy can access the enterprise GDB directly? Are there performance advantages to running analysis against map & feature services vs directly against the feature classes they represent? For now, it seems to me that i'll be using the python API to help manage our Enterprise site. Anyone else have thoughts to share?
... View more
12-12-2019
11:04 AM
|
0
|
4
|
2745
|
|
POST
|
In this particular case I'm trying to use the arcgis.features.analysis module's join_features function using two feature layers I've applied queries to. I'm using Jupyter Labs to work on this and I've not included the outputs/responses which the code does return successfully and the queried layers appear as expected in the ipython display. from arcgis.gis import GIS
from arcgis.features import FeatureLayer #Not needed here
from IPython.display import display #Not needed here
from arcgis import features
gis = GIS("https://amazingportal.com/portal", "me", "m3LoG!!N")
print("Logged in as: " + gis.properties.user.username)
#Access feature layers
cruiseFeatureLayer = gis.content.search('title: NortheastCruisePoints', 'Feature Layer')
cruisePoints = cruiseFeatureLayer[0].layers[0]
print("Item ID:{0}".format(cruiseFeatureLayer[0].id))
print("Input Layer:{0}".format(cruisePoints.properties.name))
cruisePoints
clientsFeatureLayer = gis.content.search('title: NortheastClientsCollector', item_type='Feature Layer')
clients = clientsFeatureLayer[0].layers[2]
print("Item ID:{0}".format(clientsFeatureLayer[0].id))
print("Input Layer:{0}".format(clients.properties.name))
clients
#Query based on ClientID
clientQuery = clients.query(where="LVI_CODE ='7282'")
cruiseQuery = cruisePoints.query(where="LVI_CODE ='7282'")
print("{0} stands selected".format(len(clientQuery.features)))
print("{0} cruise points selected".format(len(cruiseQuery.features)))
#Review queried feature layers in ipython display [need to modify so queried layers are zoomed-to]
queryMap = gis.map()
queryMap.extent = clientsFeatureLayer[0].extent
queryMap.add_layer(clientQuery)
queryMap.add_layer(cruiseQuery)
queryMap
features.analysis.join_features(target_layer=clientQuery,join_layer=cruiseQuery, spatial_relationship='intersects') Here is the error I get: Exception: Invalid format of input layer. url string, feature service Item, feature service instance or dict supported So does the analysis module only work for feature layers, not feature sets? Is there a way to supply a queried/filtered input to the analysis w/o having to create an entirely new item in your portal?
... View more
12-09-2019
08:42 AM
|
0
|
0
|
618
|
|
POST
|
Many of the solutions we have created for our organization have been released as Python based Geoprocessing Tools (sometimes rolled-up into widgets, other times simply a GP Service). Since we've implemented a (federated) Enterprise system, we've been exploring leveraging the Python API much more. As I see it, the primary difference here is that the GP services can access the underlying geodatabase infrastructure directly. Conversely, the Python API is designed to be web-based and would therefore access the data via feature services. I realize this is the Python API forum/group so this may need to be posted elsewhere to get a good discussion going. That said, what do you see as the advantages to using the Python API vs 'conventional' geoprocessing tools? Are there performance considerations? Ease of deployment?
... View more
12-06-2019
07:04 AM
|
1
|
6
|
3045
|
|
POST
|
I just can't find any reliable documentation about this. I have had a ticket open with tech support that's older than a month now.
... View more
12-05-2019
11:21 AM
|
0
|
0
|
6604
|
|
POST
|
When I embarked on this quest several weeks back I had no idea it would be so difficult! If it's any testament to this: I've had a ticket open with support services for almost 2 weeks and they've just escalated it. If/when I find an answer I'll be happy to share it back here!
... View more
11-22-2019
10:30 AM
|
0
|
1
|
2663
|
|
POST
|
I modified the the loop a bit and it seemed like it was writing the JSON back, but when viewing the map still no luck. Can anyone help??? for layer in newWebMapObject.layers:
for lyz in layersList:
if layer.title == lyz:
print(layer.title)
jsonCopy['operationalLayers'][0]['definitionExpression'] = lyrFilter
newWebMap.update(item_properties={'text':json.dumps(jsonCopy)})
... View more
11-08-2019
12:55 PM
|
0
|
3
|
2663
|
|
POST
|
I keep going in circles on this! Where is the information specific to 'definitionExpression' and 'layerDefinition? what exactly needs to be supplied when updating the JSON for a web map item? In the API reference I can find nothing about these for the update() method [and the examples given for update() appear to be identical to what's provided for save()]. All of the examples on these forums utilize both of these keys:values such as this thread here and here. Is there a section of the API reference I've missed?
... View more
11-07-2019
12:18 PM
|
0
|
0
|
738
|
|
POST
|
There are several threads on here that have gotten me this far, but I've still not found any solid documentation about what needs to be supplied to the JSON dictionary in order to properly update it. Note: I can get this to work when there is only one layer in the feature layer/feature collection. I'm just stuck. Here is my code so far. """
#Import Modules
import copy,json
from arcgis.gis import GIS
from arcgis.mapping import WebMap
#Log into ArcGIS Enterprise
gis = GIS("https://awesomeportalname.com/portal", "DougMcGrave", "a1ntL!FeGr@nd!")
print("Logged in as: " + gis.properties.user.username)
#Retrieve NortheastFieldData web map
webMapSearch = gis.content.search("title: NortheastFieldData2",item_type = "Web Map")
sourceWebMap= webMapSearch[0]
#itemID = webMapTest.id
#print(itemID)
#Read the web map as a WebMap object
webMapObject = WebMap(sourceWebMap)
#Create a copy of the web map with a new title
webmap_item_properties = {'title': 'TestCopyThis', 'snippet':'testcopydis', 'tags':'Test'}
webMapObject.save(webmap_item_properties)
#Retrieve new web map
newWebMapSearch = gis.content.search("title: TestCopyThis",item_type = "Web Map")
newWebMap = newWebMapSearch[0]
for layer in newWebMap.layers:
print(layer.title)
#Extract JSON from webmap
pubMapJson = newWebMap.get_data(try_json=True)
jsonCopy = copy.deepcopy(pubMapJson)
#Layers in web map which need filter applied
layersList = ['NortheastCruisePoints','NortheastClientsCollector - NortheastPoints','NortheastClientsCollector - NortheastPoints','NortheastClientsCollector - NortheastLines','NortheastClientsCollector - NortheastStands','NortheastClientsCollector - Harvest Operations Status']
#Filter to be applied
lyrFilter = "LVI_CODE = '{0}'".format("7532")
#Extract JSON from webmap and create a copy
pubMapJson = newWebMap.get_data(try_json=True)
jsonCopy = copy.deepcopy(pubMapJson)
#Loop through each layer
for lyr in layersList:
if 'layerDefinition' in lyr:
print(lyr)
jsonCopy['operationalLayers'][0]['layerDefinition']['definitionExpression']=lyrFilter
#Update JSON
newWebMap.update(item_properties={'text':json.dumps(jsonCopy)}) No errors are given and the JSON update returns 'True'
... View more
11-04-2019
12:18 PM
|
0
|
7
|
2787
|
|
POST
|
Thanks for the insight. We have reproduced this with multiple users, both are level 2 users: one admin, one data editor. We've also tried this on devices what only have Beta installed and devices with both apps installed so it doesn't seem to be any app conflict. Tomorrow we're going to see if we can actually collect in Beta while connected. We've only tested Beta offline because that is our #1 business use case. Does the app have any internal logging we can check? I'd be posting this on the beta forums but that place is like tumbleweeds blowing by. Thanks for your help!!
... View more
10-31-2019
03:57 PM
|
1
|
2
|
3205
|
|
POST
|
Not to hijack the thread but having a very similar issue here across multiple android devices. latest version of Collector Beta fails to sync with the error being 'Check getCause() for further error information'. Not very helpful. Nothing in Portal or Server logs. Here's some background: ArcGIS Enterprise 10.7 MSSQL 2017 Standard Same device collects and syncs for Collector Classic just fine Collector Beta fails with the error: 'Check getCause() for further error information' Nothing in Portal or Server logs Some feature classes have attachments enabled
... View more
10-31-2019
12:59 PM
|
0
|
4
|
3205
|
|
POST
|
Jeff Bigos I'm looking to implement something nearly identical to this: modifying a filter to a feature layer within a web map and saving a new copy. I'm struggling to find what arguments (proper documentation) are expected for fldMapJsonCopy['operationalLayers'][z[0]]['layerDefinition']['definitionExpression'] = lyrFilter I've looked at your other example here and have tried to piece things together but I'm not having any luck. I don't fully understand what the enumeration process here is and don't think i need it. from arcgis.gis import GIS
from arcgis.mapping import WebMap
import json, copy
gis = GIS("https://my/portal", "UseMe", "L1f3izGr@nd!")
webMapSearch = gis.content.search("title: NortheastFieldData2",item_type = "Web Map")
pubMapJson = webMapTest.get_data(try_json=True)
layerMod = [l for l in pubMapJson['operationalLayers'] if l ['title']=='NortheastCruisePoints']
lyrFilter = "LVI_CODE = '{0}'".format("7532")
fieldMapCopy = copy.deepcopy(pubMapJson)
fieldMapCopy['operationalLayers'][layerMod]['layerDefinition']['definitionExpression']=lyrFilter Error: ---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-37-aec78b329a7c> in <module>
----> 1 fieldMapCopy['operationalLayers'][layerMod]['layerDefinition']['definitionExpression'] = lyrFilter
TypeError: list indices must be integers or slices, not list
... View more
10-31-2019
10:55 AM
|
0
|
2
|
6604
|
| Title | Kudos | Posted |
|---|---|---|
| 9 | 03-24-2026 11:41 AM | |
| 1 | 11-06-2024 06:58 AM | |
| 1 | 12-16-2022 07:01 AM | |
| 1 | 08-09-2024 06:55 AM | |
| 1 | 08-13-2024 05:58 PM |
| Online Status |
Offline
|
| Date Last Visited |
03-24-2026
12:51 PM
|