在好例子网,分享、交流、成长!
您当前所在位置:首页Python 开发实例Python GUI开发 → python生成googleKML工具增强版

python生成googleKML工具增强版

Python GUI开发

下载此实例
  • 开发语言:Python
  • 实例大小:6.96M
  • 下载次数:15
  • 浏览次数:379
  • 发布时间:2021-04-29
  • 实例类别:Python GUI开发
  • 发 布 人:Non-existante
  • 文件格式:.rar
  • 所需积分:3
 相关标签: python google kML 生成 go

实例介绍

【实例简介】


-------------------------------------------------------------------------------------------------

扇区标注:选择扇区标注后,会将每一行表格所有内容附加到对应的图形中,点击即可显示。

分段功能:选中“分段”则开启该功能,后面选择对应的列。列中有多少不重复的项就生成多少个google文件和csv文件。

视野&像素功能:

视野:是一个经纬度到正上(下/左/右)方向的距离单位是米

像素:是在经纬度上下左右“视野”区域的像素希望值。

当经纬度“视野”区域内,实际像素大于希望值的时候才显示该经纬度对应的图层。实际像素和电脑分辨率有关系。

kml&kmz:

kml:文件较大,图层使用编辑器打开后可编辑。

kmz:文件很小,适合发送。图层不可使用编辑器编辑。

颜色:

点:选择对应的图像即可,包含了google标准的大部分图标和颜色。

扇形:选择有颜色,不选无颜色,颜色可自定义,通名都可自定义。另线条颜色后为线条宽度,可自定义。

高度&贴地面:选择无高度后高度设置失效,扇形贴地面显示,不会被地形遮挡。

