まず、私がハードコーディングしたものを紹介し、代表的なデータセットであると仮定します。これは本当にあなたが質問に提供しているべきものですが、私は、このホリデーシーズン寛大な感じている:私は、各ラインの重心のx座標とy座標を計算するつもりだだから今
from shapely.geometry import Point, LineString
import geopandas
line1 = LineString([
Point(0, 0),
Point(0, 1),
Point(1, 1),
Point(1, 2),
Point(3, 3),
Point(5, 6),
])
line2 = LineString([
Point(5, 3),
Point(5, 5),
Point(9, 5),
Point(10, 7),
Point(11, 8),
Point(12, 12),
])
line3 = LineString([
Point(9, 10),
Point(10, 14),
Point(11, 12),
Point(12, 15),
])
gdf = geopandas.GeoDataFrame(
data={'name': ['A', 'B', 'A']},
geometry=[line1, line2, line3]
)
を、それらの平均、行の平均と名前で並べ替え、中間の列を削除します。
output = (
gdf.assign(x=lambda df: df['geometry'].centroid.x)
.assign(y=lambda df: df['geometry'].centroid.y)
.assign(rep_val=lambda df: df[['x', 'y']].mean(axis=1))
.sort_values(by=['name', 'rep_val'])
.loc[:, gdf.columns]
)
print(output)
name geometry
0 A LINESTRING (0 0, 0 1, 1 1, 1 2, 3 3, 5 6)
2 A LINESTRING (9 10, 10 14, 11 12, 12 15)
1 B LINESTRING (5 3, 5 5, 9 5, 10 7, 11 8, 12 12)
私はこの十分に強調することはできません
:私はここに私の答えで行ったように、あなたの質問にハードコードにいくつかの代表的なデータセットを必要とする:https://stackoverflow.com/a/47972529/1552748 –
(とそれは*いくつかのランダムなシェイプファイルへのリンクを意味しません) –