From 8fcbdc3eddb9359da7f4487c5a1196861d125d06 Mon Sep 17 00:00:00 2001 From: ingalls Date: Mon, 25 Sep 2023 12:51:21 -0600 Subject: [PATCH] Draw Features by Geom Type --- openaddr/preview.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/openaddr/preview.py b/openaddr/preview.py index be3ac0fa..4abf5e64 100644 --- a/openaddr/preview.py +++ b/openaddr/preview.py @@ -40,9 +40,10 @@ def render(src_filename, png_filename, width, resolution, mapbox_key): # Map units per reference pixel (http://www.w3.org/TR/css3-values/#reference-pixel) muppx = resolution / scale + feature_fill = 0x74/0xFF, 0xA5/0xFF, 0x78/0xFF + black = 0x00, 0x00, 0x00 off_white = 0xFF/0xFF, 0xFC/0xFF, 0xF9/0xFF - point_fill = 0x74/0xFF, 0xA5/0xFF, 0x78/0xFF water_fill = 0xC7/0xFF, 0xDE/0xFF, 0xF5/0xFF # 0xDD/0xFF, 0xEA/0xFF, 0xF8/0xFF road_stroke = 0xC0/0xFF, 0xE0/0xFF, 0xE0/0xFF # 0xE0/0xFF, 0xE3/0xFF, 0xE5/0xFF park_fill = 0xDD/0xFF, 0xF6/0xFF, 0xDE/0xFF @@ -67,14 +68,20 @@ def render(src_filename, png_filename, width, resolution, mapbox_key): context.set_line_width(.25 * muppx) for geom in iterate_file_geoms(src_filename): - (x, y, e) = geom.PointOnSurface().GetPoint() + if geom.GetGeometryType() == ogr.wkbMultiLineString or geom.GetGeometryType() == ogr.wkbLineString: + stroke_geometries(context, [geom]) + elif geom.GetGeometryType() == ogr.wkbMultiPolygon or geom.GetGeometryType() == ogr.wkbPolygon: + fill_geometries(context, [geom], muppx, feature_fill) + else: + (x, y, e) = geom.PointOnSurface().GetPoint() - context.arc(x, y, 15, 0, 2 * pi) - context.set_source_rgb(*point_fill) - context.fill() - context.arc(x, y, 15, 0, 2 * pi) - context.set_source_rgb(*black) - context.stroke() + context.arc(x, y, 15, 0, 2 * pi) + context.set_source_rgb(*feature_fill) + context.fill() + context.arc(x, y, 15, 0, 2 * pi) + context.set_source_rgb(*black) + context.stroke() + (x, y, e) = geom.PointOnSurface().GetPoint() surface.write_to_png(png_filename) @@ -330,6 +337,8 @@ def fill_geometries(ctx, geometries, muppx, rgb): else: raise NotImplementedError() + print(parts) + for part in parts: for ring in part: points = ring.GetPoints()