Skip to content

Commit

Permalink
Draw Features by Geom Type
Browse files Browse the repository at this point in the history
  • Loading branch information
ingalls committed Sep 25, 2023
1 parent 32e5511 commit 8fcbdc3
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions openaddr/preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 8fcbdc3

Please sign in to comment.