當前位置: 首頁>>代碼示例>>Python>>正文


Python Kml.newdocument方法代碼示例

本文整理匯總了Python中simplekml.Kml.newdocument方法的典型用法代碼示例。如果您正苦於以下問題:Python Kml.newdocument方法的具體用法?Python Kml.newdocument怎麽用?Python Kml.newdocument使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在simplekml.Kml的用法示例。


在下文中一共展示了Kml.newdocument方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: create_kml

# 需要導入模塊: from simplekml import Kml [as 別名]
# 或者: from simplekml.Kml import newdocument [as 別名]
def create_kml(start_dt, traces):
    mintime = datetime(2100,1,1)
    maxtime = datetime(1901,1,1)
    bbox_nw = (sys.maxint, sys.maxint)
    bbox_se = (-sys.maxint, -sys.maxint)

    kml = Kml(name="Tracer")
    doc = kml.newdocument()

    fol = doc.newfolder(name="Traces")

    i = 0
    for id_, trace in traces:
        trace = list(trace)
        trk = fol.newgxtrack(name='Trace id: %s' % id_)

        times = [start_dt + timedelta(seconds=int(p['time'])) for p in trace]
        trk.newwhen([format_date(t) for t in times])

        places = [
            (float(p['lon']), float(p['lat']), 0)
            for p in trace
        ]
        trk.newgxcoord(places)

        m = min(places, key=operator.itemgetter(0))
        if m[0] < bbox_nw[0] and not (m[0] == 0.0 or m[1] == 0.0):
            bbox_nw = m[:2]

        m = max(places, key=operator.itemgetter(0))
        if m[0] > bbox_se[0] and not (m[0] == 0.0 or m[1] == 0.0):
            bbox_se = m[:2]

        mintime = min([mintime] + times)
        maxtime = max([maxtime] + times)

        trk.altitudemode = 'relativeToGround'

        trk.stylemap.normalstyle.iconstyle.icon.href = 'http://earth.google.com/images/kml-icons/track-directional/track-0.png'
        trk.stylemap.normalstyle.linestyle.color = CATEGORICAL_COLORS[i % len(CATEGORICAL_COLORS)]
        trk.stylemap.normalstyle.linestyle.width = 5
        trk.stylemap.normalstyle.labelstyle.scale = 1
        trk.stylemap.highlightstyle.iconstyle.icon.href = 'http://earth.google.com/images/kml-icons/track-directional/track-0.png'
        trk.stylemap.highlightstyle.iconstyle.scale = 1.2
        trk.stylemap.highlightstyle.linestyle.color = CATEGORICAL_COLORS[i % len(CATEGORICAL_COLORS)]
        trk.stylemap.highlightstyle.linestyle.width = 8

        i += 1

    doc.lookat.gxtimespan.begin = format_date(mintime)
    doc.lookat.gxtimespan.end   = format_date(maxtime)
    doc.lookat.longitude = bbox_nw[0] + (bbox_se[0] - bbox_nw[0]) / 2
    doc.lookat.latitude = bbox_nw[1] + (bbox_se[1] - bbox_nw[1]) / 2
    doc.lookat.range = 13000.00

    #doc.lookat.longitude, doc.lookat.latitude = list(list(traces)[0][1])[0]

    return kml.kml()
開發者ID:jazzido,項目名稱:tracer,代碼行數:60,代碼來源:tracer.py

示例2: from_locations

# 需要導入模塊: from simplekml import Kml [as 別名]
# 或者: from simplekml.Kml import newdocument [as 別名]
    def from_locations(self, doc_name, track_name, locations):
        when = {}
        for l in locations:
            try:
                if(l.bssid not in when):
                    when[l.bssid]=[]
                when[l.bssid].append({"time": l.time.strftime("%Y-%m-%dT%H:%M:%SZ-05:00"), "coords": (l.lon,l.lat)})
            except:
                continue

        kml = Kml(name=doc_name)
        doc = kml.newdocument(name=track_name)
開發者ID:jhannah01,項目名稱:wifinets,代碼行數:14,代碼來源:utils.py

示例3: write_track_kml

