how to create a tool in ArcMap, the input is a polyline shp and the function is create 8…
- User
how to create a tool in ArcMap, the input is a polyline shp and the function is create 8 fields in its attribute table, namely start point Longitude, start point Latitude, start point Timbalai X, start point Timbalai Y, end point Longitude, end point Latitude, end point Timbalai X, end point Timbalai Y, and fill them with the info. note that the latitude and longitude should be in decimal degree format
- Assistant
To create a tool in ArcMap that adds the required fields to the polyline shapefile and fills them with the corresponding information, you can follow these steps:
-
Open ArcMap and load the polyline shapefile by clicking
File>Add Data>Add Data..., then navigate to the location of the polyline SHP file and clickOpen. -
Open ArcToolbox by clicking the red toolbox icon in the upper left-hand corner of the application window.
-
Right-click within the ArcToolbox window, and choose
Add Toolbox. Choose an existing toolbox or create a new one. -
Right-click on your chosen toolbox, then click
New>Script. -
In the Add Script wizard, type a name and label for the script, then click
Next. -
For the script file, click the folder icon and navigate to where you want to save your Python script. Type a name for the script and click
Save. -
Click
Next, and now you can define the input parameters. Click theNewbutton and define the input parameter as follows: Display Name: "Polyline Shapefile", Data Type: "Shapefile", Type: "Required", Direction: "Input", Shape Type: "Polyline", Filter: "File", then clickFinish. -
Now you can edit the Python script to create the required fields, and populate them with the right information. Open your Python script file in any suitable text editor or Python IDE. Here is the code you need to add to the script:
import arcpy input_shp = arcpy.GetParameterAsText(0) arcpy.AddField_management(input_shp, "START_LONG", "DOUBLE") arcpy.AddField_management(input_shp, "START_LAT", "DOUBLE") arcpy.AddField_management(input_shp, "START_TIMBALAI_X", "DOUBLE") arcpy.AddField_management(input_shp, "START_TIMBALAI_Y", "DOUBLE") arcpy.AddField_management(input_shp, "END_LONG", "DOUBLE") arcpy.AddField_management(input_shp, "END_LAT", "DOUBLE") arcpy.AddField_management(input_shp, "END_TIMBALAI_X", "DOUBLE") arcpy.AddField_management(input_shp, "END_TIMBALAI_Y", "DOUBLE") # Iterate through the features of the polyline shapefile cursor = arcpy.UpdateCursor(input_shp) spatial_ref = arcpy.Describe(input_shp).spatialReference utm_sr = arcpy.SpatialReference(5345) # Timbalai 1948 / RSO Borneo for row in cursor: feat = row.Shape start_point = feat.firstPoint end_point = feat.lastPoint # Convert coordinates to decimal degrees start_point_geom = arcpy.PointGeometry(start_point, spatial_ref) end_point_geom = arcpy.PointGeometry(end_point, spatial_ref) start_point_dd = start_point_geom.projectAs(arcpy.SpatialReference(4326)) end_point_dd = end_point_geom.projectAs(arcpy.SpatialReference(4326)) # Convert coordinates to Timbalai coordinate system start_point_timbalai = start_point_geom.projectAs(utm_sr) end_point_timbalai = end_point_geom.projectAs(utm_sr) # Update the attribute table with the coordinate values row.setValue("START_LONG", start_point_dd.firstPoint.X) row.setValue("START_LAT", start_point_dd.firstPoint.Y) row.setValue("START_TIMBALAI_X", start_point_timbalai.firstPoint.X) row.setValue("START_TIMBALAI_Y", start_point_timbalai.firstPoint.Y) row.setValue("END_LONG", end_point_dd.firstPoint.X) row.setValue("END_LAT", end_point_dd.firstPoint.Y) row.setValue("END_TIMBALAI_X", end_point_timbalai.firstPoint.X) row.setValue("END_TIMBALAI_Y", end_point_timbalai.firstPoint.Y) cursor.updateRow(row) del cursor- Save and close the script file. Now, you should be able to run your custom tool in ArcMap by double-clicking the script tool within your toolbox and selecting the polyline shapefile you added earlier.
Upon running the script tool, ArcMap will create the eight fields (Start point Longitude, Latitude, Timbalai X, Y and end point Longitude, Latitude, Timbalai X, Y), and populate them in the attribute table based on the input polyline shapefile.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.