|
POST
|
I've always had difficulties in working with date functions in the Filter's sql statement. The workaround I came up with (working with some of my own data) is to use the OrderBy function to sort by the FeatureSet by the state and date and use the Distinct function to get the unique states. I then loop through the distinct states to filter the sorted list and use the first entry. This also uses @jcarlson's Memorize function, since lots of Filter calls will slow down your script. function Memorize(fs) {
var temp_dict = {
fields: Schema(fs)['fields'],
geometryType: '',
features: []
}
for (var f in fs) {
var attrs = {}
for (var attr in f) {
attrs[attr] = Iif(TypeOf(f[attr]) == 'Date', Number(f[attr]), f[attr])
}
Push(
temp_dict['features'],
{attributes: attrs}
)
}
return FeatureSet(Text(temp_dict))
}
var fs = FeatureSetByPortalItem(
Portal('https://noaa.maps.arcgis.com'),
'b9c527e0cb6d4c7fac39981f966fdd65',
0,
['STATE', "BEGIN_DATE", 'Station_ID'],
false
);
//var fs_gp = GroupBy(fs, ['STATE'], [{name: 'recentDate', expression: 'BEGIN_DATE', statistic: 'MAX' }]);
var orderedFS = Memorize(OrderBy(fs, "STATE ASC, BEGIN_DATE DESC"))
var distinctStates = Distinct(fs, ["STATE"]);
var theDict = {
fields: [{name: 'Name', type: 'esriFieldTypeString'},
{name: 'Station', type: 'esriFieldTypeString'},
{name: 'BEGIN_DATE', type: 'esriFieldTypeDate'}],
geometryType: "",
features: [],
};
var i = 0;
for (var s in distinctStates) {
var state = s.STATE;
if (!IsEmpty(state)) {
var f = First(Filter(orderedFS, 'STATE = @state'))
theDict.features[i++] = {
attributes: {
Name: state,
Station: f.Station_ID,
BEGIN_DATE: f.Begin_Date
}
}
}
}
return FeatureSet(Text(theDict));
... View more
05-22-2024
09:05 AM
|
1
|
1
|
1390
|
|
POST
|
If you trying to calculate the average for all the records in the FeatureSet, you'll have to loop through the collection to get that average. var fs = FeatureSetByPortalItem(
portal,
'9437842bc29b54b07993a9b6b3d63c0d1"',
0,
[
'InitiateDate',
'DateWoClosed'
],
false
);
var sumDiff;
for (var f in fs) {
var startDate = f.InitiateDate
var endDate = f.DateWoClosed
sumDiff += DateDiff(EndDate, startDate, 'hours')
}
var DiffDate = {
'fields': [{'name':'calc_date', 'type':'esriFieldTypeDouble'}],
'geometryType': '',
'features':
[{'attributes':
{
'calc_Date': sumDiff/Count(fs)
}}]};
return FeatureSet(DiffDate);
... View more
05-21-2024
11:33 AM
|
0
|
6
|
4202
|
|
POST
|
It's difficult to to read and test your code when it's in an image. Use the code editor when posting a question about syntax. A Data Expression must return a FeatureSet, so it won't work with the simple variable you're returning
... View more
05-21-2024
06:43 AM
|
0
|
0
|
2915
|
|
POST
|
It looks like you're trying to use multiple fields from the $reference variable, but that only has the one value set up on the Data tab in the Reference section. Take a look at using Arcade to create a Data Expression that you'll use as the data source for the indicator. That will give you access to more things. There's a github page on expression examples you can look at for ideas.
... View more
05-17-2024
03:31 PM
|
0
|
1
|
2974
|
|
POST
|
I've added a video to a popup using the code below, using the Arcade element. My feature has a field that contains the name of the file (and another saying if there's a video at the site). The video has to be accessible on the internet to be able to play. var output
var url = theUrl
if ($feature.VideoExists == "Yes") {
output = `<video controls>
<source src="${url}${$feature.Video_ID}.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>`
}
return {
type : 'text',
text : output //this property supports html tags
} giving me this popup
... View more
05-17-2024
11:16 AM
|
2
|
2
|
6267
|
|
POST
|
When I add an Esri support person to a group to share data with them, I have to turn on the "Search all ArcGIS Online organization members" option and turn off the "Collaboration coordinators only" option. the other person does have to have an account somewhere on AGOL, so it's not open to all the general public.
... View more
05-16-2024
07:46 AM
|
0
|
0
|
837
|
|
POST
|
Sorry...I left out a quotation mark on line 15 'fields': [{ 'name': 'ave_flight_time', 'type': 'esriFieldTypeDouble'}],
... View more
05-13-2024
09:24 AM
|
0
|
1
|
2491
|
|
POST
|
Sure. This adds the sum to the bottom of the list var Sqft_Total = 1000;
var Price_Per_SQFT = 3.00
var Number_Of_Years = 10
var Escalator = 1.5
var total = Sqft_Total * Price_Per_SQFT
var sum = total
var output = `Year 1: ${Text(Round(total, 2),'$#,###.00')}`
for (var i = 2; i <= Number_Of_Years; i++) {
total = total * (1 + Escalator/100)
output += `${TextFormatting.NewLine}Year ${i}: ${Text(Round(total, 2),'$#,###.00')}`
sum += total;
}
return `${output} ${TextFormatting.NewLine}Sum: ${Text(Round(sum, 2),'$#,###.00')}`
... View more
05-10-2024
02:16 PM
|
0
|
0
|
2415
|
|
POST
|
This will give you the expected output (checked with a compound interest calculator) var Sqft_Total = 1000;
var Price_Per_SQFT = 3.00
var Number_Of_Years = 10
var Escalator = 1.5
var total = Sqft_Total * Price_Per_SQFT
var output = `Year 1: ${Text(Round(total, 2),'$#,###.00')}`
for (var i = 2; i <= Number_Of_Years; i++) {
total = total * (1 + Escalator/100)
output += `${TextFormatting.NewLine} Year ${i}: ${Text(Round(total, 2),'$#,###.00')}`
}
return output which returns this "Year 1: $3,000.00 Year 2: $3,045.00 Year 3: $3,090.67 Year 4: $3,137.04 Year 5: $3,184.09 Year 6: $3,231.85 Year 7: $3,280.33 Year 8: $3,329.53 Year 9: $3,379.48 Year 10: $3,430.17"
... View more
05-10-2024
01:31 PM
|
0
|
3
|
2421
|
|
POST
|
So this is a much different question than you originally asked. Are you trying to filter finalFeatures? Do the arrays 'output_yes' and 'output_undesired' refer to one of the fields in that FeatureSet?
... View more
05-10-2024
01:02 PM
|
0
|
0
|
4675
|
|
POST
|
How do you link a feature to an image? Is there a field in the country layer that contains the URL for each country?
... View more
05-10-2024
11:02 AM
|
1
|
1
|
4979
|
|
POST
|
That's the field, which contains a value like "AA2017_258", which is part of the url of the photo. I made a fake one in the image I sent, but the working version of the string in the hyperlink field looks like this: "https://www.nodc.noaa.gov/archive/arc0166/0222391/2.2/data/0-data/LakeMichigan_2017_2018_Videos_Photos/Photos/{Site_ID}_1.png" while the URL uses this for the thumbnail: "https://www.nodc.noaa.gov/archive/arc0166/0222391/2.2/data/0-data/LakeMichigan_2017_2018_Videos_Photos/Photos/thumbnails/{Site_ID}_1.png" What would be an example of a URL for you and what field would hold the unique part of it?
... View more
05-10-2024
09:59 AM
|
0
|
3
|
4986
|
|
POST
|
Glad to help you find the solution. Don't forget to click the "Accept as Solution" button. As for your followup question, the script ends after the return on line 6, so anything you add after that won't be run. If you want to add a console statement after running the filter, you can do something like this var array1 = [1,3,5,6]
var array2 = [3,6]
function exists(i){
return !Includes(array2, i)
}
var newArray = Filter(array1, exists)
console(array1)
return newArray To convert the array into a dictionary that can be used in a table, you have to use code like this: var array1 = [1,3,5,6]
var array2 = [3,6]
function exists(i){
return !Includes(array2, i)
}
var newArray = Filter(array1, exists)
var features = [];
for (var i in newArray) {
console(newArray[i])
Push(features, {
attributes: {
value: newArray[i]
}
});
}
var theDict = {
fields: [{name: 'value', type: 'esriFieldTypeInteger'}],
geometryType: '',
features: features
}
return FeatureSet(theDict);
... View more
05-10-2024
09:48 AM
|
0
|
0
|
4716
|
|
POST
|
You can use the Filter function var array1 = [1,3,5,6]
var array2 = [3,6]
function exists(i){
return !Includes(array2, i)
}
return Filter(array1, exists)
... View more
05-10-2024
08:29 AM
|
1
|
2
|
4775
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 02-04-2025 06:39 AM | |
| 1 | 05-01-2026 08:26 AM | |
| 1 | 04-10-2026 12:01 PM | |
| 1 | 04-13-2026 09:11 AM | |
| 1 | 10-11-2023 06:18 AM |
| Online Status |
Offline
|
| Date Last Visited |
yesterday
|