# 需要導入模塊: from simplekml import Kml [as 別名]
# 或者: from simplekml.Kml import newdocument [as 別名]
def write_track_kml(csvreader):
    """
    Inputs: csv contains lon/lat
    Output:	glider track kml file
    """
    coord = []
    timerange = []

    lat_f = int(cfg.get(section1, "LAT_COLUMN"))
    lon_f = int(cfg.get(section1, "LON_COLUMN"))
    date_f = int(cfg.get(section1, "DATE_COLUMN"))
    date_fmt = cfg.get(section1, "DATE_FORMAT")
    kml_dir = cfg.get(section1, "KML_DIR")
    mission_date = cfg.get(section1, "MISSION_START_DATE")
    organization = cfg.get(section1, "ORGANIZATION")
    vehicle_name = cfg.get(section1, "VEHICLE_NAME")
    kml_title = cfg.get(section1, "KML_DOC_TITLE")
    kml_lookat_lon = float(cfg.get(section1, "KML_LOOKAT_LON"))
    kml_lookat_lat = float(cfg.get(section1, "KML_LOOKAT_LAT"))
    kml_lookat_range = float(cfg.get(section1, "KML_LOOKAT_RANGE"))
    kml_cdata_title = cfg.get(section1, "KML_CDATA_TITLE")
    plot_url = cfg.get(section1, "PLOT_URL")
    plot_width = int(cfg.get(section1, "PLOT_WIDTH"))
    plot_height = int(cfg.get(section1, "PLOT_HEIGHT"))
    plot_temp = cfg.get(section1, "PLOT_TEMP")
    plot_oxyg = cfg.get(section1, "PLOT_OXYG")
    plot_sali = cfg.get(section1, "PLOT_SALI")
    plot_chlo = cfg.get(section1, "PLOT_CHLO")
    plot_cdom = cfg.get(section1, "PLOT_CDOM")
    icon_url = cfg.get(section1, "ICON_URL")
    icon_normal_scale = cfg.get(section1, "ICON_NORMAL_SCALE")
    icon_normal_color = cfg.get(section1, "ICON_NORMAL_COLOR")
    icon_normal_width = cfg.get(section1, "ICON_NORMAL_WIDTH")
    icon_highlight_url = cfg.get(section1, "ICON_HIGHLIGHT_URL")
    icon_highlight_scale = cfg.get(section1, "ICON_HIGHLIGHT_SCALE")
    icon_highlight_color = cfg.get(section1, "ICON_HIGHLIGHT_COLOR")
    icon_highlight_width = cfg.get(section1, "ICON_HIGHLIGHT_WIDTH")
    path_line_color = cfg.get(section1, "PATH_LINE_COLOR")
    path_line_width = int(cfg.get(section1, "PATH_LINE_WIDTH"))

    csvheader = cfg.get(section1, "CSV_HEADER")
    if csvheader == "YES":
        csvreader.next()
    else:
        pass

    for row in csvreader:
        coord.append((row[lon_f - 1], row[lat_f - 1], 0.0))  # -1 for python order
        timestamp = time.strptime(row[date_f - 1], date_fmt)
        kmltime = time.strftime("%Y-%m-%dT%H:%M:%SZ", timestamp)  # KML requires specific time format
        timerange.append(kmltime)  # time stamp

    # This constructs the KML document from the CSV file.
    kml = Kml(name="%s %s" % (organization, vehicle_name))
    doc = kml.newdocument(name="%s" % kml_title, snippet=Snippet(timerange[0]))
    doc.lookat.gxtimespan.begin = timerange[0]
    doc.lookat.gxtimespan.end = timerange[-1]
    doc.lookat.longitude = kml_lookat_lon
    doc.lookat.latitude = kml_lookat_lat
    doc.lookat.range = kml_lookat_range
    # Create a folder
    ge_dir = doc.newfolder(name="Tracks")
    # Create a schema for extended data: heart rate, cadence and power
    schema = kml.newschema()

    # Create a new track in the folder
    trk = ge_dir.newgxtrack(name="%s %s" % (organization, vehicle_name))
    desc1 = "<![CDATA[\n%s<br />\n<br />\n" % kml_cdata_title
    desc2 = "<a href='%s/glider.html' target='_blank'>Link to Plot</a><br />\n" % plot_url
    desc_temp = "<img src='%s/%s' height='%d' width='%d' /><br />\n" % (plot_url, plot_temp, plot_height, plot_width)
    desc_oxyg = "<img src='%s/%s' height='%d' width='%d' /><br />\n" % (plot_url, plot_oxyg, plot_height, plot_width)
    desc_sali = "<img src='%s/%s' height='%d' width='%d' /><br />\n" % (plot_url, plot_sali, plot_height, plot_width)
    desc_chlo = "<img src='%s/%s' height='%d' width='%d' /><br />\n" % (plot_url, plot_chlo, plot_height, plot_width)
    desc_cdom = "<img src='%s/%s' height='%d' width='%d' /><br />\n" % (plot_url, plot_cdom, plot_height, plot_width)
    desc3 = "]]>\n"
    trk.description = desc1 + desc2 + desc_temp + desc_oxyg + desc_sali + desc_chlo + desc_cdom + desc3
    # Apply the above schema to this track
    trk.extendeddata.schemadata.schemaurl = schema.id
    # Add all information to the track
    trk.newwhen(timerange)  # Each item in the give nlist will become a new <when> tag
    trk.newgxcoord(coord)  # Ditto

    # Style
    trk.stylemap.normalstyle.iconstyle.icon.href = icon_url
    trk.stylemap.normalstyle.iconstyle.scale = icon_normal_scale
    trk.stylemap.normalstyle.linestyle.color = icon_normal_color
    trk.stylemap.normalstyle.linestyle.width = icon_normal_width
    trk.stylemap.highlightstyle.iconstyle.icon.href = icon_highlight_url
    trk.stylemap.highlightstyle.iconstyle.scale = icon_highlight_scale
    trk.stylemap.highlightstyle.linestyle.color = icon_highlight_color
    trk.stylemap.highlightstyle.linestyle.width = icon_highlight_width

    # Create a path line
    gpath = kml.newlinestring(name="%s %s" % (organization, vehicle_name))
    gpath.description = trk.description
    gpath.timespan.begin = timerange[0]
    gpath.timespan.end = ""
    gpath.coords = coord
    gpath.style.linestyle.color = path_line_color
    gpath.style.linestyle.width = path_line_width
