Пример #1
0
def main():
    #检查输入参数是否正确
    check_params()

    all_pois = []
    for index in range(int(WindowSize['xNum'] * WindowSize['yNum'])):
        smallRect = getSmallRect(BigRect, WindowSize, index)

        print(smallRect)
        pois = requestBaiduApi(keyWords=KeyWord,
                               smallRect=smallRect,
                               baiduAk=baiduAk)
        all_pois.extend(pois)
        time.sleep(1)

    data_csv = {}
    uids, names, provinces, citys, areas, addresses, lngs, lats = [], [], [], [], [], [], [], []
    for poi in all_pois:
        if poi == None:
            continue
        uids.append(poi.get('uid'))
        names.append(poi.get('name'))
        provinces.append(poi.get('province'))
        citys.append(poi.get('city'))
        areas.append(poi.get('area'))
        addresses.append(poi.get('address'))
        location = poi['location']
        lng = location['lng']
        lat = location['lat']

        result = bd09_to_wgs84(float(lng), float(lat))
        lng = result[0]
        lat = result[1]

        lngs.append(lng)
        lats.append(lat)
    data_csv['uid'] = uids
    data_csv['name'] = names
    data_csv['province'] = provinces
    data_csv['city'] = citys
    data_csv['area'] = areas
    data_csv['address'] = addresses
    data_csv['lng'] = lngs
    data_csv['lat'] = lats

    df = pd.DataFrame(data_csv)
    data_path = os.getcwd() + os.sep + "data" + os.sep
    if not os.path.exists(data_path):
        os.mkdir(data_path)
    df.to_csv(data_path + "bmap-poi-" + KeyWord + '.csv',
              index=False,
              encoding='utf_8_sig')
Пример #2
0
def create_yichuxing_data(points_coordinate_result):
    '''生成宜出行爬取的数据各式'''
    text = 'OBJECTID,x,y\n'
    for i, point in enumerate(points_coordinate_result):
        lng = points_coordinate_result[i][0]
        lat = points_coordinate_result[i][1]
        res = transCoordinateSystem.bd09_to_wgs84(lng, lat)
        lng = res[0]
        lat = res[1]
        text += str(i) + ',' + str(lng) + ',' + str(lat) + '\n'

    with open('data.txt', 'w') as f:
        f.write(text.strip())
    print('写入成功')
Пример #3
0
def main():
    index = 0
    for boun in bounds:
        for key in keywords:
            all_pois = requestBaiduApi(keyWords=key,
                                       smallRect=boun,
                                       baiduAk=baiduAk)
            data_csv = {}
            uids, names, provinces, citys, areas, addresses, lngs, lats = [], [], [], [], [], [], [], []
            for poi in all_pois:
                if poi == None:
                    continue
                uids.append(poi.get('uid'))
                names.append(poi.get('name'))
                provinces.append(poi.get('province'))
                citys.append(poi.get('city'))
                areas.append(poi.get('area'))
                addresses.append(poi.get('address'))
                location = poi['location']
                lng = location['lng']
                lat = location['lat']

                coords = transCoordinateSystem.bd09_to_wgs84(
                    float(lng), float(lat))

                lngs.append(coords[0])
                lats.append(coords[1])
            data_csv['uid'] = uids
            data_csv['name'] = names
            data_csv['province'] = provinces
            data_csv['city'] = citys
            data_csv['area'] = areas
            data_csv['address'] = addresses
            data_csv['lng'] = lngs
            data_csv['lat'] = lats

            df = pd.DataFrame(data_csv)
            data_path = os.getcwd() + os.sep + "data" + os.sep
            if not os.path.exists(data_path):
                os.mkdir(data_path)
            df.to_csv(data_path + "bmap-poi-" + str(index) + key + '.csv',
                      index=False,
                      encoding='utf_8_sig')
        index += 1
Пример #4
0
def transfer(orgcoord, targetcoord, filename):
    '''
    坐标转换
    默认第一二列为经纬度
    :param filename:
    :return:
    '''
    workbook = xlrd.open_workbook(filename)
    new_workbook = copy(workbook)
    new_worksheet = new_workbook.get_sheet(0)
    sheet = workbook.sheets()[0]
    index = 0
    for i in range(1, sheet.nrows):
        lon, lat = sheet.cell_value(i, 0), sheet.cell_value(i, 1)

        # 坐标转换
        if orgcoord == "1":
            if targetcoord == "1":
                pass
            elif targetcoord == "2":
                result = gcj02_to_wgs84(float(lon), float(lat))
                lon = result[0]
                lat = result[1]
            elif targetcoord == "3":
                result = gcj02_to_bd09(float(lon), float(lat))
                lon = result[0]
                lat = result[1]
        elif orgcoord == "2":
            if targetcoord == "1":
                result = wgs84_to_gcj02(float(lon), float(lat))
                lon = result[0]
                lat = result[1]
            elif targetcoord == "2":
                pass
            elif targetcoord == "3":
                result = wgs84_to_bd09(float(lon), float(lat))
                lon = result[0]
                lat = result[1]

        elif orgcoord == "3":
            if targetcoord == "1":
                result = bd09_to_gcj02(float(lon), float(lat))
                lon = result[0]
                lat = result[1]
            elif targetcoord == "2":
                result = bd09_to_wgs84(float(lon), float(lat))
                lon = result[0]
                lat = result[1]
            elif targetcoord == "3":
                pass

        for j in range(sheet.ncols):
            if index == 0:
                new_worksheet.write(i - 1, sheet.ncols + 1, 'lon-new')
                new_worksheet.write(i - 1, sheet.ncols + 2, 'lat-new')
            else:
                new_worksheet.write(i - 1, sheet.ncols + 1, lon)
                new_worksheet.write(i - 1, sheet.ncols + 2, lat)
        index = index + 1
    new_file_name = "upload/" + str(filename).split("/")[-1].split(
        ".")[0] + "-new" + ".xls"
    new_file_path = os.path.abspath(os.getcwd()) + "/" + new_file_name
    new_workbook.save(new_file_path)  # 保存工作簿
    return new_file_name
Пример #5
0
data_csv = {}
numbers, xs, ys, uids = [], [], [], []
index = 1
for i in range(len(csv_file)):
    boundary = str(csv_file['boundary'][i])

    uid = str(csv_file['uid'][i])

    if boundary != ' ' and boundary != 'nan' and boundary != None:
        for point in boundary.split(";"):
            print(boundary)
            lng = point.split(",")[0]
            lat = point.split(",")[1]

            #转换为WGS84坐标系
            coord_wgs84 = bd09_to_wgs84(float(lng), float(lat))
            lng = coord_wgs84[0]
            lat = coord_wgs84[1]

            xs.append(lng)
            ys.append(lat)
            numbers.append(index)
            uids.append(uid)

            index = index + 1
data_csv['number'] = numbers
data_csv['x'] = xs
data_csv['y'] = ys
data_csv['uid'] = uids

df = pd.DataFrame(data_csv)