Example #1
0
    def _get_egrid_coord(self, params):
        """
        Returns a list with the matched EGRIDs for the given coordinates.

        Args:
            params (pyramid_oereb.views.webservice.Parameter): The parameter object.

        Returns:
            list of pyramid_oereb.core.records.real_estate.RealEstateRecord:
                The list of all found records filtered by the passed criteria.
        """
        en = self._params.get('EN')
        gnss = self._params.get('GNSS')
        if en or gnss:
            geom_wkt = 'SRID={0};{1}'
            if en:
                geom_wkt = geom_wkt.format(
                    Config.get('srid'),
                    self.__parse_en__(en, buffer_dist=1.0).wkt)
            elif gnss:
                geom_wkt = geom_wkt.format(Config.get('srid'),
                                           self.__parse_gnss__(gnss).wkt)
            processor = create_processor()
            return processor.real_estate_reader.read(params,
                                                     **{'geometry': geom_wkt})
        else:
            raise HTTPBadRequest('EN or GNSS must be defined.')
Example #2
0
    def _get_egrid_address(self, params):
        """
        Returns a list with the matched EGRIDs for the given postal address.

        Args:
            params (pyramid_oereb.views.webservice.Parameter): The parameter object.

        Returns:
            list of pyramid_oereb.core.records.real_estate.RealEstateRecord:
                The list of all found records filtered by the passed criteria.
        """
        postalcode = self._params.get('POSTALCODE')
        localisation = self._params.get('LOCALISATION')
        number = self._params.get('NUMBER')
        if postalcode and localisation and number:
            reader = AddressReader(
                Config.get_address_config().get('source').get('class'),
                **Config.get_address_config().get('source').get('params'))
            addresses = reader.read(params, localisation, int(postalcode),
                                    number)
            if len(addresses) == 0:
                raise HTTPNoContent()
            geometry = 'SRID={srid};{wkt}'.format(srid=Config.get('srid'),
                                                  wkt=addresses[0].geom.wkt)
            processor = create_processor()
            return processor.real_estate_reader.read(params,
                                                     **{'geometry': geometry})
        else:
            raise HTTPBadRequest(
                'POSTALCODE, LOCALISATION and NUMBER must be defined.')
def test_properties(pyramid_oereb_test_config):
    processor = create_processor()
    assert isinstance(processor.extract_reader, ExtractReader)
    assert isinstance(processor.municipality_reader, MunicipalityReader)
    assert isinstance(processor.disclaimer_reader, DisclaimerReader)
    assert isinstance(processor.glossary_reader, GlossaryReader)
    assert isinstance(processor.plr_sources, list)
    assert isinstance(processor.real_estate_reader, RealEstateReader)
def test_process(processor_data, real_estate_data):
    request = MockRequest()
    request.matchdict.update(request_matchdict)
    request.params.update(request_params)
    processor = create_processor()
    webservice = PlrWebservice(request)
    params = webservice.__validate_extract_params__()
    real_estate = processor.real_estate_reader.read(params, egrid=u'TEST')
    extract = processor.process(real_estate[0], params, 'http://test.ch')
    assert isinstance(extract, ExtractRecord)
def test_filter_published_documents(processor_data, real_estate_data, main_schema, land_use_plans):
    request = MockRequest()
    request.matchdict.update(request_matchdict)
    request.params.update(request_params)
    processor = create_processor()
    webservice = PlrWebservice(request)
    params = webservice.__validate_extract_params__()
    real_estate = processor.real_estate_reader.read(params, egrid=u'TEST')
    extract = processor.process(real_estate[0], params, 'http://test.ch')
    plrs = extract.real_estate.public_law_restrictions
    assert len(plrs) == 1
    for plr in plrs:
        if plr.theme.code == u'ch.Nutzungsplanung':
            assert len(plr.documents) == 1
def test_process_geometry_testing(processor_data, real_estate_data, land_use_plans):
    request = MockRequest()
    request.matchdict.update(request_matchdict)
    request.params.update(request_params)
    processor = create_processor()
    webservice = PlrWebservice(request)
    params = webservice.__validate_extract_params__()
    real_estate = processor.real_estate_reader.read(params, egrid=u'TEST')
    extract = processor.process(real_estate[0], params, 'http://test.ch')
    plrs = extract.real_estate.public_law_restrictions
    assert len(plrs) == 1
    for plr in plrs:
        for g in plr.geometries:
            assert g._test_passed
def test_processor_without_images(processor_data, real_estate_data):
    request = MockRequest()
    request.matchdict.update(request_matchdict)
    request.params.update(request_params)
    request.params.update({
        'LANG': 'de'
    })
    processor = create_processor()
    webservice = PlrWebservice(request)
    params = webservice.__validate_extract_params__()
    real_estate = processor.real_estate_reader.read(params, egrid=u'TEST')
    extract = processor.process(real_estate[0], params, 'http://test.ch')
    assert extract.real_estate.plan_for_land_register.image == {}
    for plr in extract.real_estate.public_law_restrictions:
        assert plr.view_service.image == {}