#.........這裏部分代碼省略.........
開發者ID:GCOOS,項目名稱:csv2kml-for-gliders-2013-2014,代碼行數:103,代碼來源:csv2kml_glider.py

示例4: Kml

# 需要導入模塊: from simplekml import Kml [as 別名]
# 或者: from simplekml.Kml import newdocument [as 別名]
coord = [(-122.207881,37.371915,156.000000),
    (-122.205712,37.373288,152.000000),
    (-122.204678,37.373939,147.000000),
    (-122.203572,37.374630,142.199997),
    (-122.203451,37.374706,141.800003),
    (-122.203329,37.374780,141.199997),
    (-122.203207,37.374857,140.199997)]

cadence = [86, 103, 108, 113, 113, 113, 113]
heartrate = [181, 177, 175, 173, 173, 173, 173]
power = [327.0, 177.0, 179.0, 162.0, 166.0, 177.0, 183.0]

# Create the KML document
kml = Kml(name="Tracks", open=1)
doc = kml.newdocument(name='GPS device', snippet=Snippet('Created Wed Jun 2 15:33:39 2010'))
doc.lookat.gxtimespan.begin = '2010-05-28T02:02:09Z'
doc.lookat.gxtimespan.end = '2010-05-28T02:02:56Z'
doc.lookat.longitude = -122.205544
doc.lookat.latitude = 37.373386
doc.lookat.range = 1300.000000

# Create a folder
fol = doc.newfolder(name='Tracks')

# Create a schema for extended data: heart rate, cadence and power
schema = kml.newschema()
schema.newgxsimplearrayfield(name='heartrate', type=Types.int, displayname='Heart Rate')
schema.newgxsimplearrayfield(name='cadence', type=Types.int, displayname='Cadence')
schema.newgxsimplearrayfield(name='power', type=Types.float, displayname='Power')
開發者ID:andreamad8,項目名稱:SIR_MODEL,代碼行數:31,代碼來源:KML.py

示例5: Kml

# 需要導入模塊: from simplekml import Kml [as 別名]
# 或者: from simplekml.Kml import newdocument [as 別名]
"""
The very basics of simplekml.
"""

from __future__ import unicode_literals
import os
from simplekml import Kml, ColorMode, AltitudeMode, Style

# Create an instance of Kml
kml = Kml(name="Basics", open=1)

# Create a new document
doc = kml.newdocument(name="A Document")

# Create a nested document
nestdoc = doc.newdocument()
nestdoc.name = "A Nested Document"
nestdoc.description = "\u2013 This is the nested document's description with unicode."

# Create a new folder at the top level
fol = kml.newfolder()
fol.name = "A Folder"
fol.description = "Description of a folder"

# Some sub folders
fol = fol.newfolder(name='A Nested Folder', description="Description of a nested folder")
fol = kml.newfolder(name='Point Tests', description="Description of Point Folder")

# A folder containing points with style
stpnt = fol.newpoint(name="Cape Town Stadium", description='The Cape Town stadium built for the 2010 world cup soccer.', coords=[(18.411102, -33.903486)])
vapnt = fol.newpoint()
開發者ID:PseudoAj,項目名稱:simplekml,代碼行數:33,代碼來源:E01+Basics.py


注:本文中的simplekml.Kml.newdocument方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。