当前位置: 首页>>代码示例>>Python>>正文


Python KML_ElementMaker.end方法代码示例

本文整理汇总了Python中pykml.factory.KML_ElementMaker.end方法的典型用法代码示例。如果您正苦于以下问题:Python KML_ElementMaker.end方法的具体用法?Python KML_ElementMaker.end怎么用?Python KML_ElementMaker.end使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pykml.factory.KML_ElementMaker的用法示例。


在下文中一共展示了KML_ElementMaker.end方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import end [as 别名]

#.........这里部分代码省略.........
    except:
        print "%%%%%%%%%%"
        print "Error:\nThe input file is not geocoded\n"
        print "%%%%%%%%%%"
        Usage()
        sys.exit(1)

    #######################################################
    ###################  Output KMZ  ######################

    ############### Make PNG file
    print "Making png file ..."
    length = data.shape[0]
    width = data.shape[1]
    fig = plt.figure()
    fig = plt.figure(frameon=False)
    # fig.set_size_inches(width/1000,length/1000)
    ax = plt.Axes(fig, [0.0, 0.0, 1.0, 1.0])
    ax.set_axis_off()
    fig.add_axes(ax)

    aspect = width / (length * 1.0)
    # ax.imshow(data,aspect='normal')

    try:
        ax.imshow(data, aspect="normal", vmax=Vmax, vmin=Vmin)
    except:
        ax.imshow(data, aspect="normal")

    ax.set_xlim([0, width])
    ax.set_ylim([length, 0])

    # figName = k[0]+'.png'
    figName = outName + ".png"
    plt.savefig(figName, pad_inches=0.0, dpi=dpi)
    # plt.show()

    ############### Making colorbar
    pc = plt.figure(figsize=(1, 4))
    axc = pc.add_subplot(111)
    cmap = mpl.cm.jet
    norm = mpl.colors.Normalize(vmin=Vmin * 1000, vmax=Vmax * 1000)
    clb = mpl.colorbar.ColorbarBase(axc, cmap=cmap, norm=norm, orientation="vertical")
    clb.set_label("mm/yr")
    pc.subplots_adjust(left=0.25, bottom=0.1, right=0.4, top=0.9)
    pc.savefig("colorbar.png", transparent=True, dpi=300)

    ############## Generate KMZ file
    print "generating kml file"
    doc = KML.kml(KML.Folder(KML.name("PySAR product")))
    slc = KML.GroundOverlay(
        KML.name(figName),
        KML.Icon(KML.href(figName)),
        KML.TimeSpan(KML.begin("2003"), KML.end("2010")),
        KML.LatLonBox(KML.north(str(North)), KML.south(str(South)), KML.east(str(East)), KML.west(str(West))),
    )
    doc.Folder.append(slc)

    #############################
    print "adding colorscale"
    latdel = North - South
    londel = East - West
    slc1 = KML.GroundOverlay(
        KML.name("colorbar"),
        KML.Icon(KML.href("colorbar.png")),
        KML.altitude("9000"),
        KML.altitudeMode("absolute"),
        KML.LatLonBox(
            KML.north(str(North - latdel / 2.0 + 0.5)),
            KML.south(str(South + latdel / 2.0 - 0.5)),
            KML.east(str(West - 0.2 * londel)),
            KML.west(str(West - 0.4 * londel)),
        ),
    )
    doc.Folder.append(slc1)

    #############################
    from lxml import etree

    kmlstr = etree.tostring(doc, pretty_print=True)
    # kmlname=k[0]+'.kml'
    kmlname = outName + ".kml"
    print "writing " + kmlname
    kmlfile = open(kmlname, "w")
    kmlfile.write(kmlstr)
    kmlfile.close()

    # kmzName = k[0]+'.kmz'
    kmzName = outName + ".kmz"
    print "writing " + kmzName
    # cmdKMZ = 'zip ' + kmzName +' '+ kmlname +' ' + figName
    cmdKMZ = "zip " + kmzName + " " + kmlname + " " + figName + " colorbar.png"
    os.system(cmdKMZ)

    cmdClean = "rm " + kmlname
    os.system(cmdClean)
    cmdClean = "rm " + figName
    os.system(cmdClean)
    cmdClean = "rm colorbar.png"
    os.system(cmdClean)
开发者ID:,项目名称:,代码行数:104,代码来源:


注:本文中的pykml.factory.KML_ElementMaker.end方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。