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


Python KML_ElementMaker.begin方法代码示例

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


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

示例1: _buildSwath

# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import begin [as 别名]
def _buildSwath(line, data, polyalt=5000):
    """
    So far, an ugly hack on building the KML elements
    """

    # split input line
    line = line.split()

    # add polygon altitude to end of line tuple
    line.append(polyalt)

    # parse the time element of the line
    dt = _makeTime(line[1])
    date = dt.date()
    time = dt.time()

    # define time format string
    format = "%Y-%m-%dT%H:%M:%SZ"

    # ensure longitude is between -/+ 180 degrees
    for i in [4, 6, 8, 10]:
        if float(line[i]) > 180.0:
            val = float(line[i]) - 360.0
            line[i] = str(val)

    # build the vertices of the swath (remember the first vertex has to
    # repeat at the end.
    vertices = []
    for c in [3, 5, 7, 9, 3, 5]:
        vertices.append(",".join([line[i] for i in [c + 1, c, -1]]))

    # get center of swath
    clat, clng = _swathCenter(line)

    # create an image placemark for the kml
    image = KML.Placemark(
        # define name based on experiment and filter/channel
        KML.name('{}: {}'.format(data['experiment'], data['filter'])),
        # define description
        # TODO: come up with a more flexible way of doing this...
        KML.description(
            'Orbit no.:                          {}\n'.format(
                data['orbit']),
            'Pericenter time (UTC):              {}\n'.format(
                data['pericenter time'].replace('_', ' ')),
            'First image time (UTC):             {}\n'.format(
                data['first image time'].replace('_', ' ')),
            'First image time (from pericenter): {}\n'.format(
                data['first image time from pericenter'].replace('_',
                                                                 ' ')),
            'Last image time (UTC):              {}\n'.format(
                data['last image time'].replace('_', ' ')),
            'Last image time (from pericenter):  {}\n\n'.format(
                data['last image time from pericenter'].replace('_', ' ')),
            'Image sequence:                     {}\n'.format(line[0]),
            'Image date:                         {}\n'.format(date),
            'Image time:                         {}\n'.format(time),
            'Orbit no.:                          {}\n\n'.format(
                data['orbit']),
            'Pericentre relative time:           {}\n'.format(
                line[2].replace('_', ' ')),
            'Duration:                           {}\n\n'.format(line[20]),
            'S/C altitude:                       {}\n'.format(line[21]),
            'S/C latitude:                       {}\n'.format(line[22]),
            'S/C longitude:                      {}\n'.format(line[23]),
            'S/C target elevation:               {}\n'.format(line[24]),
            'S/C target azimuth:                 {}\n\n'.format(line[25]),
            'Reflection Angle:                   {}\n'.format(line[27]),
            'Sun target elevation:               {}\n'.format(line[28]),
            'Sun target azimuth:                 {}\n'.format(line[29]),
            'Target phase:                       {}\n'.format(line[30]),
            'Target elongation:                  {}\n'.format(line[31]),
            'Local Time:                         {}\n'.format(line[32]),
            'Image smear:                        {}\n'.format(line[33]),
            'Mercury True Anomaly:               {}\n'.format(line[35])
        ),
        # specify appearance time
        KML.TimeSpan(
            #KML.begin(str(tempTime))
            KML.begin(dt.strftime(format))
        ),
        # the style for this swath has been mapped in <swath>stylemap
        KML.styleUrl('#{}stylemap'.format(data['filter'])),
        #KML.styleUrl('#{}1'.format(data['filter'])),
        # define where the 'eye' looks when this swath is double clicked
        KML.LookAt(
            KML.longitude(clng),
            KML.latitude(clat),
            KML.altitude('5000'),
            KML.heading('0'),
            KML.tilt('30'),
            KML.roll('0'),
            KML.altitudeMode('relativeToGround'),
            KML.range('1500000')
        ),
        # defined the geometry object that will hold the swath polygon
        KML.MultiGeometry(
            # defined the swath polygon
            KML.Polygon(
                #KML.tessellate('1'),
#.........这里部分代码省略.........
开发者ID:johnnycakes79,项目名称:pyops,代码行数:103,代码来源:maps.py

示例2: main

# 需要导入模块: from pykml.factory import KML_ElementMaker [as 别名]
# 或者: from pykml.factory.KML_ElementMaker import begin [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.begin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。