Example #1
0
def make_kml(data_t,
             name='红色栅格',
             cc='ff0000ff',
             xiankuan=0,
             namea='grid_id',
             list_data='list_data',
             description='description'):
    style = simplekml.Style()
    #style.linestyle.color = simplekml.Color.changealphaint(150, cc)  # 最终线条上色
    style.polystyle.outline = xiankuan
    style.polystyle.color = simplekml.Color.changealphaint(125, cc)  # 最终形状上色
    lod1 = simplekml.Lod(minlodpixels=3,
                         maxlodpixels=-1,
                         minfadeextent=None,
                         maxfadeextent=None)
    grid_red = kml.newfolder(name=name)
    for grid, list_data, description_str in zip(data_t[namea],
                                                data_t[list_data],
                                                data_t[description]):
        pol_r = grid_red.newpolygon(name=grid, outerboundaryis=list_data[0])
        pol_r.description = description_str
        pol_r.altitudemode = simplekml.AltitudeMode.clamptoground
        lon_dd, lat_dd, lon1_dd, lat1_dd = list_data[1]
        latlonaltbox = simplekml.LatLonAltBox(east=lon_dd,
                                              north=lat_dd,
                                              south=lat1_dd,
                                              west=lon1_dd,
                                              minaltitude=None,
                                              maxaltitude=None,
                                              altitudemode=None)
        pol_r.region.latlonaltbox = latlonaltbox
        pol_r.region.lod = lod1
        pol_r.style = style
Example #2
0
 def _makeKmlRegion(self, level, tileIndex):
     '''Sets up the KML region object for a single tile'''
     # Stop showing the low res tiles when they exceed their natural size
     maxLod = self._tileSize + 128
     if level == 0:  # The highest res tiles stay regardless of zoom level
         maxLod = -1
     return simplekml.Region(
         latlonaltbox=self._getLatLonAltBox(level, tileIndex),
         lod=simplekml.Lod(minlodpixels=128,
                           maxlodpixels=maxLod))  # TODO: Set this?
