Skip to content

Commit

Permalink
Merge pull request #204 from akrherz/geojson
Browse files Browse the repository at this point in the history
Cleanup a geojson export
  • Loading branch information
akrherz committed Jun 25, 2024
2 parents f2fb2b0 + b750506 commit bf7d1b1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ci:
autoupdate_schedule: quarterly
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.4.7"
rev: "v0.4.10"
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dependencies:
# For the future warning
- pandas>=2.2
- pygrib
- pyogrio
- pyproj
- pytest
- pytest-runner
Expand Down
10 changes: 5 additions & 5 deletions src/iemws/util.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Helpers."""

import logging
import tempfile
from contextlib import contextmanager
from functools import wraps
from io import BytesIO
from typing import Callable

from fastapi import Request, Response
Expand Down Expand Up @@ -67,10 +67,10 @@ def deliver_df(df: DataFrame, fmt: str):
if df.empty:
res = '{"type": "FeatureCollection", "features": []}'
else:
with tempfile.NamedTemporaryFile("w", delete=True) as tmp:
df.to_file(tmp.name, driver="GeoJSON")
with open(tmp.name, encoding="utf8") as fh:
res = fh.read()
with BytesIO() as tmp:
df.crs = "EPSG:4326"
df.to_file(tmp, driver="GeoJSON", engine="pyogrio")
res = tmp.getvalue()
return Response(res, media_type=MEDIATYPES[fmt])


Expand Down

0 comments on commit bf7d1b1

Please sign in to comment.