Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Nov 10, 2023
2 parents 39ec2f1 + de309ed commit 09d14d1
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 17 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
repos:
# Versioning: Commit messages & changelog
- repo: https://github.com/commitizen-tools/commitizen
rev: 3.10.1
rev: 3.12.0
hooks:
- id: commitizen
stages: [commit-msg]

# Autoformat: Python code
- repo: https://github.com/psf/black
rev: 23.9.1
rev: 23.10.1
hooks:
- id: black

# Lint / autoformat: Python code
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: "v0.0.292"
rev: "v0.1.4"
hooks:
- id: ruff
args: [--exit-non-zero-on-fix]
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ nav:
- External Data: about/externaldata.md
- Data conflation: about/conflation.md
- The Config File: about/configuring.md
- XLSForm Design: about/xlsforms.md
# - odk2geojson: api/odk2geojson.md
# - odk2csv: api/odk2csv.md
# - odk2osm: api/odk2osm.md
Expand Down
12 changes: 8 additions & 4 deletions osm_fieldwork/basemapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import argparse
import concurrent.futures
import json
import geojson
import logging
import queue
import re
Expand Down Expand Up @@ -101,6 +101,7 @@ def dlthread(
# Create the subdirectories as pySmartDL doesn't do it for us
Path(dest).mkdir(parents=True, exist_ok=True)

dl = None
try:
if site["source"] == "topo":
filespec += "." + site["suffix"]
Expand All @@ -112,7 +113,10 @@ def dlthread(
log.debug("%s exists!" % (outfile))
except Exception as e:
log.error(e)
log.error("Couldn't download from %r: %s" % (filespec, dl.get_errors()))
if dl:
log.error(f"Couldn't download {filespec}: {dl.get_errors()}")
else:
log.error(f"Couldn't download {filespec}")


class BaseMapper(object):
Expand Down Expand Up @@ -292,10 +296,10 @@ def makeBbox(

log.debug(f"Reading geojson file: {boundary}")
with open(boundary, "r") as f:
poly = json.load(f)
poly = geojson.load(f)
if "features" in poly:
geometry = shape(poly["features"][0]["geometry"])
if "geometry" in poly:
elif "geometry" in poly:
geometry = shape(poly["geometry"])
else:
geometry = shape(poly)
Expand Down
6 changes: 3 additions & 3 deletions osm_fieldwork/json2osm.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def parse(
tags[key] = v
total.append(tags)

log.debug(f"Finsished parsing JSON file {filespec}")
# log.debug(f"Finished parsing JSON file {filespec}")
return total

def createEntry(
Expand Down Expand Up @@ -417,10 +417,10 @@ def json2osm(input_file, yaml_file=None):
log.warning(f"Bad record! {feature}")
continue # Skip bad records

log.debug("Writing final OSM XML file...")
jsonin.writeOSM(feature)
# log.debug("Writing final OSM XML file...")

jsonin.finishOSM()
# jsonin.finishOSM()
log.info(f"Wrote OSM XML file: {osmoutfile}")

return osmoutfile
Expand Down
12 changes: 8 additions & 4 deletions osm_fieldwork/osmfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ def createWay(
for ref in way["refs"]:
osm += '\n <nd ref="%s"/>' % ref

import epdb; epdb.st()
if "tags" in way:
for key, value in way["tags"].items():
if value is None:
Expand All @@ -208,8 +209,9 @@ def createWay(
continue
if key not in attrs:
newkey = escape(key)
osm += "\n <tag k='%s' v=%r/>" % (newkey, str(value))
if modified:
newval = escape(str(value))
osm += f"\n <tag k='{newkey}' v='{newval}'/>"
if modified and key != 'note':
osm += '\n <tag k="note" v="Do not upload this without validation!"/>'
osm += "\n"

Expand Down Expand Up @@ -296,8 +298,10 @@ def createNode(
if not value:
continue
if key not in attrs:
osm += "\n <tag k='%s' v=%r/>" % (key, str(value))
if modified:
newkey = escape(key)
newval = escape(str(value))
osm += f"\n <tag k='{newkey}' v='{newval}'/>"
if modified and key != 'note':
osm += '\n <tag k="note" v="Do not upload this without validation!"/>'
osm += "\n </node>\n"
else:
Expand Down
5 changes: 2 additions & 3 deletions tests/test_basemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
log = logging.getLogger(__name__)

rootdir = os.path.dirname(os.path.abspath(__file__))
infile = f"{rootdir}/testdata/Rollinsville.geojson"
boundary = f"{rootdir}/testdata/Rollinsville.geojson"
outfile = f"{rootdir}/testdata/rollinsville.mbtiles"
base = "./tiles"
# boundary = open(infile, "r")
Expand All @@ -45,7 +45,7 @@
def test_create():
"""See if the file got loaded."""
hits = 0
basemap = BaseMapper(infile, base, "topo", False)
basemap = BaseMapper(boundary, base, "topo", False)
tiles = list()
for level in [8, 9, 10, 11, 12]:
basemap.getTiles(level)
Expand All @@ -65,6 +65,5 @@ def test_create():

assert hits == 2


if __name__ == "__main__":
test_create()

0 comments on commit 09d14d1

Please sign in to comment.