def convert_by_type(lng, lat, type): if type == 'g2b': return gcj02_to_bd09(lng, lat) elif type == 'b2g': return bd09_to_gcj02(lng, lat) elif type == 'w2g': return wgs84_to_gcj02(lng, lat) elif type == 'g2w': return gcj02_to_wgs84(lng, lat) elif type == 'b2w': return bd09_to_wgs84(lng, lat) elif type == 'w2b': return wgs84_to_bd09(lng, lat) else: print('Usage: type must be in one of g2b, b2g, w2g, g2w, b2w, w2b') sys.exit()
def tPoint(lng, lat, type): if type == 'g2b': tcoord = gcj02_to_bd09(lng, lat) elif type == 'b2g': tcoord = bd09_to_gcj02(lng, lat) elif type == 'w2g': tcoord = wgs84_to_gcj02(lng, lat) elif type == 'g2w': tcoord = gcj02_to_wgs84(lng, lat) elif type == 'b2w': tcoord = bd09_to_wgs84(lng, lat) elif type == 'w2b': tcoord = wgs84_to_bd09(lng, lat) else: tcoord = [lng, lat] return tcoord
reversePointDicts, G) fixed = minDistanceBetweenNodeInDiffSubGs.values() G.add_edges_from(fixed) fixedLine.extend(fixed) for i in fixedLine: simplePipes.append(i) simplePipeInfo.append(219) # 文件处理 data = [] for k, v in pointDicts.items(): x, y = k lat, lng = transform(2437, 4326, y, x) lng, lat = wgs84_to_bd09(float(lng), float(lat)) data.append((v, lng, lat)) pointsSavePath = r"D:\Users\Illusion\Desktop\points_.csv" saveFile(pointsSavePath, data) pipeSavePath = r"D:\Users\Illusion\Desktop\pipes_.csv" pipeInfo = [] for p, info in zip(simplePipes, simplePipeInfo): s, e = p sx, sy = reversePointDicts[s] slat, slng = transform(2437, 4326, sy, sx) ex, ey = reversePointDicts[e] elat, elng = transform(2437, 4326, ey, ex) lens = geodesic((slat, slng), (elat, elng)).m pipeInfo.append((s, e, lens, info))
return 0.0 s = arr[0][1] * (arr[arr_len - 1][0] - arr[1][0]) for i in range(1, arr_len): s += arr[i][1] * (arr[i - 1][0] - arr[(i + 1) % arr_len][0]) return round(math.fabs(s / 2) * 10000, 3) ''' 2、坐标转换 input:原坐标,转换前后的坐标类别函数 output:转换后的坐标 ''' from coordTransform_utils import wgs84_to_bd09 import pandas as pd result1 = wgs84_to_bd09(116.469271, 39.985568) df = pd.read_csv('E:/Desktop/workf/shdistrict.csv', encoding='utf8') newlist = pd.DataFrame(list(map(wgs84_to_bd09, df['lon'], df['lat']))) df['bdlat'] = newlist[1] df['bdlon'] = newlist[0] ''' 3、画简易热力图 input:有坐标点和该点权重组成的数据集 output:能反应坐标及热点(不明显)分布情况的热量力图 ''' import pandas as pd import numpy as np import matplotlib.pyplot as plt
import glob import csv from coordTransform_utils import wgs84_to_bd09 for file in glob.glob("./visual/assets/*.csv"): if 'bd09' in file: continue with open(file, "rt") as csvfile: output = file.replace(".csv", ".bd09.csv") with open(output, "wt") as outputfile: reader = csv.reader(csvfile) for row in reader: lon, lat = wgs84_to_bd09(float(row[2]), float(row[3])) outputfile.write("%s,%s,%s,%s\n" % (row[0], row[1], lon, lat))