Example #3
0
    def strat_kml(self):  ##################################################
        try:
            data_yuan = MyMainWindow.data_table1
            if self.shanqu.isChecked() == True and self.biaoji.isChecked(
            ) == True:
                lon_n = self.comboBox.currentText()  # 下拉菜单选择的项目赋值变量
                lat_n = self.comboBox_2.currentText()
                fw_n = self.comboBox_3.currentText()
                id_n = self.id_box.currentText()
                banjing_n = self.banjing.text()  #获取单行输入框
                jia_jiao = self.lineEdit_3.text()  #获取单行输入框
                shiye_n = self.lineEdit.text()  #获取单行输入框
                xiangsu_n = self.lineEdit_2.text()  #获取单行输入框
                gaodu_n = self.lineEdit_4.text()
                toumingdu = self.horizontalSlider.value()  #滑动取值spinbox
                yanse_shanqu = MyMainWindow.shanquyanse
                yanse_xiantiao = MyMainWindow.xiantiaoyanse

                print(lon_n, lat_n, fw_n, id_n, jia_jiao, toumingdu,
                      yanse_shanqu, yanse_xiantiao)
                print(1)
                data_yuan['gaodu'] = int(gaodu_n)
                print(2)
                data_yuan_shi = self.add_sectors(
                    df=data_yuan,
                    coords=[lon_n, lat_n, 'gaodu', fw_n],
                    has_z=True)
                # data_yuan_shi.to_csv('d:/up/shuchu.csv',index=False,encoding = 'gbk')
                ##========================================
                row_table = data_yuan_shi.copy()
                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.color = colour_alpha_x  # 最终线条上色
                style.polystyle.color = colour_alpha_m  # 最终形状上色
                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)

                for i in range(len(row_table.index)):
                    row_1 = row_table.iloc[i, :]
                    df2 = row_1.filter(regex="[^geometry,^lon_n,^lat_n]")
                    id_n_v, polygon1, lon_yuan, lat_yuan, fw_yuan = row_1[[
                        id_n, 'geometry', lon_n, lat_n, fw_n
                    ]]
                    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 是一个扇区

                    # lieming = row_1[['小区中文名','空口上下行业务字节数KByte']]#^^^^^^标注可选择,不选则全部
                    lie_ming = list(df2.index)
                    for i in lie_ming:  # ^^^^^^可选去掉不加标注
                        pol.extendeddata.schemadata.newsimpledata(i, df2[i])
                    pol.extrude = 1  # 高度需添加
                    pol.altitudemode = simplekml.AltitudeMode.relativetoground  # 高度需添加
                    # pol.snippet.maxlines = 1 #名字下面的间隔
                    # pol.snippet.content = "名字下面的文字"
                    lon_b, lat_b = self.point_lon_lat(lon=lon_yuan,
                                                      lat=lat_yuan,
                                                      azimuth=lat_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
                lu_name = MyMainWindow.data_name
                res_kml_name = lu_name.split(".")[0]
                if self.radioButton_4.isChecked() == True:
                    kml.save(res_kml_name + ".kml")
                    print('ok1')
                    QMessageBox.about(self, "标题", "图层制作完成")
                else:
                    kml.save(res_kml_name + ".kmz")
                    print('ok1')
                    QMessageBox.about(self, "标题", "图层制作完成")
            elif self.shanqu.isChecked() == True and self.biaoji.isChecked(
            ) == False:
                """无标注代码后面再加"""
                lon_n = self.comboBox.currentText()  # 下拉菜单选择的项目赋值变量
                lat_n = self.comboBox_2.currentText()
                fw_n = self.comboBox_3.currentText()
                id_n = self.id_box.currentText()
                banjing_n = self.banjing.text()  #获取单行输入框
                jia_jiao = self.lineEdit_3.text()  #获取单行输入框
                shiye_n = self.lineEdit.text()  #获取单行输入框
                xiangsu_n = self.lineEdit_2.text()  #获取单行输入框
                gaodu_n = self.lineEdit_4.text()
                toumingdu = self.horizontalSlider.value()  #滑动取值spinbox
                yanse_shanqu = MyMainWindow.shanquyanse
                yanse_xiantiao = MyMainWindow.xiantiaoyanse

                print(lon_n, lat_n, fw_n, id_n, jia_jiao, toumingdu,
                      yanse_shanqu, yanse_xiantiao)
                print(1)
                data_yuan['gaodu'] = int(gaodu_n)
                print(2)
                data_yuan_shi = self.add_sectors(
                    df=data_yuan,
                    coords=[lon_n, lat_n, 'gaodu', fw_n],
                    has_z=True)
                # data_yuan_shi.to_csv('d:/up/shuchu.csv',index=False,encoding = 'gbk')
                ##========================================
                row_table = data_yuan_shi.copy()
                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.color = colour_alpha_x  # 最终线条上色
                style.polystyle.color = colour_alpha_m  # 最终形状上色
                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)

                for i in range(len(row_table.index)):
                    row_1 = row_table.iloc[i, :]
                    df2 = row_1.filter(regex="[^geometry,^lon_n,^lat_n]")
                    id_n_v, polygon1, lon_yuan, lat_yuan, fw_yuan = row_1[[
                        id_n, 'geometry', lon_n, lat_n, fw_n
                    ]]
                    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 是一个扇区

                    # lieming = row_1[['小区中文名','空口上下行业务字节数KByte']]#^^^^^^标注可选择,不选则全部
                    # lie_ming = list(df2.index)
                    # for i in lie_ming:  # ^^^^^^可选去掉不加标注
                    #     pol.extendeddata.schemadata.newsimpledata(i, df2[i])
                    pol.extrude = 1  # 高度需添加
                    pol.altitudemode = simplekml.AltitudeMode.relativetoground  # 高度需添加
                    # pol.snippet.maxlines = 1 #名字下面的间隔
                    # pol.snippet.content = "名字下面的文字"
                    lon_b, lat_b = self.point_lon_lat(lon=lon_yuan,
                                                      lat=lat_yuan,
                                                      azimuth=lat_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
                lu_name = MyMainWindow.data_name
                res_kml_name = lu_name.split(".")[0]
                if self.radioButton_4.isChecked() == True:
                    kml.save(res_kml_name + ".kml")
                    print('ok1')
                    QMessageBox.about(self, "标题", "图层制作完成")

                else:
                    kml.save(res_kml_name + ".kmz")
                    print('ok1')
                    QMessageBox.about(self, "标题", "图层制作完成")
            elif self.pot.isChecked() == True:  #制作点''''''
                kml = simplekml.Kml()
                row_table = MyMainWindow.data_table1.copy()
                lon_n = self.comboBox.currentText()  # 下拉菜单选择的项目赋值变量
                lat_n = self.comboBox_2.currentText()
                id_n = self.id_box.currentText()
                shiye_n = self.lineEdit.text()  #获取单行输入框
                xiangsu_n = self.lineEdit_2.text()  #获取单行输入框
                style = simplekml.Style()
                pot_ss = MyMainWindow.k
                zz = pot_style.dict[pot_ss]
                style.iconstyle.icon.href = zz
                print(pot_ss, zz)
                lod_p = simplekml.Lod(minlodpixels=xiangsu_n,
                                      maxlodpixels=-1,
                                      minfadeextent=None,
                                      maxfadeextent=None)
                for i in range(len(row_table.index)):
                    row_v = row_table.iloc[i, :]
                    mingcheng, lon_p, lat_p = row_v[[
                        id_n, lon_n, lat_n
                    ]]  # +++++++++++++++++++++++名称和经纬度必须
                    # -----------添加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
                    # lie_ming = list(row_v.index)  # 标注全部列
                    # for i in lie_ming:
                    #     pnt.extendeddata.schemadata.newsimpledata(i, row_v[i])
                lu_name = MyMainWindow.data_name
                res_kml_name = lu_name.split(".")[0]
                if self.radioButton_4.isChecked() == True:
                    kml.save(res_kml_name + "_pot.kml")
                    print('ok1')
                    QMessageBox.about(self, "标题", "图层制作完成")
                else:
                    kml.save(res_kml_name + "_pot.kmz")
                    print('ok1')
                    QMessageBox.about(self, "标题", "图层制作完成")
        except:
            QMessageBox.warning(self, "标题", "请核对经纬度方位角不为空,或者特殊字符")
Example #4
0
                                          xunits=simplekml.Units.fraction,
                                          yunits=simplekml.Units.fraction)
    screen2.size.x = 0.85
    screen2.size.y = 0.08
    screen2.size.xunits = simplekml.Units.fraction
    screen2.size.yunits = simplekml.Units.fraction
    print 'Screen Overlay completed'


