本文整理匯總了Python中simplekml.Kml.newpolygon方法的典型用法代碼示例。如果您正苦於以下問題:Python Kml.newpolygon方法的具體用法?Python Kml.newpolygon怎麽用?Python Kml.newpolygon使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類simplekml.Kml
的用法示例。
在下文中一共展示了Kml.newpolygon方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1:
# 需要導入模塊: from simplekml import Kml [as 別名]
# 或者: from simplekml.Kml import newpolygon [as 別名]
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)
# Saving
kml.save(os.path.splitext(__file__)[0] + ".kml")
示例2: csv_to_kml
# 需要導入模塊: from simplekml import Kml [as 別名]
# 或者: from simplekml.Kml import newpolygon [as 別名]
def csv_to_kml(input_filename):
# open input file
csv_file = open(input_filename,'rU')
reader = csv.DictReader(csv_file)
# preamble
input_filename_base, input_filename_ext = os.path.splitext(input_filename)
# open output file
kml_file = open(input_filename_base + '.kml','w')
kml_file.write(r"""<?xml version="1.0" encoding="utf-8" ?>
<kml xmlns="http://www.opengis.net/kml/2.2">
""")
kml_file.write("<Document><name>%s</name>" % input_filename_base)
kml_file.write(r""" <Style id="grid1k"><IconStyle> <Icon> <color>ff0000</color> </Icon> </IconStyle></Style>""")
kml_file.write(r"""
<Schema name="sample" id="sample">
<SimpleField name="Name" type="string"></SimpleField>
<SimpleField name="Description" type="string"></SimpleField>
<SimpleField name="GID" type="string"></SimpleField>
</Schema>
""")
gids_unique = set()
gids = []
locs_1k = []
# main loop
for line in reader:
kml_file.write(' <Placemark>\n')
kml_file.write(' <name>GID=%s</name>\n' % (line['GID_100m']))
kml_file.write('\t<ExtendedData><SchemaData schemaUrl=\"#sample\">\n')
kml_file.write(' <SimpleField name="GID">%s</SimpleField>\n' % (line['GID_100m']))
kml_file.write('\t\t</SchemaData></ExtendedData>\n')
kml_file.write(" <Point><coordinates>%s,%s</coordinates></Point>\n" % (line['x'], line['y']))
kml_file.write(' </Placemark>\n')
gids_unique.add(line['GID_1k'])
gids.append(line['GID_1k'])
locs_1k.append([line['x_1k'], line['y_1k']])
# epilogue
kml_file.write('\t</Document>\n\t</kml>')
csv_file.close()
kml_file.close()
gids_unique = list(gids_unique)
locs_1k_unique = []
for gid in gids_unique:
locs_1k_unique.append([locs_1k[k] for k, x in enumerate(map(lambda x: x==gid, gids)) if x][0])
for i, loc in enumerate(locs_1k_unique):
kml=Kml()
proj_para = "+proj=laea +ellps=WGS84 +lon_0=20 +lat_0=5 +units=m +no_defs"
project = pyproj.Proj(proj_para)
loc_laea = list(project(loc[0], loc[1]))
center_pt = kml.newpoint(name=gids_unique[i], description="1k by 1k grid", coords=[(loc[0], loc[1])])
pol = kml.newpolygon(name="1k grid", description="A pathway in Kirstenbosch",
outerboundaryis=[project(loc_laea[0]-500, loc_laea[1]+500, inverse=True),
project(loc_laea[0]+500, loc_laea[1]+500, inverse=True),
project(loc_laea[0]+500, loc_laea[1]-500, inverse=True),
project(loc_laea[0]-500, loc_laea[1]-500, inverse=True),
project(loc_laea[0]-500, loc_laea[1]+500, inverse=True)],
innerboundaryis=[project(loc_laea[0]-500, loc_laea[1]+500, inverse=True),
project(loc_laea[0]+500, loc_laea[1]+500, inverse=True),
project(loc_laea[0]+500, loc_laea[1]-500, inverse=True),
project(loc_laea[0]-500, loc_laea[1]-500, inverse=True),
project(loc_laea[0]-500, loc_laea[1]+500, inverse=True)])
pol.polystyle.color = 'ff0000ff'
kml.save("csv/"+gids_unique[i]+".kml")