数据过滤:数据中所有为空的单元格替换为“空”,并替换了特殊字符[:<>\@$!%*#?& /]为""无。


【实例截图】

from clipboard

【核心代码】

# -*- coding: utf-8 -*-
# from shapely.geometry import Polygon
import pandas as pd
import pot_style
import simplekml
import qdarkstyle
from geographiclib.geodesic import Geodesic
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow,  QFileDialog, QColorDialog, QMessageBox, QProgressDialog
from PyQt5.QtCore import Qt, pyqtSignal,  QThread
from PyQt5.QtGui import QCursor

from Ui_kml_shetup import *
# ___________插入窗体2_____________
from kml_shetup_2 import *
# kml_shetup_2.
class Widget(QMainWindow, Ui_Form):
    k = '1-1'

    def __init__(self, parent=None):
        super(Widget, self).__init__(parent)
        self.setupUi(self)
        Widget.hang_v_z = self.hang_v.text()
        print(Widget.hang_v_z)
        Widget.lie_v_z = self.lie_v.text()
        print(Widget.lie_v_z)
        self.pushButton.clicked.connect(self.tt)

    def tt(self):
        hang_v_z = self.hang_v.text()
        print(hang_v_z)
        lie_v_z = self.lie_v.text()
        print(lie_v_z)
        Worker.k = str(hang_v_z) '-' str(lie_v_z)
        self.close()
# -^^^^^^^^^^^^^^窗体2^^^^^^^^^^^^^^^^

# ___________插入帮助_____________
from help import *
class Widget_help(QMainWindow, Ui_Dialog):
    def __init__(self, parent=None):
        super(Widget_help, self).__init__(parent)
        self.setupUi(self)



#----------主工作类-线程-------==============工作---worker----------------------工作----------

class Worker(QThread):
    yanse_xiantiao = 'ffff0000'
    yanse_shanqu = 'ffff0000'
    data_table1 = pd.DataFrame()
    data_name = ''
    k = '1-1'
    nn = 0

    lon_n, lat_n, id_n, fw_n ,jl_df,gd_df= 0, 0, 0, 0,0,0
    banjing_n, jia_jiao, shiye_n, xiantiao_kuan = 0, 0, 0, 0
    xiangsu_n, gaodu_n, toumingdu,fenduan_id = 0, 0, 0, 0
    shanqu_is, dian_is, biaoji_is,biaoji_is2, shanquyanse_is = False, False, False, False,False
    xiantiaoyanse_is, kml_is, kmz_is,fenduan_is,wugaodu_is = False, False, False, False,False
    progressBarValue = pyqtSignal(int)  # 更新进度条
    def __init__(self):
        super(Worker, self).__init__()


    def run(self):
        print('第一个实验成功,恭喜',self.data_table1.shape)
        print('lon_n, lat_n, id_n, fw_n,',self.lon_n, self.lat_n, self.id_n, self.fw_n)
        print('banjing_n, jia_jiao, shiye_n, xiantiao_kuan',self.banjing_n, self.jia_jiao, self.shiye_n, self.xiantiao_kuan)
        print('xiangsu_n, gaodu_n, toumingdu, fenduan_id',self.xiangsu_n, self.gaodu_n, self.toumingdu, self.fenduan_id)
        print('shanqu_is, dian_is, biaoji_is, shanquyanse_is',self.shanqu_is, self.dian_is, self.biaoji_is, self.shanquyanse_is)
        print('xiantiaoyanse_is, kml_is, kmz_is,fenduan_is,wugaodu_is',self.xiantiaoyanse_is, self.kml_is, self.kmz_is,self.fenduan_is,self.wugaodu_is)
        print('progressBarValue',self.progressBarValue)

        self.progressBarValue.emit(10)  # 发送进度条的值 信号
        self.run_kml()


    def run_kml(self):

        self.nn = 0
        if self.fenduan_is == True:
            data_groupy = self.data_table1.groupby(by=self.fenduan_id)
            lu_name = self.data_name
            res_kml_name = lu_name.split(".")[0]
            jia_y = 20
            for da in data_groupy:
                name1 = da[0]
                df = da[1]
                try:
                    df.to_csv(res_kml_name '_' name1 '.csv', encoding='gbk', index=False)
                except:
                    try:
                        df.to_csv(res_kml_name '_' name1 '.csv', index=False)
                    except:
                        df.to_csv(res_kml_name '_' name1 '.csv', encoding='utf-8', index=False)
                df_yuxing = df.copy()
                self.start_kml(df_yuxing, name1)
                self.progressBarValue.emit(jia_y)
                jia_y = jia_y 6
                if jia_y>80:
                    jia_y = 80

            if self.nn == 1:
                pass
            else:
                self.progressBarValue.emit(-2)
                # QMessageBox.about(self, "标题", "图层制作完成")
        else:
            self.start_kml(self.data_table1, '')
            if self.nn == 1:
                pass
            else:
                self.progressBarValue.emit(-2)
                # QMessageBox.about(self, "标题", "图层制作完成")
    def start_kml(self,data_yuan,name_kml):
        # try:
        data_yuan1 = data_yuan.copy()
        print('开始制作图层,行列数为',data_yuan1.shape)
        if self.dian_is == True:
            print('制作点开始')
            kml = simplekml.Kml()
            row_table = data_yuan.copy()
            lon_n = self.lon_n  # 下拉菜单选择的项目赋值变量
            lat_n = self.lat_n
            id_n = self.id_n
            # 数据过滤

            row_table[id_n].fillna('空', inplace=True)
            row_table.loc[:, lon_n] = pd.to_numeric(row_table[lon_n])  # 改成number
            row_table.loc[:, lat_n] = pd.to_numeric(row_table[lat_n])  # 改成number

            shiye_n = self.shiye_n  # 获取单行输入框
            xiangsu_n = self.xiangsu_n  # 获取单行输入框
            style = simplekml.Style()
            pot_ss = self.k
            zz = pot_style.dict[pot_ss]
            style.iconstyle.icon.href = zz
            print(pot_ss, zz)
            if self.fenduan_is == False:
                self.progressBarValue.emit(20)
            lod_p = simplekml.Lod(minlodpixels=xiangsu_n, maxlodpixels=-1, minfadeextent=None, maxfadeextent=None)
            if self.fenduan_is == False:
                self.progressBarValue.emit(30)

            def guocheng_pot(mingcheng, lon_p, lat_p, shiye_n=shiye_n, style=style, lod_p=lod_p):
                # -----------添加lod
                lon_dd, lat_dd, lon1_dd, lat1_dd = self.lod_lon_lat(lon=lon_p, lat=lat_p, azimuth=45,
                                                                    azimuth1=225, radius=int(shiye_n))
                latlonaltbox_p = simplekml.LatLonAltBox(east=lon_dd, north=lat_dd, south=lat1_dd, west=lon1_dd,
                                                        minaltitude=None, maxaltitude=None, altitudemode=None)
                rgn_p = simplekml.Region(latlonaltbox_p, lod_p)
                # ------------创建点
                pnt = kml.newpoint(name=mingcheng, region=rgn_p)  #
                pnt.coords = [(lon_p, lat_p)]
                pnt.style = style
            if self.fenduan_is == False:
                self.progressBarValue.emit(-1)
            for x in zip(row_table[id_n], row_table[lon_n], row_table[lat_n]):
                guocheng_pot(*x, shiye_n=shiye_n, style=style, lod_p=lod_p)


            lu_name = self.data_name
            res_kml_name = lu_name.split(".")[0]
            if self.kml_is == True:
                kml.save(res_kml_name name_kml "_pot.kml")
                print('ok,点图已经做好kml')
            else:
                kml.savekmz(res_kml_name name_kml "_pot.kmz", False)
                print('ok,点图已经做好-kmz')


        #----------扇区
        elif self.shanqu_is == True :

            lon_n = self.lon_n
            lat_n = self.lat_n
            fw_n = self.fw_n
            id_n = self.id_n
            # 数据过滤
            data_yuan[id_n].fillna('空', inplace=True)
            data_yuan.loc[:, lon_n] = pd.to_numeric(data_yuan1[lon_n])  # 改成number
            data_yuan.loc[:, lat_n] = pd.to_numeric(data_yuan1[lat_n])  # 改成number
            data_yuan.loc[:, fw_n] = pd.to_numeric(data_yuan1[fw_n])  # 改成number
            banjing_n = self.jl_df
            jia_jiao = self.jia_jiao
            shiye_n = self.shiye_n
            xiangsu_n = self.xiangsu_n
            xiantiao_kuan = self.xiantiao_kuan
            gaodu_n = self.gd_df
            toumingdu = self.toumingdu
            yanse_shanqu = self.yanse_shanqu
            yanse_xiantiao = self.yanse_xiantiao
            if self.fenduan_is == False:
                self.progressBarValue.emit(20)
            print(lon_n,lat_n,gaodu_n,fw_n,banjing_n,jia_jiao, toumingdu, yanse_shanqu, yanse_xiantiao)
            data_yuan[lon_n] = pd.to_numeric(data_yuan[lon_n])
            data_yuan[lat_n] = pd.to_numeric(data_yuan[lat_n])
            data_yuan[gaodu_n] = pd.to_numeric(data_yuan[gaodu_n])
            data_yuan[fw_n] = pd.to_numeric(data_yuan[fw_n])
            data_yuan[banjing_n] = pd.to_numeric(data_yuan[banjing_n])

            data_yuan_shi = self.add_sectors(data_yuan,
                    coords=[lon_n,lat_n,banjing_n,gaodu_n,fw_n],
                    has_z=True,
                    sec_col='geometry',
                    shape_dict={
                        'beam': int(jia_jiao),
                        'per_degree': 10})
            if self.fenduan_is == False:
                self.progressBarValue.emit(25)
            ##========================================
            row_table = data_yuan_shi.copy()

            if self.biaoji_is == True:
                row_table_1 = row_table.drop(['geometry'], axis=1)  # , lon_n,lat_n
                lie_a = list(row_table_1.columns)
                row_table['标记'] = row_table_1.apply(lambda x: ','.join(x.astype(str)), axis=1)
            kml = simplekml.Kml()
            # colour = 'ff00ffff'  # ^^设置一个颜色
            colour_alpha_x = simplekml.Color.changealphaint(int(toumingdu), yanse_xiantiao)  # ^^^^^将颜色添加透明度0-255
            colour_alpha_m = simplekml.Color.changealphaint(int(toumingdu), yanse_shanqu)
            style = simplekml.Style()
            style.iconstyle.icon.href = None  # 不显示图标
            style.linestyle.width = xiantiao_kuan
            if self.xiantiaoyanse_is == True:
                style.linestyle.color = colour_alpha_x  # 最终线条上色
            else:
                wu_yan_se = simplekml.Color.changealphaint(0, 'ffff0000')
                style.linestyle.color = wu_yan_se  # 最终线条上色
            if self.shanquyanse_is == True:
                style.polystyle.color = colour_alpha_m  # 最终形状上色
            else:
                wu_yan_se = simplekml.Color.changealphaint(0, 'ffff0000')
                style.polystyle.color = wu_yan_se  # 最终形状上色
            style.labelstyle.scale = 0.8  # 字体大小1是正常
            poif = kml.newfolder(name='名称')
            polf = kml.newfolder(name='扇区')
            lod1 = simplekml.Lod(minlodpixels=xiangsu_n, maxlodpixels=-1, minfadeextent=None, maxfadeextent=None)
            biao_zhu = ""
            if self.fenduan_is == False:
                self.progressBarValue.emit(-1)


            def guocheng_kml1(id_n_v, polygon1, lon_yuan, lat_yuan, fw_yuan, biao_zhu,banjing_n, lod1=lod1,
                              shiye_n=shiye_n,  style=style):
                lon_dd, lat_dd, lon1_dd, lat1_dd = self.lod_lon_lat(lon=lon_yuan, lat=lat_yuan, azimuth=45,
                                                                    azimuth1=225, radius=int(shiye_n))
                latlonaltbox = simplekml.LatLonAltBox(east=lon_dd, north=lat_dd, south=lat1_dd, west=lon1_dd,
                                                      minaltitude=None, maxaltitude=None, altitudemode=None)
                pol = polf.newpolygon(name=id_n_v)  # ,description = biaozhu_r
                pol.region.latlonaltbox = latlonaltbox
                pol.region.lod = lod1
                # polygon2=ast.literal_eval(polygon1)
                pol.outerboundaryis = polygon1  # polygon_1 是一个扇区
                if self.biaoji_is == True:
                    # lieming = row_1[['小区中文名','空口上下行业务字节数KByte']]#^^^^^^标注可选择,不选则全部
                    in_i = 0
                    for x in biao_zhu.split(','):  # ^^^^^^可选去掉不加标注
                        y = lie_a[in_i]
                        in_i = in_i 1
                        pol.extendeddata.schemadata.newsimpledata(y, x)
                pol.extrude = 1  # 高度需添加凸出
                if self.wugaodu_is == True:
                    pol.altitudemode = simplekml.AltitudeMode.clamptoground  # 高度需添加-贴地
                else:
                    pol.altitudemode = simplekml.AltitudeMode.relativetoground  # 高度需添加-贴地
                # pol.snippet.maxlines = 1 #名字下面的间隔
                # pol.snippet.content = "名字下面的文字"
                
                #下面为生成点的标注名称
                if self.biaoji_is2 == True:
                    lon_b, lat_b = self.point_lon_lat(lon=lon_yuan, lat=lat_yuan, azimuth=fw_yuan,
                                                      radius=int(banjing_n) * 0.7)
                    pnt = poif.newpoint(name=id_n_v)
                    pnt.region.latlonaltbox = latlonaltbox
                    pnt.region.lod = lod1
                    pnt.coords = [(lon_b, lat_b)]
                    pnt.style = style


                pol.style = style

            if self.biaoji_is == True:
                for x in zip(row_table[id_n], row_table['geometry'], row_table[lon_n], row_table[lat_n],
                             row_table[fw_n], row_table['标记'],row_table[banjing_n]):
                    guocheng_kml1(*x, lod1=lod1,
                                  shiye_n=shiye_n, style=style)
            else:
                for x,y,z,a,b,c, in zip(row_table[id_n], row_table['geometry'], row_table[lon_n], row_table[lat_n],
                             row_table[fw_n],row_table[banjing_n]):
                    guocheng_kml1(id_n_v=x, polygon1=y, lon_yuan=z, lat_yuan=a, fw_yuan=b, biao_zhu = False , lod1=lod1,
                                 shiye_n=shiye_n, banjing_n=c, style=style)

            lu_name = self.data_name
            res_kml_name = lu_name.split(".")[0]
            if self.kml_is == True:
                kml.save(res_kml_name name_kml ".kml")
                print('ok1')

            else:
                kml.savekmz(res_kml_name name_kml ".kmz", False)
                print('ok1')

        # except:
        #     self.nn=1
        #     self.progressBarValue.emit(-3)

    # ---------找Polygon中标注名称位置的函数

    def point_lon_lat(self, lon=114.198312, lat=30.630697, azimuth=0, radius=50):
        res = Geodesic.WGS84.Direct(lat, lon, azimuth, radius)
        lon = res['lon2']
        lat = res['lat2']
        return lon, lat

    # ---------找lod的四个角

    def lod_lon_lat(self,lon=114.198312, lat=30.630697, azimuth=45, azimuth1=225, radius=7000):  # ^^^^^^^设置视野
        res = Geodesic.WGS84.Direct(lat, lon, azimuth, radius)
        lon_1 = res['lon2']
        lat_1 = res['lat2']
        res1 = Geodesic.WGS84.Direct(lat, lon, azimuth1, radius)
        lon_2 = res1['lon2']
        lat_2 = res1['lat2']
        return lon_1, lat_1, lon_2, lat_2
    def __draw_sector(self,lon=114.198312,
                      lat=30.630697,
                      radius = 0,
                      height=5,
                      azimuth=0,
                      has_z=True,
                      shape_dict={
                          'beam': 30,
                          'per_degree': 10
                      },
                      **kwargs):
        """制作扇区形状,可以2d也可以3d  has_z就是3d

        """
        beam, per_degree = (shape_dict['beam'],shape_dict['per_degree'])
        azimuth_list = list(
            range(
                int(azimuth - beam / 2),
                int(azimuth beam / 2) 1, per_degree))

        if has_z:
            points = [(lon, lat, height)]
            for azi in azimuth_list:
                res = Geodesic.WGS84.Direct(lat, lon, azi, radius)
                points.append((res['lon2'], res['lat2'], height))
        else:
            points = [(lon, lat)]
            for azi in azimuth_list:
                res = Geodesic.WGS84.Direct(lat, lon, azi, radius)
                points.append((res['lon2'], res['lat2']))
        points.append(points[0])
        return list(points)

    def add_sectors(self,df,
                    coords=['lon', 'lat', 'radius', 'height','azimuth'],
                    has_z=True,
                    sec_col='geometry',
                    shape_dict={
                        'beam': 30,
                        'per_degree': 10
                    },
                    **kwargs):
        """根据经纬度挂高方向角所在列,为df增加CRS和 geometry 列
        shape_dict={
                          'radius': 100,
                          'beam': 30,
                          'per_degree': 10
                      },
        Returns:
            [type] -- [description]
        """
        lon, lat,radius,height,azimuth = coords
        df = df.copy()
        if has_z:
            df.loc[:, sec_col] = [
                self.__draw_sector(*x, shape_dict=shape_dict, has_z=has_z)
                for x in zip(df[lon], df[lat],df[radius], df[height], df[azimuth])
            ]
        else:
            df.loc[:, sec_col] = [
                self.__draw_sector(lon=a,lat=b,radius =c,azimuth=d, shape_dict=shape_dict, has_z=has_z)
                for a,b,c,d in zip(df[lon], df[lat],df[radius], df[azimuth])]
        return df
#------------主窗体------------
class MyMainWindow(QMainWindow, Ui_MainWindow):
    xiantiaoyanse = 'ffff0000'
    shanquyanse = 'ffff0000'
    def __init__(self, parent=None):
        super(MyMainWindow, self).__init__(parent)
        self.setupUi(self)
        # self.widget.setStyleSheet(self.button_style_widget_bian())

        self.open.clicked.connect(self.openMsg)  # 菜单的点击事件,当点击打开菜单时连接槽函数 openMsg()
        self.comboBox.currentIndexChanged.connect(self.my_comboBox)  # 当下拉索引发生改变时发射信号触发绑定的事件
        self.comboBox_2.currentIndexChanged.connect(self.my_comboBox)
        self.comboBox_3.currentIndexChanged.connect(self.my_comboBox)
        self.comboBox_4.currentIndexChanged.connect(self.my_comboBox)
        self.comboBox_5.currentIndexChanged.connect(self.my_comboBox)
        self.id_box.currentIndexChanged.connect(self.my_comboBox)
        self.fenduan1.currentIndexChanged.connect(self.my_comboBox)

        self.xiantiao.clicked.connect(self.showDialog2)  # 点击弹出颜色窗体
        self.shanqu_2.clicked.connect(self.showDialog1)  # 点击弹出颜色窗体
        # self.shengcheng.clicked.connect(self.strat_kml)  # 点击制作图层开始制作kml
        self.shengcheng.clicked.connect(self.git_canshu)  # 点击制作图层开始制作kml
        self.pushButton.clicked.connect(self.on_pushButton_2_clicked)
        self.pushButton_2.clicked.connect(self.on_pushButton_clicked)
        # 两个按钮,选择一个关闭另一个
        self.radioButton_4.toggled.connect(lambda: self.btnstate1(self.radioButton_4))
        self.radioButton_3.toggled.connect(lambda: self.btnstate1(self.radioButton_3))
        self.shanqu.toggled.connect(lambda: self.btnstate(self.shanqu))
        self.pot.toggled.connect(lambda: self.btnstate(self.pot))
        # self.statusBar.showMessage('制作点方位角可以不选', 0)  # 状态栏本身显示的信息 第二个参数是信息停留的时间,单位是毫秒,默认是0(0表示在下一个操作来临前一直显示)
        self.setWindowFlags(Qt.FramelessWindowHint)  # 无边框模式
        self.setAttribute(Qt.WA_TranslucentBackground)



    # 无边框模式
    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            try:
                self.m_flag = True
                self.m_Position = event.globalPos() - self.pos()  # 获取鼠标相对窗口的位置
                event.accept()
                self.setCursor(QCursor(Qt.OpenHandCursor))  # 更改鼠标图标
            except:
                pass

    def mouseMoveEvent(self, QMouseEvent):
        try:
            if Qt.LeftButton and self.m_flag:
                self.move(QMouseEvent.globalPos() - self.m_Position)  # 更改窗口位置
                QMouseEvent.accept()
        except:
            pass

    def mouseReleaseEvent(self, QMouseEvent):
        try:
            self.m_flag = False
            self.setCursor(QCursor(Qt.ArrowCursor))
        except:
            pass

    # 关闭最小化
    def on_pushButton_clicked(self):
        """
        关闭窗口
        """
        self.close()

    def on_pushButton_2_clicked(self):
        """
        最小化窗口
        """
        self.showMinimized()

    # 无边框模式^^^^^^^^^^^^^^^^^^^^

    def btnstate(self, btn):  # 两个按钮,选择一个关闭另一个
        if btn.text() == "创建扇区":
            if btn.isChecked() == True:
                print(btn.text() " is selected")

        if btn.text() == "创建点":
            if btn.isChecked() == True:
                print(btn.text() " is selected")

    def btnstate1(self, btn):  # 两个按钮,选择一个关闭另一个
        if btn.text() == "kml":
            if btn.isChecked() == True:
                print(btn.text() " is selected")

        if btn.text() == "kmz":
            if btn.isChecked() == True:
                print(btn.text() " is selected")

    def showDialog1(self):  # 颜色按钮的窗体
        col = QColorDialog.getColor()
        if col.isValid():
            self.shanqu_2.setStyleSheet('QWidget QPushButton{background-color:%s}' % col.name())
        rgb1 = col.getRgb()
        gg = simplekml.Color.rgb(rgb1[0], rgb1[1], rgb1[2], rgb1[3])
        self.shanquyanse = gg
        print('之前:', col.name(), '之后:', gg)

    def showDialog2(self):  # 颜色窗体
        col = QColorDialog.getColor()
        if col.isValid():
            self.xiantiao.setStyleSheet('QWidget QPushButton{background-color:%s}' % col.name())
        rgb1 = col.getRgb()
        gg = simplekml.Color.rgb(rgb1[0], rgb1[1], rgb1[2], rgb1[3])

        self.xiantiaoyanse = gg
        print('之前:', col.name(), '之后:', gg)

    # def msg5(self):
    #     QMessageBox.about(self, "标题", "图层制作完成")

    def my_comboBox(self):
        # 标签用来显示选中的文本
        lon_n = self.comboBox.currentText()  # 下拉菜单选择的项目赋值变量
        lat_n = self.comboBox_2.currentText()
        fw_n = self.comboBox_3.currentText()
        jl_df = self.comboBox_4.currentText()
        gaodu_df = self.comboBox_5.currentText()
        id_n = self.id_box.currentText()
        fenduan_id = self.fenduan1.currentText()
        print(id_n, lon_n, lat_n, fw_n, fenduan_id)
        return id_n, lon_n, lat_n, fw_n, fenduan_id
    def openMsg(self):
        try:
            file, ok = QFileDialog.getOpenFileName(self, "打开", "C:/", "CSV files (*.txt , *.csv);;Excel files(*.xlsx , *.xls)")
            Worker.data_name=file
            if file:
                print(0)
                self.comboBox.clear()
                self.comboBox_2.clear()
                self.comboBox_3.clear()
                self.comboBox_4.clear()
                self.comboBox_5.clear()
                self.id_box.clear()
                self.fenduan1.clear()

                self.statusBar.showMessage(file)# 在状态栏显示文件地址
                try:
                    try:
                        data_yy = pd.read_csv(open(file,encoding='gbk'))  # pandas
                        data_yy=data_yy.astype("str")
                        print('gbk格式',data_yy.shape)
                        Worker.data_table1 = data_yy.replace('[:<>\@$!%*#?&      /]', '_', regex=True)
                        print('另个一类', Worker.data_table1.shape)
                        QMessageBox.about(self, "标题", "选择数据成功")
                    except:
                        data_yy = pd.read_csv(open(file))  # pandas
                        data_yy=data_yy.astype("str")
                        Worker.data_table1 = data_yy.replace('[:<>\@$!%*#?&      /]', '_', regex=True)
                        QMessageBox.about(self, "标题", "选择数据成功")
                except:
                    try:
                        data_yy = pd.read_excel(file, encoding='gbk',sheet_name=0)
                        data_yy=data_yy.astype("str")
                        Worker.data_table1 = data_yy.replace('[:<>\@$!%*#?&      /]', '_', regex=True)
                        QMessageBox.about(self, "标题", "选择excel数据成功")
                    except:
                        data_yy = pd.read_excel(file, encoding="utf-8", )
                        data_yy=data_yy.astype("str")
                        Worker.data_table1 = data_yy.replace('[:<>\@$!%*#?&      /]', '_', regex=True)
                        QMessageBox.about(self, "标题", "选择excel数据成功")

                def xxx(ss, vv='ca'):
                    nu_x = 0
                    for x in enumerate(ss):
                        if vv in x[1]:
                            nu_x = x[0]
                            break
                    return nu_x
                self.mulu.setText(file)  # 在文本框中显示文件地址
                lie = data_yy.columns.values  # pandas
                self.comboBox.addItems(lie)  # 增加下拉菜单从列表中
                lon_a = xxx(lie,vv='lon')
                lon_b = xxx(lie, vv='经度')
                xulie_x=max(lon_a,lon_b)
                if xulie_x>0:
                    self.comboBox.setCurrentIndex(xulie_x)
                self.comboBox_2.addItems(lie)  # 增加下拉菜单从列表中
                lat_a = xxx(lie, vv='lat')
                lat_b = xxx(lie, vv='纬度')
                xulie_y = max(lat_a, lat_b)
                if xulie_y > 0:
                    self.comboBox_2.setCurrentIndex(xulie_y)
                self.comboBox_3.addItems(lie)  # 增加下拉菜单从列表中
                fw_x_1 = xxx(lie, vv='方位')
                fw_x_2 = xxx(lie, vv='az')
                fw_x = max(fw_x_1, fw_x_2)
                if xulie_y > 0:
                    self.comboBox_3.setCurrentIndex(fw_x)

                self.comboBox_4.addItems(lie)  # 增加下拉菜单从列表中
                jldf_x_1 = xxx(lie, vv='距离')
                jldf_x_2 = xxx(lie, vv='distance')
                jldf_x = max(jldf_x_1, jldf_x_2)
                if jldf_x > 0:
                    self.comboBox_4.setCurrentIndex(jldf_x)

                self.comboBox_5.addItems(lie)  # 增加下拉菜单从列表中
                gddf_x_1 = xxx(lie, vv='高')
                gddf_x_2 = xxx(lie, vv='hi')
                gddf_x = max(gddf_x_1, gddf_x_2)
                if gddf_x > 0:
                    self.comboBox_5.setCurrentIndex(gddf_x)


                self.id_box.addItems(lie)  # 增加下拉菜单从列表中
                id_x_1 = xxx(lie, vv='CGI')
                id_x_2 = xxx(lie, vv='cgi')
                id_x_3 = xxx(lie, vv='名')
                id_x = max(id_x_1, id_x_2,id_x_3)
                if id_x > 0:
                    self.id_box.setCurrentIndex(id_x)

                self.fenduan1.addItems(lie)  # 增加下拉菜单从列表中
                # combobox1.SelectedIndex = combobox1.Items.IndexOf("xxx");
                # print(MyMainWindow.data_table1.shape)

        except:
            QMessageBox.warning(self, "标题", "选择数据有误")

    def git_canshu(self):

        Worker.lon_n = self.comboBox.currentText()  # 下拉菜单选择的项目赋值变量
        Worker.lat_n = self.comboBox_2.currentText()
        Worker.id_n = self.id_box.currentText()
        Worker.fw_n = self.comboBox_3.currentText()
        Worker.jl_df = self.comboBox_4.currentText()
        Worker.gd_df = self.comboBox_5.currentText()

        # Worker.banjing_n = self.banjing.text()  # 获取单行输入框
        Worker.jia_jiao = self.lineEdit_3.text()  # 获取单行输入框
        Worker.shiye_n = self.lineEdit.text()  # 获取单行输入框
        Worker.xiantiao_kuan = self.kuandu_bian.text()  # 获取单行输入框
        Worker.xiangsu_n = self.lineEdit_2.text()  # 获取单行输入框
        # Worker.gaodu_n = self.lineEdit_4.text()
        Worker.toumingdu = self.horizontalSlider.value()  # 滑动取值spinbox
        Worker.yanse_shanqu = self.shanquyanse
        Worker.yanse_xiantiao = self.xiantiaoyanse
        Worker.fenduan_id = self.fenduan1.currentText()
        Worker.shanqu_is = self.shanqu.isChecked()
        Worker.fenduan_is = self.shanqu_3.isChecked()
        Worker.dian_is = self.pot.isChecked()
        Worker.biaoji_is = self.biaoji.isChecked()
        Worker.biaoji_is2 = self.biaoji2.isChecked()
        Worker.shanquyanse_is =self.biaoji_2.isChecked()
        Worker.xiantiaoyanse_is = self.biaoji_3.isChecked()
        Worker.kml_is = self.radioButton_4.isChecked()
        Worker.kmz_is = self.radioButton_3.isChecked()
        Worker.wugaodu_is = self.wugaodu.isChecked()
        self.jindutiao()

    def jindutiao(self):
        progress = QProgressDialog(self)
        progress.setFixedWidth(600)
        progress.setWindowTitle("请稍等")
        progress.setLabelText("正在操作...")
        progress.setCancelButtonText(None)
        progress.setMinimumDuration(5)
        progress.setWindowModality(Qt.WindowModal)
        progress.setRange(0, 100)

        def gengxin(i):
            if i == -1:
                progress.setRange(0, 0)
            elif i == -3:
                progress.setRange(0, 100)
                progress.setValue(100)
                QMessageBox.warning(self, "标题", "错误信息:经纬度、方位角无特殊字符或者空值,请检查数据")
            elif i == -2:
                progress.setRange(0, 100)
                progress.setValue(100)
                QMessageBox.information(self, "提示", "操作成功")
            elif i <99:
                progress.setValue(i 1)
            else:
                progress.setValue(100)
                # progress.setAutoReset(True)
                # progress.setAutoClose(True)
                QMessageBox.information(self, "提示", "操作成功")
        self.thread_1 = Worker()
        self.thread_1.progressBarValue.connect(gengxin)
        # if progress.wasCanceled():
        #     QMessageBox.warning(self, "提示", "操作失败")
        #     os._exit(0)
        #     progress.close()
        self.thread_1.start()


if __name__ == "__main__":
    QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
    app = QApplication(sys.argv)  # 声明变量
    myWin = MyMainWindow()  # 创建窗口
    myWin1 = Widget()  # 创建窗口2
    myWin_help = Widget_help()  # 创建窗口help
    app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())  # 批量修改样式

    btn = myWin.dianyangshi  # 通过toolButton将两个窗体关联
    btn.clicked.connect(myWin1.show)  # 通过toolButton将两个窗体关联

    btn_help = myWin.toolButton  # 通过toolButton将两个窗体关联
    btn_help.clicked.connect(myWin_help.show)  # 通过toolButton将两个窗体关联

    myWin.show()  # todo 正常比例显示
    sys.exit(app.exec_())  # 应用程序事件循环

标签: python google kML 生成 go

实例下载地址

python生成googleKML工具增强版

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警