From 7345c9c78f6b6b1b1e81d4c26c322d1fc23a0f1b Mon Sep 17 00:00:00 2001 From: Doug Morgenthaler Date: Thu, 15 Dec 2022 09:01:27 -0800 Subject: [PATCH] minor updates --- .../CalculateValueUsingOtherFields.md | 4 ++-- form_calculation/CurrentTime.md | 24 ++++++++++++++++--- .../FetchAttributeFromNearbyFeature.md | 22 ++++++++--------- .../FetchAttributeFromRelatedRecord.md | 13 ++++------ form_calculation/FetchUserInfo.md | 6 ++--- form_calculation/GeometryAsAttribute.md | 18 +++++++------- form_calculation/README.md | 6 ++--- form_calculation/SpatialInheritance.md | 21 +++++++++------- 8 files changed, 67 insertions(+), 47 deletions(-) diff --git a/form_calculation/CalculateValueUsingOtherFields.md b/form_calculation/CalculateValueUsingOtherFields.md index 29e0b0e..912c225 100644 --- a/form_calculation/CalculateValueUsingOtherFields.md +++ b/form_calculation/CalculateValueUsingOtherFields.md @@ -7,5 +7,5 @@ Often, it can be useful to calculate a value based on one or more fields that th I need to calculate the score when doing a damage assessment report. Certain things (e.g., the roof, foundation, habitability.) are scored based on their damage level. I need to sum all these independent scores into a single value to use for filtering and visualization. ```js - $feature["foundation_condition"] + $feature["roof_condition"] + $feature["habitability"] - ``` \ No newline at end of file + $feature["foundation_condition"] + $feature["roof_condition"] + $feature["habitability"]; + ``` diff --git a/form_calculation/CurrentTime.md b/form_calculation/CurrentTime.md index 66304fb..4cfb53b 100644 --- a/form_calculation/CurrentTime.md +++ b/form_calculation/CurrentTime.md @@ -4,8 +4,26 @@ When performing inspections, it’s often useful to set the inspection date to t ## Examples -I’m filling out a damage inspection report and need to set the inspection date. +I’m filling out a damage inspection report and need to set the inspection date and time. I only want to return the current date and time when creating a new inspection. ```js -Now() -``` \ No newline at end of file +// if updating an existing inspection, return current date/time +if ($editcontext.editType == 'INSERT'){ + return Now(); +} + +// otherwise return the original date +return $originalFeature.inspectionDate; +``` + +I’m filling out a damage inspection report and need to set the inspection date. I only want to return the current date when creating a new inspection. + +```js +// if updating an existing inspection, return current date +if ($editcontext.editType == 'INSERT'){ + return Today(); +} + +// otherwise return the original date +return $originalFeature.inspectionDate; +``` diff --git a/form_calculation/FetchAttributeFromNearbyFeature.md b/form_calculation/FetchAttributeFromNearbyFeature.md index 4be2005..64f5fc4 100644 --- a/form_calculation/FetchAttributeFromNearbyFeature.md +++ b/form_calculation/FetchAttributeFromNearbyFeature.md @@ -8,18 +8,18 @@ I’m planting new trees in a neighborhood and want to store the nearest address ```js // If feature doesn't have geometry return null -if (IsEmpty(Geometry($feature))) { return null } +if (IsEmpty(Geometry($feature))) { return null; } // Get the parcels layer -var parcels = FeatureSetByName($map, 'Parcels') +var parcels = FeatureSetByName($map, 'Parcels'); // Buffer the current location and intersect with parcels -var bufferedLocation = Buffer($feature, 100, 'feet') -var candidateParcels = Intersects(parcels, bufferedLocation) +var bufferedLocation = Buffer($feature, 100, 'feet'); +var candidateParcels = Intersects(parcels, bufferedLocation); // Calculate the distance between the parcel and the current location // Store the feature and distance as a dictionary and push it into an array -var featuresWithDistances = [] +var featuresWithDistances = []; for (var f in candidateParcels) { Push(featuresWithDistances, { @@ -31,16 +31,16 @@ for (var f in candidateParcels) { // Sort the candidate parcels by distance using a custom function function sortByDistance(a, b) { - return a['distance'] - b['distance'] + return a['distance'] - b['distance']; } -var sorted = Sort(featuresWithDistances, sortByDistance) +var sorted = Sort(featuresWithDistances, sortByDistance); // Get the closest feature -var closestFeatureWithDistance = First(sorted) +var closestFeatureWithDistance = First(sorted); // If there was no feature, return null -if (IsEmpty(closestFeatureWithDistance)) { return null } +if (IsEmpty(closestFeatureWithDistance)) { return null; } // Return the address -return `${closestFeatureWithDistance['feature']['ADDNUM']} ${closestFeatureWithDistance['feature']['ADDRESSNAM']}` -``` \ No newline at end of file +return `${closestFeatureWithDistance['feature']['ADDNUM']} ${closestFeatureWithDistance['feature']['ADDRESSNAM']}`; +``` diff --git a/form_calculation/FetchAttributeFromRelatedRecord.md b/form_calculation/FetchAttributeFromRelatedRecord.md index 425aead..0f9ff46 100644 --- a/form_calculation/FetchAttributeFromRelatedRecord.md +++ b/form_calculation/FetchAttributeFromRelatedRecord.md @@ -9,17 +9,14 @@ I’m inspecting hydrants and need to record the Facility ID with each inspectio ## Example Code ```js -// Get the feature set for the hydrants -var hydrants = FeatureSetByRelationshipName($feature, 'wHydrant', ['facilityid'], true) - -// Get the first hydrant (should only be one) -var hydrant = First(hydrants) +// Get the feature set for the hydrants and return the first; +var hydrants = First(FeatureSetByRelationshipName($feature, 'wHydrant', ['facilityid'], false)); // If there was a hydrant, return the facilityid of it, // Otherwise, return null if (!IsEmpty(hydrant)) { - return hydrant['facilityid'] + return hydrant['facilityid']; } else { - return null + return null; } -``` \ No newline at end of file +``` diff --git a/form_calculation/FetchUserInfo.md b/form_calculation/FetchUserInfo.md index 241e924..0d93bab 100644 --- a/form_calculation/FetchUserInfo.md +++ b/form_calculation/FetchUserInfo.md @@ -7,11 +7,11 @@ When performing inspections or collecting new data, editor tracking works great I’m filling out a damage inspection report and need to provide my name. ```js -GetUser($layer).fullName +GetUser($layer).fullName; ``` I’m filling out a damage inspection report and need to provide my email address. ```js -GetUser($layer).email -``` \ No newline at end of file +GetUser($layer).email; +``` diff --git a/form_calculation/GeometryAsAttribute.md b/form_calculation/GeometryAsAttribute.md index 4614ef9..07bd68c 100644 --- a/form_calculation/GeometryAsAttribute.md +++ b/form_calculation/GeometryAsAttribute.md @@ -10,9 +10,9 @@ I need to store the x and y locations as separate attributes so I can import it // Get the X value var geom = Geometry($feature) if (IsEmpty(geom)) { - return null + return null; } else { - return geom.X + return geom.X; } ``` @@ -23,15 +23,15 @@ I need to store the latitude and longitude values to conform to some standard da // Create a function to convert meters to lat, long function MetersToLatLon(geometry) { if (IsEmpty(geometry)) { - return [null, null] + return [null, null]; } - var originShift = 2.0 * PI * 6378137.0 / 2.0 - var lon = (geometry.x / originShift) * 180.0 - var lat = (geometry.y / originShift) * 180.0 - lat = 180.0 / PI * (2.0 * Atan( Exp( lat * PI / 180.0)) - PI / 2.0) - return [Round(lat, 6), Round(lon, 6)] + var originShift = 2.0 * PI * 6378137.0 / 2.0; + var lon = (geometry.x / originShift) * 180.0; + var lat = (geometry.y / originShift) * 180.0; + lat = 180.0 / PI * (2.0 * Atan( Exp( lat * PI / 180.0)) - PI / 2.0); + return [Round(lat, 6), Round(lon, 6)]; } // Call the function and return the latitude or longitude value -MetersToLatLon(Geometry($feature))[0] +MetersToLatLon(Geometry($feature))[0]; ``` diff --git a/form_calculation/README.md b/form_calculation/README.md index c57e631..310696d 100644 --- a/form_calculation/README.md +++ b/form_calculation/README.md @@ -20,8 +20,8 @@ See the list below for sample expressions: ## Resources -* [ArcGIS Arcade Documentation](https://developers.arcgis.com/arcade/) -* [ArcGIS Arcade Playground](https://developers.arcgis.com/arcade/playground/) +- [ArcGIS Arcade Documentation](https://developers.arcgis.com/arcade/) +- [ArcGIS Arcade Playground](https://developers.arcgis.com/arcade/playground/) ## Contributing @@ -29,7 +29,7 @@ Esri welcomes [contributions](CONTRIBUTING.md) from anyone and everyone. Please ## License -Copyright 2018 Esri +Copyright 2022 Esri Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/form_calculation/SpatialInheritance.md b/form_calculation/SpatialInheritance.md index 9300a20..5a70ef3 100644 --- a/form_calculation/SpatialInheritance.md +++ b/form_calculation/SpatialInheritance.md @@ -7,18 +7,23 @@ Sometimes, it can be valuable to store the geographic area a feature was collect I am recording bird sightings and want to automatically store the region I’m in. ```js -// Create a feature set using the 'Regions' layer in the map -var regions = FeatureSetByName($map, 'Regions', ['name']) +// If feature doesn't have geometry return null +if (IsEmpty(Geometry($feature))) { return null; } -// Intersect the current location with the regions and +// Create a feature set using the 'Regions' layer in the map, and +// intersect the current location with the regions. +var regions = Intersects($feature,FeatureSetByName($map, 'Regions', ['name'])); + // get the first region -var region = First(Intersects($feature, regions)) +for (var r in regions){ + region = r; +} // If the current location does intersect a feature, -// return the name of the region. Otherwise, return null +// return the name of the region, otherwise return null. if (!IsEmpty(region)) { - return region['name'] + return region['name']; } else { - return null + return null; } -``` \ No newline at end of file +```