## GENERAL REQUIREMENTS FOR SHAPE FILES AND KML FILES ##
if vchoice == 'Y':
    ## CREATING A SIMPLEKML OBJECT ##
    kml = simplekml.Kml()
    box = simplekml.Box(north=46.86, south=4.32, east=-57.523, west=-90)
    lod = simplekml.Lod(minlodpixels=128,
                        maxlodpixels=-1,
                        minfadeextent=0,
                        maxfadeextent=0)
    reg = simplekml.Region(box, lod)
    c = interpolate(float(len(levels)), palette)
    hex = []
    for i in c:
        hex.append(rgb_to_hex(i))
    createcolorbar(hex, levels)
    screen(kml)
else:
    ## DEFINING SPATIAL REFERENCE ##
    crs = {
        'no_defs': True,
        'ellps': 'WGS84',
        'datum': 'WGS84',
        'proj': 'longlat'
Example #5
0
def make_parent(con, ground_boxes):
    # add tiles
    kmls = find_kml('./temp/kml')
    cur = con.cursor()

    # make the parent
    parent = simplekml.Kml()
    camera = simplekml.Camera(
        latitude=52.39296111111111,
        longitude=13.012166666666667,
        altitude=10000,
        altitudemode=simplekml.AltitudeMode.relativetoground,
        tilt=0)
    parent.camera = camera

    for tile in kmls:
        # get bb
        tile_id = re.findall('([0-91].*)_', tile)
        statement = get_sql('sql/get_tile_bb.sql')
        statement = statement % tile_id[0]
        cur.execute(statement)
        the_str = cur.fetchone()

        # get the coords only
        coords = make_coords(the_str[0])

        # add region and link
        coords = np.array(coords).astype(float)
        east = max(coords[:, 0])
        west = min(coords[:, 0])
        north = max(coords[:, 1])
        south = min(coords[:, 1])

        box = simplekml.LatLonAltBox(minaltitude=0,
                                     maxaltitude=20,
                                     altitudemode='clampToGround',
                                     east=east,
                                     west=west,
                                     north=north,
                                     south=south)
        the_link = parent.newnetworklink(
            name=tile,
            region=simplekml.Region(box, lod=simplekml.Lod(minlodpixels=2400)))
        the_link.link.href = tile

    # add ground kmls
    for the_set in ground_boxes:
        the_id = the_set[1]
        coords = make_coords(the_set[0])

        # add region and link
        coords = np.array(coords).astype(float)
        east = max(coords[:, 0])
        west = min(coords[:, 0])
        north = max(coords[:, 1])
        south = min(coords[:, 1])

        box = simplekml.LatLonAltBox(minaltitude=0,
                                     maxaltitude=20,
                                     altitudemode='clampToGround',
                                     east=east,
                                     west=west,
                                     north=north,
                                     south=south)
        the_link = parent.newnetworklink(
            name='ground_%s' % the_id,
            region=simplekml.Region(box, lod=simplekml.Lod(minlodpixels=360)))
        the_link.link.href = 'kml/ground/%s.kml' % the_id

    cur.close()
    make_screen(parent)
    parent.save('./temp/parent.kml')
    def updateKml(self, *args, **kwargs):
        print("updateKml: args=%s kwargs=%s" % (args, kwargs))
        
        if not self._need_update:
            print("No update needed...")
            return nupstring
        
        
        print("Update needed, regenerating...")
        
 
        kml = simplekml.Kml()
        
        pnt = kml.newpoint(name="Machu Picchu, Peru")
        ##pnt.coordinates = simplekml.Coordinates(-72.516244)
        pnt.lookat = simplekml.LookAt(gxaltitudemode=simplekml.GxAltitudeMode.relativetoseafloor,
                              latitude=-13.209676, longitude=-72.503364, altitude=0.0,
                              range=14794.882995, heading=71.131493, tilt=66.768762)
                              
        # Generate data for states
        for state in geo_state["features"]:
 
            val, col, desc = self.mapData(data_state[state["properties"]["STATE"]], indexmap_state)
            
            fold = kml.newfolder(name = state["properties"]["NAME"])
            
            geo = fold.newmultigeometry()

            geo.name = state["properties"]["NAME"]

            box = simplekml.LatLonBox(north=-1000, south=1000, west=1000, east=-1000)

            if state["geometry"]["type"] == "Polygon":
                p = geo.newpolygon()
                p.altitudemode = "relativeToGround"
                p.extrude=1
                p.outerboundaryis = self.addZ(state["geometry"]["coordinates"][0], (((self._scale * val)/1000)*2692)+308)
                update_box(box, state["geometry"]["coordinates"][0])
            else:     
                for poly in state["geometry"]["coordinates"]:
                    p = geo.newpolygon()
                    p.altitudemode = "relativeToGround"
                    p.extrude=1
                    p.outerboundaryis = self.addZ(poly[0], (((self._scale * val)/1000)*2692)+308)
                    update_box(box, poly[0])

            switchsize = 600
            fadesize = 100

            geo.region = simplekml.Region(box, simplekml.Lod(minlodpixels = 0, maxlodpixels = switchsize, minfadeextent = 0, maxfadeextent = fadesize))

            # Network link for counties
            clink = kml.newnetworklink(name = "Counties for %s" % geo.name)
            clink.region = simplekml.Region(box, simplekml.Lod(minlodpixels = switchsize - fadesize, maxlodpixels = -1, minfadeextent = fadesize, maxfadeextent = 0))
            clink.link.href="http://127.0.0.1:20605/state?state=%s" % state["properties"]["STATE"]
            clink.link.refreshmode = "onInterval"
            clink.link.refreshinterval = 2


            geo.style.polystyle.outline = 0

            # Map data to color
            geo.description = desc
            geo.style.polystyle.color = col

            geo = None


        stateskml = kml
        
        self._need_update = False        
        
        return stateskml.kml(False)