POST
|
Thanks Glen, that works well. As a follow-on, my test data only has one layer [0]. I'll have other situations where there are multiple sublayers. I'm a bit confused how to use gis.content to return the separate layers. Any help pointing me in the right direction is appreciated. Thanks again.
... View more
03-06-2025
05:27 AM
|
0
|
1
|
443
|
POST
|
and if I use field_to_add outside of any brackets it completes without any errors but doesn't add any fields feature_layer.manager.add_to_definition({"fields":field_to_add}) with the print statements as they currently are: Field 'newfield1' will be added. Field 'newfield2' will be added. Field 'newfield3' will be added. [{'name': 'newfield1', 'alias': 'New Field 1', 'type': 'esriFieldTypeInteger'}, {'name': 'newfield2', 'alias': 'New Field 2', 'type': 'esriFieldtypeInteger'}, {'name': 'newfield3', 'alias': 'New Field 3', 'type': 'esriFieldtypeInteger'}] {'name': 'newfield1', 'alias': 'New Field 1', 'type': 'esriFieldTypeInteger'} {'name': 'newfield2', 'alias': 'New Field 2', 'type': 'esriFieldtypeInteger'} {'name': 'newfield3', 'alias': 'New Field 3', 'type': 'esriFieldtypeInteger'} Am I missing something in the field definition?
... View more
03-05-2025
07:57 PM
|
0
|
0
|
488
|
POST
|
That gives the same error, except it doesn't add the first field, when left out of brackets: feature_layer.manager.add_to_definition({"fields":fields_to_add_list}) And does not create the first field when placed in brackets: feature_layer.manager.add_to_definition({"fields":[fields_to_add_list]}) but gives a bit different error: Exception: Unable to add feature service layer definition. Invalid definition for System.Collections.Generic.List`1[ESRI.ArcGIS.SDS.FieldInfo] Unable to cast object of type 'System.Object[]' to type 'System.Collections.Generic.IDictionary`2[System.String,System.Object]'. (Error Code: 400)
... View more
03-05-2025
07:48 PM
|
0
|
1
|
488
|
POST
|
I'm attempting to add new fields to a hosted feature layer if they don't already exist. Currently my code will add the first field in the list (dictionary), but then fails with the message: Exception: Unable to add feature service layer definition. Invalid definition for System.Collections.Generic.List`1[ESRI.ArcGIS.SDS.FieldInfo] Object reference not set to an instance of an object. (Error Code: 400) If it's run a second time it does not add the second field and gives the same error. I added the sleep thinking it may help but it doesn't. Any suggestions appreciated. Thanks. from arcgis.gis import GIS
from arcgis.features import FeatureLayer
import time
username = ''
password = ''
gis = GIS("<url>", username, password, verify_cert=False)
item_id = "<item_id>"
feature_layer_item = gis.content.get(item_id)
feature_layer = FeatureLayer.fromitem(feature_layer_item)
#feature_layer = FeatureLayer.fromitem(feature_url)
fields = feature_layer.properties.fields
existing_field_names = [field.name for field in fields]
new_fields = [
{"name":"newfield1", "alias": "New Field 1","type": "esriFieldTypeInteger"},
{"name":"newfield2", "alias": "New Field 2","type":"esriFieldtypeInteger"},
{"name":"newfield3", "alias": "New Field 3","type":"esriFieldtypeInteger"}
]
fields_to_add_list = [] # this is named 'list' but is actually a dictionary
for new_field in new_fields:
if new_field["name"] not in existing_field_names:
fields_to_add_list.append(new_field)
print(f"Field '{new_field['name']}' will be added.")
else:
print(f"Field '{new_field['name']}' already exists.")
for field_to_add in fields_to_add_list:
print(field_to_add)
feature_layer.manager.add_to_definition({"fields":[field_to_add]})
time.sleep(20)
... View more
03-05-2025
04:26 PM
|
0
|
6
|
528
|
POST
|
Thanks @AndreasHall - I've have an indicator to give me total attachments (see below), but I just need a list with a count for every feature/record. I'm drawing a blank today... var portal = Portal('https://------.maps.arcgis.com');
var assets = FeatureSetByPortalItem(
portal,
'item_id',
0,
['*'],
false
)
var photo_count = 0
for(var feat in assets){
photo_count += Count(Attachments(feat))
}
return photo_count
... View more
02-04-2025
12:25 PM
|
0
|
0
|
231
|
POST
|
I've discovered the hard way that the Arcade function Count(Attachments($feature)) cannot be used in a Field Maps Calculated Expression to automatically update and return a count of the attachments, because the attachments can't be counted until the record is submitted. Fine. Is there a way to display the number of attachments per record in a Dashboard List? I cannot figure out how to make this work. I'm doing all of this in AGO using hosted data. Any chance @jcarlson has done something like this? Thanks
... View more
02-03-2025
07:55 PM
|
0
|
2
|
269
|
POST
|
Thank you erica_poisson. I am attempting to use this in a survey to collect new features for an internal 'GeoGuessr' style game for GIS Day. When I enter a duplicate value, it does not identify it as being duplicate until the very end of the survey, not at the beginning as anticipated. Everything else is working, but it doesn't provide an error message until the end of the survey. Attached is a sanitized .xlsx to remove our URLs/IDs, etc. and a screenshot of the data for reference and the messages we receive during (after!) entry. I think I'm missing something small/basic somewhere... Thanks for any help! /*
* JavaScript functions for Survey123
*/
function returnFeatures(map_user, token, debugmode) {
// Output value. Initially set to an empty string (XLSForm null)
let outValue = "";
let layerURL = "https://<our service url>";
let response ="";
// Set up query parameters
let f = "f=json";
let where = `where=map_user='${map_user}'`;
let outFields = "outFields=*";
let returnGeometry = "returnGeometry=false";
let returnCount = "returnCount=1";
let parameters = [f,where,outFields,returnGeometry,returnCount].join("&");
let url = `${layerURL}/query?${parameters}`;
if (token){
url = url + "&token=" + token;
}
// Create the request object
let xhr = new XMLHttpRequest();
// Make the request. Note the 3rd parameter, which makes this a synchronous request
xhr.open("GET", url, false);
xhr.send();
// Process the result
if (xhr.readyState === xhr.DONE) {
if (xhr.status !== 200) {
// The http request did not succeed
return "bad request: " + url
} else {
// Parse the response into an object
response = JSON.parse(xhr.responseText);
if (response.error) {
return (debugmode? JSON.stringify(response.error):"");
} else {
if (response.features[0]) {
return "That Player name is already taken, please enter a different name."
//JSON.stringify(response.features[0]);
} else {
if (map_user !== "") {
return "Player name entered."}
//(debugmode? "No Features Found":"");
}
}
}
}
}
... View more
11-12-2024
09:13 AM
|
0
|
1
|
394
|
POST
|
Is there a way to create a point symbol callout with a leader tangent to the point symbol, in my case a circle? In the attached image I'd like to display the callout leader like the markup in red. Thanks
... View more
06-12-2023
11:03 AM
|
0
|
0
|
320
|
POST
|
jschuckert - This was a while ago, and under a previous employer, but I believe I used the output .csv from the code above as input to arcpy.conversion.TableToTable, and specified a field map which contained all the necessary fields. -Justin
... View more
06-12-2023
10:46 AM
|
0
|
0
|
3455
|
POST
|
Thanks GK. I was trying this earlier, but $map isn't recognized, and I'm not sure how to define it as a variable, if it's possible. I no longer have access to ArcGIS Assistant but would be curious to look at the .json of the Dashboard List element in ArcGIS Assistant Beta. Maybe that would have a clue how a 'default' Dashboard element is referencing the $map.
... View more
05-01-2023
01:05 PM
|
0
|
0
|
2217
|
POST
|
Hello, I have an Arcade expression put together for a Dashboard List, using FeatureSetByPortalItem to reference a Portal feature service. The purpose is to create a list that sorts tracts by the latest date in any of three date type fields. Because this is directly referencing the source feature service, and not the web map in the Dashboard, several Actions are unavailable, including 'Show Popup' and 'Zoom'. Instead of using FeatureSetByPortalItem(<Portal>,<Portal Item ID>), is there a way to reference the layer from a web map, or otherwise define the popup so that can be displayed as an action? Below is the Expression referencing the Portal feature service item and layer directly. I just can't use this to zoom or display a pop-up. var portal = Portal(<portal>);
var fs = FeatureSetByPortalItem(portal,"<id>",<layer>,['*'],false);
var date_dict = {
fields: [{name: "MaxDate", type: "esriFieldTypeString"},{name: "Tract", type: "esriFieldTypeString"}],
geometryType: "esriGeometryPolygon",
features: [],
};
var acq_sql = "Appraisal IS NOT NULL and Survey IS NOT NULL and Opinion IS NOT NULL";
var acq_filter = Filter(fs, acq_sql);
for (var feature in acq_filter){
var max_appr = Number(feature['Appraisal'])
var max_surv = Number(feature['Survey'])
var max_titl = Number(feature['Opinion'])
var tract_num = (feature['tracts'])
var max_date = Text(Max(max_appr, max_surv, max_titl));
Push(date_dict.features, {"attributes": {"MaxDate": max_date,"Tract": tract_num},geometry: Geometry(feature)})
};
var newFeature = FeatureSet(Text(date_dict));
var orderFS = OrderBy(newFeature, 'MaxDate desc')
return orderFS A temporary workaround I have set is an action from this data expression list to filter another list using the same filter criteria but sorted by 'tracts'. Users have to click twice, but that's not a huge deal - would be nice to be one click though.
... View more
05-01-2023
12:21 PM
|
0
|
3
|
2232
|
POST
|
Using ArcGIS Pro 2.9.5 Advanced and file geodatabase for all data workspaces. I have a model built using an iterator to perform various geoprocessing on input polygon geometry*, where the goal is output in a table where each row contains beginning and end x/y coordinate pairs, which will be used elsewhere outside of the model to create line features. Following geoprocessing of the input shapes, I'm perform four Sort functions on a table to get the minimum or maximum value for a specific field, then a Get Field Value to capture that first record from the sort for each of the four Sorts. This is where I get stuck: I'm currently using the Get Field Value results, followed by Collect Values and exporting those results to separate tables, then merging the four tables together. The result is close to what I need, but I need to dissolve the records together but am not sure how with a standalone table. Because this is within an iterate, ideally I could just use the four Get Field Values and use those to calculate fields in another table (where each iteration calculates on the same record) - but I cannot figure out how to do that. Perhaps I'm approaching this wrong altogether, or perhaps there's a way to use Pandas to dissolve/melt the merged table output...I'm stuck. Any help would be appreciated. Thanks *I am manually merging parcel data together by PLSS section, and then using this model builder process to create PLSS quarter section lines based on the geometry of the merged parcels. The model builder iteration is to perform the various geoprocessing section-by-section. The desired result is for cleaner cartographic displays where at least the section lines and parcel boundaries are coincident. So far this model is only focused on the West-East quarter section lines. If I can get it working I'll expand it to also create South-North lines as well.
... View more
04-18-2023
06:44 AM
|
0
|
0
|
550
|
POST
|
I'm not great with Arcade and stumped. I'm trying to create a pie chart in a Dashboard based on two date fields, 'Ordered' and 'Received'. Records are either null or populated with the date ordered or received. I'd like the pie chart to show counts of Ordered and Received. I think I need to use the GroupBy function, but I'm not sure what I'm doing. Thanks. var p = <portal>;
var tracts = FeatureSetByPortalItem(Portal(p),<item>,
<id>,
[
'OBJECTID',
'Name',
‘Ordered',
'Received',
],
false
);
var count = GroupBy(tracts,
[ // fields/expressions to group statistics by
{ name: ‘Ordered', expression: 'Received IS NOT NULL'},
{ name: ‘Received', expression: 'Received IS NULL'}
],
[
{name: 'Ordered', expression: '1', statistic: 'COUNT'}
]);
return(count)
... View more
03-10-2023
12:11 PM
|
0
|
0
|
387
|
POST
|
I have a feature class with multiple overlapping polygon layers (state boundary, county boundaries, legislative boundaries and city boundaries) for use in a dashboard. It's published as a feature service, and saved in a map with the 'merged' layer visible, and a copy of the merged layer set with a filter to isolate each type (state, legislature, county and city) as separate layers - these are turned off in the map. Basically i need a pop up to return everything all the time, but not return an empty value for Municipalities when users don't click on a city. I'm attempting to use Arcade where a user click in the map (on the 'merged' layer) returns a pop up with values from all intersecting, individual type layers at that location. These are returned in a popup where users would toggle using the arrows from one layer to another. I'm stuck using the intersectLayer function within an if/then, or how to accomplish this otherwise...maybe some of this needs to be handled in the pop up HTML. Below is what little I have, and the current results (which are not accurate): Arcade expression: var buff = Buffer($feature, -50, 'feet')
var intersectLayer = Intersects(FeatureSetByName($map,"Counties"), buff)
for (var f in intersectLayer) {return '$' + Text(Round(Number(f.Total_Funds),2),'#,###,###,###.##')} Pop up configure HTML: <div style="text-align: center;"><font color="#c0c0c0" size="4"><b>{expression/expr2}</b></font></div><b><font color="#FFC843">First Tranche Allocation:</font></b> {expression/expr6}<br /> <b><font color="#FFC843">Total Fund Allocation:</font></b> {expression/expr5} We are working in Portal 10.8.1 and we won't be upgrading until 10.9.1, at which point we may utilize some extended Arcade functionality in Dashboards, but this project is moving forward now. Thanks
... View more
09-15-2021
02:03 PM
|
0
|
0
|
739
|
POST
|
I never followed-up with the solution I found using csv and pandas: with open(cama_csv_file, 'r') as f1: with open(cama_csv_file_final, 'w+') as f2: df = pd.read_csv(f1) df.replace(',',' ', regex=True, inplace=True) df.to_csv(f2, index=False, line_terminator='\r') f2.close() f1.close() Creating a new .csv is not an issue, because I delete all of them at the end of the process.
... View more
06-16-2021
01:50 PM
|
1
|
2
|
5509
|
Title | Kudos | Posted |
---|---|---|
1 | 06-16-2021 01:50 PM | |
2 | 12-09-2020 12:51 PM | |
1 | 12-04-2018 01:23 PM | |
1 | 03-16-2016 02:52 PM | |
1 | 05-10-2019 10:54 AM |
Online Status |
Offline
|
Date Last Visited |
03-19-2025
06:04 PM
|