move clip_altitudes() to base RenderEngine
This commit is contained in:
parent
400f2892bb
commit
80fb9e2df7
2 changed files with 18 additions and 23 deletions
|
@ -2,6 +2,8 @@ import math
|
|||
from abc import ABC, abstractmethod
|
||||
from typing import Optional
|
||||
|
||||
from shapely.ops import unary_union
|
||||
|
||||
|
||||
class FillAttribs:
|
||||
__slots__ = ('color', 'opacity')
|
||||
|
@ -42,11 +44,26 @@ class RenderEngine(ABC):
|
|||
|
||||
self.background_rgb = tuple(int(background[i:i + 2], 16) for i in range(1, 6, 2))
|
||||
|
||||
# keep track which area of the image has which altitude currently
|
||||
self.altitudes = {}
|
||||
self.last_altitude = None
|
||||
|
||||
@abstractmethod
|
||||
def get_png(self) -> bytes:
|
||||
# render the image to png.
|
||||
pass
|
||||
|
||||
def clip_altitudes(self, new_geometry, new_altitude=None):
|
||||
# register new geometry with an altitude
|
||||
# a geometry with no altitude will reset the altitude information of its area as if nothing was ever there
|
||||
if self.last_altitude is not None and self.last_altitude > new_altitude:
|
||||
raise ValueError('Altitudes have to be ascending.')
|
||||
|
||||
if new_altitude in self.altitudes:
|
||||
self.altitudes[new_altitude] = unary_union([self.altitudes[new_altitude], new_geometry])
|
||||
else:
|
||||
self.altitudes[new_altitude] = new_geometry
|
||||
|
||||
def add_geometry(self, geometry, fill: Optional[FillAttribs] = None, stroke: Optional[StrokeAttribs] = None,
|
||||
altitude=None, height=None, shape_cache_key=None):
|
||||
# draw a shapely geometry with a given style
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue