def kml(self): """ Exports trek into KML format, add geometry as linestring and POI as place marks """ kml = simplekml.Kml() # Main itinerary geom3d = self.geom_3d.transform(4326, clone=True) # KML uses WGS84 line = kml.newlinestring(name=self.name, description=plain_text(self.description), coords=simplify_coords(geom3d.coords)) line.style.linestyle.color = simplekml.Color.red # Red line.style.linestyle.width = 4 # pixels # Place marks for poi in self.published_pois: place = poi.geom_3d.transform(settings.API_SRID, clone=True) kml.newpoint(name=poi.name, description=plain_text(poi.description), coords=simplify_coords([place.coords])) return kml.kml()
def kml(self): """Exports sensitivearea into KML format""" kml = simplekml.Kml() geom = self.geom if geom.geom_type == 'Point': geom = geom.buffer(self.species.radius or settings.SENSITIVITY_DEFAULT_RADIUS, 4) if self.species.radius: geometry = () for coords in geom.coords[0]: coords += (self.species.radius, ) geometry += (coords, ) geom = GEOSGeometry(Polygon(geometry), srid=settings.SRID) geom = geom.transform(4326, clone=True) # KML uses WGS84 line = kml.newpolygon(name=self.species.name, description=plain_text(self.description), altitudemode=simplekml.AltitudeMode.relativetoground, outerboundaryis=simplify_coords(geom.coords[0])) line.style.linestyle.color = simplekml.Color.red # Red line.style.linestyle.width = 4 # pixels return kml.kml()
def to_representation(self, instance): """Round bbox coordinates""" feature = super().to_representation(instance) feature['bbox'] = simplify_coords(feature['bbox']) return feature