Skip to content

ScaleBar? #35

Description

@petered

First off - thank you for making this very useful tool.

It would be great to have some way to add a scalebar.

I recognise it gets a little tricky over large-projections where scale is not uniform - but most maps are local.

Here's my attempt so far:

    def render(self, width: int, height: int, add_scalebar: bool = True) -> BGRImageArray:
        image = self.context.render_pillow(width, height)
        bgr_image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
        if add_scalebar:
            center, zoom = self.context.determine_center_zoom(width, height)
            trans = Transformer(width, height, zoom, center, tile_size=256)  # TODO: Get actual tile size from context
            lower_left=trans.pixel2ll(0, 0)
            lower_right=trans.pixel2ll(width-1, 0)
            upper_left=trans.pixel2ll(0, height-1)
            map_width_m = inter_latlong_distance_m((lower_left.lat().degrees, lower_left.lng().degrees), (lower_right.lat().degrees, lower_right.lng().degrees))
            map_height_m = inter_latlong_distance_m((lower_left.lat().degrees, lower_left.lng().degrees), (upper_left.lat().degrees, upper_left.lng().degrees))
            bgr_image = ImageBuilder(bgr_image).draw_corner_text(text='Scale: {:.2f} x {:.2f} km'.format(map_width_m/1000, map_height_m/1000), colour=BGRColors.WHITE, shadow_color=BGRColors.BLACK).get_image()
        return bgr_image

Which puts a little text-box in the corner:

image

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions