Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

used osm-rawdata instead of osm-fieldwork for data extracts from osm #877

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions src/backend/app/projects/project_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
from loguru import logger as log
from osm_fieldwork import basemapper
from osm_fieldwork.json2osm import json2osm
from osm_fieldwork.make_data_extract import PostgresClient
from osm_fieldwork.OdkCentral import OdkAppUser
from osm_fieldwork.xlsforms import xlsforms_path
from osm_rawdata.postgres import PostgresClient
from shapely import wkt
from shapely.geometry import (
LineString,
Expand Down Expand Up @@ -1448,8 +1448,6 @@ def generate_appuser_files(
one = result.first()

if one:
prefix = one.project_name_prefix

# Get odk credentials from project.
odk_credentials = {
"odk_central_url": one.odk_central_url,
Expand Down Expand Up @@ -1477,21 +1475,31 @@ def generate_appuser_files(
upload_custom_data_extracts(db, project_id, extracts_contents)

else:
import osm_fieldwork as of

rootdir = of.__path__[0]

project = (
db.query(db_models.DbProject)
.filter(db_models.DbProject.id == project_id)
.first()
)
config_file_contents = project.form_config_file

project_log.info("Extracting Data from OSM")

# OSM Extracts for whole project
pg = PostgresClient(settings.UNDERPASS_API_URL, "underpass")
# This file will store osm extracts
outfile = f"/tmp/{prefix}_{xform_title}.geojson"
config_path = "/tmp/config.yaml"
if config_file_contents:
with open(config_path, "w", encoding="utf-8") as config_file_handle:
config_file_handle.write(config_file_contents.decode("utf-8"))
else:
config_path = f"{rootdir}/data_models/{category}.yaml"

# # OSM Extracts for whole project
pg = PostgresClient("underpass", config_path)
outline = json.loads(one.outline)
outline_geojson = pg.getFeatures(
boundary=outline,
filespec=outfile,
polygon=extract_polygon,
xlsfile=f"{category}.xls",
category=category,
)
boundary = {"type": "Feature", "properties": {}, "geometry": outline}
outline_geojson = pg.execQuery(boundary)

updated_outline_geojson = {"type": "FeatureCollection", "features": []}

Expand Down Expand Up @@ -1519,7 +1527,6 @@ def generate_appuser_files(
}
updated_outline_geojson["features"].append(feature)
feature_mappings.append(feature_mapping)

# Bulk insert the osm extracts into the db.
db.bulk_insert_mappings(db_models.DbFeatures, feature_mappings)

Expand Down
Loading