How to use the pykml.factory.KML_ElementMaker.Icon 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 insarlab / MintPy / mintpy / save_kmz.py View on Github external
label=label)

    # 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 isce-framework / isce2 / contrib / stack / stripmapStack / saveKml.py View on Github external
South, North, West, East = get_lat_lon(file)  
  ############## Generate kml file
  print ('generating kml file')
  doc = KML.kml(KML.Folder(KML.name(os.path.basename(file))))
  slc = KML.GroundOverlay(KML.name(os.path.basename(img)),KML.Icon(KML.href(os.path.basename(img))),\
                          KML.TimeSpan(KML.begin(),KML.end()),\
                          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.ScreenOverlay(KML.name('colorbar'),KML.Icon(KML.href(os.path.basename(colorbarImg))),
        KML.overlayXY(x="0.0",y="1",xunits="fraction",yunits="fraction",),
        KML.screenXY(x="0.0",y="1",xunits="fraction",yunits="fraction",),
        KML.rotationXY(x="0.",y="1.",xunits="fraction",yunits="fraction",),
        KML.size(x="0",y="0.3",xunits="fraction",yunits="fraction",),
      )


  doc.Folder.append(slc1)

  

  #############################
  from lxml import etree
  kmlstr = etree.tostring(doc, pretty_print=True)
  print (kmlstr)
  kmlname = file + '.kml'
github insarlab / MintPy / mintpy / save_kmz.py View on Github external
out_name_base = os.path.splitext(out_file)[0]
    data_png_file = out_name_base + '.png'
    print('writing {} with dpi={}'.format(data_png_file, inps.fig_dpi))
    plt.savefig(data_png_file, pad_inches=0.0,
                transparent=True, dpi=inps.fig_dpi)    

    # 2.3 Generate KML file
    proj_name = metadata.get('PROJECT_NAME', 'InSAR_MintPy')
    doc = KML.kml(KML.Folder(KML.name(proj_name)))

    # Add data png file
    img_name = os.path.splitext(os.path.basename(data_png_file))[0]
    img = KML.GroundOverlay(
        KML.name(img_name),
        KML.Icon(
            KML.href(os.path.basename(data_png_file))
        ),
        KML.altitudeMode('clampToGround'),
        KML.LatLonBox(KML.north(str(north)),
                      KML.east(str(east)),
                      KML.south(str(south)),
                      KML.west(str(west)))
    )
    doc.Folder.append(img)

    # Add colorbar png file
    cbar_file = '{}_cbar.png'.format(out_name_base)
    cbar_overlay = generate_cbar_element(cbar_file,
                                         vmin=inps.vlim[0],
                                         vmax=inps.vlim[1],
                                         unit=inps.disp_unit,
github pykml / pykml / src / examples / data_conversion / example_csv_to_kml.py View on Github external
[2,'ff000000'],
    [3,'ffff0000'],
    [4,'ff00ff55'],
    [5,'ffff00aa'],
    [6,'ff00ffff'],
    [7,'ff0000ff'],
]

# create a series of Icon Styles
for threshold,color in iconstyles:
    doc.append(
        KML.Style(
            KML.IconStyle(
                KML.color(color),
                KML.scale(threshold/2),
                KML.Icon(
                    KML.href("http://maps.google.com/mapfiles/kml/shapes/earthquake.png"),
                ),
                KML.hotSpot(x="0.5",y="0",xunits="fraction",yunits="fraction"),
            ),
            balloonstyle,
            id="earthquake-style-{threshold}".format(threshold=threshold),
        )
    )

doc.append(KML.Folder())

# read in a csv file, and create a placemark for each record
url="http://earthquake.usgs.gov/earthquakes/catalogs/eqs7day-M2.5.txt"
fileobject = urllib2.urlopen(url)
for row in csv.DictReader(fileobject):
    timestamp = datetime.strptime(row["Datetime"], "%A, %B %d, %Y %H:%M:%S %Z")
github clawpack / visclaw / src / python / visclaw / plotpages.py View on Github external
# ------------------- create subdirs with images ----------------------
            if (not plotfigure.kml_tile_images):
                print("KML ===> Adding %s.png to %s.kmz" \
                    " file (no tiling)" % (fname_str,plotdata.kml_index_fname))

                # The 'etree'
                doc_notile = KML.kml(KML.Document())

                c = TS[i].getchildren()
                desc = "t = %g\n" % frametimes[frameno] + c[0]

                fstr = "%s.png" % fname_str
                doc_notile.Document.append(
                    KML.GroundOverlay(
                        KML.name(fstr),
                        KML.Icon(KML.href(fstr)),
                        KML.LatLonBox(
                            KML.north(ur[1]),
                            KML.south(lr[1]),
                            KML.east(ur[0]),
                            KML.west(ul[0]))))

                # Easier to just move into this directory to construct everything
                os.chdir(fig_dir)

                shutil.rmtree(fname_str,True)  # remove directory and ignore errors
                os.mkdir(fname_str)

                # PNG file gets moved into subdirectory and will eventually be
                # zipped into KMZ file.
                if plotdata.html:
                    shutil.copy(os.path.join("..","%s.png" % fname_str),fname_str)
github pykml / pykml / src / examples / KmlReference / animatedupdate_example.py View on Github external
* The  element should not be a subelement of .
* The  element should be the first subelement of 
'''

from lxml import etree
from pykml.parser import Schema
from pykml.factory import KML_ElementMaker as KML
from pykml.factory import GX_ElementMaker as GX

doc = KML.kml(
  KML.Document(
    KML.name("gx:AnimatedUpdate example"),
    KML.Style(
      KML.IconStyle(
        KML.scale(1.0),
        KML.Icon(
          KML.href("http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png"),
        ),
        id="mystyle"
      ),
      id="pushpin"
    ),
    KML.Placemark(
      KML.name("Pin on a mountaintop"),
      KML.styleUrl("#pushpin"),
      KML.Point(
        KML.coordinates(170.1435558771009,-43.60505741890396,0)
      ),
      id="mountainpin1"
    ),
    GX.Tour(
      KML.name("Play me!"),
github arthur-e / unmixing / unmixing / lsma.py View on Github external
print('One or more endmembers may be photometric shade')

        if data_dict is None:
            data_dict = {
                'wavelength': range(1, len(coords) + 1),
                'wavelength units': 'MNF Component',
                'z plot titles': ['', '']
            }

        ico = 'http://maps.google.com/mapfiles/kml/paddle/%i.png'
        pmarks = []
        for i, pair in enumerate(coords):
            pmarks.append(KML.Placemark(
                KML.Style(
                    KML.IconStyle(
                        KML.Icon(KML.href(ico % (i + 1))))),
                KML.name(data_dict['wavelength units'] + ' %d' % (i + 1)),
                KML.Point(KML.coordinates('%f,%f' % pair))))

        doc = KML.kml(KML.Folder(*pmarks))
        with open(path, 'wb') as source:
            source.write(etree.tostring(doc, pretty_print=True))