점이 있는 geopandas 데이터 프레임에서 다각형 만들기 (Creating a polygon from a geopandas dataframe with points)


문제 설명

점이 있는 geopandas 데이터 프레임에서 다각형 만들기 (Creating a polygon from a geopandas dataframe with points)

저는 X, Y 좌표, 해당 위도 및 경도 및 점으로 기하학을 저장한 geopandas 데이터 프레임을 가지고 있습니다. Data snippet:

             long     lat    X    Y      geometry
55898  ‑45.520195 ‑18.571566  151  179    POINT (‑45.52019 ‑18.57157)
55902  ‑45.520227 ‑18.582375  151  183    POINT (‑45.52023 ‑18.58238)
55910  ‑45.520293 ‑18.603994  151  191    POINT (‑45.52029 ‑18.60399)
56267  ‑45.517361 ‑18.571574  152  179    POINT (‑45.51736 ‑18.57157)

내가 하고 싶은 것은 4개의 점을 순차적으로 결합하는 것입니다. 즉, 데이터 프레임의 순서에 따라 정사각형의 좌표를 얻을 수 있습니다. 원하는 출력은 실제로 다른 열을 포함할 필요가 없으며 다각형의 기하학만 포함하면 다음과 유사합니다.

1    POLYGON ((977855.4451904297 188082.3223876953,...
2    POLYGON ((1017949.977600098 225426.8845825195,...
3    POLYGON ((988872.8212280273 146772.0317993164,...
4    POLYGON ((1000721.531799316 136681.776184082, ...
5    POLYGON ((915517.6877458114 120121.8812543372,...

참조 솔루션

방법 1:

One should provide the lat and lon coordinates as a nested list to the Shapely Polygon object. See https://stackoverflow.com/a/30461816/12987768

With gdf being the GeoDataFrame:

    from shapely.geometry import Polygon

    rows_numbers= [i for i in range(0, len(gdf), 4)]
    polygons = []

    for idx, _ in enumerate(rows_numbers):
        if idx == len(rows_numbers)‑1:
            print("end of gdf")
            break
        polygon_coords = []
        for point in gdf.geometry.values[rows_numbers[idx]: rows_numbers[idx+1]]:
            polygon_coords.append([point.x, point.y])
        polygons.append(Polygon(polygon_coords))

with the resulting polygons list containing the 4‑point Polygons

(by PCosmeTDeg)

참조 문서

  1. Creating a polygon from a geopandas dataframe with points (CC BY‑SA 2.5/3.0/4.0)

#coordinates #geopandas #Python #geometry






관련 질문

지구의 모든 좌표를 생성하시겠습니까? (Generate all coordinates of earth?)

Spritekit이 부모를 변경하면 노드가 사라집니다. (Spritekit changing parent makes the node disappear)

C++의 파일에서 읽은 값을 사용하는 데 도움이 되나요? (Some help using my values read from a file in C++?)

Java의 캔버스에 마우스가 그리는 좌표만 화면에 인쇄하려면 어떻게 해야 합니까? (How do I only print to the screen the coordinates of what the mouse is drawing on a canvas in Java?)

좌표가 영역 내부에 있는지 감지하는 방법은 무엇입니까? (How to detect if coordinate is inside region?)

대상 사각형을 포함하여 그리드의 두 사각형 사이의 거리를 계산하는 방법 (How do I calculate the distance between two squares on a grid, including the target square)

두 좌표 배열 간의 대응 관계 찾기 (Find correspondence between 2 arrays of coordinates)

Postgres 쿼리에서 포인트 유형을 사용하는 방법 (Postgres how to use point type in query)

좌표 목록으로 작업하고 싶습니다 [Haskell] (I want to work with a list of coordinates [Haskell])

C 프로그램에서 해당 선의 특정 점에서 특정 거리, 선 위의 점 찾기 (Find a point on a line, a certain distance from a certain point on that line in c program)

점이 있는 geopandas 데이터 프레임에서 다각형 만들기 (Creating a polygon from a geopandas dataframe with points)

Netlogo는 특정 xycor를 설정합니다. (Netlogo set specific xycor)







코멘트