Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'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))
## 2. Create KML Document
kml_document = KML.Document()
# 2.1 Set and normalize colormap to defined vlim
colormap = mpl.cm.get_cmap(inps.colormap)
norm = mpl.colors.Normalize(vmin=inps.vlim[0], vmax=inps.vlim[1])
# 2.2 Set number of pixels to use
num_pixel = int(length / step) * int(width / step)
msg = "create KML doc for box {}/{}: {}".format(i+1, num_box, box)
msg += ", step: {} pixels, {} pixels in total ...".format(step, num_pixel)
print(msg)
# 2.3 Create data folder for all points
data_folder = KML.Folder(KML.name("Data"))
for i in range(0, length, step):
for j in range(0, width, step):
if mask[i, j]: # add point if it's not marked as masked out
lat = lats[i, j]
lon = lons[i, j]
row = rows[i, j]
col = cols[i, j]
ts = ts_data[:, i, j]
v = vel[i, j]
vc = vel_c[i, j]
vstd = vel_std[i, j]
tcoh = temp_coh[i, j]
# 2.3.1 Create KML icon style element
style = KML.Style(
KML.IconStyle(
output_queue.task_done()
except Queue.Empty:
break
# clear the referenced list and replace contents with new hit_regions
del prior_hit_regions[:]
prior_hit_regions += hit_regions
print "Tiles in %d regions at level %d" % (len(netlinks), levelno)
if len(netlinks) == 0:
return None
else:
outfilename = os.path.join(output_dir, "%02d"%level.level+".kml")
with open(outfilename, 'w') as outfile:
folder = KML.Folder(KML.name( "%02d" % level.level) )
for netlink in netlinks:
folder.append(netlink)
kml = KML.kml(folder)
assert_valid(kml)
outfile.write( etree.tostring( kml, pretty_print=True ) )
return make_netlink(os.path.basename(outfilename), None, name="%02d"%level.level)
print('Cannot find reference point info!')
width = int(metadata['WIDTH'])
length = int(metadata['LENGTH'])
ax.set_xlim([0, width])
ax.set_ylim([length, 0])
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)
KML.Style(
KML.IconStyle(
KML.color('FF1400FF'),
KML.scale('1.25'),
KML.Icon(
KML.href('http://maps.google.com/mapfiles/kml/shapes/open-diamond.png')
)
),
id = 'star'
),
)
for network in list_of_networks:
network_folder=KML.Folder(KML.name("Network Code: "+str(network.code)+" reportnum: "+network.reportnum))
for shot_line in network.shot_lines:
folder = KML.Folder(KML.name("ShotLine "+str(shot_line.name[-3:])))
for shot in shot_line.shots:
place_marker=(KML.Placemark(
KML.styleUrl("#star"),
KML.name(network.code+'.'+str(shot.shot_id)),
KML.description('Shot size: '+str(shot.mag)+' '+shot.mag_units+'\n Shot Time: '+shot.start_time+'\n\n'+shot.description),
KML.Point(
KML.coordinates(str(shot.lon)+','+str(shot.lat)+','+str(shot.elev))
)
))
folder.append(place_marker)
network_folder.append(folder)
doc.append(network_folder)
target = open(outfile, 'w')
target.write(etree.tostring(etree.ElementTree(doc),pretty_print=True))
return
print('re-wrapping data to {} cm/year for color coding'.format(inps.vlim))
##--------- Create root KML file with network links to data KML files --------------##
kml_root_doc = KML.Document()
# 1 Create Overlay element for colorbar
cbar_overlay = generate_cbar_element(cbar_file=inps.cbar_file,
vmin=inps.vlim[0],
vmax=inps.vlim[1],
cmap=inps.colormap)
kml_root_doc.append(cbar_overlay)
# 2 Generate the placemark for the Reference Pixel
ref_point = create_reference_point_element(inps, lats, lons, ts_obj)
print('add reference point.')
ref_folder = KML.Folder(KML.name("ReferencePoint"))
ref_folder.append(ref_point)
kml_root_doc.append(ref_folder)
# 3 Create data folder to contain actual data elements
net_link1 = generate_network_link(inps, ts_obj, step=inps.steps[0], lod=(0, inps.lods[0]))
net_link2 = generate_network_link(inps, ts_obj, step=inps.steps[1], lod=(inps.lods[0], inps.lods[1]))
net_link3 = generate_network_link(inps, ts_obj, step=inps.steps[2], lod=(inps.lods[1], inps.lods[2]))
# 3.3 Append network links to data folder
data_folder = KML.Folder(KML.name("Data"))
data_folder.append(net_link1)
data_folder.append(net_link2)
data_folder.append(net_link3)
kml_root_doc.append(data_folder)
tiles = search_tiles_by_region(plate, region)
if len(tiles) == 0:
return None
#if len(tiles) > options.max_features: # TODO: Implement (or remove) max features / netlinks
t = tiles[0]
region.tile_degree_size = math.sqrt(t.degree_width * t.degree_height) # this is actually consistent for the whole level.
for t in tiles:
goverlay = t.kml_overlay()
goverlays.append(goverlay)
region.latlon_bbox.expand(t.west,t.south)
region.latlon_bbox.expand(t.east,t.north)
folder = KML.Folder()
for goverlay in goverlays:
folder.append(goverlay)
kml = KML.kml(folder)
assert_valid(kml)
kmlstr = etree.tostring(kml, pretty_print=True)
kmzfile = zipfile.ZipFile(os.path.join(output_dir, region.kmz_filename), 'w')
kmzfile.writestr('doc.kml', kmlstr)
kmzfile.close()
return region
KML.width('4'),
),
KML.PolyStyle(
KML.color('400000ff'),
),
id="style-highlight",
),
#Time Folders will be appended here
),
)
try:
s = db.Session()
for time in s.query(db.Time).all():
# create a folder for the time
timefld = KML.Folder(
# KML.Style(
# KML.ListStyle(
# KML.listItemType('checkHideChildren'),
# KML.bgColor('00ffffff'),
# KML.maxSnippetLines('2'),
# ),
# ),
KML.name(time.as_xml_date()),
# placemarks will be appended here
)
for val in time.value:
poly_desc = (
''
''
''
''<table border="1"><tbody><tr><th>Variable</th><td>{variable}</td></tr><tr><th>Date/Time (UTC)</th><td>{time}</td></tr></tbody></table>