Skip to content

Replace custom OGC API implementation with pygeoapi (mounted in FastAPI)#545

Merged
jirhiker merged 39 commits intostagingfrom
jir-ogc
Feb 26, 2026
Merged

Replace custom OGC API implementation with pygeoapi (mounted in FastAPI)#545
jirhiker merged 39 commits intostagingfrom
jir-ogc

Conversation

@jirhiker
Copy link
Copy Markdown
Member

@jirhiker jirhiker commented Feb 24, 2026

Summary

Replaced the custom OGC implementation with a pygeoapi-based OGC API Features stack, mounted into FastAPI, and moved pygeoapi support objects to DB-managed views/migrations.

What changed

FastAPI + pygeoapi integration

  • Mounted pygeoapi as a sub-application under PYGEOAPI_MOUNT_PATH (now /ogcapi).
  • Moved pygeoapi server/resource configuration into a dedicated YAML template:
    • core/pygeoapi-config.yml
  • Runtime config/openapi files are generated in a runtime-writable directory (/tmp/pygeoapi by default).
  • Route registration pattern consolidated (no duplicate registration paths).

OGC data model changes

  • Removed custom hand-rolled OGC route behavior in favor of pygeoapi collections backed by SQL views/materialized views.
  • Added/updated pygeoapi collections for thing types and derived well datasets.
  • Set collection bbox extents to New Mexico.

DB/Alembic

  • Added pygeoapi supporting views in Alembic (d5e6f7a8b9c0...), including:
    • ogc_* thing-type views
    • ogc_latest_depth_to_water_wells (materialized)
    • ogc_avg_tds_wells (materialized; sourced from NMA_MajorChemistry)
  • Removed fallback WHERE FALSE stub behavior; migration now fails clearly when required source tables are missing.
  • Improved required-table error messages with explicit missing table names.
  • Updated latest-depth logic:
    • measuring_point_height nulls are now treated as 0 (COALESCE) for depth-to-water BGS.
  • Added pg_cron scheduling in the same migration:
    • creates refresh function
    • schedules nightly refresh job
    • unschedules/drops on downgrade
    • fixed DO-block quoting bug ($do$ / $cmd$).

CLI

  • Added command to refresh pygeoapi materialized views on demand:
    • refresh-pygeoapi-materialized-views
    • supports --view and --concurrently
  • CLI dotenv behavior changed to load_dotenv(override=True) so .env values win.

Infra/workflows/env

  • Added/standardized pygeoapi DB env vars in CI/CD/test workflows:
    • PYGEOAPI_POSTGRES_HOST
    • PYGEOAPI_POSTGRES_PORT
    • PYGEOAPI_POSTGRES_DB
    • PYGEOAPI_POSTGRES_USER
    • PYGEOAPI_POSTGRES_PASSWORD
  • Added pygeoapi to default app_read grant membership.
  • Docker DB setup updated for pg_cron support:
    • new docker/db/Dockerfile installs postgresql-17-cron
    • compose DB command preloads pg_cron and sets cron.database_name.

Cleanup

  • Removed custom OGC references/tests/routes where applicable while preserving pygeoapi-based OGC API behavior.
  • Unstaged/ignored local .pygeoapi runtime artifacts from versioned code paths.

Why

  • Align OGC API implementation with a standard server (pygeoapi) instead of maintaining custom OGC logic.
  • Make OGC collection generation and DB support deterministic via migrations.
  • Improve operability with explicit refresh mechanisms (manual CLI + nightly pg_cron).
  • Reduce routing/config drift and deployment surprises across local/CI/staging/prod.

Notes

  • pg_cron must be available on the target PostgreSQL server/instance for scheduled refresh setup.

Copilot AI review requested due to automatic review settings February 24, 2026 19:08
@jirhiker jirhiker marked this pull request as draft February 24, 2026 19:08
@jirhiker jirhiker changed the title feat: integrate pygeoapi for OGC API - Features endpoints and update related configurations Replace custom OGC API implementation with pygeoapi (mounted in FastAPI) Feb 24, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a427cd60ef

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Integrates pygeoapi to serve OGC API - Features endpoints under /oapi, replacing the in-repo /ogc router, and updates application initialization, documentation, and tests accordingly.

