If you want full control, here's a script to convert shapefile polygons to kml, I've just been piping the output of the script to a file, windows: c:\script.py > c:\output.kml. The script also creates a popup and link to a url. If you want separate files, you'll need to open, write to, and close a file on each iteration. Something to start with...Have fun!
import arcpy
import sys
class CursorManager:
def __init__(self, *cursors):
self.cursors = cursors
def __enter__(self):
pass
def __exit__(self, exc_type, exc_value, traceback):
for cur in self.cursors:
del cur
class CentroidLabel:
def __init__(self, label, pos, large, extent):
self.label = label
self.pos = pos
self.large = large
self.extent = extent
#change these paths and file names to appropriate feature classes
fc_arterial = sys.path[0] + r"\arterials_nad83.shp"
#change string substitution into this pdf_link_template to appropriate string
pdf_link_template = """http://YOURSERVER/maplinks/%s/"""
info_popup_template = """<![CDATA[<div style="margin:10px 10px 10px 10px;">%s</div>]]>"""
grid_poly_template = """ <Placemark>
<name><![CDATA[<span style="font-size:24px">%s</span>]]></name>
<styleUrl>#%s</styleUrl>
<description>%s</description>
<MultiGeometry>
<Polygon>
<tessellate>1</tessellate>
<extrude>0</extrude>
<altitudeMode>clampToGround</altitudeMode>
<outerBoundaryIs>
<LinearRing>
<coordinates>%s</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</MultiGeometry>
</Placemark>"""
label_point_template = """ <Placemark>
<name>%s</name>
<styleUrl>#%s</styleUrl>
<Point>
<coordinates> %f,%f </coordinates>
</Point>
<Region>
<LatLonAltBox>
<north>%f</north>
<south>%f</south>
<east>%f</east>
<west>%f</west>
</LatLonAltBox>
<Lod>
<minLodPixels>%d</minLodPixels>
</Lod>
</Region>
</Placemark>"""
#start creation of kml
print """<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document id="crsmaps">
<name>CRS Maps</name>
<Snippet></Snippet>"""
print """ <Folder id="arterial">
<name>Arterial</name>
<Snippet></Snippet>"""
print """ <Folder id="arterial_grid">
<name>Grid</name>
<Snippet></Snippet>"""
#process arterial grid feature class
centroids = []
inCur = arcpy.SearchCursor(fc_arterial)
with CursorManager(inCur):
for row in inCur:
poly = row.Shape
path = poly.getPart(0)
outer_cell = row.ARTERIAL
file_dir = pdf_link_template % outer_cell.lower()
if (outer_cell != None and outer_cell.strip() != ""):
outer_link = file_dir + "%s.pdf" % outer_cell.lower()
centroid = CentroidLabel(outer_cell, poly.trueCentroid, False, poly.extent)
link_text = 'Get Arterial Map <a href="%s">%s</a><br/>' % (outer_link, outer_cell)
allPoints = []
for point in path:
if point != None:
allPoints.append(point)
if len(allPoints) > 0 and allPoints[0].X != allPoints[-1].X or allPoints[0].Y != allPoints[-1].Y:
allPoints.append(allPoints[0])
if len(allPoints) >= 4:
coord_str = ""
firstPt = allPoints[0]
for i in range(len(allPoints)):
point = allPoints[i]
coord_str = coord_str + " %f,%f" % (point.X, point.Y)
if i > 0 and firstPt.X == point.X and firstPt.Y == point.Y:
break
name = outer_cell
desc = info_popup_template % link_text
style = "ag"
place_str = grid_poly_template % (name, style, desc, coord_str)
print place_str
centroids.append(centroid)
print """ </Folder>
<Folder id="arterial_labels">
<name>Labels</name>
<Snippet></Snippet>"""
#Create labels for arterial grid
pixels = 50
style = "a"
for p in centroids:
point_str = label_point_template % (p.label, style, p.pos.X, p.pos.Y, p.extent.YMax, p.extent.YMin, p.extent.XMax, p.extent.XMin, pixels)
print point_str
print """ </Folder>
</Folder>"""
#create styles - short style names reduce kml size
#a = arterial label style
#ag = arterial polygon grid style
print """ <Style id="a">
<LabelStyle>
<color>ff0066ff</color>
<scale>1.5</scale>
</LabelStyle>
<IconStyle><Icon/></IconStyle>
</Style>
<Style id="ag">
<LineStyle>
<color>ff0066ff</color>
<width>2</width>
</LineStyle>
<PolyStyle>
<fill>0</fill>
<outline>1</outline>
</PolyStyle>
</Style>
</Document>
</kml>
"""