Skip to content

Commit

Permalink
Merge branch 'master' into revise_toc_calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
peterschaer committed Dec 18, 2024
2 parents aa54d49 + de30714 commit 509abbd
Show file tree
Hide file tree
Showing 14 changed files with 411 additions and 105 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ jobs:

lint:
name: Check style (lint)
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- run: sudo rm /etc/apt/sources.list.d/*.list
- run: sudo apt update
- run: sudo apt-get install libpq-dev
Expand All @@ -16,9 +16,9 @@ jobs:

gitattributes:
name: Check style (git-attributes)
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- run: sudo rm /etc/apt/sources.list.d/*.list
- run: sudo apt update
- run: sudo apt-get install libpq-dev
Expand All @@ -27,7 +27,7 @@ jobs:

test-py:
name: Test Python
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
services:
# Label used to access the service container
postgres:
Expand All @@ -52,7 +52,7 @@ jobs:
- '3.11'
- '3.12'
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Set up Python v${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
Expand All @@ -76,9 +76,9 @@ jobs:

test-fed-data:
name: Check federal data definitions
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- run: sudo rm /etc/apt/sources.list.d/*.list
- run: sudo apt update
- run: sudo apt-get install xsltproc
Expand All @@ -93,24 +93,24 @@ jobs:
doc:
name: Make and deploy documentation
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Make documentation
run: |
sudo rm /etc/apt/sources.list.d/*.list
sudo apt update
sudo apt-get install libpq-dev
make doc-html
- name: Deploy 🚀
uses: JamesIves/[email protected].3
uses: JamesIves/[email protected].8
with:
branch: gh-pages # The branch the action should deploy to.
folder: doc/build/html # The folder the action should deploy.

build-and-publish:
name: Build and publish Python 🐍 distributions 📦 to PyPI
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
needs: [lint, gitattributes]
steps:
- uses: actions/checkout@master
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/daily_check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ on:
jobs:
test-fed-data:
name: Check federal data definitions
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- run: sudo rm /etc/apt/sources.list.d/*.list
- run: sudo apt update
- run: sudo apt-get install xsltproc
Expand All @@ -22,7 +22,7 @@ jobs:
test-py:
name: Test Python
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
services:
# Label used to access the service container
postgres:
Expand All @@ -47,7 +47,7 @@ jobs:
- python3.11
- python3.12
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- run: sudo rm /etc/apt/sources.list.d/*.list
- run: sudo apt update
- run: sudo apt-get install libpq-dev
Expand Down
11 changes: 11 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ Notes:
------
- This python package specifies the version numbers only of directly imported python packages. This approach may result in a build failure of older versions of the project if incompatibilities arise between imported packages over time. The build process of the master branch is regularly tested in an automatic process.

master
------
- Support Oereblex API version 1.2.5 via geolink-formatter 2.0.6 (#2081)

2.5.4
-----
- New parameter default_toc_length to define a default table of content pages number (#2042)
- Add timeout in address source (#2043)
- Optimize legend entries retrieval (#2050)
- Library upgrades (waitress, sqlalchemy, psycopg2, urllib3)

2.5.3
-----
- Provide a general WMS verify certificate option
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.12.5-bullseye
FROM python:3.13.0-bullseye

ENV DEBIAN_FRONTEND=noninteractive

Expand Down
17 changes: 13 additions & 4 deletions dev/config/pyramid_oereb.yml.mako
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,18 @@ pyramid_oereb:
# Will make an estimation of the total length of the Table of Content (TOC) and control that the page
# numbering in the output pdf is consistent with TOC numbering. If it is known that the TOC is very long and
# could run over more than one page, it is preferred to set this to true. The drawback is that it might need
# more time to generate the PDF. If set to false, it will assume that only one TOC page exists, and this can
# lead to wrong numbering in the TOC.
compute_toc_pages: true
# more time to generate the PDF. If set to false, the expected_toc_length setting below will be used. If it is
# not set it will assume that only one TOC page exists, and this can lead to wrong numbering in the TOC, which
# will be fixed by a second PDF extract call that has an impact on performance.
compute_toc_pages: false
# In order to skip the computation of the estimated number of TOC pages which might return an erroneous result
# for your setting, you can specify a default for the number of TOC pages. For most of the cantons the number of
# TOC pages is pretty constant unless a real estate is concerned by none or a huge number of restrictions.
# In both cases (computing an estimate or setting a default for the number of TOC pages) the exact number of TOC
# pages is extracted from the created PDF and if it differs from the expected value the PDF is created a second
# time with the correct page numbers.
# Note that if "compute_toc_pages" is set true the "expected_toc_length" is not taken into account.
expected_toc_length: 2
# Specify any additional URL parameters that the print shall use for WMS calls
wms_url_params:
TRANSPARENT: 'true'
Expand Down Expand Up @@ -171,7 +180,7 @@ pyramid_oereb:
# OEREBlex host
host: https://oereblex.sg.ch
# geoLink schema version
version: 1.2.2
version: 1.2.5
# Pass schema version in URL
pass_version: true
# Enable/disable XML validation
Expand Down
20 changes: 18 additions & 2 deletions doc/source/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@ Changes/Hints for migration
This chapter will give you hints on how to handle version migration, in particular regarding what you may need
to adapt in your project configuration, database etc. when upgrading to a new version.

master
------
- Support of Oereblex API version 1.2.5 via geolink-formatter 2.0.6 added (#2081). The oereblex schema version that is used to download oereblex xmls can be set in the file pyramid_oereb.yaml.

Version 2.5.4
-------------
Feature and maintenance release:

* New parameter 'expected_toc_length' allows to define a default table of content pages number avoiding a
second call for the pdf extract in most cases. This value may be be set if most of the PDF extracts have
the same number of TOC pages. It complements the 'compute_toc_pages' parameter. If the latter is set to true,
'expected_toc_length' is ignored.
* Add timeout in address source (#2043)
* Optimize legend entries retrieval (#2050)
* Library upgrades (waitress, sqlalchemy, psycopg2, urllib3)

Version 2.5.3
-------------
Feature and maintenance release:
Expand Down Expand Up @@ -92,7 +108,7 @@ Maintenance release:

* Add support for newest oereblex API (via geolink-formatter, #1703)
* Various minor library upgrades (SQLAlchemy, geoalchemy, psycopg2, pypdf)


Version 2.4.2
-------------
Expand Down Expand Up @@ -165,7 +181,7 @@ Version 2.2.4
-------------
New functionality for configuring tolerance (optional):

* Support tolerance per geometry type (#1603). See example definitions in the example project configuration file.
* Support tolerance per geometry type (#1603). See example definitions in the example project configuration file.
* Library updates (#1604)

.. _changes-version-2.2.3:
Expand Down
26 changes: 13 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "pyramid_oereb"
version = "2.5.3"
version = "2.5.4"
description = "pyramid_oereb, extension for pyramid web frame work to provide a basic server part for the oereb project"

classifiers=[
Expand Down Expand Up @@ -35,22 +35,22 @@ Changelog = "https://github.com/openoereb/pyramid_oereb/blob/master/CHANGES.rst"
[project.optional-dependencies]
# Dependencies listed in "recommend" must be included in "no-version" without explicit version number
recommend = [
"pypdf==4.3.1",
"pypdf==5.1.0",
"filetype==1.2.0",
"geoalchemy2==0.15.2",
"pyramid==2.0.2",
"pyramid-debugtoolbar==4.12.1",
"qrcode==7.4.2",
"qrcode==8.0",
"image==1.5.33",
"shapely==2.0.6",
"SQLAlchemy==2.0.32",
"SQLAlchemy==2.0.36",
"pyaml-env==1.2.1",
"urllib3==2.2.2",
"waitress==3.0.0",
"urllib3==2.2.3",
"waitress==3.0.1",
"pyreproj==3.0.0",
"mako-render==0.1.0",
"requests==2.32.3",
"geolink-formatter==2.0.5",
"geolink-formatter==2.0.6",
"pyconizer==0.1.4",
"c2cwsgiutils[standard]==6.0.8"]
no-version = [
Expand All @@ -75,21 +75,21 @@ no-version = [
testing = [
"jsonschema==4.23.0",
"lxml==5.3.0",
"pytest==8.3.2",
"pytest-cov==5.0.0",
"pytest==8.3.3",
"pytest-cov==6.0.0",
"pytest-ordering==0.6",
"requests-mock==1.12.1",
"responses==0.25.3",
"webtest==3.0.0",
"pillow==10.4.0"]
"webtest==3.0.1",
"pillow==11.0.0"]
dev = [
"flake8==7.1.1",
"Flake8-pyproject==1.2.3",
"pyflakes==3.2.0",
"pycodestyle==2.12.1",
"Sphinx==7.4.7",
"sphinx_rtd_theme==2.0.0",
"psycopg2==2.9.9",
"sphinx_rtd_theme==3.0.1",
"psycopg2==2.9.10",
"mccabe==0.7.0",
"c2c.template==2.4.2",
"yappi"]
Expand Down
58 changes: 38 additions & 20 deletions pyramid_oereb/contrib/data_sources/interlis_2_3/sources/plr.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,20 +470,33 @@ def collect_related_geometries_by_real_estate(self, session, real_estate):
.selectinload(self.models.MultilingualUri.localised_uri)
).all()

def collect_legend_entries_by_bbox(self, session, bbox, law_status):
def get_legend_entries_from_db(self, session, legend_entry_ids):
"""
Retrieves the legend entries for a list of t_id-values.
Args:
session (sqlalchemy.orm.Session): The requested clean session instance ready for use
legend_entry_ids (list): list of the egend entry ids
Returns:
list: the query result represented as a list.
"""
return session.query(self.legend_entry_model).filter(
self.legend_entry_model.t_id.in_(legend_entry_ids)).all()

def collect_legend_entries_by_bbox(self, session, bbox):
"""
Extracts all legend entries in the topic which have spatial relation with the passed bounding box of
visible extent.
Args:
session (sqlalchemy.orm.Session): The requested clean session instance ready for use
bbox (shapely.geometry.base.BaseGeometry): The bbox to search the records.
law_status (str): String of the law status for which the legend entries should be queried.
Returns:
list: The result of the related geometries unique by the public law restriction id and law status
"""
distinct_legend_entry_ids = []
# Select the legend entries of all plr within bbox
geometries = session.query(self._model_).filter(
or_(
self._model_.point.ST_Intersects(from_shape(bbox, srid=Config.get('srid'))),
Expand All @@ -493,13 +506,29 @@ def collect_legend_entries_by_bbox(self, session, bbox, law_status):
selectinload(self.models.Geometry.public_law_restriction)
).all()

# Compile a list of unique legend entry ids for each law status
legend_entry_ids = dict()
for geometry in geometries:
if geometry.public_law_restriction.legend_entry_id not in distinct_legend_entry_ids\
and geometry.public_law_restriction.law_status == law_status:
distinct_legend_entry_ids.append(geometry.public_law_restriction.legend_entry_id)
if geometry.public_law_restriction.law_status not in legend_entry_ids:
legend_entry_ids[geometry.public_law_restriction.law_status] = {
geometry.public_law_restriction.legend_entry_id
}
else:
legend_entry_ids[geometry.public_law_restriction.law_status].add(
geometry.public_law_restriction.legend_entry_id
)

return session.query(self.legend_entry_model).filter(
self.legend_entry_model.t_id.in_((distinct_legend_entry_ids))).all()
# Retrieve legend entries
legend_entries_from_db = []
for law_status in legend_entry_ids:
legend_entries_from_db.append(
[
self.get_legend_entries_from_db(session, list(legend_entry_ids[law_status])),
law_status
]
)

return legend_entries_from_db

def read(self, params, real_estate, bbox):
"""
Expand Down Expand Up @@ -537,20 +566,9 @@ def read(self, params, real_estate, bbox):
else:
# We found spatially related elements. This means we need to extract the actual plr
# information related to the found geometries.
law_status_of_geometry = []
# get distinct values of law_status for all geometries found
for geometry in geometry_results:
if (geometry.public_law_restriction.law_status not in law_status_of_geometry):
law_status_of_geometry.append(geometry.public_law_restriction.law_status)

legend_entries_from_db = []
# get legend_entries per law_status
for law_status in law_status_of_geometry:
legend_entry_with_law_status = [
self.collect_legend_entries_by_bbox(session, bbox, law_status),
law_status
]
legend_entries_from_db.append(legend_entry_with_law_status)
legend_entries_from_db = self.collect_legend_entries_by_bbox(session, bbox)

self.records = []
for geometry_result in geometry_results:
Expand Down
Loading

0 comments on commit 509abbd

Please sign in to comment.