Skip to content

Commit

Permalink
feat: use flatgeobuf data extracts (#1047)
Browse files Browse the repository at this point in the history
* fix: allow creating organisations without logo

* build(frontend): add flatgeobuf dependency

* refactor: extra typing and docstring for geojson_to_flatgeobuf

* fix: geojson --> fgb async, handle empty return

* feat: upload custom extract to s3, insert url to db

* refactor: check_crs geojson parsing

* test: fix extract upload test

* refactor: consolidate building+line geojson --> extract geojson

* fix: sort category list during form selection

* build: bump fmtm-splitter --> 0.2.5 to avoid fgb errors

* fix: task_split endpoint always take data extract param

* feat: add endpoint to get data extract as flatgeobuf

* feat: get new data extract on page change if selected

* feat: handle fgb custom data extract upload

* feat: add data extract url to project on submit

* refactor: remove extra log.warning in project_crud

* hotfix:check geom type Feature in get_data_extract_url

* fix: check geom type Feature in preview tasks

* refactor: replace pkg_resources deprecation with importlib

---------

Co-authored-by: Niraj Adhikari <nrjadkry@gmail.com>
  • Loading branch information
spwoodcock and nrjadkry authored Jan 4, 2024
1 parent 43fe756 commit 06b64db
Show file tree
Hide file tree
Showing 19 changed files with 737 additions and 470 deletions.
22 changes: 18 additions & 4 deletions src/backend/app/db/postgis_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,16 @@ def get_centroid(geometry: Geometry, properties: str = {}, id: int = None):
return {}


def geojson_to_flatgeobuf(db: Session, geojson: FeatureCollection):
"""From a given FeatureCollection, return a memory flatgeobuf obj."""
async def geojson_to_flatgeobuf(db: Session, geojson: FeatureCollection) -> bytes:
"""From a given FeatureCollection, return a memory flatgeobuf obj.
Args:
db (Session): SQLAlchemy db session.
geojson (FeatureCollection): a geojson.FeatureCollection object.
Returns:
flatgeobuf (bytes): a Python bytes representation of a flatgeobuf file.
"""
sql = f"""
DROP TABLE IF EXISTS public.temp_features CASCADE;
Expand All @@ -93,7 +101,13 @@ def geojson_to_flatgeobuf(db: Session, geojson: FeatureCollection):
# Run the SQL
result = db.execute(text(sql))
# Get a memoryview object, then extract to Bytes
flatgeobuf = result.fetchone()[0].tobytes()
flatgeobuf = result.fetchone()[0]

# Cleanup table
db.execute(text("DROP TABLE IF EXISTS public.temp_features CASCADE;"))
return flatgeobuf

if flatgeobuf:
return flatgeobuf.tobytes()

# Nothing returned (either no features passed, or failed)
return None
3 changes: 2 additions & 1 deletion src/backend/app/organization/organization_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ async def create_organization(
db.refresh(db_organization)

# Update the logo field in the database with the correct path
db_organization.logo = await upload_logo_to_s3(db_organization, logo)
if logo:
db_organization.logo = await upload_logo_to_s3(db_organization, logo)
db.commit()

except Exception as e:
Expand Down
Loading

0 comments on commit 06b64db

Please sign in to comment.