How to use the pykml.factory.KML_ElementMaker.kml function in pykml

To help you get started, we’ve selected a few pykml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PX4 / Firmware / Tools / sdlog2 / geo_tag_images.py View on Github external
def gen_kml(self):
        """
        Generate a KML file with keypoints on the locations of the pictures, including height
        :return:
        """
        style_dot = "sn_shaded_dot"
        style_path = "red_path"

        doc = KML.kml(
            KML.Document(
                KML.Name("GPS of the images"),
                KML.Style(
                    KML.IconStyle(
                        KML.scale(0.4),
                        KML.Icon(
                            KML.href(
                                "http://maps.google.com/mapfiles/kml/shapes/shaded_dot.png")
                        ),
                    ),
                    id=style_dot,
                ),
                KML.Style(
                    KML.LineStyle(
                        KML.color('7f0000ff'),
                        KML.width(6),
github insarlab / MintPy / mintpy / save_kmz_timeseries.py View on Github external
def write_network_link_file(region_docs, ts_obj, box_list, lod, net_link_file):
    """Write 1) the list of KML.Document() into data KML file and 2) the root kml file for the list"""

    ## 1. Create directory to store regioalized KML data files
    links_dir = os.path.splitext(net_link_file)[0]
    if not os.path.isdir(links_dir):
        os.makedirs(links_dir)
    print("create KML region links directory: {}".format(os.path.basename(links_dir)))

    ## 2. Create root KML element and KML Document element
    kml = KML.kml()
    kml_document = KML.Document()

    ## 3. Generate a new network link element for each region
    for num, (region_doc, box) in enumerate(zip(region_docs, box_list)):
        region_kml_file = os.path.join(links_dir, "region_{}.kml".format(num))

        ## 3.1 Write the first region_document to a file and move it to the proper subdircetory
        kml_1 = KML.kml()
        kml_1.append(region_doc)
        with open(region_kml_file, 'w') as f:
            f.write(etree.tostring(kml_1, pretty_print=True).decode('utf-8'))

        ## 3.2 Flatten lats and lons data
        lats, lons = flatten_lat_lon(box, ts_obj)

        ## 3.3 Define new NetworkLink element
github Wireless-Innovation-Forum / Spectrum-Access-System / src / data / resample_uscabdry.py View on Github external
'..', '..', 'data', 'fcc')

# Read input KML as dict of LineString
input_file = os.path.join(data_dir, input_kml)
uscabdry = zones._ReadKmlBorder(input_file)

# Resample the LineStrings
uscabdry_fine = {}
for name, ls in uscabdry.items():
  uscabdry_fine[name] = ResampleUsCanadaBorderLineString(ls, step_meters)
  print '  segment %s: Before %d After %d' % (
      name, len(ls.xy[0]), len(uscabdry_fine[name].xy[0]))


# Build the output KML
doc = KML.kml(
  KML.Document(
    KML.name('US-Canada Border'),
    KML.Style(
      KML.LineStyle(
        KML.color('ffff00ff'),
        KML.width(3)
      ),
      id="stl"
    ),
    KML.Style(
      KML.LineStyle(
        KML.color('00ffff00'),
        KML.width(15)
      ),
      id="stlx"
    ),
github Wireless-Innovation-Forum / Spectrum-Access-System / src / data / uscabdry.py View on Github external
doc = ReadKML(os.path.join(dataDir, 'uscabdry.kmz'))
segments = list(doc.Folder.Document)
coordinateLists = []
for seg in segments:
  lineString = ConvertSegmentToLineString(seg)
  coordinateLists.append(lineString)

# Note: this deep copy is for debugging purposes: to add the source data
# to the output KML file for comparison to the derived data.
coordx = copy.deepcopy(coordinateLists)

consolidatedStrings = ConsolidateLists(coordinateLists)
lineStrings = SpliceLists(consolidatedStrings)


doc = KML.kml(
  KML.Document(
    KML.name('US-Canada Border'),
    KML.Style(
      KML.LineStyle(
        KML.color('ff0000ff'),
        KML.width(5)
      ),
      id="stl"
    ),
    KML.Style(
      KML.LineStyle(
        KML.color('0000ffff'),
        KML.width(15)
      ),
      id="stlx"
    ),
github clawpack / visclaw / src / python / visclaw / plotpages.py View on Github external
"span.title {font-weight:bold;font-size:12pt} " + \
                "" + \
                "%s" % basehref + \
                "<center><span class="\&quot;title\&quot;">$[name]</span></center>" + \
                "<pre>" + \
                "Time     : t1 = $[t1], t2 = $[t2]\n" + \
                "Location : x1 = $[x1], y1 = $[y1]\n" + \
                "</pre>" + \
                "<center><img src="\&quot;$[pngfile]\&quot;/" style="\&quot;width:500\&quot;"></center>" + \
                "<pre><b>File : $[pngfile]</b></pre><b>"

        # the 'text' tag will replace Placemark description
        bstyle = KML.text("" % btext)

        # Start builing KML document
        doc_gauges = KML.kml(KML.Document())

        # Only one style for all of the gauges
        doc_gauges.Document.append(KML.Style(
            KML.BalloonStyle(bstyle),
            id="gauge_style"))

        # Loop over all gauges
        for gnum,gauge in enumerate(gauges):
            gaugeno = int(gauge[0])
            if plotdata.print_gaugenos != 'all':
                if gaugeno not in plotdata.print_gaugenos:
                    #print('+++ skipping gauge %i, not in print_gaugenos' % gaugeno)
                    continue # to next gauge
            t1,t2 = gauge[3:5]
            x1,y1 = gauge[1:3]
            if plotdata.kml_map_topo_to_latlong is not None:</b>
github clawpack / visclaw / src / python / visclaw / plotpages.py View on Github external
kml_text = etree.tostring(etree.ElementTree(doc_frames[i][j]),
                                                pretty_print=True)
            kml_frame_file.write(kml_text.decode())
            kml_frame_file.close()

    # Print out level files containing time stamps and references to frame files
    for i in range(0,maxlevels+1-level_base):
        kml_level_file = open(os.path.join(kml_dir,level_dir,level_files[i]+".kml"),'w')
        kml_level_file.write('\n')
        kml_text = etree.tostring(etree.ElementTree(doc_levels[i]),
                                                pretty_print=True)
        kml_level_file.write(kml_text.decode())
        kml_level_file.close()

    # Folders in top level file 'levels.kml'
    doc_levels_top = KML.kml(KML.Document())
    for i in range(0,maxlevels+1-level_base):
        level_file_name = "level_" + str(i+level_base).rjust(2,'0')
        f = KML.Folder(KML.name("Level " + str(i+level_base)))
        f.append(KML.NetworkLink(
            KML.name("Frames"),
            KML.Link(
                KML.href(os.path.join(level_dir,level_file_name + ".kml")))))

        doc_levels_top.Document.append(f)

    kml_levels = open(os.path.join(kml_dir,level_kml_file),'wt')
    kml_levels.write('\n')
    kml_text = etree.tostring(etree.ElementTree(doc_levels_top),
                                    pretty_print=True).decode()
    kml_levels.write(kml_text)
    kml_levels.close()
github clawpack / visclaw / src / python / visclaw / plotpages.py View on Github external
if i == 0:
                vis = 0  # Don't show first level
            else:
                vis = 1

            N = KML.NetworkLink(
                KML.name("Frame %s" % str(frameno).rjust(4,'0')),
                KML.visibility(vis),
                deepcopy(TS[j]),
                KML.Link(
                    KML.href(os.path.join(level_files[i],frame_file_name))))
            doc_levels[i].Document.append(deepcopy(N))


            # Create files in each subdirectory
            doc_frames[i][j] = KML.kml(KML.Document())
            doc_frames[i][j].Document.append(deepcopy(styles[i]))

    print("     Re-reading output files to get patch information")
    print(" ")
    for j in range(0,numframes):
        frameno = framenos[j]

        framesolns = []
        # loop over all outdirs:
        if len(plotdata._outdirs) == 0:
            plotdata._outdirs = [plotdata.outdir]

        for outdir in plotdata._outdirs:
            framesolns.append(plotdata.getframe(frameno, outdir))

        if type(framesolns) is not list:
github clawpack / visclaw / src / python / visclaw / sample.py View on Github external
from lxml import etree
from pykml.factory import KML_ElementMaker as KML
from pykml.factory import ATOM_ElementMaker as ATOM
from pykml.factory import GX_ElementMaker as GX

fileout = open('googleearth.kml','w')
fileout.write('\n')
framenos = 10

midnight = datetime.datetime.combine( datetime.date.today(), datetime.time() )
seconds = datetime.timedelta( seconds=234 )
time = midnight + seconds
time.strftime( '%H:%M:%S' )

doc = KML.kml(
KML.Document(
KML.Folder()))

for i in range(1,framenos+1):
    doc.Document.Folder.append(
        KML.GroundOverlay(
            KML.TimeSpan(
                KML.begin('2013-10-02T00:00:00Z', time),
                KML.end('2013-10-02T00:01:00Z', time),
            ),
            KML.drawOrder(i)
        )
    )

fileout.write(etree.tostring(etree.ElementTree(doc),pretty_print=True))
#print etree.tostring(etree.ElementTree(doc),pretty_print=True)