Changes:

  • Add pygeoapi==0.22.0 and its transitive dependencies to project dependencies and lockfiles.
  • Mount pygeoapi as a sub-application at /oapi with generated config, plus DB views to back collections.
  • Update OGC-related tests and documentation from /ogc to /oapi.

Reviewed changes

Copilot reviewed 9 out of 12 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
uv.lock Locks new dependencies introduced by adding pygeoapi and related packages.
requirements.txt Exports updated runtime dependency set including pygeoapi and geospatial deps (e.g., rasterio).
pyproject.toml Adds pygeoapi==0.22.0 to application dependencies.
main.py Refactors app setup into create_app() and delegates middleware/admin setup to initializers.
core/initializers.py Replaces /ogc router inclusion with mount_pygeoapi(app) and adds middleware/admin configurators.
core/pygeoapi.py Implements mounting logic, config generation, and supporting-view creation for pygeoapi-backed collections.
core/pygeoapi-config.yml Adds a pygeoapi configuration template for PostGIS-backed collections.
tests/test_ogc.py Updates tests to hit /oapi endpoints and adjusts expectations for pygeoapi responses.
api/README.md Updates API module documentation to reflect pygeoapi-mounted OGC endpoints.
README.md Updates public docs and examples to use /oapi and references pygeoapi.
CLAUDE.md Updates developer docs to reference /oapi instead of /ogc.
.gitignore Ignores the generated .pygeoapi/ directory.

jirhiker and others added 4 commits February 24, 2026 14:18
…ensitive information

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@jirhiker jirhiker marked this pull request as ready for review February 25, 2026 00:20
Copilot AI review requested due to automatic review settings February 25, 2026 00:20
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 19 changed files in this pull request and generated 8 comments.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 87d1b9ee5b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 25, 2026 16:44
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 19 changed files in this pull request and generated 1 comment.

Copilot AI review requested due to automatic review settings February 26, 2026 00:15
@jirhiker jirhiker review requested due to automatic review settings February 26, 2026 00:15
Copilot AI review requested due to automatic review settings February 26, 2026 00:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 35 out of 38 changed files in this pull request and generated 5 comments.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 26, 2026 03:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 36 out of 39 changed files in this pull request and generated 3 comments.

Copilot AI review requested due to automatic review settings February 26, 2026 04:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 36 out of 39 changed files in this pull request and generated 7 comments.

jirhiker and others added 2 commits February 25, 2026 21:10
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 26, 2026 04:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 36 out of 39 changed files in this pull request and generated 1 comment.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 26, 2026 04:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 36 out of 39 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

tests/test_ogc.py:55

  • The test file imports override_authentication from tests but this fixture is module-scoped and applied via autouse=True (line 36-37). However, if pygeoapi is not installed, the entire test module is skipped via the pytestmark (lines 30-33). This means the authentication override will never be set up or torn down when pygeoapi is missing. While this is functionally correct (tests are skipped), the fixture setup/teardown pattern might confuse future maintainers. Consider adding a docstring to the fixture explaining this behavior.

def pytest_configure():
load_dotenv(override=True)
os.environ.setdefault("POSTGRES_PORT", "54321")
# NOTE: This hardcoded secret key is for tests only and must NEVER be used in production.
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conftest.py and main initialization set a default SESSION_SECRET_KEY for tests, but this hardcoded secret is documented as test-only with a clear warning. However, the comment in conftest.py line 21-22 should use more emphatic language matching the rest of the codebase, such as "MUST NEVER" instead of "must NEVER" for consistency with security warnings elsewhere.

Suggested change
# NOTE: This hardcoded secret key is for tests only and must NEVER be used in production.
# NOTE: This hardcoded secret key is for tests only and MUST NEVER be used in production.

Copilot uses AI. Check for mistakes.
@jirhiker jirhiker merged commit 32237e3 into staging Feb 26, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants