def _draw_railway(self, ctx: Context, line_string: LineString):
        CairoHelper.draw_line_string(ctx, line_string)

        # Todo: Buffer the linestring outwards
        # ShapelyHelper.buffer_linestring()

        ctx.stroke()
 def _draw_stroke(self, ctx: Context, geom: Union[Polygon, MultiPolygon]):
     if isinstance(geom, MultiPolygon):
         for sub_geom in geom.geoms:
             self._draw_stroke(ctx, sub_geom)
         return
     CairoHelper.draw_polygon(ctx, geom)
     ctx.stroke()
示例#3
0
 def _draw_stroke(self, ctx: Context, geom: Union[LineString,
                                                  MultiLineString]):
     if isinstance(geom, MultiLineString):
         for sub_geom in geom.geoms:
             self._draw_stroke(ctx, sub_geom)
         return
     CairoHelper.draw_line_string(ctx, geom)
     ctx.stroke()
示例#4
0
    def draw(self, ctx: Context, outline: Union[Polygon, MultiPolygon]):
        if isinstance(outline, MultiPolygon):
            shadow_line_strings = []
            for sub_outline in outline.geoms:
                shadow_line_string = self.draw(ctx, sub_outline)
                shadow_line_strings.append(shadow_line_string)
            return shadow_line_strings
        buffered_outline = outline.buffer(-self.outline_line_width / 2, cap_style=3, join_style=2)

        shadow_line_strings = self._get_shadow_lines(buffered_outline)
        for shadow_line_string in shadow_line_strings:
            CairoHelper.draw_line_string(ctx, shadow_line_string)
            ctx.stroke()
        pass
示例#5
0
    def draw(self, ctx: Context):

        if not self.canvas_set:
            raise Exception("Canvas size not set!")

        top_left = (0, 0)
        top_right = (self.canvas_width, 0)
        bottom_left = (0, self.canvas_height)
        bottom_right = (self.canvas_width, self.canvas_height)

        canvas = Polygon(
            [top_left, top_right, bottom_right, bottom_left, top_left])

        ctx.set_source_rgba(*self.color)
        CairoHelper.draw_polygon(ctx, canvas)
        ctx.fill()
 def _draw_grass_area(self, ctx: Context, outline: Polygon):
         tags = outline.get_osm_tags()
         if 'leisure' in tags and tags['leisure'] == 'park':
             ctx.set_source_rgba(0, 0, 0, 0.03)
         elif 'leisure' in tags and tags['leisure'] == 'garden':
             ctx.set_source_rgba(0, 0, 0, 0.1)
         elif 'leisure' in tags and tags['leisure'] == 'common':
             ctx.set_source_rgba(0, 0, 0, 0.03)
         elif 'leisure' in tags and tags['leisure'] == 'recreation_ground':
             ctx.set_source_rgba(0, 0, 0, 0.03)
         elif 'landuse' in tags and tags['landuse'] == 'grass':
             ctx.set_source_rgba(0, 0, 0, 0.03)
         elif 'landuse' in tags and tags['landuse'] == 'forest':
             ctx.set_source_rgba(0, 0, 0, 0.03)
         elif 'natural' in tags and tags['natural'] == 'wood':
             ctx.set_source_rgba(0, 0, 0, 0.03)
         CairoHelper.draw_polygon(ctx, outline)
         ctx.fill()
 def _draw_ripple(self, ctx: Context, ripple: Polygon, iteration: int):
     CairoHelper.draw_polygon(ctx, ripple)
     ctx.stroke()
    def _draw_water(self, ctx: Context, outline: Union[Polygon, MultiPolygon]):
        # Draw outline of ripple
        CairoHelper.draw_polygon(ctx, outline)
        ctx.stroke()

        self._draw_ripples(ctx, outline)
 def _draw_water_area(self, ctx: Context, outline: Union[Polygon, MultiPolygon]):
     CairoHelper.draw_polygon(ctx, outline)
     ctx.fill()
