Hi
I created a script to convert UTM32N coordinates to WGS84 Coordinates and put them in a Google Street View parameter to get a dynamic link to Google Street View for every property.
The script runs just fine and even returns a nice string that seems very correct when i'm testing the script. Once I save the script and deploy to use in a popup the script doesn't return anything. Is there something I'm doing wrong?
Solved! Go to Solution.
I figured out the issue, it seems as though Arcade Script in Portal is more limited than in ArcGIS Pro, so I had to simplify the code and calculations. Here is the final result:
var PointGeometry = Centroid(Geometry($feature));
var ArcadeX = PointGeometry.x;
var ArcadeY = PointGeometry.y;
var ArcadeSr = PointGeometry.spatialReference.wkid;
var Latitude, Longitude;
function utmToLatLon(x, y, utmz) {
var a = 6378137.0;
var f = 1 / 298.2572236;
var drad = PI / 180;
var k0 = 0.9996;
var b = a*(1 - f);
var e = Sqrt(1 - (b/a)*(b/a));
var e0 = e / Sqrt(1 - e*e);
var esq = (1 - (b/a) * (b/a));
var e0sq = e*e / (1 - e*e);
// First some validation:
if (x < 160000 || x > 840000) {
// Outside permissible range of easting values.
return "";
}
if (y < 0){
// Negative values are not allowed for northing.
return "";
}
if (y > 10000000) {
// Northing may not exceed 10,000,000.
return "";
}
// Now the actual calculation:
var zcm = 3 + 6*(utmz-1) - 180;
var e1 = (1 - Sqrt(1 - e*e)) / (1 + Sqrt(1 - e*e));
var M0 = 0;
var M = M0 + y / k0;
var mu = M / (a * (1 - esq*(1/4 + esq*(3/64 + 5*esq/256))));
var phi1 = mu + e1*(3/2 - 27*e1*e1/32)*Sin(2*mu) + e1*e1*(21/16 -55*e1*e1/32)*Sin(4*mu); // footprint Latitude
phi1 = phi1 + e1*e1*e1*(Sin(6*mu)*151/96 + e1*Sin(8*mu)*1097/512);
var C1 = e0sq * Pow(Cos(phi1), 2);
var T1 = Pow(Tan(phi1), 2);
var N1 = a / Sqrt(1 - Pow(e * Sin(phi1), 2));
var R1 = N1 * (1 - e*e) / (1 - Pow(e * Sin(phi1), 2));
var D = (x - 500000) / (N1*k0);
var phi = (D*D) * (1/2 - D*D * (5 + 3*T1 + 10*C1 - 4*C1*C1 - 9*e0sq) / 24);
phi = phi + Pow(D, 6) * (61 + 90*T1 + 298*C1 + 45*T1*T1 -252*e0sq - 3*C1*C1) / 720;
phi = phi1 - (N1 * Tan(phi1) / R1) * phi;
// Output Latitude:
Latitude = Floor(1000000*phi / drad) / 1000000;
var lng = D * (1 + D*D * ((-1 -2*T1 -C1)/6 + D*D * (5 - 2*C1 + 28*T1 - 3*C1*C1 + 8*e0sq + 24*T1*T1) / 120)) / Cos(phi1);
var lngd = zcm + lng/drad;
// Output Longitude:
Longitude = Floor(1000000*lngd)/1000000;
}
if (ArcadeSr == 4326) {
Latitude = ArcadeY;
Longitude = ArcadeX;
return "https://www.google.com/maps/@?api=1&map_action=pano&viewpoint=" + text(Latitude) + "," + text(Longitude) + "&heading=-45&pitch=38&fov=80";
} else if (ArcadeSr == 25832) {
utmToLatLon(ArcadeX, ArcadeY, 32);
return "https://www.google.com/maps/@?api=1&map_action=pano&viewpoint=" + text(Latitude) + "," + text(Longitude) + "&heading=-45&pitch=38&fov=80";
} else {
return "";
}
By the way, the script works perfectly in ArcGIS Pro but not in ArcGIS Online or Portal.
I figured out the issue, it seems as though Arcade Script in Portal is more limited than in ArcGIS Pro, so I had to simplify the code and calculations. Here is the final result:
var PointGeometry = Centroid(Geometry($feature));
var ArcadeX = PointGeometry.x;
var ArcadeY = PointGeometry.y;
var ArcadeSr = PointGeometry.spatialReference.wkid;
var Latitude, Longitude;
function utmToLatLon(x, y, utmz) {
var a = 6378137.0;
var f = 1 / 298.2572236;
var drad = PI / 180;
var k0 = 0.9996;
var b = a*(1 - f);
var e = Sqrt(1 - (b/a)*(b/a));
var e0 = e / Sqrt(1 - e*e);
var esq = (1 - (b/a) * (b/a));
var e0sq = e*e / (1 - e*e);
// First some validation:
if (x < 160000 || x > 840000) {
// Outside permissible range of easting values.
return "";
}
if (y < 0){
// Negative values are not allowed for northing.
return "";
}
if (y > 10000000) {
// Northing may not exceed 10,000,000.
return "";
}
// Now the actual calculation:
var zcm = 3 + 6*(utmz-1) - 180;
var e1 = (1 - Sqrt(1 - e*e)) / (1 + Sqrt(1 - e*e));
var M0 = 0;
var M = M0 + y / k0;
var mu = M / (a * (1 - esq*(1/4 + esq*(3/64 + 5*esq/256))));
var phi1 = mu + e1*(3/2 - 27*e1*e1/32)*Sin(2*mu) + e1*e1*(21/16 -55*e1*e1/32)*Sin(4*mu); // footprint Latitude
phi1 = phi1 + e1*e1*e1*(Sin(6*mu)*151/96 + e1*Sin(8*mu)*1097/512);
var C1 = e0sq * Pow(Cos(phi1), 2);
var T1 = Pow(Tan(phi1), 2);
var N1 = a / Sqrt(1 - Pow(e * Sin(phi1), 2));
var R1 = N1 * (1 - e*e) / (1 - Pow(e * Sin(phi1), 2));
var D = (x - 500000) / (N1*k0);
var phi = (D*D) * (1/2 - D*D * (5 + 3*T1 + 10*C1 - 4*C1*C1 - 9*e0sq) / 24);
phi = phi + Pow(D, 6) * (61 + 90*T1 + 298*C1 + 45*T1*T1 -252*e0sq - 3*C1*C1) / 720;
phi = phi1 - (N1 * Tan(phi1) / R1) * phi;
// Output Latitude:
Latitude = Floor(1000000*phi / drad) / 1000000;
var lng = D * (1 + D*D * ((-1 -2*T1 -C1)/6 + D*D * (5 - 2*C1 + 28*T1 - 3*C1*C1 + 8*e0sq + 24*T1*T1) / 120)) / Cos(phi1);
var lngd = zcm + lng/drad;
// Output Longitude:
Longitude = Floor(1000000*lngd)/1000000;
}
if (ArcadeSr == 4326) {
Latitude = ArcadeY;
Longitude = ArcadeX;
return "https://www.google.com/maps/@?api=1&map_action=pano&viewpoint=" + text(Latitude) + "," + text(Longitude) + "&heading=-45&pitch=38&fov=80";
} else if (ArcadeSr == 25832) {
utmToLatLon(ArcadeX, ArcadeY, 32);
return "https://www.google.com/maps/@?api=1&map_action=pano&viewpoint=" + text(Latitude) + "," + text(Longitude) + "&heading=-45&pitch=38&fov=80";
} else {
return "";
}
That is what I need! And it works fine, also with EPSG:25833
Thanks....
Nice, you're welcome 🙂