Skip to content

Commit

Permalink
Merge branch 'main' of github.com:hotosm/osm-fieldwork
Browse files Browse the repository at this point in the history
Sync with upstream
  • Loading branch information
robsavoye committed Sep 11, 2023
2 parents d7292b9 + 8e56479 commit ad9d316
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 31 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ on:
jobs:
test:
runs-on: ubuntu-latest
environment:
name: ${{ github.ref_name }}

steps:
- uses: actions/checkout@v3
Expand Down
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
## 0.3.6rc2 (2023-09-11)

### Fix

- json2osm handle polygons and points (#192)
- Update raw-osmdata to 0.1.1
- add osm-rawdata dependency
- Major refactoring to use the new osm-rawdata module
- Add join_or tag which is now required in the enhanced YAML format
- Use optional env variable for the raw data API
- initialize variable
- Arg, change the raw data URI again
- json2osm calling via api
- The URL for raw data has changed
- Add config file for waterways

## 0.3.6rc1 (2023-09-07)

### Fix
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

PACKAGE := org.osm_fieldwork.py
NAME := osm-fieldwork
VERSION := 0.3.6rc1
VERSION := 0.3.6rc2

# All python source files
FILES := $(wildcard ./osm_fieldwork/*.py)
Expand Down
2 changes: 1 addition & 1 deletion osm_fieldwork/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.3.6rc1"
__version__ = "0.3.6rc2"
62 changes: 36 additions & 26 deletions osm_fieldwork/json2osm.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import sys
import json
import geojson
import shapely
from sys import argv
from osm_fieldwork.convert import Convert, escape
from osm_fieldwork.osmfile import OsmFile
Expand Down Expand Up @@ -203,9 +204,9 @@ def parse(self,
else:
log.error("Need to specify a JSON or GeoJson file!")
return all_tags
elif type(data) == str:
elif isinstance(data, str):
reader = geojson.loads(data)
elif type(data) == list:
elif isinstance(data, list):
reader = data

total = list()
Expand All @@ -221,6 +222,12 @@ def parse(self,
# log.info(f"ROW: {row}")
tags = dict()
if 'geometry' in row:
# If geom not point, convert to centroid
if row['geometry']['type'] != 'Point':
log.debug(f"Converting {row['geometry']['type']} geometry to centroid point")
geom = shapely.from_geojson(str(row))
centroid = shapely.to_geojson(geom.centroid)
row['geometry'] = centroid
tags['geometry'] = row['geometry']
else:
pat = re.compile("[-0-9.]*, [0-9.-]*, [0-9.]*")
Expand Down Expand Up @@ -253,13 +260,15 @@ def parse(self,
# a JSON file from ODK Central always uses coordinates as
# the keyword
if key == 'coordinates':
if type(v) == list:
if isinstance(v, list):
lat = v[1]
lon = v[0]
tags['geometry'] = f"{lat} {lon}"
continue
tags[key] = v
total.append(tags)

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

def createEntry(self,
Expand Down Expand Up @@ -298,31 +307,30 @@ def createEntry(self,
# Otherwise use the GPS coordinates where you are.
lat = None
lon = None
if type(value) == float:
if isinstance(value, float):
continue
# log.debug(f"FIXME: {key} = {value} {type(value)}")
if key == "xid" and value is not None:
attrs['id'] = int(value)
if key == "geometry":
# The GeoJson file has the geometry field. Usually it's a dict
# The GeoJson file has the geometry field. Usually it's a list
# but on occasion it's a string instead, so turn it into a list
if type(value) == str:
if value[0] == '[':
coords = eval(value)
lat = coords[1]
lon = coords[0]
else:
coords = value.split(' ')
lat = coords[0]
lon = coords[1]
# log.debug(f"VALUE STRING: {coords}")
elif type(value) == geojson.geometry.Point:
lat = value['coordinates'][1]
lon = value['coordinates'][0]
# log.debug(f"VALUE POINT: {lat}/{lon}")
elif type(value) == list:
lat = float(value[1])
lon = float(value[0])
if isinstance(value, str) and len(coords:=value.split(' ')) >= 2:
lat = coords[0]
lon = coords[1]

# Parse as geojson
else:
geom = shapely.from_geojson(str(value))

if geom.geom_type != 'Point':
# Use centroid if polygon
geom = geom.centroid

# Get coords from point
lat = geom.y
lon = geom.x

attrs["lat"] = lat
attrs["lon"] = lon
# log.debug(f"ATTRS: {attrs}")
Expand All @@ -342,7 +350,9 @@ def createEntry(self,
# tags[entry] = "yes"
# continue

if value is not None and value != "no" and value != "unknown":
if isinstance(value, str) and (value == "no" or value == "unknown"):
pass
elif value is not None:
if key == "track" or key == "geoline":
refs.append(tag)
log.debug("Adding reference %s" % tag)
Expand All @@ -351,9 +361,9 @@ def createEntry(self,
priv[key] = value
else:
item = self.convertEntry(key, value)
if item is not None and type(item) == dict:
if item is not None and isinstance(item, dict):
tags.update(item)
elif type(item) == list:
elif isinstance(item, list):
for entry in item:
tags.update(entry)

Expand Down Expand Up @@ -408,7 +418,7 @@ def json2osm(input_file, yaml_file=None):
if len(feature) > 0:
if "lat" not in feature["attrs"]:
if 'geometry' in feature['tags']:
if type(feature['tags']['geometry']) == str:
if isinstance(feature["tags"]["geometry"], str):
coords = list(feature['tags']['geometry'])
# del feature['tags']['geometry']
elif 'coordinates' in feature['tags']:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pythonpath = "osm_fieldwork"

[tool.commitizen]
name = "cz_conventional_commits"
version = "0.3.6rc1"
version = "0.3.6rc2"
version_files = [
"pyproject.toml:version",
"osm_fieldwork/__version__.py",
Expand Down

0 comments on commit ad9d316

Please sign in to comment.