Beispiel #1
0
 def coord_transform(self, lng, lat):
     coord = self.config.get("DEFAULT", "coord")
     if coord == "bd-09":
         return lng, lat
     if coord == "gcj02":
         return bd09_to_gcj02(lng, lat)
     if coord == "WGS84":
         return bd09_to_wgs84(lng, lat)
Beispiel #2
0
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()
Beispiel #3
0
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
Beispiel #4
0
import os
import csv
import coordTransform_utils
f_orig = csv.reader(open('sheet1.csv', 'r'))

f_new = 'sheet1_converted.csv'
with open(f_new, 'w', newline='') as f:
    f_new_writer = csv.writer(f, delimiter=',')
    num_line = 0
    for eachline_in_f_orig in f_orig:
        num_line = num_line + 1
        print(
            'The origin data of line ',
            num_line,
            'is ',
            eachline_in_f_orig,
        )

        try:
            # newline_in_f_new = eachline_in_f_orig.split(',')

            result = coordTransform_utils.bd09_to_wgs84(
                float(eachline_in_f_orig[1]), float(eachline_in_f_orig[2]))
            print('Successful. Result is ', result)
        except BaseException as error:
            result = [0, 0]
            print('Error occured. Set the result to [0,0]')
            print('Error info: ', error)
        # print(eachline_in_f_orig+result)
        f_new_writer.writerow(eachline_in_f_orig + result)
Beispiel #5
0
import os
import csv
import coordTransform_utils
import pandas as pd
f_orig = open('lnglat.csv', 'r', encoding='gbk')

da = pd.read_csv(f_orig)
f_new = 'Wgslnglat.csv'
with open(f_new, 'w', newline='') as f:
    # writer=csv.writer(f)与下面一行等价,delimiter默认是逗号
    writer = csv.writer(f, delimiter=',')

    # for row in img:
    #   writer.writerow(row)
    print(f_orig)
    for eachline in f_orig:
        try:
            # print("I am here")
            eachline = eachline.split(',')
            print(eachline)
            # 需要改一下经纬度顺序 和转换的坐标系
            result = coordTransform_utils.bd09_to_wgs84(
                float(eachline[0]), float(eachline[1]))

        # result.extend(eachline.split(',')[0],eachline.split(',')[1],eachline.split(',')[2])
        except BaseException:
            result = [0, 0]
            print("There is BaseException")

        writer.writerow(eachline + result)
def wgs_to_grid(lon,lat):
    slon = 112.95850716
    slat = 22.51436103
    mlon = 0.00242610105286935
    mlat = 0.00226617728902972
    lon1 = int((lon-slon)/mlon)
    lat1 = int((lat-slat)/mlat)    
    return [lon1,lat1]

g1['center'] = '广州市增城区新塘镇凤凰城凤锦苑天麓街9号'
g2['center'] = '广州市增城市新塘镇凤凰城凤凰广场步行街南二号之八'
g3['center'] = '广州市花都区商业大道35号'

g1 = [113.5896980000,23.1547220000]
g1 = bd09_to_wgs84(g1[0],g1[1])
g1 = wgs_to_grid(g1[0],g1[1])
g11 = foo(g1[0],g1[1])

g2 = [113.5807570000,23.1315810000]
g2 = bd09_to_wgs84(g2[0],g2[1])
g2 = wgs_to_grid(g2[0],g2[1])
g22 = foo(g2[0],g2[1])

g3 = [113.2179970000,23.3823500000]
g3 = bd09_to_wgs84(g3[0],g3[1])
g3 = wgs_to_grid(g3[0],g3[1])
g33 = foo(g3[0],g3[1])

gall = g11+g22+g33