import geopandas as gpd
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import math
# 读取shp文件
gdf_1 = gpd.read_file(r'C:\Users\m1959\Desktop\buildings1_all_data\8outline_to_points\outline_GeneratePointsAlongLines_withPCA_ID.shp')
# 读取shp文件
gdf_2 = gpd.read_file(r'C:\Users\m1959\Desktop\buildings2_all_data\8outline_to_points\outline_GeneratePointsAlongLines_withPCA_ID.shp')
print(gdf_1)
print(gdf_2)
# 将列转换为列表
length_list = gdf_1['length'].tolist()
# 显示列表
print("'length':", length_list)
# 将列转换为列表
length_list = gdf_2['length'].tolist()
# 显示列表
print("'length':", length_list)
# 将列转换为列表
length_list = gdf_1['angle'].tolist()
# 显示列表
print("'angle':", length_list)
# 将列转换为列表
length_list = gdf_2['angle'].tolist()
# 显示列表
print("'angle':", length_list)
# 将列转换为列表
length_list = gdf_1['POINT_X'].tolist()
# 显示列表
print("'POINT_X':", length_list)
# 将列转换为列表
length_list = gdf_2['POINT_X'].tolist()
# 显示列表
print("'POINT_X':", length_list)
# 将列转换为列表
length_list = gdf_1['POINT_Y'].tolist()
# 显示列表
print("'POINT_Y':", length_list)
# 将列转换为列表
length_list = gdf_2['POINT_Y'].tolist()
# 显示列表
print("'POINT_Y':", length_list)
# 假设已经创建了名为“df”的DataFrame对象
# 这里是一个示例DataFrame
data = {
'length': [294.7719896123299, 294.7719896123299, 294.7719896123299, 294.7719896123299, 294.7719896123299, 13.229242552607724, 13.229242552607724, 13.229242552607724, 13.229242552607724, 13.229242552607724, 188.99402377241236, 188.99402377241236, 188.99402377241236, 188.99402377241236, 188.99402377241236, 245.23703145550328, 245.23703145550328, 245.23703145550328, 245.23703145550328, 245.23703145550328, 8.379548710070713, 8.379548710070713, 8.379548710070713, 8.379548710070713, 8.379548710070713, 42.46137655658909, 42.46137655658909, 42.46137655658909, 42.46137655658909, 42.46137655658909, 24.501876457508484, 24.501876457508484, 24.501876457508484, 24.501876457508484, 24.501876457508484, 89.63307787494263, 89.63307787494263, 89.63307787494263, 89.63307787494263, 89.63307787494263, 21.235787726473035, 21.235787726473035, 21.235787726473035, 21.235787726473035, 21.235787726473035, 18.19898855444241, 18.19898855444241, 18.19898855444241, 18.19898855444241, 18.19898855444241, 10.94404173116706, 10.94404173116706, 10.94404173116706, 10.94404173116706, 10.94404173116706, 69.1752531193241, 69.1752531193241, 69.1752531193241, 69.1752531193241, 69.1752531193241],
'angle': [106.8575459035506, 106.8575459035506, 106.8575459035506, 106.8575459035506, 106.8575459035506, 153.08755559721476, 153.08755559721476, 153.08755559721476, 153.08755559721476, 153.08755559721476, 195.38135551979565, 195.38135551979565, 195.38135551979565, 195.38135551979565, 195.38135551979565, 286.2178417604907, 286.2178417604907, 286.2178417604907, 286.2178417604907, 286.2178417604907, 16.26147481404098, 16.26147481404098, 16.26147481404098, 16.26147481404098, 16.26147481404098, 286.07399772135716, 286.07399772135716, 286.07399772135716, 286.07399772135716, 286.07399772135716, 330.47657949293813, 330.47657949293813, 330.47657949293813, 330.47657949293813, 330.47657949293813, 17.27628169108715, 17.27628169108715, 17.27628169108715, 17.27628169108715, 17.27628169108715, 285.89795953446844, 285.89795953446844, 285.89795953446844, 285.89795953446844, 285.89795953446844, 16.033336914044014, 16.033336914044014, 16.033336914044014, 16.033336914044014, 16.033336914044014, 105.86183045004174, 105.86183045004174, 105.86183045004174, 105.86183045004174, 105.86183045004174, 22.3400559612557, 22.3400559612557, 22.3400559612557, 22.3400559612557, 22.3400559612557],
'POINT_X': [396596.374042, 396666.900357, 396737.426672, 396807.952987, 396878.479302, 396878.479302, 396879.976285, 396881.473267, 396882.97025, 396884.467233, 396884.467233, 396871.934927, 396859.402621, 396846.870314, 396834.338008, 396834.338008, 396775.468444, 396716.59888, 396657.729316, 396598.859752, 396598.859752, 396599.446365, 396600.032978, 396600.619591, 396601.206204, 396601.206204, 396591.005868, 396580.805532, 396570.605195, 396560.404859, 396560.404859, 396557.386355, 396554.367851, 396551.349346, 396548.330842, 396548.330842, 396554.985641, 396561.64044, 396568.29524, 396574.950039, 396574.950039, 396569.844153, 396564.738268, 396559.632383, 396554.526497, 396554.526497, 396555.783122, 396557.039747, 396558.296371, 396559.552996, 396559.552996, 396562.184829, 396564.816662, 396567.448495, 396570.080328, 396570.080328, 396576.653757, 396583.227185, 396589.800613, 396596.374042],
'POINT_Y': [3989347.71038, 3989326.33991, 3989304.96945, 3989283.59899, 3989262.22852, 3989262.22852, 3989259.27939, 3989256.33027, 3989253.38114, 3989250.43202, 3989250.43202, 3989204.87587, 3989159.31972, 3989113.76357, 3989068.20742, 3989068.20742, 3989085.33049, 3989102.45356, 3989119.57663, 3989136.6997, 3989136.6997, 3989138.71078, 3989140.72186, 3989142.73294, 3989144.74402, 3989144.74402, 3989147.68318, 3989150.62234, 3989153.5615, 3989156.50067, 3989156.50067, 3989161.83077, 3989167.16087, 3989172.49098, 3989177.82108, 3989177.82108, 3989199.21837, 3989220.61567, 3989242.01296, 3989263.41026, 3989263.41026, 3989264.86451, 3989266.31876, 3989267.77302, 3989269.22727, 3989269.22727, 3989273.60004, 3989277.9728, 3989282.34557, 3989286.71834, 3989286.71834, 3989285.97053, 3989285.22273, 3989284.47493, 3989283.72713, 3989283.72713, 3989299.72294, 3989315.71875, 3989331.71457, 3989347.71038],
'ID': range(60) # 假设ID列从0开始递增
}
df = pd.DataFrame(data)
# 删除特定行
df = df.drop([0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55,])
# 重新设置ID列
df.reset_index(drop=True, inplace=True)
# 显示结果
print(df)
# 将DataFrame转换为GeoDataFrame
gdf_result = gpd.GeoDataFrame(df, geometry=gpd.points_from_xy(df.POINT_X, df.POINT_Y), crs=gdf_1.crs)
# 保存为shapefile格式的文件
gdf_result.to_file(r'C:\Users\m1959\Desktop\delate_some\build1\result.shp', driver='ESRI Shapefile')
以上是2.1删除特定行.py
运行会得到这样的结果,将其粘贴进去代码,得到shp文件,其中ID无间断排列
'length': [294.7719896123299, 294.7719896123299, 294.7719896123299, 294.7719896123299, 294.7719896123299, 13.229242552607724, 13.229242552607724, 13.229242552607724, 13.229242552607724, 13.229242552607724, 188.99402377241236, 188.99402377241236, 188.99402377241236, 188.99402377241236, 188.99402377241236, 245.23703145550328, 245.23703145550328, 245.23703145550328, 245.23703145550328, 245.23703145550328, 8.379548710070713, 8.379548710070713, 8.379548710070713, 8.379548710070713, 8.379548710070713, 42.46137655658909, 42.46137655658909, 42.46137655658909, 42.46137655658909, 42.46137655658909, 24.501876457508484, 24.501876457508484, 24.501876457508484, 24.501876457508484, 24.501876457508484, 89.63307787494263, 89.63307787494263, 89.63307787494263, 89.63307787494263, 89.63307787494263, 21.235787726473035, 21.235787726473035, 21.235787726473035, 21.235787726473035, 21.235787726473035, 18.19898855444241, 18.19898855444241, 18.19898855444241, 18.19898855444241, 18.19898855444241, 10.94404173116706, 10.94404173116706, 10.94404173116706, 10.94404173116706, 10.94404173116706, 69.1752531193241, 69.1752531193241, 69.1752531193241, 69.1752531193241, 69.1752531193241]
'length': [202.37430478125816, 299.6539586019801, 299.6539586019801, 299.6539586019801, 299.6539586019801, 299.6539586019801, 30.971202179106854, 30.971202179106854, 30.971202179106854, 30.971202179106854, 30.971202179106854, 88.02539574860671, 88.02539574860671, 88.02539574860671, 88.02539574860671, 88.02539574860671, 68.05693713073609, 68.05693713073609, 68.05693713073609, 68.05693713073609, 68.05693713073609, 39.71510977327448, 39.71510977327448, 39.71510977327448, 39.71510977327448, 39.71510977327448, 295.4538356866431, 295.4538356866431, 295.4538356866431, 295.4538356866431, 295.4538356866431, 202.37430478125816, 202.37430478125816, 202.37430478125816, 202.37430478125816]
'angle': [106.8575459035506, 106.8575459035506, 106.8575459035506, 106.8575459035506, 106.8575459035506, 153.08755559721476, 153.08755559721476, 153.08755559721476, 153.08755559721476, 153.08755559721476, 195.38135551979565, 195.38135551979565, 195.38135551979565, 195.38135551979565, 195.38135551979565, 286.2178417604907, 286.2178417604907, 286.2178417604907, 286.2178417604907, 286.2178417604907, 16.26147481404098, 16.26147481404098, 16.26147481404098, 16.26147481404098, 16.26147481404098, 286.07399772135716, 286.07399772135716, 286.07399772135716, 286.07399772135716, 286.07399772135716, 330.47657949293813, 330.47657949293813, 330.47657949293813, 330.47657949293813, 330.47657949293813, 17.27628169108715, 17.27628169108715, 17.27628169108715, 17.27628169108715, 17.27628169108715, 285.89795953446844, 285.89795953446844, 285.89795953446844, 285.89795953446844, 285.89795953446844, 16.033336914044014, 16.033336914044014, 16.033336914044014, 16.033336914044014, 16.033336914044014, 105.86183045004174, 105.86183045004174, 105.86183045004174, 105.86183045004174, 105.86183045004174, 22.3400559612557, 22.3400559612557, 22.3400559612557, 22.3400559612557, 22.3400559612557]
'angle': [17.380220523895332, 107.68621471168262, 107.68621471168262, 107.68621471168262, 107.68621471168262, 107.68621471168262, 152.09707488301274, 152.09707488301274, 152.09707488301274, 152.09707488301274, 152.09707488301274, 195.3531494162959, 195.3531494162959, 195.3531494162959, 195.3531494162959, 195.3531494162959, 197.08482011760606, 197.08482011760606, 197.08482011760606, 197.08482011760606, 197.08482011760606, 245.75675307913735, 245.75675307913735, 245.75675307913735, 245.75675307913735, 245.75675307913735, 288.04421097551506, 288.04421097551506, 288.04421097551506, 288.04421097551506, 288.04421097551506, 17.380220523895332, 17.380220523895332, 17.380220523895332, 17.380220523895332]
'POINT_X': [396596.374042, 396666.900357, 396737.426672, 396807.952987, 396878.479302, 396878.479302, 396879.976285, 396881.473267, 396882.97025, 396884.467233, 396884.467233, 396871.934927, 396859.402621, 396846.870314, 396834.338008, 396834.338008, 396775.468444, 396716.59888, 396657.729316, 396598.859752, 396598.859752, 396599.446365, 396600.032978, 396600.619591, 396601.206204, 396601.206204, 396591.005868, 396580.805532, 396570.605195, 396560.404859, 396560.404859, 396557.386355, 396554.367851, 396551.349346, 396548.330842, 396548.330842, 396554.985641, 396561.64044, 396568.29524, 396574.950039, 396574.950039, 396569.844153, 396564.738268, 396559.632383, 396554.526497, 396554.526497, 396555.783122, 396557.039747, 396558.296371, 396559.552996, 396559.552996, 396562.184829, 396564.816662, 396567.448495, 396570.080328, 396570.080328, 396576.653757, 396583.227185, 396589.800613, 396596.374042]
'POINT_X': [397574.625664, 397574.625664, 397645.998338, 397717.371012, 397788.743686, 397860.11636, 397860.11636, 397863.739796, 397867.363233, 397870.98667, 397874.610106, 397874.610106, 397868.783536, 397862.956966, 397857.130396, 397851.303825, 397851.303825, 397846.305263, 397841.306701, 397836.308138, 397831.309576, 397831.309576, 397822.256413, 397813.20325, 397804.150087, 397795.096924, 397795.096924, 397724.866233, 397654.635543, 397584.404852, 397514.174162, 397514.174162, 397529.287037, 397544.399913, 397559.512789]
'POINT_Y': [3989347.71038, 3989326.33991, 3989304.96945, 3989283.59899, 3989262.22852, 3989262.22852, 3989259.27939, 3989256.33027, 3989253.38114, 3989250.43202, 3989250.43202, 3989204.87587, 3989159.31972, 3989113.76357, 3989068.20742, 3989068.20742, 3989085.33049, 3989102.45356, 3989119.57663, 3989136.6997, 3989136.6997, 3989138.71078, 3989140.72186, 3989142.73294, 3989144.74402, 3989144.74402, 3989147.68318, 3989150.62234, 3989153.5615, 3989156.50067, 3989156.50067, 3989161.83077, 3989167.16087, 3989172.49098, 3989177.82108, 3989177.82108, 3989199.21837, 3989220.61567, 3989242.01296, 3989263.41026, 3989263.41026, 3989264.86451, 3989266.31876, 3989267.77302, 3989269.22727, 3989269.22727, 3989273.60004, 3989277.9728, 3989282.34557, 3989286.71834, 3989286.71834, 3989285.97053, 3989285.22273, 3989284.47493, 3989283.72713, 3989283.72713, 3989299.72294, 3989315.71875, 3989331.71457, 3989347.71038]
'POINT_Y': [3989064.84552, 3989064.84552, 3989042.08652, 3989019.32751, 3988996.56851, 3988973.8095, 3988973.8095, 3988966.96686, 3988960.12423, 3988953.28159, 3988946.43896, 3988946.43896, 3988925.21796, 3988903.99697, 3988882.77598, 3988861.55499, 3988861.55499, 3988845.29158, 3988829.02817, 3988812.76476, 3988796.50135, 3988796.50135, 3988792.42448, 3988788.34761, 3988784.27074, 3988780.19387, 3988780.19387, 3988803.07313, 3988825.95239, 3988848.83166, 3988871.71092, 3988871.71092, 3988919.99457, 3988968.27822, 3989016.56187]
建立新的列命名为:bianhao,与FID相同
运行2.2对剩余行操作.py
# 此文件可得出每个点对应的夹角,验证无误
import geopandas as gpd
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import math
# 读取shp文件
gdf_1 = gpd.read_file(r'C:\Users\m1959\Desktop\delate_some\build1\result.shp')
# 读取shp文件
gdf_2 = gpd.read_file(r'C:\Users\m1959\Desktop\delate_some\build2\result.shp')
pd.set_option('display.max_rows', None) # 显示全部行
pd.set_option('display.max_columns', None) # 显示全部列
print(gdf_1)
print(gdf_2)
# 获取包含方位角属性的数据
angles = gdf_1['angle']
# 根据公式计算每个点对应的夹角
calculated_angles = []
n = len(angles)
for i in range(n):
prev_angle = angles[i - 1] if i != 0 else angles[n - 1]
self_angle = angles[i]
# 计算夹角
angle = 180 + prev_angle - self_angle
# 确保夹角在0到360度之间
if angle < 0:
angle += 360
if angle > 360:
angle -= 360
calculated_angles.append(angle)
# 输出每个点对应的角度
for i, angle in enumerate(calculated_angles):
print(f"Point {i}: Angle = {angle} degrees")
得到
Point 0: Angle = 95.4825100577051 degrees
Point 1: Angle = 180.0 degrees
Point 2: Angle = 180.0 degrees
Point 3: Angle = 180.0 degrees
Point 4: Angle = 133.76999030633584 degrees
Point 5: Angle = 180.0 degrees
Point 6: Angle = 180.0 degrees
Point 7: Angle = 180.0 degrees
Point 8: Angle = 137.7062000774191 degrees
Point 9: Angle = 180.0 degrees
Point 10: Angle = 180.0 degrees
Point 11: Angle = 180.0 degrees
Point 12: Angle = 89.16351375930492 degrees
Point 13: Angle = 180.0 degrees
Point 14: Angle = 180.0 degrees
Point 15: Angle = 180.0 degrees
Point 16: Angle = 89.95636694644975 degrees
Point 17: Angle = 180.0 degrees
Point 18: Angle = 180.0 degrees
Point 19: Angle = 180.0 degrees
Point 20: Angle = 270.1874770926838 degrees
Point 21: Angle = 180.0 degrees
Point 22: Angle = 180.0 degrees
Point 23: Angle = 180.0 degrees
Point 24: Angle = 135.59741822841903 degrees
Point 25: Angle = 180.0 degrees
Point 26: Angle = 180.0 degrees
Point 27: Angle = 180.0 degrees
Point 28: Angle = 133.20029780185098 degrees
Point 29: Angle = 180.0 degrees
Point 30: Angle = 180.0 degrees
Point 31: Angle = 180.0 degrees
Point 32: Angle = 271.3783221566187 degrees
Point 33: Angle = 180.0 degrees
Point 34: Angle = 180.0 degrees
Point 35: Angle = 180.0 degrees
Point 36: Angle = 89.86462262042443 degrees
Point 37: Angle = 180.0 degrees
Point 38: Angle = 180.0 degrees
Point 39: Angle = 180.0 degrees
Point 40: Angle = 90.17150646400228 degrees
Point 41: Angle = 180.0 degrees
Point 42: Angle = 180.0 degrees
Point 43: Angle = 180.0 degrees
Point 44: Angle = 263.52177448878604 degrees
Point 45: Angle = 180.0 degrees
Point 46: Angle = 180.0 degrees
Point 47: Angle = 180.0 degrees
与人眼认知相符