0 votes
in Python Imaging Library by
How to Draw GeoJSON polygon over image returned by Mapbox in Python

1 Answer

0 votes
by
I managed to reproduce the same result as MapBox by introducing magnify method.. It is working for all scenarios of GeoJSON I used. Not sure why I had to magnify/zoom though.

    def draw(self, mapbox_image, zoom, **kwargs) -> None:

      geometries = get_geometries(kwargs['geojson'])

      left_x = kwargs['left_x']

      top_y = kwargs['top_y']

      actual_x_padding = kwargs['actual_x_padding']

      actual_y_padding = kwargs['actual_y_padding']

      draw = ImageDraw.Draw(mapbox_image)

      for geometry in geometries:

        for coordinates in geometry['coordinates']:

            polygon = [(self.magnify(longitude_to_x(coordinate[0], zoom) - left_x, 100),

                        self.magnify(latitude_to_y(coordinate[1], zoom) - top_y, 100)) for coordinate in

                       coordinates]

            draw.polygon(polygon, fill=None, outline="blue")

   def magnify(self, value, magnification):

     return value + (value * magnification) / 100
...