Skip to content

Commit

Permalink
minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
doug-m committed Dec 15, 2022
1 parent 1b08cfa commit 7345c9c
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 47 deletions.
4 changes: 2 additions & 2 deletions form_calculation/CalculateValueUsingOtherFields.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
```
$feature["foundation_condition"] + $feature["roof_condition"] + $feature["habitability"];
```
24 changes: 21 additions & 3 deletions form_calculation/CurrentTime.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
```
// 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;
```
22 changes: 11 additions & 11 deletions form_calculation/FetchAttributeFromNearbyFeature.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
{
Expand All @@ -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']}`
```
return `${closestFeatureWithDistance['feature']['ADDNUM']} ${closestFeatureWithDistance['feature']['ADDRESSNAM']}`;
```
13 changes: 5 additions & 8 deletions form_calculation/FetchAttributeFromRelatedRecord.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
```
```
6 changes: 3 additions & 3 deletions form_calculation/FetchUserInfo.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
GetUser($layer).email;
```
18 changes: 9 additions & 9 deletions form_calculation/GeometryAsAttribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
```

Expand All @@ -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];
```
6 changes: 3 additions & 3 deletions form_calculation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ 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

Esri welcomes [contributions](CONTRIBUTING.md) from anyone and everyone. Please see our [guidelines for contributing](https://github.com/esri/contributing).

## 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.
Expand Down
21 changes: 13 additions & 8 deletions form_calculation/SpatialInheritance.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
```
```

0 comments on commit 7345c9c

Please sign in to comment.