Hello
I found this code from esri blog :
https://www.esri.com/arcgis-blog/products/field-maps/field-mobility/common-calculated-expressions-for-arcgis-field-maps/
I am trying to get information of building specific BBL from MapPLUTO when they create or move point near the building
I get this code from above blog but I am getting this error
Execution Error:Cannot create Geometry in this SpatialReference. Engine is using a different spatial reference.
// If feature doesn't have geometry return null
if (IsEmpty(Geometry($feature))) { return null }
// Get the parcels layer
var parcels = FeatureSetByName($map,"MapPLUTO")
// Buffer the current location and intersect with parcels
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 = []
for (var f in candidateParcels) {
Push(featuresWithDistances,
{
'distance': Distance($feature, f, 'feet'),
'feature': f
}
)
}
// Sort the candidate parcels by distance using a custom function
function sortByDistance(a, b) {
return a['distance'] - b['distance']
}
var sorted = Sort(featuresWithDistances, sortByDistance)
// Get the closest feature
var closestFeatureWithDistance = First(sorted)
// If there was no feature, return null
if (IsEmpty(closestFeatureWithDistance)) { return null }
// Return the address
return `${closestFeatureWithDistance['feature']['ADDNUM']} ${closestFeatureWithDistance['feature']['ADDRESSNAM']}`
XanderBakker but I don't know where I need to add it and how combine them to one code
function LatLonToMeters(lat, lon) {
// convert from long/lat to google mercator (or EPSG:4326 to EPSG:900913)
// Source: https://gist.github.com/springmeyer/871897
var x = lon * 20037508.34 / 180;
var y = Log(Tan((90 + lat) * PI / 360)) / (PI / 180);
y = y * 20037508.34 / 180;
return [x, y];
}
var lon = -118.15;
var lat = 33.80;
var xy = LatLonToMeters(lat, lon);
Console(xy);
var pointJSON = {'x' : xy[0], 'y' : xy[1], 'spatialReference' : {'wkid' : 102100}};
var pnt = Point(pointJSON);
Console(pnt);
return pnt;