diff --git a/topologytool.py b/topologytool.py index 6828978..162cbc0 100644 --- a/topologytool.py +++ b/topologytool.py @@ -147,7 +147,55 @@ class Topology: else: print("Elevation file does not exist, fetching") self.create_elevation_file() + # get png data to cols x rows grid + values = self.convert_png_to_data() + # now make a line drawing of it + surface = cairo.SVGSurface(self.target_region_name+".svg", + self.linemap_size[0], + self.linemap_size[1]) + cr = cairo.Context(surface) + + # Background + cr.set_source_rgb(1, 1, 1) + cr.paint() + + # Simple Orthographic Projection Matrix (pseudo-3D) + # Projects (x,y,z) -> (x+z/2, y+z/2) + def project(x, y, z, xscale=20, yscale=10, offset=(0, 0)): + shelf = 0 if z == 0 else z + 2 + shelf = z + return (offset[0] + x * xscale, offset[1] + y * yscale + shelf) + # return (offset[0] + x * scale + z * 2, offset[1] + y * scale + z * 2) + + rows, cols = values.shape + max_val = values.max() + + # Normalize data for visualization height (0-100) + norm_data = (values / max_val) * 100 + + # Draw Lines along rows + cr.set_source_rgb(0, 0, 0) # Black lines + cr.set_line_width(1.0) + x = 0 + y = 0 + for r in range(rows): + for c in range(cols): + z = norm_data[r, c] + x, y = project(c, r, -z, xscale=800 / cols, yscale=800 / rows) # -z to make higher values go "up" in 2D + if c == 0: + cr.move_to(x, y + 50) + cr.line_to(x, y) + else: + cr.line_to(x, y) + cr.line_to(x, y + 50) + cr.close_path() + cr.set_source_rgb(1, 1, 1) + cr.fill_preserve() + cr.set_source_rgb(0, 0, 0) + cr.set_line_width(1.0) + cr.stroke() + surface.finish() def main(): topology = Topology(country="Switzerland",