Esempio n. 1
0
 def set_highlight_url(self, sld_url):
     configured_params = Config.get_real_estate_config().get(
         'visualisation').get('url_params')
     additional_url_params = {}
     for param in configured_params:
         additional_url_params.update({param: getattr(self, param)})
     updated_sld_url = add_url_params(sld_url, additional_url_params)
     self.highlight = ViewServiceRecord(
         add_url_params(self.plan_for_land_register.reference_wms,
                        {'sld': updated_sld_url}), '')
     self.highlight.download_wms_content()
Esempio n. 2
0
def produce_sld_content(request):
    """
    This is the standard hook method to provide the sld content. Of course you can set it to another one. For
    instance to use another template. Or to use other parameters to provide the correctly constructed SLD.

    .. note:: What to know about this Method: REQUEST-Method: GET, parameters only as url parameters

    When you are replacing this method take care that it has to accept a pyramid request as input and must
    deliver a valid SLD wrapped in a pyramid response instance as output. It is in your responsibility.

    Args:
        request (pyramid.request.Request): The request from the pyramid application.

    Returns:
        pyramid.response.Response: The
    """
    response = request.response
    template = Template(filename=AssetResolver('pyramid_oereb').resolve(
        'standard/templates/sld.xml').abspath(),
                        input_encoding='utf-8',
                        output_encoding='utf-8')
    layer = Config.get_real_estate_config().get('visualisation').get('layer')
    template_params = {}
    template_params.update(
        Config.get_real_estate_config().get('visualisation').get('style'))
    template_params.update({'layer_name': layer.get('name')})
    template_params.update({'identifier': request.params.get('egrid')})
    try:
        if isinstance(
                response, Response
        ) and response.content_type == response.default_content_type:
            response.content_type = 'application/xml'
        response.body = template.render(**template_params)
        return response
    except Exception:
        response.content_type = 'text/html'
        response.body = exceptions.html_error_template().render()
        return response
Esempio n. 3
0
    def read(self, nb_ident=None, number=None, egrid=None, geometry=None):
        """
        The central read accessor method to get all desired records from configured source.

        .. note:: If you subclass this class your implementation needs to offer this method in the same
            signature. Means the parameters must be the same and the return must be a list of
            :ref:`api-pyramid_oereb-lib-records-real_estate-realestaterecord`. Otherwise the API like way the
            server works would be broken.

        Args:
            nb_ident (int or None): The identification number of the desired real estate. This
                parameter is directly related to the number parameter and both must be set!
                Combination will deliver only one result or crashes.
            number (str or None): The number of parcel or also known real estate. This parameter
                is directly related to the nb_ident parameter and both must be set!
                Combination will deliver only one result or crashes.
            (str or None): The unique identifier of the desired real estate. This will deliver
                only one result or crashes.
            geometry (str): A geometry as WKT string which is used to obtain intersected real
                estates. This may deliver several results.

        Returns:
            list of pyramid_oereb.lib.records.real_estate.RealEstateRecord:
                The list of all found records filtered by the passed criteria.
        """
        real_estate_view_service = ViewServiceRecord(
            reference_wms=Config.get_real_estate_config().get(
                'view_service').get('reference_wms'),
            legend_at_web=Config.get_real_estate_config().get(
                'view_service').get('legend_at_web'))
        self._source_.read(nb_ident=nb_ident,
                           number=number,
                           egrid=egrid,
                           geometry=geometry)
        for r in self._source_.records:
            if isinstance(r, RealEstateRecord):
                r.set_view_service(real_estate_view_service)
        return self._source_.records
def get_surveying_data_provider(real_estate):
    """
    Args:
        real_estate (pyramid_oereb.lib.records.real_estate.RealEstateRecord): The real estate for which the
            provider of the surveying data should be delivered.
    Returns:
        provider (pyramid_oereb.lib.records.office.OfficeRecord): The provider who produced the used
            surveying data.
    """
    params = Config.get_real_estate_config().get('source').get('params')
    session = database_adapter.get_session(params.get('db_connection'))
    try:
        model = DottedNameResolver().resolve(params.get('model'))
        re = session.query(model).filter(model.egrid == real_estate.egrid).one()
        provider = OfficeRecord(re.data_provider)
        return provider
    finally:
        session.close()
def get_surveying_data_update_date(real_estate):
    """
    Gets the date of the latest update of the used survey data data for the
    situation map. The method you find here is only matching the standard configuration. But you can provide
    your own one if your configuration is different. The only thing you need to take into account is that the
    input of this method is always and only a real estate record. And the output of this method must be a
    datetime.date object.
    Args:
        real_estate (pyramid_oereb.lib.records.real_estate.RealEstateRecord): The real
            estate for which the last update date of the base data should be indicated
    Returns:
        update_date (datetime.datetime): The date of the last update of the cadastral base data
    """
    params = Config.get_real_estate_config().get('source').get('params')
    session = database_adapter.get_session(params.get('db_connection'))
    try:
        model = DottedNameResolver().resolve(params.get('model'))
        re = session.query(model).filter(model.egrid == real_estate.egrid).one()
        return datetime.datetime.combine(re.currentness, datetime.time.min)
    finally:
        session.close()
Esempio n. 6
0
    def set_highlight_url(self, sld_url):
        """
        Set the highlight of the real estate.

        Args:
            sld_url (str): The URL which provides the sld to style and filter the highlight of the real
            estate.
        """
        configured_params = Config.get_real_estate_config().get(
            'visualisation').get('url_params')
        additional_url_params = {}
        for param in configured_params:
            additional_url_params.update({param: getattr(self, param)})
        updated_sld_url = add_url_params(sld_url, additional_url_params)
        self.highlight = ViewServiceRecord(
            add_url_params(self.plan_for_land_register.reference_wms,
                           {'sld': updated_sld_url}),
            self.plan_for_land_register.layer_index,
            self.plan_for_land_register.layer_opacity,
            legend_at_web={})
        self.highlight.download_wms_content()
Esempio n. 7
0
    def get_sld(self):
        """
        Webservice which delivers an SLD file from parameter input. However
        this is a proxy pass through only. We use it to call the real method
        configured in the dedicated yaml file and hope that this method is
        accepting a pyramid.request.Request as input and is returning a
        pyramid.response.Response which encapsulates a well designed SLD.

        .. note:: The config path to define this hook method is:
            *pyramid_oereb.real_estate.visualisation.method*

        Returns:
             pyramid.response.Response: The response provided by the hooked method provided by the
                configuration

        Raises:
            pyramid.httpexceptions.HTTPInternalServerError: When the return
            value of the hooked method was not of type pyramid.response.Response
            pyramid.httpexceptions.HTTPNotFound: When the configured method was not found.
        """
        dnr = DottedNameResolver()
        visualisation_config = Config.get_real_estate_config().get('visualisation')
        method_path = visualisation_config.get('method')
        method = dnr.resolve(method_path)
        if method:
            result = method(self._request_)
            if isinstance(result, Response):
                return result
            else:
                log.error(
                    u'The called method {path} does not returned the expected '
                    u'pyramid.response.Response instance. Returned value was {type}'.format(
                        path=method_path,
                        type=type(result)
                    )
                )
                raise HTTPInternalServerError()
        log.error(u'method in path "{path}" not found'.format(path=method_path))
        raise HTTPNotFound()