示例#10
0
    def get_text_baseline(self, ctx):
        bottom_offset = self.text_height / 2 + self.line_text_offset
        top_offset = -self.text_height / 2 + self.line_text_offset
        line_string_right = Text.parallel_offset(self.line_string,
                                                 bottom_offset)
        line_string_left = Text.parallel_offset(self.line_string, top_offset)

        center_start_pos = self.line_string.interpolate(0)
        right_start_pos = line_string_right.interpolate(0)
        left_start_pos = line_string_left.interpolate(0)

        reverse_lines = math.atan2(left_start_pos.y - right_start_pos.y,
                                   left_start_pos.x - right_start_pos.x) < 0
        if self.force_upside_down:
            reverse_lines = not reverse_lines

        if reverse_lines:
            bottom_offset = self.text_height / 2 - self.line_text_offset
            top_offset = -self.text_height / 2 - self.line_text_offset
            line_string_right = Text.parallel_offset(self.line_string,
                                                     bottom_offset)
            line_string_left = Text.parallel_offset(self.line_string,
                                                    top_offset)

            line_string_right = LineString(reversed(line_string_right.coords))
            line_string_left = LineString(reversed(line_string_left.coords))

            temp = line_string_right
            line_string_right = line_string_left
            line_string_left = temp

            center_start_pos = self.line_string.interpolate(0)
            right_start_pos = line_string_right.interpolate(0)
            left_start_pos = line_string_left.interpolate(0)

        if self.debug:
            ctx.set_line_width(0.1)
            ctx.set_source_rgba(0, 1, 0, 0.5)
            CairoHelper.draw_point(ctx, center_start_pos, 0.5)
            CairoHelper.draw_line_string(ctx, self.line_string)
            ctx.stroke()
            ctx.set_source_rgba(0, 1, 1, 0.5)
            CairoHelper.draw_point(ctx, right_start_pos, 0.5)
            CairoHelper.draw_line_string(ctx, line_string_right)
            ctx.stroke()
            ctx.set_source_rgba(0, 0, 0, 0.5)
            CairoHelper.draw_point(ctx, left_start_pos, 0.5)
            CairoHelper.draw_line_string(ctx, line_string_left)
            ctx.stroke()

        return line_string_left
 def _draw_wall(self, ctx: Context, line_string: LineString):
     CairoHelper.draw_line_string(ctx, line_string)
     ctx.stroke()
示例#12
0
 def _draw_stroke(self, ctx: Context, geom: Point):
     CairoHelper.draw_circle(ctx, geom, self.size)
     ctx.stroke()
示例#13
0
 def _draw_fill(self, ctx: Context, geom: Point):
     CairoHelper.draw_circle(ctx, geom, self.size)
     ctx.fill()
示例#14
0
    def draw(self, ctx: Context):

        if not self.canvas_set or not self.margin_set or not self.legend_set:
            raise Exception("Canvas, margin or legend not set!")

        margin_exterior_top_left = (0, 0)
        margin_exterior_top_right = (self.canvas_width, 0)
        margin_exterior_bottom_left = (0, self.canvas_height)
        margin_exterior_bottom_right = (self.canvas_width, self.canvas_height)
        legend_exterior_top_left = (self.margin_left, self.margin_top)
        legend_exterior_top_right = (self.canvas_width - self.margin_right,
                                     self.margin_top)
        legend_exterior_bottom_left = (self.margin_left,
                                       self.canvas_height - self.margin_bottom)
        legend_exterior_bottom_right = (self.canvas_width - self.margin_right,
                                        self.canvas_height -
                                        self.margin_bottom)
        legend_interior_top_left = (self.margin_left + self.legend_left,
                                    self.margin_top + self.legend_top)
        legend_interior_top_right = (self.canvas_width - self.margin_right -
                                     self.legend_right,
                                     self.margin_top + self.legend_top)
        legend_interior_bottom_left = (self.margin_left + self.legend_left,
                                       self.canvas_height -
                                       self.margin_bottom - self.legend_bottom)
        legend_interior_bottom_right = (self.canvas_width - self.margin_right -
                                        self.legend_right, self.canvas_height -
                                        self.margin_bottom -
                                        self.legend_bottom)

        margin_and_legend = Polygon([
            margin_exterior_top_left, margin_exterior_top_right,
            margin_exterior_bottom_right, margin_exterior_bottom_left,
            margin_exterior_top_left
        ], [
            list(
                reversed([
                    legend_interior_top_left, legend_interior_top_right,
                    legend_interior_bottom_right, legend_interior_bottom_left,
                    legend_interior_top_left
                ]))
        ])

        legend_exterior = Polygon([
            legend_exterior_top_left, legend_exterior_top_right,
            legend_exterior_bottom_right, legend_exterior_bottom_left,
            legend_exterior_top_left
        ])

        legend_interior = Polygon([
            legend_exterior_top_left, legend_exterior_top_right,
            legend_exterior_bottom_right, legend_exterior_bottom_left,
            legend_exterior_top_left
        ], [
            list(
                reversed([
                    legend_interior_top_left, legend_interior_top_right,
                    legend_interior_bottom_right, legend_interior_bottom_left,
                    legend_interior_top_left
                ]))
        ])

        ctx.set_line_width(0.05)

        ctx.set_source_rgb(1, 1, 1)
        CairoHelper.draw_polygon(ctx, margin_and_legend)
        ctx.fill()

        # ctx.set_line_width(self.exterior_stroke_width)
        ctx.set_source_rgb(0, 0, 0)
        CairoHelper.draw_polygon(ctx, legend_exterior)
        ctx.stroke()
        # ctx.set_line_width(self.interior_stroke_width)
        CairoHelper.draw_polygon(ctx, legend_interior)
        ctx.stroke()