|
POST
|
This seems misleading... If you have a joined table, you have to reference the fields with "TableName.FieldName". This applies to Arcade and to Python (field calculation and labeling). The join field shouldn't play a role in this. In the documentation's example, they probably have a feature class "Counties" with the primary key "CountyID" and a table "ElectionResults" with the fields "CountyID" (linking the table to the feature class), "VotedDem2012" and "VotedDem2016". They then joined the table to the feature class using "CountyID" as join field. To display the vote change in the layer's popup, you would then use this expression: var demVotes2016 = $feature["ElectionResults.VotedDem2016"]; // table name, not key
var demVotes2012 = $feature["ElectionResults.VotedDem2012"];
// returns % change in votes from 2012 to 2016
Round( ( ( demVotes2016 - demVotes2012 ) / demVotes2012 ) * 100, 2); The join key shouldn't have anything to do with this. It is used to link two tables to each other and is chosen by the data owner when designing the tables / database. In database lingo they're called primary key and foreign key. In the ArcGIS environments, it can be used for joins, relates, and relationship classes. see above This has some impact on feature sets: //If you have a relationship class between two tables, you can get the related records of a feature using the FeatureSetByRelationshipName() function.
var related_features = FeatureSetByRelationshipName($feature, "RelationshipName")
//If you don't have a relationship class, but still have the key fields, you can Filter() a feature set for the related records.
var related_fs = FeatureSetByName(...)
var primary_key = $feature.PrimaryKey
var related_features = Filter(related_fs, "ForeignKey = @primary_key")
//If you load a joined feature set (e.g. using the $map global or from a feature service), you have to use the bracket notation and you have to fully qualify the field names.
var joined_table = FeatureSetByName(...)
var f = First(joined_table)
// these won't work
// f.Field
// f["Field"]
// This could work
f["TableName.Field"]
// It could be that you have to _fully_ qualify the field name by using the names of the database and the dataowner:
f["DatabaseName.DataOwnerName.TableName.Field"]
... View more
03-07-2022
07:12 AM
|
1
|
1
|
1705
|
|
POST
|
import random
capitals = {
"Austria": "Vienna",
"Belgium": "Brussels",
"Bulgaria": "Sofia",
"Croatia": "Zagreb",
"Cyprus": "Nicosia",
"Czech Republic": "Prague",
"Denmark": "Copenhagen",
"Estonia": "Tallin",
"Finland": "Helsinki",
"France": "Paris",
"Germany": "Berlin",
"Greece": "Athens",
"Hungary": "Budapest",
"Ireland": "Dublin",
"Italy": "Rome",
"Latvia": "Riga",
"Lithuania": "Vilnius",
"Luxembourg": "Luxembourg City",
"Malta": "Valletta",
"Netherlands": "Amsterdam",
"Poland": "Warsaw",
"Portugal": "Lisbon",
"Romania": "Bucharest",
"Slovakia": "Bratislava",
"Slovenia": "Ljubljana",
"Spain": "Madrid",
"Sweden": "Stockholm",
}
exit_keywords = ["exit", "quit", "q"]
def quiz(state=None, continue_until_exit=False):
if not state:
state = random.sample(capitals.keys(), 1)[0]
capital = capitals[state]
answer = input("Input the capital of {} or type 'exit': ".format(state)).lower()
if answer in exit_keywords:
print("The right answer was {}. Thanks for playing!".format(capital))
return
answer_is_correct = answer == capital.lower()
print("That's correct!" if answer_is_correct else "Wrong, try again!")
if continue_until_exit or not answer_is_correct:
state = None if answer_is_correct else state
quiz(state, continue_until_exit)
print("Play until you get the correct answer\n")
quiz()
print("\n\nPlay until you quit manually\n")
quiz(continue_until_exit=True) Play until you get the correct answer
Input the capital of Sweden or type 'exit': Oslo
Wrong, try again!
Input the capital of Sweden or type 'exit': Stockholm
That's correct!
Play until you quit manually
Input the capital of Hungary or type 'exit': budapest
That's correct!
Input the capital of Slovenia or type 'exit': bratislava
Wrong, try again!
Input the capital of Slovenia or type 'exit': Ljubljana
That's correct!
Input the capital of Malta or type 'exit': VALLETTA
That's correct!
Input the capital of Czech Republic or type 'exit': prague
That's correct!
Input the capital of France or type 'exit': PaRiS
That's correct!
Input the capital of Latvia or type 'exit': q
The right answer was Riga. Thanks for playing!
>>>
... View more
03-07-2022
01:52 AM
|
0
|
0
|
2363
|
|
POST
|
You can use the GroupBy function. // load your feature set (lines 1-8 in your code)
var dict = {
fields: [
{ name: "wholename", type: "esriFieldTypeString" }
],
geometryType: "",
features: [
{"attributes": {"wholename": "John Doe"}},
{"attributes": {"wholename": "John Doe"}},
{"attributes": {"wholename": "John Doe"}},
{"attributes": {"wholename": "Jane Doe"}},
{"attributes": {"wholename": "Jane Doe"}},
{"attributes": {"wholename": "Jane Doe"}},
{"attributes": {"wholename": "Jane Doe"}},
],
};
var fs = FeatureSet(Text(dict))
// Aggregate by wholename, use count as statistic
var aggregated_fs = GroupBy(fs, ["wholename"], {"name": "NameCount", "expression": "wholename", "statistic": "Count"})
return aggregated_fs
... View more
03-07-2022
01:03 AM
|
0
|
0
|
5259
|
|
POST
|
Two basic examples: Counting var interesting_features = 0
for(var f in feature_set) {
// do something with every feature
// ...
// only count interesting features
if(f.IsInteresting == 1) {
interesting_features++ // the same as interesting_features += 1
}
} Legacy Appending var arr = []
// Previously, you had to append elements like this
var i = 0
arr[i++] = "a"
arr[i++] = "b"
// Now, you can also do it like this:
Push(arr, "a")
Push(arr, "b") Why would we want to return the "initial value of the variable" For example, to implement a stack: var i = 0
var stack = []
function stack_push(val) {stack[i++] = val}
function stack_pop() {return stack[--i]}
stack_push(1)
stack_push(2)
stack_push(3)
Console("stack: " + stack)
Console(stack_pop())
Console(stack_pop())
stack_push("a")
Console("stack: " + stack) stack: [1,2,3]
3
2
stack: [1,"a",3]
... View more
03-07-2022
12:37 AM
|
0
|
0
|
5227
|
|
POST
|
Null values are basically handled like zero (or "" for strings), though I'm trying to get that changed. Console("1 + null = " + (1 + null))
Console("'foo' + null = " + ('foo' + null))
Console("null == null = " + (null == null))
Console("null != null = " + (null != null))
Console("\nOther stuff:")
Console("Abs(null) = " + Abs(null))
Console("Min([null, 1, 2]) = " + Min([null, 1, 2])) 1 + null = 1
'foo' + null = foo
null == null = true
null != null = false
Other stuff:
Abs(null) = 0
Min([null, 1, 2]) = 0 How does aggregating on nulls work? If there are nulls in the "flag_1" field, will they be included in the average's count? If you aggregate on a feature set, nulls will be filtered out (at least for Min). For arrays, You have to do it yourself.
... View more
03-07-2022
12:17 AM
|
0
|
0
|
1061
|
|
POST
|
So, are you challenging us or do you want help? If you want help, what do you already have?
... View more
03-06-2022
11:35 PM
|
0
|
1
|
2396
|
|
POST
|
I haven't worked with the new MapViewer, yet. When I tested right now, it did seem to delete unwanted components in the style attributes of HTML tags, and I couldn't get a plain "display: none;" to work. I got it to work with "display: {expression/expr1};", though. I'd have to test more to get an idea of what is and isn't allowed. In the meantime, something like this works (switches between showing a google search link or plain text depending on whether the discharge is maintained by a public authority/company or a private citizen): // show_maintainer
// returns "none" if the maintainer field is empty or set to "privat", else "inline"
if(Includes([null, "privat"], $feature.Unterhaltungsträger)) {
return "none"
}
return "inline" // show_private
// same as show_maintainer, only the other way around
if(Includes([null, "privat"], $feature.Unterhaltungsträger)) {
return "inline"
}
return "none" HTML source of the popup's text element: <figure class="table">
<table>
<tbody>
<tr>
<td style="width:50%;">
Maintained by
</td>
<td>
<div style="display:{expression/show_maintainer};">
<a href="www.google.de/search?q={Unterhaltungsträger}" target="_blank">{Unterhaltungsträger}</a>
</div>
<div style="display:{expression/show_private};">
private or unknown
</div>
</td>
</tr>
<tr>
<td>
Discharge Rate
</td>
<td>
{expression/expr4}
</td>
</tr>
</tbody>
</table>
</figure>
... View more
03-06-2022
11:29 PM
|
0
|
2
|
6046
|
|
POST
|
var labels_and_values = [
["Name = ", $feature.Name],
["Type = ", $feature.Type],
["River = ", $feature.River],
]
var lines = []
for(var i in labels_and_values) {
if(!IsEmpty(labels_and_values[i][1])) {
Push(lines, Concatenate(labels_and_values[i]))
}
}
return Concatenate(lines, TextFormatting.NewLine)
... View more
03-04-2022
12:40 AM
|
1
|
0
|
1504
|
|
POST
|
but you can only see those messages in the Expression Builder interface, such as in AGOL I recently learned that you can also see them in Pro: Verify the expression, then you can click on the button.
... View more
03-03-2022
06:35 AM
|
1
|
2
|
4012
|
|
POST
|
Are the types considered to be object oriented? No idea how the types are implemented behind the scene, but if you take a basic interpretation of "object oriented" as child class IS A subset of parent class parent class defines some attributes and/or methods that get inherited by child class, so sibling classes have some similarities child classes can define their own attributes and/or methods then yes. For Arcade, similar to the question about arcpy that you linked, the class hirarchy (the "IS A" relationship) would be Geometry Point Mutipoint Ployline Polygon Extent Geometry would define the common attributes (type, hasZ, hasM, spatialReference), while the types define their own special attributes. Note that you can't use a Geometry object, but only the distinct types. I wouldn't consider the rings and paths attributes to be part of the class hirarchy. They are components of their respective types, implementing a "HAS A" relationship (e.g. a Polyline has an array of arrays of points).
... View more
03-03-2022
06:26 AM
|
1
|
0
|
1217
|
|
POST
|
In my experience, yes. For example, you can't do something like this: var pt = Point({ 'x': 100, 'y': 100, 'spatialReference':{'wkid':102100} });
Console(pt)
// attempt to change x coordinate
// this will fail
pt.x += 5
Console(pt) "Immutable" just means "This object and its values can not be changed". To work around it, you have to make a copy of the geometry's values, change them and then create a new geometry with these changed values: var pt = Point({ 'x': 100, 'y': 100, 'spatialReference':{'wkid':102100} });
Console(pt)
// attempt to change x coordinate
//pt.x += 5
var new_pt = Point({'x': pt.x + 5, 'y': pt.y, 'spatialReference': pt.spatialReference})
Console(new_pt)
// you could also extract the geometry's dictionary and change the values there:
var pt_dict = Dictionary(Text(pt))
pt_dict.y += 5
var new_pt_2 = Point(pt_dict)
Console(new_pt_2) To change the geometry of polylines or polygons, you have to take it a step further: you have to recreate the paths/rings. var old_path = Geometry($feature).paths[0]
var sr = Geometry($feature).spatialReference
var new_path = []
for(var i in old_path) {
// move vertext to north east and remove digits, because why not?
var new_vert = Point({'x': Round(old_path[i].x) + 100, 'y': Round(old_path[i].y) + 100, 'spatialReference': sr})
Push(new_path, new_vert)
}
var new_geo = Polyline({'paths': [new_path], 'spatialReference': sr})
Console(Geometry($feature))
Console(new_geo)
... View more
03-03-2022
12:29 AM
|
2
|
6
|
4040
|
|
POST
|
I'm sure there are more elegant solutions... var attributes = Dictionary(Text($feature))["attributes"]
var field_names = ["ASSETTYPE", "OBJECTID"]
for(var i in field_names) {
Console(attributes[field_names[i]])
}
... View more
03-02-2022
02:33 AM
|
1
|
1
|
1233
|
|
POST
|
You can't do it with labels. You have to use symbology. You need the image as byte data in the layer. That means you have to store it in the featureclass (field type BLOB). That means it won't be dynamic. If you want to change images, you have to change them in the featureclass. I outlined the process in these threads: Labelling points with attached photos - Esri Community Solved: Re: Can you import multiple geocoded png files as ... - Esri Community
... View more
03-02-2022
12:13 AM
|
1
|
0
|
6933
|
|
POST
|
That's a very helpful video, that I missed completely, thanks!
... View more
03-01-2022
11:23 PM
|
0
|
0
|
3286
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 01-30-2023 09:57 AM | |
| 1 | 05-18-2023 12:51 AM | |
| 1 | 03-05-2023 12:46 PM | |
| 1 | 12-07-2022 07:01 AM | |
| 1 | 06-21-2022 08:27 AM |
| Online Status |
Offline
|
| Date Last Visited |
02-03-2024
06:14 PM
|