Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
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")
pm = KML.Placemark(
KML.name("Magnitude={0}".format(row['Magnitude'])),
KML.TimeStamp(
KML.when(timestamp.strftime('%Y-%m-%dT%H:%M:%SZ')),
),
KML.styleUrl(
"#earthquake-style-{thresh}".format(
thresh=int(float(row['Magnitude']))
)
),
makeExtendedDataElements(row),
KML.Point(
KML.coordinates("{0},{1}".format(row["Lon"],row["Lat"]))
)
)
doc.Folder.append(pm)
# check if the schema is valid
from pykml.parser import Schema
schema_gx = Schema("kml22gx.xsd")
schema_gx.assertValid(doc)
print etree.tostring(doc, pretty_print=True)
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))
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!"),
GX.Playlist(
GX.FlyTo(
GX.duration(3),
GX.flyToMode("bounce"),
KML.Camera(
KML.longitude(170.157),
KML.latitude(-43.671),
KML.altitude(9700),
KML.heading(-6.333),
KML.tilt(33.5),
def AddPlacemarkAndZone(doc, site):
name = site[0]
lat = float(site[1]) + float(site[2])/60.0 + float(site[3])/3600.0;
if site[4] == 'S':
lat = -lat
lng = float(site[5]) + float(site[6])/60.0 + float(site[7])/3600.0;
if site[8] == 'W':
lng = -lng
print 'Adding placemark for %s at (%f, %f)' % (name, lat, lng)
pm = KML.Placemark(
KML.name(name),
KML.styleUrl('#pm'),
KML.Point(
KML.coordinates('%f,%f,0' % (lng, lat))
)
)
doc.append(pm)
zone = KML.Placemark(
KML.name('%s zone' % name),
KML.styleUrl('#ts'),
KML.Polygon(
KML.extrude(0),
KML.altitudeMode('clampToGround')
)
)
poly = zone.Polygon
d = float(zone_radius) / float(earth_radius)
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)
has_data = True
network_folder.append(folder)
doc.append(network_folder)
if has_data:
if outfile and hasattr(outfile, 'write'):
target = outfile
elif outfile:
target = open(outfile, 'w')
else:
snippet = "t1 = %g, t2 = %g\n" % (t1,t2) + \
"x1 = %g, y1 = %g\n" % (x1,y1)
snippet_str = "<b>%s</b>]]>" % snippet
# ExtendedData is used in BalloonStyle.text() fields.
placemark = KML.Placemark(
KML.name("%s %d" % (plotfigure.kml_gauge_name,gaugeno)),
KML.Snippet(snippet_str),
KML.styleUrl(chr(35) + "gauge_style"),
KML.ExtendedData(
KML.Data(KML.value(figname),name="pngfile"),
KML.Data(KML.value("%g" % t1),name="t1"),
KML.Data(KML.value("%g" % t2),name="t2"),
KML.Data(KML.value("%g" % x1),name="x1"),
KML.Data(KML.value("%g" % y1),name="y1")),
KML.Point(
KML.coordinates(coords)))
doc_gauges.Document.append(placemark)
kml_file = open(gauge_kml_file,'wt')
kml_file.write('\n')
kml_text = etree.tostring(etree.ElementTree(doc_gauges),
pretty_print=True).decode()
kml_text = kml_text.replace('>','>') # Needed for CDATA blocks
kml_text = kml_text.replace('<','<')
kml_file.write(kml_text)
kml_file.close()
# -------------- add gauge image and KML files -----------------
if row.has_key(description_field):
pm.append(
KML.description(clean_xml_string(row[description_field]))
)
else:
desc = '
)
),
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