本文整理匯總了Python中simplekml.Kml.newlinestring方法的典型用法代碼示例。如果您正苦於以下問題:Python Kml.newlinestring方法的具體用法?Python Kml.newlinestring怎麽用?Python Kml.newlinestring使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類simplekml.Kml
的用法示例。
在下文中一共展示了Kml.newlinestring方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: exportToKml2
# 需要導入模塊: from simplekml import Kml [as 別名]
# 或者: from simplekml.Kml import newlinestring [as 別名]
def exportToKml2() :
# KML
kml = Kml()
for aGroupedWayKey in subRoutes :
aGroupedWay = subRoutes[aGroupedWayKey][0]
lineNames = ','.join(aGroupedWay.lines)
coords = list()
for aNodeKey in aGroupedWay.nodesList :
if type(aNodeKey) is str :
aNode = nodesDict[aNodeKey]
lat = aNode.lat
lon = aNode.lon
elif type(aNodeKey) is OsmNode:
lat = aNodeKey.lat
lon = aNodeKey.lon
else :
lat = aNodeKey[0]
lon = aNodeKey[1]
coords.append((lon,lat))
lin = kml.newlinestring(name="Pathway", description='-', coords= coords)
r = lambda: random.randint(0,255)
randomColor = '#ff%02X%02X%02X' % (r(),r(),r()) #random ARGB color
lin.style.linestyle.color = randomColor
lin.style.linestyle.width= 10 # 10 pixels
kml.save("singlestyle.kml")
示例2: exportToKml
# 需要導入模塊: from simplekml import Kml [as 別名]
# 或者: from simplekml.Kml import newlinestring [as 別名]
def exportToKml() :
# KML
kml = Kml()
for aMergedWayTupleKey in tramRoutes :
aMergedWayTuple = tramRoutes[aMergedWayTupleKey]
aMergedWay = aMergedWayTuple[1]
lineNames = ','.join(aMergedWayTuple[0])
coords = list()
for aCoordTuple in aMergedWay :
lat = aCoordTuple[0]
lon = aCoordTuple[1]
coords.append((lon,lat))
lin = kml.newlinestring(name="Pathway", description='-', coords= coords)
r = lambda: random.randint(0,255)
randomColor = '#ff%02X%02X%02X' % (r(),r(),r())
lin.style.linestyle.color = randomColor
lin.style.linestyle.width= 10 # 10 pixels
kml.save("singlestyle.kml")
示例3:
# 需要導入模塊: from simplekml import Kml [as 別名]
# 或者: from simplekml.Kml import newlinestring [as 別名]
# A normal Point with both a LabelStyle and IconStyle
pnt = kml.newpoint(name="Kirstenbosch Normal", description="A style map.", coords=[(18.431486,-33.988)])
pnt.labelstyle.color = 'ff0000ff'
pnt.labelstyle.scale = 2 # Text twice as big
pnt.labelstyle.color = "ffff0000"
pnt.iconstyle.color = 'ffff0000' # Blue
pnt.iconstyle.scale = 3 # Icon thrice as big
pnt.iconstyle.icon.href = 'http://maps.google.com/mapfiles/kml/shapes/info-i.png' # Culry 'information i
# A Point with a styleMap. The Text changes from blue to red on mouse over.
pnt = kml.newpoint(name="Kirstenbosch StyleMap", coords=[(18.432314,-33.988862)])
pnt.stylemap.normalstyle.labelstyle.color = 'ffff0000'
pnt.stylemap.highlightstyle.labelstyle.color = 'ff0000ff'
# A red thick LineString
lin = kml.newlinestring(name="Pathway", description="A pathway in Kirstenbosch",
coords=[(18.43312,-33.98924), (18.43224,-33.98914), (18.43144,-33.98911), (18.43095,-33.98904)])
lin.linestyle.color = Color.red # Red
lin.linestyle.width = 10 # 10 pixels
# A Polygon with a hole. Half invisible.
pol = kml.newpolygon(name="Atrium Garden",
outerboundaryis=[(18.43348,-33.98985), (18.43387,-33.99004262216968), (18.43410,-33.98972), (18.43371,-33.98952), (18.43348,-33.98985)],
innerboundaryis=[(18.43360,-33.98982), (18.43386,-33.98995), (18.43401,-33.98974), (18.43376,-33.98962), (18.43360,-33.98982)])
pol.polystyle.color = '990000ff' # Red
pol.polystyle.outline = 0
# A Point showing off a BalloonStyle
pnt = kml.newpoint(name="BallonStyle", coords=[(18.429191, -33.987286)])
pnt.balloonstyle.text = "These are trees and this text is blue with a green background."
pnt.balloonstyle.bgcolor = Color.lightgreen
pnt.balloonstyle.textcolor = Color.rgb(0, 0, 255)
示例4: write_track_kml
# 需要導入模塊: from simplekml import Kml [as 別名]
# 或者: from simplekml.Kml import newlinestring [as 別名]
def write_track_kml(csvreader):
"""
Inputs: csv contains lon/lat
Output: glider track kml file
"""
coord = []
timerange = []
lat_f = int(cfg.get(section1, "LAT_COLUMN"))
lon_f = int(cfg.get(section1, "LON_COLUMN"))
date_f = int(cfg.get(section1, "DATE_COLUMN"))
date_fmt = cfg.get(section1, "DATE_FORMAT")
kml_dir = cfg.get(section1, "KML_DIR")
mission_date = cfg.get(section1, "MISSION_START_DATE")
organization = cfg.get(section1, "ORGANIZATION")
vehicle_name = cfg.get(section1, "VEHICLE_NAME")
kml_title = cfg.get(section1, "KML_DOC_TITLE")
kml_lookat_lon = float(cfg.get(section1, "KML_LOOKAT_LON"))
kml_lookat_lat = float(cfg.get(section1, "KML_LOOKAT_LAT"))
kml_lookat_range = float(cfg.get(section1, "KML_LOOKAT_RANGE"))
kml_cdata_title = cfg.get(section1, "KML_CDATA_TITLE")
plot_url = cfg.get(section1, "PLOT_URL")
plot_width = int(cfg.get(section1, "PLOT_WIDTH"))
plot_height = int(cfg.get(section1, "PLOT_HEIGHT"))
plot_temp = cfg.get(section1, "PLOT_TEMP")
plot_oxyg = cfg.get(section1, "PLOT_OXYG")
plot_sali = cfg.get(section1, "PLOT_SALI")
plot_chlo = cfg.get(section1, "PLOT_CHLO")
plot_cdom = cfg.get(section1, "PLOT_CDOM")
icon_url = cfg.get(section1, "ICON_URL")
icon_normal_scale = cfg.get(section1, "ICON_NORMAL_SCALE")
icon_normal_color = cfg.get(section1, "ICON_NORMAL_COLOR")
icon_normal_width = cfg.get(section1, "ICON_NORMAL_WIDTH")
icon_highlight_url = cfg.get(section1, "ICON_HIGHLIGHT_URL")
icon_highlight_scale = cfg.get(section1, "ICON_HIGHLIGHT_SCALE")
icon_highlight_color = cfg.get(section1, "ICON_HIGHLIGHT_COLOR")
icon_highlight_width = cfg.get(section1, "ICON_HIGHLIGHT_WIDTH")
path_line_color = cfg.get(section1, "PATH_LINE_COLOR")
path_line_width = int(cfg.get(section1, "PATH_LINE_WIDTH"))
csvheader = cfg.get(section1, "CSV_HEADER")
if csvheader == "YES":
csvreader.next()
else:
pass
for row in csvreader:
coord.append((row[lon_f - 1], row[lat_f - 1], 0.0)) # -1 for python order
timestamp = time.strptime(row[date_f - 1], date_fmt)
kmltime = time.strftime("%Y-%m-%dT%H:%M:%SZ", timestamp) # KML requires specific time format
timerange.append(kmltime) # time stamp
# This constructs the KML document from the CSV file.
kml = Kml(name="%s %s" % (organization, vehicle_name))
doc = kml.newdocument(name="%s" % kml_title, snippet=Snippet(timerange[0]))
doc.lookat.gxtimespan.begin = timerange[0]
doc.lookat.gxtimespan.end = timerange[-1]
doc.lookat.longitude = kml_lookat_lon
doc.lookat.latitude = kml_lookat_lat
doc.lookat.range = kml_lookat_range
# Create a folder
ge_dir = doc.newfolder(name="Tracks")
# Create a schema for extended data: heart rate, cadence and power
schema = kml.newschema()
# Create a new track in the folder
trk = ge_dir.newgxtrack(name="%s %s" % (organization, vehicle_name))
desc1 = "<![CDATA[\n%s<br />\n<br />\n" % kml_cdata_title
desc2 = "<a href='%s/glider.html' target='_blank'>Link to Plot</a><br />\n" % plot_url
desc_temp = "<img src='%s/%s' height='%d' width='%d' /><br />\n" % (plot_url, plot_temp, plot_height, plot_width)
desc_oxyg = "<img src='%s/%s' height='%d' width='%d' /><br />\n" % (plot_url, plot_oxyg, plot_height, plot_width)
desc_sali = "<img src='%s/%s' height='%d' width='%d' /><br />\n" % (plot_url, plot_sali, plot_height, plot_width)
desc_chlo = "<img src='%s/%s' height='%d' width='%d' /><br />\n" % (plot_url, plot_chlo, plot_height, plot_width)
desc_cdom = "<img src='%s/%s' height='%d' width='%d' /><br />\n" % (plot_url, plot_cdom, plot_height, plot_width)
desc3 = "]]>\n"
trk.description = desc1 + desc2 + desc_temp + desc_oxyg + desc_sali + desc_chlo + desc_cdom + desc3
# Apply the above schema to this track
trk.extendeddata.schemadata.schemaurl = schema.id
# Add all information to the track
trk.newwhen(timerange) # Each item in the give nlist will become a new <when> tag
trk.newgxcoord(coord) # Ditto
# Style
trk.stylemap.normalstyle.iconstyle.icon.href = icon_url
trk.stylemap.normalstyle.iconstyle.scale = icon_normal_scale
trk.stylemap.normalstyle.linestyle.color = icon_normal_color
trk.stylemap.normalstyle.linestyle.width = icon_normal_width
trk.stylemap.highlightstyle.iconstyle.icon.href = icon_highlight_url
trk.stylemap.highlightstyle.iconstyle.scale = icon_highlight_scale
trk.stylemap.highlightstyle.linestyle.color = icon_highlight_color
trk.stylemap.highlightstyle.linestyle.width = icon_highlight_width
# Create a path line
gpath = kml.newlinestring(name="%s %s" % (organization, vehicle_name))
gpath.description = trk.description
gpath.timespan.begin = timerange[0]
gpath.timespan.end = ""
gpath.coords = coord
gpath.style.linestyle.color = path_line_color
gpath.style.linestyle.width = path_line_width
#.........這裏部分代碼省略.........
示例5: Kml
# 需要導入模塊: from simplekml import Kml [as 別名]
# 或者: from simplekml.Kml import newlinestring [as 別名]
kml = Kml()
tab = []
firstPos = None
for position in nmeaLog.NewPosition:
if firstPos == None:
firstPos = position
#ne pas mettre les 0.0
if position.longitude == 0.0 and position.latitude == 0.0:
continue
tab.append( ( position.longitude,position.latitude) )
if len(tab) == KML_LINE_POINT_LIMIT:
line = kml.newlinestring(name=str(firstPos.newTime), description="", coords=tab)
tab = []
if firstPos.newTime.hour < 12 or (firstPos.newTime.hour == 12 and firstPos.newTime.minute < 30):
#blue line
line.style.linestyle.color = 'ffff0000'
else:
#red line
line.style.linestyle.color = 'ff0000ff'
firstPos = None
if len(tab) > 0:
line = kml.newlinestring(name=str(firstPos.newTime), description="", coords=tab)
示例6: kmlManager
# 需要導入模塊: from simplekml import Kml [as 別名]
# 或者: from simplekml.Kml import newlinestring [as 別名]
class kmlManager(object):
def init(self):
self.kml_list_start_time = None
self.kml_list = []
self.kml_interest_line_list = []
self.kml_interest_point_list = []
def __init__(self, line_limit_point, pathDirectory):
self.kml = Kml()
self.init()
self.kml_interest_line_already_meeted = {}
self.kml_interest_point_already_meeted = {}
self.line_limit_point = line_limit_point
self.pathDirectory = pathDirectory
self.midday = (12,0,)
def addPointOfInterest(self,point):
if point.descr not in self.kml_interest_point_already_meeted: #not yet printed ?
self.kml_interest_point_already_meeted[point.descr] = True
self.kml_interest_point_list.append(point)
def addLineOfInterest(self, line):
if line.descr not in self.kml_interest_line_already_meeted: #not yet printed ?
self.kml_interest_line_already_meeted[line.descr] = True
self.kml_interest_line_list.append(line)
def addLinePoint(self,gpoint, utcdatetime, colorMarker):
if self.line_limit_point > 0:#don't want to write the line of the road ?
if len(self.kml_list) == 0: #set start time
self.kml_list_start_time = utcdatetime
self.kml_list.append( (gpoint.lat, gpoint.lon,) )
if len(self.kml_list) >= self.line_limit_point:
#kml process
if len(self.kml_list) > 0:
line = self.kml.newlinestring(name="From "+self.kml_list_start_time.isoformat()+" to "+utcdatetime.isoformat(), description="", coords=self.kml_list)
#if past midday, colour the line in red
if utcdatetime.hour < self.midday[0] or (utcdatetime.hour == self.midday[0] and utcdatetime.minute < self.midday[1]):
line.style.linestyle.color = 'afff0000'#morning, blue line
else:
line.style.linestyle.color = 'af0000ff'#afternoon, red line
#write the meeted line of interest
for interest_line in self.kml_interest_line_list:
#line
line = self.kml.newlinestring(name=interest_line.descr, description="", coords=((interest_line.start.lat,interest_line.start.lon,), (interest_line.end.lat,interest_line.end.lon,),))
line.style.linestyle.color = 'af00ff00' #green
#start point
point = self.kml.newpoint(name="Start point of "+interest_line[2], description="",coords=(interest_line.start.lat,interest_line.start.lon,))
point.style.iconstyle.icon.href = "http://maps.google.com/mapfiles/dd-start.png"
#end point
point = self.kml.newpoint(name="End point of "+interest_line[2], description="",coords=(interest_line.end.lat,interest_line.end.lon,))
point.style.iconstyle.icon.href = "http://maps.google.com/mapfiles/dd-end.png"
#write the meeted point of interest
for interest_point in self.kml_interest_point_list:
point = self.kml.newpoint(name=interest_point.name, description=interest_point.descr,coords=( (interest_point.lat, interest_point.lon,), ))
point.style.iconstyle.icon.href = colorMarker.getColorPath(interest_point.name)
#save the file (for every line written, overwrite the file)
date = datetime.datetime.now()
self.kml.save(self.pathDirectory+"skidump_"+str(date.day)+"_"+str(date.month)+"_"+str(date.year)+".kml")
#reset list
self.init()
def addEventPointList(self,l):
#get point of interest from proxy
self.kml_interest_point_list.extend(l)
示例7: list
# 需要導入模塊: from simplekml import Kml [as 別名]
# 或者: from simplekml.Kml import newlinestring [as 別名]
#!/usr/bin/python
from simplekml import Kml
import sys
in_file, out_file = sys.argv[1], sys.argv[2];
data = list()
kml = Kml(name = in_file, open = 1)
with open(in_file) as file:
lines = file.readlines()
for x in lines:
# Ignore lines that start with "//".
if x.startswith("//"):
continue
elements = x.split(",")[:3]
group = tuple(elements)
data.append(group)
path = kml.newlinestring(name = "Flight", description = in_file, coords = data)
path.altitudemode = "absolute"
path.extrude = 1
path.style.polystyle.color = "7fff575c"
kml.save(out_file)
示例8: createRoute
# 需要導入模塊: from simplekml import Kml [as 別名]
# 或者: from simplekml.Kml import newlinestring [as 別名]
#.........這裏部分代碼省略.........
if DEBUG:
print(str(tour[j])+" = "+str(col)+","+str(tmpValue % size))
tour[j] = searchArea[i][col][row]
ac += len(coord[i])
route.append(tour)
m = Mission()
m.save()
for userId in range(0, len(userPK)):
m.inSearch.add(Clients.objects.get(pk=userPK[userId]))
try:
drones = Drone.objects.all()[0]
except:
print colored("Oops! No drones found un database", 'red')
return HttpResponse('configerror')
colorArray = [
'ff00008b', # darkred
'ff8b0000', # darkblue
'ff006400', # darkgreen
'ff008cff', # darkorange
'ff9314ff', # darkpink
'ffff0000', # blue
'ff2fffad', # greenyellow
'ff5c5ccd', # indianred
'ffcbc0ff', # pink
'ffe16941', # royalblue
'ff00ffff', # yellow
]
drone_secuencial = 0
# Creates the KML file
from os import mkdir
for r in route:
rm = Route(mission=m, drone=Drone.objects.all()[drone_secuencial], baseLat=base[0], baseLng=base[1], initialWp=0)
rm.save()
tmpRoute = []
tmpCounter = 0
kmlName = 'IBRI' + str(m.id) + 'R' + str(rm.id)
kml = Kml(name=kmlName)
kml.newpoint(name="Base", coords=[(base[1], base[0])])
pnt = kml.newlinestring(name='Route {}'.format(tmpCounter))
coords = []
for wp in r:
coords.append((wp[1], wp[0], altitude))
tmpRoute.append(WayPoint(route=rm, lat=wp[0], lng=wp[1], ref=tmpCounter))
tmpCounter += 1
pnt.coords = coords
pnt.style.linestyle.width = 6
pnt.style.linestyle.color = colorArray[drone_secuencial % len(colorArray)]
pnt.altitudemode = AltitudeMode.relativetoground
pnt.lookat.gxaltitudemode = GxAltitudeMode.relativetoseafloor
pnt.lookat.latitude = coords[0][0]
pnt.lookat.longitude = coords[0][1]
pnt.lookat.range = 122
pnt.lookat.heading = 0.063
pnt.lookat.tilt = 0
tmpRoute.append(WayPoint(route=rm, lat=base[0], lng=base[1], ref=tmpCounter))
kml.newpoint(name="Back to base", coords=[(base[1], base[0])])
rm.initialWp = len(tmpRoute)-2 # -2 for the last tmp counter and array 0 position
rm.save()
WayPoint.objects.bulk_create(tmpRoute)
place = KML_DIR + '/IBRI' + str(m.id)
try:
mkdir(place)
except Exception as e:
print colored(e, 'red')
pass
place = place + '/' + kmlName + '.kml'
place.replace('//', '/')
try:
kml.save(place) # Saving
except Exception as e:
print colored(e, 'red')
return HttpResponse('errorKmlPath')
drone_secuencial += 1
preshared = u'' + PRESHAREDKEY
return HttpResponse(AESCipher(preshared).encrypt(json.dumps([m.pk, route])))
示例9: Kml
# 需要導入模塊: from simplekml import Kml [as 別名]
# 或者: from simplekml.Kml import newlinestring [as 別名]
#Converts to KML
kml = Kml()
#folder = kml.newfolder(name="Gliders")
#Defines the kmnl document name
kml.document.name = "GliderProfile"
#Makes a list of styles
stylelist = []
for i in range(len(col)-1):
#if (ma.getmask(x[idx]) == False and ma.getmask(y[idx]) == False and
# ma.getmask(z[idx]) == False and ma.getmask(col[idx]) == False):
sharedstyle = Style()
sharedstyle.linestyle.color = str(colorValHex[i])
sharedstyle.linestyle.width = 10
stylelist.append(sharedstyle)
#Looops over all
for i in range(len(col)-1):
#if (ma.getmask(x[idx]) == False and ma.getmask(y[idx]) == False and
# ma.getmask(z[idx]) == False and ma.getmask(col[idx]) == False):
print x[i],y[i],colorValHexKML[i],-z[i]
lin = kml.newlinestring(name='',description='',coords=[(x[i],y[i],-z[i]),(x[i+1],y[i+1],-z[i+1])])
lin.style.linestyle.color = str(colorValHexKML[i]) #stylelist[i]
lin.style.linestyle.width = 10 #50 pixels
lin.altitudemode = simplekml.AltitudeMode.absolute
kml.save("C:\Users\john.tenhoeve\Documents\stest3.kml")