Skip to content

Commit

Permalink
Merge pull request #44 from citysciencelab/fix-gs-upload
Browse files Browse the repository at this point in the history
fix: fix geoserver upload
  • Loading branch information
hwbllmnn authored Oct 1, 2024
2 parents 2ee4c40 + 2ec5451 commit 9789477
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
21 changes: 21 additions & 0 deletions migrations/versions/1.0.6_add_postgis_extension.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""Add postgis extension
Revision ID: 1.0.6
Revises:
Create Date: 2024-10-01 14:00
"""

from alembic import op
from sqlalchemy import BigInteger, Column, String

revision = "1.0.6"
down_revision = "1.0.5"
branch_labels = "add_postgis_extension"
depends_on = "1.0.5"

def upgrade():
op.execute('create extension postgis')

def downgrade():
op.execute('drop extension postgis')
13 changes: 9 additions & 4 deletions src/ump/api/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,12 @@ def set_results_metadata(self, results_as_json):
)

for column in results_df.select_dtypes(include=[object]).to_dict():
values.append(
{column: {"type": "string", "values": list(set(results_df[column]))}}
)
try:
values.append(
{column: {"type": "string", "values": list(set(results_df[column]))}}
)
except Exception as e:
logging.error(f"Unable to store column {column}, skipping: {e}")

self.results_metadata = {"values": values}

Expand Down Expand Up @@ -320,6 +323,8 @@ async def results_to_geoserver(self):
try:

results = await self.results()
while 'results' in results:
results = results['results']
geoserver = Geoserver()

self.set_results_metadata(results)
Expand All @@ -332,7 +337,7 @@ async def results_to_geoserver(self):

except Exception as e:
logging.error(
f" --> Could not store results for job {self.process_id_with_prefix} (={self.process_id})/{self.job_id} to geoserver: {e}"
f" --> Could not store results for job {self.process_id_with_prefix} (={self.process_id})/{self.job_id} to geoserver: {e}", e
)

def __str__(self):
Expand Down
2 changes: 1 addition & 1 deletion src/ump/geoserver/geoserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def geojson_to_postgis(self, table_name: str, data: dict):
engine = create_engine(
f"postgresql://{config.postgres_user}:{config.postgres_password}@{config.postgres_host}/{config.postgres_db}"
)
gdf = gpd.GeoDataFrame.from_features(data["features"])
gdf = gpd.GeoDataFrame.from_features(data["features"], crs = 'EPSG:4326')
table = Identifier(table_name)
gdf.to_postgis(name=table.string, con=engine)

Expand Down

0 comments on commit 9789477

Please sign in to comment.