How to use pykml - 10 common examples

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 bonzanini / Book-SocialMediaMiningPython / Chap09 / micro_geo2kml.py View on Github external
return coords


if __name__ == '__main__':
    parser = get_parser()
    args = parser.parse_args()

    doc = mf2py.parse(url=args.url)
    coords = get_geo(doc)
    folder = KML.Folder()
    for item in coords[:args.n]:
        lat, lon = item['geo'].split('; ')
        place_coords = ','.join([lon, lat])
        place = KML.Placemark(
            KML.name(item['name']),
            KML.Point(KML.coordinates(place_coords))
        )
        folder.append(place)

    with open(args.output, 'w') as fout:
        xml = etree.tostring(folder, pretty_print=True).decode('utf8')
        fout.write(xml)
github pykml / pykml / src / examples / Tours / working_files / tour_from_linestring.py View on Github external
# get the coordinate string of the first KML coordinate element
coord_str = str(
    linestring_doc.getroot().find(".//{http://www.opengis.net/kml/2.2}coordinates")
).strip()

for vertex in coord_str.split(' '):
    (lon,lat,alt) = vertex.split(',')
    flyto = GX.FlyTo(
        GX.duration(2),
        GX.flyToMode("smooth"),
        KML.Camera(
          KML.longitude(lon),
          KML.latitude(lat),
          KML.altitude(0),
          KML.heading(-129.7),
          KML.tilt(90.0),
          KML.altitudeMode("relativeToGround"),
        )
    )
    tour_doc[gxns+"Tour"].Playlist.append(flyto)

assert Schema('kml22gx.xsd').validate(tour_doc)
print etree.tostring(tour_doc, pretty_print=True)

# output a KML file (named based on the Python script)
outfile = file(__file__.rstrip('.py')+'.kml','w')
outfile.write(etree.tostring(tour_doc, pretty_print=True))
github bonzanini / Book-SocialMediaMiningPython / Chap09 / micro_geo2kml.py View on Github external
'name': d['properties']['name'][0],
                'geo': d['properties']['geo'][0]['value']
            }
            coords.append(data)
        except (IndexError, KeyError):
            pass
    return coords


if __name__ == '__main__':
    parser = get_parser()
    args = parser.parse_args()

    doc = mf2py.parse(url=args.url)
    coords = get_geo(doc)
    folder = KML.Folder()
    for item in coords[:args.n]:
        lat, lon = item['geo'].split('; ')
        place_coords = ','.join([lon, lat])
        place = KML.Placemark(
            KML.name(item['name']),
            KML.Point(KML.coordinates(place_coords))
        )
        folder.append(place)

    with open(args.output, 'w') as fout:
        xml = etree.tostring(folder, pretty_print=True).decode('utf8')
        fout.write(xml)
github Wireless-Innovation-Forum / Spectrum-Access-System / src / data / uscabdry.py View on Github external
# 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"
    ),
  )
)

for ls in lineStrings:
  print 'coordinates=[%s ... %s] (%d)' % (ls[0], ls[len(ls)-1], len(ls))
  print 'Have latitude %s' % ls[0].split(',')[1]
