Skip to content

Commit

Permalink
Support GeoJSON, fix some warnings, prepare 1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Zverik committed Mar 15, 2018
1 parent 05a0337 commit 87c6ce1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## master branch

## 1.3.0

_Released 2018-03-15_

* Support for categories: `category_tag` and `categories` parameters in a profile.
* LibOsmium-based C++ filtering script for categories.
* More than one tag value works as "one of": `[('amenity', 'cafe', 'restaurant')]`.
Expand All @@ -15,6 +19,7 @@
* Better error message for Overpass API timeouts.
* Lifecycle prefixes are conflated, e.g. `amenity=*` and `was:amenity=*`.
* Dataset is checked for duplicates, which are reported (see `-d`) and removed.
* Support GeoJSON input (put identifiers into `id` property).

## 1.2.3

Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ For a simplest case, run:

conflate <profile.py> -o result.osm

You might want to add other arguments
to pass a dataset file or write the resulting osmChange somewhere. Run
You might want to add other arguments,
to pass a dataset file or prepare a preview GeoJSON. Run
``conflate -h`` to see a list of arguments.

Uploading to OpenStreetMap
Expand Down
35 changes: 30 additions & 5 deletions conflate/conflate.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,11 +471,11 @@ def parse_osm(self, fileobj):
if center is not None:
ways[way.get('id')] = [float(center.get('lat')), float(center.get('lon'))]
else:
logging.warning('Way %s does not have a center', way.get('id'))
logging.debug('Way %s does not have a center', way.get('id'))
coord = [0, 0]
count = 0
for nd in way.findall('nd'):
if nd.get('id') in nodes:
if nd.get('ref') in nodes:
count += 1
for i in range(len(coord)):
coord[i] += nodes[nd.get('ref')][i]
Expand Down Expand Up @@ -504,6 +504,7 @@ def parse_osm(self, fileobj):
if center is not None:
coord = [float(center.get('lat')), float(center.get('lon'))]
else:
logging.debug('Relation %s does not have a center', el.get('id'))
coord = [0, 0]
count = 0
for m in el.findall('member'):
Expand All @@ -515,13 +516,16 @@ def parse_osm(self, fileobj):
count += 1
for i in range(len(coord)):
coord[i] += ways[m.get('ref')][i]
coord = [coord[0] / count, coord[1] / count]
if count > 0:
coord = [coord[0] / count, coord[1] / count]
members = [
(m.get('type'), m.get('ref'), m.get('role'))
for m in el.findall('member')
]
else:
continue
if not coord or coord == [0, 0]:
continue
pt = OSMPoint(
el.tag, int(el.get('id')), int(el.get('version')),
coord[0], coord[1], tags, categories)
Expand Down Expand Up @@ -912,8 +916,29 @@ def read_dataset(profile, fileobj):
try:
data = []
reader = codecs.getreader('utf-8')
for item in json.load(reader(fileobj)):
data.append(SourcePoint(item['id'], item['lat'], item['lon'], item['tags']))
json_src = json.load(reader(fileobj))
if 'features' in json_src:
# Parse GeoJSON
for item in json_src['features']:
if item['geometry'].get('type') != 'Point' or 'properties' not in item:
continue
# Get the identifier from "id", "ref", "ref*"
iid = item['properties'].get('id', item['properties'].get('ref'))
if not iid:
for k, v in item['properties'].items():
if k.startswith('ref'):
iid = v
break
if not iid:
continue
data.append(SourcePoint(
iid,
item['geometry']['coordinates'][1],
item['geometry']['coordinates'][0],
{k: v for k, v in item['properties'].items() if k != 'id'}))
else:
for item in json_src:
data.append(SourcePoint(item['id'], item['lat'], item['lon'], item['tags']))
return data
except Exception:
logging.error('Failed to parse the source as a JSON')
Expand Down

0 comments on commit 87c6ce1

Please sign in to comment.