add: spacial data upload

v0.3
rrr-marble 4 years ago
parent 207a216be3
commit 3e004b9f73

@ -9,5 +9,7 @@
# Known restrictions
- *models.py*, *schema.py*, and current representation of column headers in `headers` db table (as initialised by alembic migration script) **must** be kept in sync
- `SQALCHEMY_DATABASE_URL` in *database.py* and `sqlalchemy.url` in *alembic.ini* **must** be kept in sync
- martin requires a restart after the very first data is uploaded into an empty database
`docker-compose --file docker/docker-compose.yml restart martin`
# Known issues

@ -2,7 +2,7 @@ from typing import List
from sqlalchemy.orm import Session
from sqlalchemy.sql.expression import func
from sqlalchemy import inspect
from sqlalchemy import inspect, text
from . import models, schemas
from .database import Base
@ -104,3 +104,29 @@ def insert_items(db: Session, items: List[schemas.ItemCreate]):
def get_headers(db: Session):
"""полные заголовки таблиц"""
return db.query(models.Header).all()
def add_spacial_data(db: Session):
"""Превращает строковые данные с координатами, полученные из таблицы
в пространственные, и помещает их в отдельный столбец в общей базе данных
"""
check_t = text(
"""SELECT true
FROM pg_attribute
WHERE attrelid = 'geodata'::regclass
AND attname = 'geom'
AND NOT attisdropped
AND attnum > 0"""
)
create_t = text(
"""SELECT AddGeometryColumn( 'public', 'geodata', 'geom', 4326, 'POINT', 2 )"""
)
populate_t = text(
"""UPDATE geodata
SET geom = ST_SetSRID(ST_Point( y_coord::numeric, x_coord::numeric),4326)
"""
)
if not db.execute(check_t).all():
db.execute(create_t)
db.execute(populate_t)
db.commit()

@ -76,6 +76,8 @@ def create_items(file: UploadFile = File(...), db: Session = Depends(get_db)):
]
# dump all the data into database
accepted, processed = crud.insert_items(db=db, items=spreadsheet_item_list)
# transform spreadsheet coordinates data into spacial
crud.add_spacial_data(db=db)
except spreadsheet.InvalidFileException:
raise HTTPException(

@ -4,6 +4,11 @@
reverse_proxy geodata:8000
}
handle_path /martin/* {
rewrite * {path}
reverse_proxy martin:3000
}
redir /openapi.json /api/v1/openapi.json permanent
root * /usr/share/caddy

@ -22,10 +22,8 @@ services:
martin:
image: "urbica/martin:pr-368"
environment:
DATABASE_URL: "postgres://geodata:QAKvBKvLe4bS9U@postgres/spatial" # TODO: change to real password
DATABASE_URL: "postgres://geodata:QAKvBKvLe4bS9U@postgres/geodata" # TODO: change to real password
restart: unless-stopped
ports:
- "3000:3000"
frontend:
image: geoshop-frontend

Loading…
Cancel
Save