def __missing__(self, color: str): style = kml.Style(id=color) if current_document is not None: current_document.append_style(style) style.append_style(LineStyle(color=color, width=2)) style.append_style(PolyStyle(color=color)) styleUrl = kml.StyleUrl(url=color) return styleUrl
def main(argv): # Get command line options try: opts, args = getopt.getopt(argv, "hf:o:a:", ["filepath=", "long-start=", "lat-start="]) except getopt.GetoptError: print 'create-haworth-cemetery-f-kml.py -f <filepath> -o <long start> -a <lat start>' sys.exit(2) for opt, arg in opts: if opt == '-h': print 'create-haworth-cemetery-f-kml.py -f <filepath> -o <long start> -a <lat start>' sys.exit() elif opt in ("-f", "--filepath"): filepath = arg elif opt in ("-o", "--long-start"): long_start = float(arg) elif opt in ("-a", "--lat-start"): lat_start = float(arg) map_origin = Point(long_start, lat_start) # Read in all the graves as objects and stick them in a grid. graveyard = [[None for i in range(GRAVEYARD_MAX_SIZE)] for j in range(GRAVEYARD_MAX_SIZE)] with open(filepath) as csvfile: reader = csv.DictReader(csvfile) for r in reader: if r['column']: row = int(r['row']) column = int(r['column']) graveyard[row][column] = Grave(r['section'], r['grave_id'], row, column, r['inscription']) # Create the root KML object. k = kml.KML() # Create the KML Document styles to use. doc_styles = [] a = [] a.append(styles.LineStyle(NS, None, 'ffbdbdbd')) a.append(styles.PolyStyle(NS, None, '4dbdbdbd')) doc_styles.append(kml.Style(NS, 'poly-BDBDBD-1-77-normal', a)) a[0] = styles.LineStyle(NS, None, 'ffbdbdbd', None, 2) doc_styles.append(kml.Style(NS, 'poly-BDBDBD-1-77-highlight', a)) doc_styles.append( kml.StyleMap(NS, "poly-BDBDBD-1-77", kml.StyleUrl(NS, None, '#poly-BDBDBD-1-77-normal'), kml.StyleUrl(NS, None, '#poly-BDBDBD-1-77-highlight'))) # Create the KML Document, and add it to the KML root object. d = kml.Document(NS, None, NAME, DESCRIPTION.format(SECTION), doc_styles) k.append(d) # Create a KML Folder for the section and add it to the Document. f = kml.Folder(NS, None, "Section {}".format(SECTION)) k.append(f) # Process the graveyard grid, creating a Placemark with a polygon for each grave. for i in range(GRAVEYARD_MAX_SIZE): for j in range(GRAVEYARD_MAX_SIZE): if graveyard[i][j]: g = graveyard[i][j] name = '{}-{}'.format(g.section, g.grave_id) p = kml.Placemark(NS, None, name.lower(), g.inscription, None, '#poly-BDBDBD-1-77') lon = long_start + (i * (LONG_2FEET * 3)) lat = lat_start + (j * (LAT_2FEET * 2)) p.geometry = Polygon([ (lon, lat, 0), (lon + LONG_3FEET + LONG_2FEET, lat, 0), (lon + LONG_3FEET + LONG_2FEET, lat + LAT_3FEET, 0), (lon, lat + LAT_3FEET, 0), (lon, lat, 0) ]) p.geometry = shapely.affinity.rotate(p.geometry, ADJUSTMENT_ANGLE, map_origin) f.append(p) # Print out the KML Object as a string. print k.to_string(prettyprint=True)
def main(argv): # Get command line options try: opts, args = getopt.getopt(argv, "ho:a:", ["long-start=", "lat-start="]) except getopt.GetoptError: print 'test-rotation-kml.py -o <long start> -a <lat start>' sys.exit(2) for opt, arg in opts: if opt == '-h': print 'test-rotation-kml.py -o <long start> -a <lat start>' sys.exit() elif opt in ("-o", "--long-start"): long_start = float(arg) elif opt in ("-a", "--lat-start"): lat_start = float(arg) map_origin = Point(long_start, lat_start) k = kml.KML() # Create the KML Document styles to use. doc_styles = [] a = [] a.append(styles.LineStyle(NS, None, 'ffbdbdbd')) a.append(styles.PolyStyle(NS, None, '4dbdbdbd')) doc_styles.append(kml.Style(NS, 'poly-BDBDBD-1-77-normal', a)) a[0] = styles.LineStyle(NS, None, 'ffbdbdbd', None, 2) doc_styles.append(kml.Style(NS, 'poly-BDBDBD-1-77-highlight', a)) doc_styles.append( kml.StyleMap(NS, "poly-BDBDBD-1-77", kml.StyleUrl(NS, None, '#poly-BDBDBD-1-77-normal'), kml.StyleUrl(NS, None, '#poly-BDBDBD-1-77-highlight'))) # Create the KML Document, and add it to the KML root object. d = kml.Document(NS, None, NAME, DESCRIPTION.format(SECTION), doc_styles) k.append(d) # Create a KML Folder for the section and add it to the Document. f = kml.Folder(NS, None, "Section {}".format(SECTION)) k.append(f) # Process a spiral of markers in a counter-clockwise direction lon = long_start + (OBJECT_START_ROW * (LONG_2FEET * 3)) lat = lat_start + (OBJECT_START_COL * (LAT_2FEET * 2)) adjustment_angle = 0.00 while adjustment_angle < 360: name = 'Degrees: {}'.format(adjustment_angle) p = kml.Placemark(NS, None, name, "Test Rotation", None, '#poly-BDBDBD-1-77') p.geometry = Polygon([(lon, lat, 0), (lon + LONG_3FEET + LONG_2FEET, lat, 0), (lon + LONG_3FEET + LONG_2FEET, lat + LAT_3FEET, 0), (lon, lat + LAT_3FEET, 0), (lon, lat, 0)]) p.geometry = shapely.affinity.rotate(p.geometry, adjustment_angle, map_origin) f.append(p) adjustment_angle += ADJUSTMENT_ANGLE_INCR # Print out the KML Object as a string. print k.to_string(prettyprint=True)