コード例 #1
0
def http_request(url, **kwargs) -> HTTPResponse:
    kwargs = dict(kwargs)

    if 'params' in kwargs:
        url = add_params(url, kwargs.pop('params'))

    method = kwargs.pop('method', 'GET').upper()
    max_age = kwargs.pop('max_age', 0)
    cache_path = _cache_path(url)

    if method == 'GET' and max_age:
        age = gws.lib.os2.file_age(cache_path)
        if 0 <= age < max_age:
            gws.log.debug(
                f'HTTP_CACHED_{method}: url={url!r} path={cache_path!r} age={age}'
            )
            return gws.unserialize_from_path(cache_path)

    ts = gws.time_start(f'HTTP_{method}={url!r}')
    res = _http_request(method, url, kwargs)
    gws.time_end(ts)

    if method == 'GET' and max_age and res.ok:
        gws.serialize_to_path(res, cache_path)

    return res
コード例 #2
0
def parse(text,
          fallback_crs: t.Optional[gws.ICrs] = None,
          **kwargs) -> t.List[gws.IFeature]:
    ts = gws.time_start('featureinfo:parse')
    res = _parse(text, fallback_crs, **kwargs)
    gws.time_end(ts)
    return res
コード例 #3
0
    def _get_box(self, req: gws.IWebRequest, p: GetBoxParams) -> gws.BytesResponse:
        layer = req.require_layer(p.layerUid)
        content = None

        mri = gws.MapRenderInput(

        )

        extra_params = {}
        if p.layers:
            extra_params['layers'] = p.layers

        view = gws.gis.render.map_view_from_bbox(
            crs=gws.gis.crs.get(p.crs) or layer.map.crs,
            bbox=p.bbox,
            size=(p.width, p.height, units.PX),
            dpi=units.OGC_SCREEN_PPI,
            rotation=0
        )

        ts = gws.time_start(f'RENDER_BOX layer={p.layerUid} view={view!r}')
        try:
            content = layer.render_box(view, extra_params)
        except:
            gws.log.exception()
        gws.time_end(ts)

        return self._image_response(content)
コード例 #4
0
 def render_box(self, view, extra_params=None):
     fr = self.render_svg_fragment(view)
     ts = gws.time_start('render_box:to_png')
     img = gws.lib.svg.fragment_to_image(fr,
                                         size=view.size_px,
                                         format='png')
     gws.time_end(ts)
     return img.to_bytes()
コード例 #5
0
ファイル: runtime.py プロジェクト: gbd-consult/gbd-websuite
def _generate(manifest_path):
    ts = gws.time_start('SPEC GENERATOR')
    try:
        genres = gws.spec.generator.generate_for_server(manifest_path)
    except Exception as exc:
        raise Error(f'system error, spec generator failed') from exc
    gws.time_end(ts)
    return genres
コード例 #6
0
    def render_svg_fragment(self, view, style=None):
        bounds = view.bounds
        if view.rotation:
            bounds = gws.Bounds(crs=view.bounds.crs,
                                extent=gws.gis.extent.circumsquare(
                                    bounds.extent))

        ts = gws.time_start('render_svg:get_features')
        found = self.get_features(bounds)
        gws.time_end(ts)

        ts = gws.time_start('render_svg:convert')
        for f in found:
            f.transform_to(bounds.crs)
            f.apply_templates(subjects=['label'])
        gws.time_end(ts)

        ts = gws.time_start('render_svg:to_svg')
        tags = [
            tag for f in found
            for tag in f.to_svg_fragment(view, style or self.style)
        ]
        gws.time_end(ts)

        return tags
コード例 #7
0
    def _get_xyz(self, req: gws.IWebRequest, p: GetXyzParams) -> gws.BytesResponse:
        layer = req.require_layer(p.layerUid)
        content = None

        ts = gws.time_start(f'RENDER_XYZ layer={p.layerUid} xyz={p.x}/{p.y}/{p.z}')
        try:
            content = layer.render_xyz(p.x, p.y, p.z)
        except:
            gws.log.exception()
        gws.time_end(ts)

        # for public tiled layers, write tiles to the web cache
        # so they will be subsequently served directly by nginx

        if content and gws.is_public_object(layer) and layer.has_cache:
            path = gws.base.layer.layer_url_path(layer.uid, kind='tile')
            path = path.replace('{x}', str(p.x))
            path = path.replace('{y}', str(p.y))
            path = path.replace('{z}', str(p.z))
            gws.gis.cache.store_in_web_cache(path, content)

        return self._image_response(content)