github pykml / pykml / src / examples / Tours / circle_around_landmarks.py View on Github external
targetId=feature['name'].replace(' ','_')
              )
            )
          )
        )
    )
    
    tour_doc.Document[gxns+"Tour"].Playlist.append(GX.Wait(GX.duration(2.0)))
    
    tour_doc.Document[gxns+"Tour"].Playlist.append(
        GX.AnimatedUpdate(
          GX.duration(2.0),
          KML.Update(
            KML.targetHref(),
            KML.Change(
              KML.Placemark(
                GX.balloonVisibility(0),
                targetId=feature['name'].replace(' ','_')
              )
            )
          )
        )
    )
    # fly to a space viewpoint
    tour_doc.Document[gxns+"Tour"].Playlist.append(
      GX.FlyTo(
        GX.duration(5),
        GX.flyToMode("bounce"),
        KML.LookAt(
          KML.longitude(feature['lon']),
          KML.latitude(feature['lat']),
          KML.altitude(0),
github bonzanini / Book-SocialMediaMiningPython / Chap09 / micro_geo2kml.py View on Github external
except (IndexError, KeyError):
            pass
    return coords


if __name__ == '__main__':
    parser = get_parser()
    args = parser.parse_args()

    doc = mf2py.parse(url=args.url)
    coords = get_geo(doc)
    folder = KML.Folder()
    for item in coords[:args.n]:
        lat, lon = item['geo'].split('; ')
        place_coords = ','.join([lon, lat])
        place = KML.Placemark(
            KML.name(item['name']),
            KML.Point(KML.coordinates(place_coords))
        )
        folder.append(place)

    with open(args.output, 'w') as fout:
        xml = etree.tostring(folder, pretty_print=True).decode('utf8')
        fout.write(xml)
github Wireless-Innovation-Forum / Spectrum-Access-System / src / data / uscabdry.py View on Github external
)

for ls in lineStrings:
  print 'coordinates=[%s ... %s] (%d)' % (ls[0], ls[len(ls)-1], len(ls))
  print 'Have latitude %s' % ls[0].split(',')[1]
  if float(ls[0].split(',')[1]) > 50:
    geo_name = 'AK-CA Boundary'
  else:
    geo_name = 'CONUS-CA Boundary'
  pm = KML.Placemark(
    KML.name('%s' % geo_name),
    KML.styleUrl('#stl'),
    KML.LineString(
      KML.extrude(1),
      KML.altitudeMode('clampToGround'),
      KML.coordinates(' '.join(ls))
    )
  )
  doc.Document.append(pm)

# For debugging: optionally include the paths of the original source data.
#ns = 100
#for ls in coordx:
#  print 'x coordinates=[%s ... %s] (%d)' % (ls[0], ls[len(ls)-1], len(ls))
#  pm = KML.Placemark(
#    KML.name('%d' % ns),
#    KML.styleUrl('#stlx'),
#    KML.LineString(
#      KML.extrude(1),
#      KML.altitudeMode('clampToGround'),
#      KML.coordinates(' '.join(ls))
#    )
github Wireless-Innovation-Forum / Spectrum-Access-System / src / data / uscabdry.py View on Github external
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"
    ),
  )
)

for ls in lineStrings:
  print 'coordinates=[%s ... %s] (%d)' % (ls[0], ls[len(ls)-1], len(ls))
  print 'Have latitude %s' % ls[0].split(',')[1]
  if float(ls[0].split(',')[1]) > 50:
    geo_name = 'AK-CA Boundary'
  else:
    geo_name = 'CONUS-CA Boundary'
  pm = KML.Placemark(
    KML.name('%s' % geo_name),
github insarlab / MintPy / mintpy / save_kmz.py View on Github external
# colobar location
    if loc.split()[0] == 'lower':
        oy, sy = '0', '0'
    elif loc.split()[0] == 'upper':
        oy, sy = '1', '1'
    if loc.split()[1] == 'left':
        ox, sx = '0', '0'
    elif loc.split()[1] == 'right':
        ox, sx = '1', '1'

    # generate KML screen overlay object
    cbar_overlay = KML.ScreenOverlay(
        KML.name('colorbar'),
        KML.Icon(
            KML.href("{}".format(os.path.basename(cbar_file))),
            KML.viewBoundScale(0.75)
        ),
        KML.overlayXY(x=ox, y=oy, xunits="fraction", yunits="fraction"),
        KML.screenXY(x=sx, y=sy, xunits="fraction", yunits="fraction"),
        KML.size(x="0", y="250", xunits="pixel", yunits="pixel"),
        KML.rotation(0),
        KML.visibility(1),
        KML.open(0)
    )
    #print('add colorbar.')
    return cbar_overlay
github Wireless-Innovation-Forum / Spectrum-Access-System / src / data / usborder.py View on Github external
print 'Reversing non-CCW ring'
    r = list(reversed(ls))
    lineStrings[k] = r

# Cleanup the coordinates to be rounded correctly with 9 precision numbers
# (ie about 0.1mm)
for k, ls in enumerate(lineStrings):
  new_ls = []
  for c in ls:
    xy = c.split(',')
    new_ls.append('%.9f,%.9f,0' % (float(xy[0]), float(xy[1])))
  lineStrings[k] = new_ls

# Create output KML  
doc = KML.kml(
  KML.Document(
    KML.name('US Area'),
    KML.Style(
      KML.LineStyle(
        KML.color('ff0000ff'),
        KML.width(2)
      ),
      KML.PolyStyle(
        KML.color('66000066')
      ),
      id="stl"
    ),
    KML.Style(
      KML.LineStyle(
        KML.color('ff00ffff'),
        KML.width(4)
      ),