Randy,
Thanks for the code snippet. I’ll give it a try. If it works properly then I’ll need to incorporate into bigger script.
Regards,
Jim
Hi Melita,
I have side question. Is there a way to project a DEM raster, from geographic to UTM15N US feet, so that the grid code z-value changes from meters to feet? Do you have to go into the spatial reference properties and the "Z coordinate system" tab and pick from there (see image below)? If so, what would the best parameter to use.
It seems that without setting a z value no change conversion to feet is evident after running Project Raster.
Thank-You,
Here is the final script that seemed to do the trick:
This script will loop thru <SPAN class="operator token">and</SPAN> calculate geometry fields X_coord <SPAN class="operator token">and</SPAN> Y_coord <SPAN class="keyword token">from</SPAN> geographic to NAD_83_UTM_Zone_15N_Feet <SPAN class="keyword token">import</SPAN> arcpy arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>overwriteOutput <SPAN class="operator token">=</SPAN> <SPAN class="number token">1</SPAN> outrastertopoint <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"S:/General-Offices-GO-Trans/SLR-Mapping/GIS_Projects_2018/Smart_T_Line_Model/geodata/NSP_RASTERTOPOINT_FT.gdb/"</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> outrastertopoint fieldName1 <SPAN class="operator token">=</SPAN> <SPAN class="string token">"X_coord"</SPAN> fieldPrecision1 <SPAN class="operator token">=</SPAN> <SPAN class="number token">9</SPAN> fieldAlias1 <SPAN class="operator token">=</SPAN> <SPAN class="string token">"longitude"</SPAN> fieldName2 <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Y_coord"</SPAN> fieldPrecision2 <SPAN class="operator token">=</SPAN> <SPAN class="number token">9</SPAN> fieldAlias2 <SPAN class="operator token">=</SPAN> <SPAN class="string token">"latitude"</SPAN> <SPAN class="comment token">#Spatial reference set using .prj file. False easting field is key to get positive values in X_coord.</SPAN> sr <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>SpatialReference<SPAN class="punctuation token">(</SPAN>r<SPAN class="string token">"S:\General-Offices-GO-Trans\SLR-Mapping\GIS_Projects_2018\Smart_T_Line_Model\geodata\coord_sys_UTM15FT.prj"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token">#Loop thru list of 1,455 features</SPAN> featureClassList <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFeatureClasses<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> featureClass <SPAN class="keyword token">in</SPAN> featureClassList<SPAN class="punctuation token">:</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>management<SPAN class="punctuation token">.</SPAN>CalculateGeometryAttributes<SPAN class="punctuation token">(</SPAN>featureClass<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"X_coord POINT_X;Y_coord POINT_Y"</SPAN><SPAN class="punctuation token">,</SPAN> None<SPAN class="punctuation token">,</SPAN> None<SPAN class="punctuation token">,</SPAN> sr<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
The false easting/false northing values have to use the same linear unit as the projected coordinate system itself. The well-known text string is using international feet (1 ft = 0.3048 m) but the false easting value is defined in meters.
Yes, this works in the script running in ArcGIS Pro. Unfortunately, the x values are still coming up negative. Also, when calculating in an interactive session they come up negative as well.
When I manually calculate geometry inside of ArcMap the x values are correct (in the plus range). Go figure.
Did this work - using a projection file?
sr = arcpy.SpatialReference(r"S:\General-Offices-GO-Trans\SLR-Mapping\GIS_Projects_2018\Smart_T_Line_Model\geodata\templateUTM.prj") featureClassList = arcpy.ListFeatureClasses() for featureClass in featureClassList: arcpy.management.CalculateGeometryAttributes(featureClass, "X_coord POINT_X;Y_coord POINT_Y", None, None, sr)<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
The spatial reference code 32165 does not provide the right values so I'm hoping to use a .prj file instead for the spatial reference. In the script below is there a way to use "sr" (spatial reference) as a parameter in the arcpy.management.CalculateGeometryAttributes command line?
<SPAN class="comment token">#This script will loop thru a ist of layers</SPAN> <SPAN class="comment token">#and calculate geometry from geographic to NAD_1983_UTM_Zone15_N, Feet</SPAN> <SPAN class="keyword token">import</SPAN> arcpy arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>overwriteOutput <SPAN class="operator token">=</SPAN> <SPAN class="number token">1</SPAN> outrastertopoint <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"S:/General-Offices-GO-Trans/SLR-Mapping/GIS_Projects_2018/Smart_T_Line_Model/geodata/TEST_RASTERTOPOINT_TEST2.gdb/"</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> outrastertopoint fieldName1 <SPAN class="operator token">=</SPAN> <SPAN class="string token">"X_coord"</SPAN> fieldPrecision1 <SPAN class="operator token">=</SPAN> <SPAN class="number token">9</SPAN> fieldAlias1 <SPAN class="operator token">=</SPAN> <SPAN class="string token">"longitude"</SPAN> fieldName2 <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Y_coord"</SPAN> fieldPrecision2 <SPAN class="operator token">=</SPAN> <SPAN class="number token">9</SPAN> fieldAlias2 <SPAN class="operator token">=</SPAN> <SPAN class="string token">"latitude"</SPAN> <SPAN class="comment token">#sr = arcpy.SpatialReference(r"S:\General-Offices-GO-Trans\SLR-Mapping\GIS_Projects_2018\Smart_T_Line_Model\geodata\templateUTM.prj")</SPAN> featureClassList <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFeatureClasses<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> featureClass <SPAN class="keyword token">in</SPAN> featureClassList<SPAN class="punctuation token">:</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>management<SPAN class="punctuation token">.</SPAN>CalculateGeometryAttributes<SPAN class="punctuation token">(</SPAN>featureClass<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"X_coord POINT_X;Y_coord POINT_Y"</SPAN><SPAN class="punctuation token">,</SPAN> None<SPAN class="punctuation token">,</SPAN> None<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"PROJCS['NAD 1983 UTM Zone 15N 1_1',GEOGCS['GCS_North_American_1983',DATUM['D_North_American_1983',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-93.0],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Feet',0.3048]]"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.