Select to view content in your preferred language

Caluculate Centroid in WGS (DD) from Polygon Feature ((NAD_1983_UTM_Zone_15N)

1114
10
10-16-2023 06:23 AM
vijaybadugu
Frequent Contributor

I was wondering, Is there any tool/ script to calculate the centroid point in  WGS (Latitude and Longitude) of the each polygon which are in  NAD_1983_UTM_Zone_15N projection system ?

 

Suppose the point has below x,y and needs to convert in to Decimal degrees. 

X =1057502.154938

Y =11252250.240797

0 Kudos
10 Replies
BobBooth1
Esri Contributor

I would try Calculate Geometry Attributes, setting a coordinate system to DD.

https://pro.arcgis.com/en/pro-app/3.0/tool-reference/data-management/calculate-geometry-attributes.h...

You can specify two new fields, specify the coordinate system, and the DD coordinate output format.

You will get your polygon feature class with the centroid fields added with the DD values.

Calc_geometry_attributes.png

Calc_geometry_attributes_new_fields.png

 In Python:

arcpy.management.CalculateGeometryAttributes(
in_features="Test",
geometry_property="X_coord CENTROID_X;Y_Coord CENTROID_Y",
length_unit="",
area_unit="",
coordinate_system='GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]',
coordinate_format="DD"
)

0 Kudos
vijaybadugu
Frequent Contributor

I have tried this tool and working as expected. I need to update centroids of a polygon in  latitude and longitude automatically whenever we create a new feature/ split/ merge features. it should behave like a trigger in SQL.

0 Kudos
clt_cabq
Frequent Contributor

You could do this as an attribute rule I suspect - I've done that to calculate automatically calculate coordinate data when adding or updating records before. Another approach I use currently is the pyproj module in a script I run every month to convert lat/lon values to state plane coordinates but you can go the other way as well - this works for me since I am starting with non-spatial data at the outset and this saves me from having to create an intermediate spatial dataset.

0 Kudos
BobBooth1
Esri Contributor
0 Kudos
vijaybadugu
Frequent Contributor

I tried that too and didn't find any arcade expression to do the same functionality and need a formulae to convert. 

0 Kudos
vijaybadugu
Frequent Contributor

Can I run python script in SQL Server Trigger ? If yes , what is syntax of it 

I want to use the below tool get the Lat and Long and I don't have clue, how to run this in SQl Trigger 

arcpy.PointGeometry()

0 Kudos
JuanManuelCruzHerrera
Occasional Contributor

y por que no haces una regla de atributo que te devuelva el centroide con Centroid($feature) en arcade? https://developers.arcgis.com/arcade/function-reference/geometry_functions/

entiendo que si deseas que cada polígono te cada vez que se cree o divida con una regla de atributo no se diferencia mucho de un Trigger porque hace lo mismo y la puedes dejar en el campo o campos para crearla y luego si quieres cambiar de Calcular el centroide en WGS (DD) a partir de la característica poligonal ((NAD_1983_UTM_Zone_15N) para esto hay varios e incluso lo último de arcade ya tenía una creada para ese cambio.

este lo creamos para meterlo como texto pero el tuyo debe ser mucho más sencillo espero que te sirva de ayuda

Latitud:

var originShift = 2.0 * PI * 6378137.0 / 2.0;

var lat = (Floor(Geometry($feature).Y,7) / originShift) * 180.0;

lat = 180.0 / PI * (2.0 * Atan( Exp( lat * PI / 180.0)) - PI / 2.0);
var latitud = Floor(lat, 7)
if(latitud > 0){
return latitud + " N"
}else{
return latitud + " S"
}

 

Longitud:

 

var originShift = 2.0 * PI * 6378137.0 / 2.0;

var lon = (Floor(Geometry($feature).X,7) / originShift) * 180.0;

var longitud = Floor(lon, 7)
if(longitud > 0){
return longitud + " E"
}else{
return longitud + " O"
}

solo debería añadirle además lo del centroide y tendría que  salir mediante reglas de atributos

 

0 Kudos
vijaybadugu
Frequent Contributor

I tried, it returns always 0. 

0 Kudos
vijaybadugu
Frequent Contributor

I tried same in Arcade playground,it was giving wrong results 

var originShift = 2.0 * PI * 6378137.0 / 2.0;

var lon = (Floor(2050970.227158,7) / originShift) * 180.0;

var longitud = Floor(lon, 7)
if(longitud > 0){
return longitud + " E"
}else{
return longitud + " O"
}
it should be -91.695526 but the result is  "18.424179 E"
 
0 Kudos