def test_processor_sort_by_law_status(processor_data, real_estate_data,
                                      main_schema, land_use_plans, contaminated_sites):

    request = MockRequest()
    request.matchdict.update(request_matchdict)
    request.params.update(request_params)
    processor = create_processor()
    webservice = PlrWebservice(request)
    params = webservice.__validate_extract_params__()
    real_estate = processor.real_estate_reader.read(params, egrid=u'TEST2')
    extract = processor.process(real_estate[0], params, 'http://test.ch')
    plrs = extract.real_estate.public_law_restrictions
    assert len(plrs) == 2
    assert plrs[0].theme.code == 'ch.Nutzungsplanung'
    assert plrs[0].law_status.code == 'inForce'
    assert plrs[1].theme.code == 'ch.BelasteteStandorte'
    assert plrs[1].law_status.code == 'inForce'
Example #9
0
    def get_capabilities(self):
        """
        Returns the capabilities of this service.

        Returns:
            pyramid.response.Response: The `capabilities` response.
        """

        output_format = self.__validate_format_param__(self._DEFAULT_FORMATS)
        params = Parameter(output_format)

        supported_languages = Config.get_language()
        themes = list()
        for theme in Config.get_themes():
            text = list()
            for lang in theme.title:
                if lang in supported_languages:
                    text.append({'Language': lang, 'Text': theme.title[lang]})
            themes.append({'Code': theme.code, 'Text': text})
        processor = create_processor()
        capabilities = {
            u'GetCapabilitiesResponse': {
                u'topic':
                themes,
                u'municipality': [
                    record.fosnr
                    for record in processor.municipality_reader.read(params)
                ],
                u'flavour':
                Config.get_flavour(),
                u'language':
                supported_languages,
                u'crs': [Config.get_crs()]
            }
        }

        renderer_name = 'json' if output_format == 'json' else 'pyramid_oereb_capabilities_xml'  # noqa: E501
        response = render_to_response(renderer_name,
                                      capabilities,
                                      request=self._request)
        if output_format == 'json':
            response.content_type = 'application/json; charset=UTF-8'
        # response.extras = OerebStats(service='GetCapabilities', output_format=output_format)
        return response
Example #10
0
    def _get_egrid_ident(self, params):
        """
        Returns a list with the matched EGRIDs for the given NBIdent and property number.

        Args:
            params (pyramid_oereb.views.webservice.Parameter): The parameter object.

        Returns:
            list of pyramid_oereb.core.records.real_estate.RealEstateRecord:
                The list of all found records filtered by the passed criteria.
        """
        identdn = self._params.get('IDENTDN')
        number = self._params.get('NUMBER')
        if identdn and number:
            processor = create_processor()
            return processor.real_estate_reader.read(
                params, **{
                    'nb_ident': identdn,
                    'number': number
                })
        else:
            raise HTTPBadRequest('IDENTDN and NUMBER must be defined.')
Example #11
0
    def get_extract_by_id(self):
        """
        Returns the extract in the specified format and flavour.

        Returns:
            pyramid.response.Response: The `extract` response.
        """
        start_time = timer()
        log.debug("get_extract_by_id() start")
        try:
            params = self.__validate_extract_params__()
            processor = create_processor()
            # read the real estate from configured source by the passed parameters
            real_estate_reader = processor.real_estate_reader
            if params.egrid:
                real_estate_records = real_estate_reader.read(
                    params, egrid=params.egrid)
            elif params.identdn and params.number:
                real_estate_records = real_estate_reader.read(
                    params, nb_ident=params.identdn, number=params.number)
            else:
                raise HTTPBadRequest("Missing required argument")
            # check if result is strictly one (we queried with primary keys)
            if len(real_estate_records) == 1:

                # Redirect for format URL
                if params.format == 'url':
                    log.debug("get_extract_by_id() calling url")
                    return self.__redirect_to_dynamic_client__(
                        real_estate_records[0])

                extract = processor.process(
                    real_estate_records[0], params,
                    self._request.route_url('{0}/sld'.format(route_prefix)))
                if params.format == 'json':
                    log.debug("get_extract_by_id() calling json")
                    response = render_to_response('pyramid_oereb_extract_json',
                                                  (extract, params),
                                                  request=self._request)
                elif params.format == 'xml':
                    log.debug("get_extract_by_id() calling xml")
                    response = render_to_response('pyramid_oereb_extract_xml',
                                                  (extract, params),
                                                  request=self._request)
                elif params.format == 'pdf':
                    log.debug("get_extract_by_id() calling pdf")
                    response = render_to_response(
                        'pyramid_oereb_extract_print', (extract, params),
                        request=self._request)
                else:
                    raise HTTPBadRequest("The format '{}' is wrong".format(
                        params.format))
                end_time = timer()
                log.debug("DONE with extract, time spent: {} seconds".format(
                    end_time - start_time))
            else:
                raise HTTPNoContent("No real estate found")
        except HTTPNoContent as err:
            response = HTTPNoContent('{}'.format(err))
        except HTTPBadRequest as err:
            response = HTTPBadRequest('{}'.format(err))
        # try:
        #     response.extras = OerebStats(service='GetExtractById',
        #                                  output_format=params.format,
        #                                  params=vars(params))
        # except UnboundLocalError:
        #     response.extras = OerebStats(service='GetExtractById', params={'error': response.message})
        # except Exception:
        #     # if params is not set we get UnboundLocalError
        #     # or we could get ValueError
        #     # in any case, the logging should never crash the response delivery
        #     try:
        #         response.extras = OerebStats(service='GetExtractById', params={'error': response.message})
        #     except AttributeError:
        #         response.extras = OerebStats(service='GetExtractById')
        return response