8/30/2023 0 Comments Calculate geometry x arcpy![]() ![]() ![]() PointGeometryList.append(projectedPointGeometry)Īrcpy. ProjectedPointGeometry = pointGeometry.projectAs("WGS 1984") PointGeometry = arcpy.PointGeometry(point) Output_fc = "C:\\temp\\geodatabase.gdb\\state_centroids"Ĭursor = arcpy.da.SearchCursor(input_fc, = Input_fc = "C:\\temp\\geodatabase.gdb\\states" See Reading Geometries and Writing Geometries for alternative workflows for version 10.x. ![]() The Data Access cursors are available only at ArcGIS 10.1 and higher. These coordinates are then used to build point geometry, which is then written to a new feature class. In the following sample, the Data Access Module is used to retrieve the centroid coordinates using the token. Use Python to calculate and build centroid points.Enabling this parameter forces the tool to calculate a centroid that is inside the feature boundaries, if it originally falls outside the boundaries the point will be adjusted to what is considered the center of gravity within the boundaries. I am trying something like this to no avail: arcpy.CalculateFieldmanagement(Maxtbl, 'XCoord', '', 'PYTHON9.3. I need to calculate the X-Coordinate and Y-Coordinate to the appropriate fields in my featureclass (XCoord, YCoord). Within the tool parameters there is an option to calculate the centroid that falls within the feature boundaries this option can be enabled by checking the box for 'inside'. This seems very easy, but I cannot figure it out. For multipoint, polylines, or polygons with multiple parts, it is computed using the weighted mean center of all feature parts. For lines, polygons, or three-dimensional features, it is the center of mass (center of gravity) and may fall inside or outside the feature. The center of gravity calculation uses the geometric center model to output the new point feature class. The tool calculates the centroid of multipoint, line, or polygon input using a center of gravity-based algorithm. The algorithms for the specific calculation are proprietary, but there are two basic concepts used. The Feature To Point tool is used to create a new feature class containing points generated from the representative locations of input features. The Feature To Point tool is only available at the Advanced Desktop or ArcInfo, license level. For multipoint, polyline, or polygon feature classes with multiple parts, the centroid is computed using the weighted mean center of all feature parts. For line, polygon, or three-dimensional features, it is the center of mass (or center of gravity) and may fall inside the feature or outside the feature. This method uses the center of gravity of the polygon the geometric center of a feature. Use the Feature To Point (Data Management) tool.This method uses the Calculate Geometry function to find the latitude (y-coordinate of the centroid) and longitude (x-coordinate) of the centroids and constructs an XY Event Layer to display them: How To: Find the centroid of polygons using Calculate Geometry. Calculate the x,y coordinates of the feature using Calculate Geometry.Instructions provided below describe these methods. ![]() Depending on how the centroid needs to calculated, there are several possible methods: calculate the features' central XY coordinates, use the Feature to Point tool, or use Python to retrieve centroid coordinates. The Polyline class has a new method called 'positionAlongLine' in ArcGIS 10.1. # Delete fields that were created from Coordinate NotationĪrcpy.Feature centroids can be calculated in several ways. UPDATE: Just saw that the question was changed to ask for the midpoint of a polyline, rather than a centroid.You can use Field Calculator to determine this location, as I explained in this answer. Print "Longitude Field Calculation Complete" Print "Latitude Field Calculation Complete"Īrcpy.CalculateField_management(input_FeatureClass, "Longitude", expression4, "PYTHON_9.3")Īrcpy.CalculateField_management(input_FeatureClass, "Longitude", expression5, "PYTHON_9.3") # Execute CalculateField of Lat/Long FieldsĮxpression1 = "".format("- !Longitude!")Īrcpy.CalculateField_management(input_FeatureClass, "Latitude", expression3, "PYTHON_9.3") The columns are calculated in meters rather than decimal degrees which is what is needed for the project.Īrcpy.AddField_management(inFeature, fieldName1, fieldType)Īrcpy.AddField_management(inFeature, fieldName2, fieldType) The projection is WGS 84 the script works fully from start to finish. The way that I did it with the expression3 and expression4 variables should work but doesn't. I could use the Add XY Tool which gets me to the same point. The below is a snippet of a python script that I am writing that basically adds two fields - Latitude and Longitude, then calculates them. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |