Select to view content in your preferred language

API for Python: How to query a layer, add symbology to it, then add layer to webmap/error

307
0
02-09-2024 12:12 PM
Labels (2)
Obstreperous
New Contributor

I'm trying to do something which I feel should be easy:

1. bringing in a feature layer from a service API.

2. Querying it. 

3. Adding symbology to this

4.. Then adding this to a webmap.

 I can run steps 1,2 and 4 fine. But adding the symbology (which will categorise the data) I'm finding very tricky, there seems to be no documentation at all on how to convert a featureset to a featurelayer with applied symbology. I feel I have achieved this, but now when I try and add this to the map it causes an error that says my file is too big (100mb+) to add, even though when I don't add the symbology and jsut add the featureset, it works fine.

Here is my code:

import json
from arcgis.gis import GIS
from arcgis.features import FeatureLayer, FeatureSet,FeatureCollection
from arcgis.mapping import WebMap
import arcpy

gis = GIS("pro")

#get webmap
webmap_search = gis.content.search(

query = "test_webmap",
item_type="Web Map"
)

webmap_item = WebMap(webmap_search[0])

#get service layer
azure_layer = FeatureLayer(
"https://arcgis.anon.com/server/rest/services/GeoAzure/NGE_AzureTasks/FeatureServer/0"
)

#get symbology of service layer
renderer_ = azure_layer.properties["drawingInfo"]["renderer"]

#Query this service layer
where_clause = "(Scheme = 2205505698) AND (TaskCode = 'A')"

results = azure_layer.query(
where = where_clause,
result_record_count = 10
)

#the query returns a featureset - so we convert it to a feature collection
results_publish = FeatureCollection.from_featureset(results)

#add layer with renderer to webmap
webmap_item.add_layer(results,{'renderer':renderer_} )

webmap_item.update()


At the very last line - webmap_item.update()...

I get this error:

Exception: The size of text cannot be more than 100Mb.
(Error Code: 400)

But when I run the code without all the renderer stuff, it works fine.

Plus I have queried the data layer to be 10 rows... so it should be small. I have also added it not to the map but as a standalone layer in My Content and it works fine.

0 Kudos
0 Replies