HOW TO
In ArcGIS Pro ist das Platzieren von Punkten in Polygonen mit ähnlichen Attributen für eine Vielzahl von räumlichen Analysen wichtig, z. B. für die räumliche Aggregation und die Datenintegration. Ein allgemeines Attribut bezieht sich in der Regel auf ein Feld oder eine Eigenschaft, die von Features in einem Dataset gemeinsam genutzt wird.

In diesem Artikel wird der Workflow zum Platzieren eines Punktes in einem Polygon mit einem gemeinsamen Attribut mithilfe von ArcPy in ArcGIS Pro beschrieben.
Note: This workflow requires a full script to run in the ArcGIS Pro Python window. All the indents are to be kept as portrayed in the code block.
Note: This workflow creates a new point feature in the geodatabase that is not added into the map.
import arcpy import os def place_points_inside_polygons(input_polygon_fc, output_point_fc, common_attribute_field): arcpy.management.CreateFeatureclass( out_path=os.path.dirname(output_point_fc), out_name=os.path.basename(output_point_fc), geometry_type="POINT", spatial_reference=input_polygon_fc )
arcpy.management.AddField(output_point_fc, common_attribute_field, "TEXT")
with arcpy.da.InsertCursor(output_point_fc, ["SHAPE@", common_attribute_field]) as cursor: with arcpy.da.SearchCursor(input_polygon_fc, ["SHAPE@", common_attribute_field]) as search_cursor: for row in search_cursor: polygon_geom = row[0] common_attribute_value = row[1] point_inside_polygon = polygon_geom.centroid cursor.insertRow([point_inside_polygon, common_attribute_value])
input_polygon_fc = r"<pathToPolygonFc>" output_point_fc = r"<pathToOriginalPointFc>" common_attribute_field = "<fieldName>"
place_points_inside_polygons(input_polygon_fc, output_point_fc, common_attribute_field)
Im folgenden Code-Block finden Sie das vollständige Skript.
import arcpy import os def place_points_inside_polygons(input_polygon_fc, output_point_fc, common_attribute_field): arcpy.management.CreateFeatureclass( out_path=os.path.dirname(output_point_fc), out_name=os.path.basename(output_point_fc), geometry_type="POINT", spatial_reference=input_polygon_fc ) arcpy.management.AddField(output_point_fc, common_attribute_field, "TEXT") with arcpy.da.InsertCursor(output_point_fc, ["SHAPE@", common_attribute_field]) as cursor: with arcpy.da.SearchCursor(input_polygon_fc, ["SHAPE@", common_attribute_field]) as search_cursor: for row in search_cursor: polygon_geom = row[0] common_attribute_value = row[1] point_inside_polygon = polygon_geom.centroid cursor.insertRow([point_inside_polygon, common_attribute_value]) input_polygon_fc = r"C:\Users\Documents\ArcGIS\Projects\MyProject40\MyProject40.gdb\Polygon" output_point_fc = r"C:\Users\Documents\ArcGIS\Projects\MyProject40\MyProject40.gdb\Pointsss" common_attribute_field = "Distance" place_points_inside_polygons(input_polygon_fc, output_point_fc, common_attribute_field)
Die folgende Abbildung zeigt den Punkt, der mit ArcPy im Polygon mit einem gemeinsamen Attribut platziert wurde.

Artikel-ID: 000032318
Unterstützung durch ArcGIS-Experten anfordern
Beginnen Sie jetzt mit dem Chatten