Support GeoJSON, fix some warnings, prepare 1.3.0
This commit is contained in:
parent
05a0337a72
commit
87c6ce1a70
3 changed files with 37 additions and 7 deletions
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
## master branch
|
## master branch
|
||||||
|
|
||||||
|
## 1.3.0
|
||||||
|
|
||||||
|
_Released 2018-03-15_
|
||||||
|
|
||||||
* Support for categories: `category_tag` and `categories` parameters in a profile.
|
* Support for categories: `category_tag` and `categories` parameters in a profile.
|
||||||
* LibOsmium-based C++ filtering script for categories.
|
* LibOsmium-based C++ filtering script for categories.
|
||||||
* More than one tag value works as "one of": `[('amenity', 'cafe', 'restaurant')]`.
|
* More than one tag value works as "one of": `[('amenity', 'cafe', 'restaurant')]`.
|
||||||
|
@ -15,6 +19,7 @@
|
||||||
* Better error message for Overpass API timeouts.
|
* Better error message for Overpass API timeouts.
|
||||||
* Lifecycle prefixes are conflated, e.g. `amenity=*` and `was:amenity=*`.
|
* Lifecycle prefixes are conflated, e.g. `amenity=*` and `was:amenity=*`.
|
||||||
* Dataset is checked for duplicates, which are reported (see `-d`) and removed.
|
* Dataset is checked for duplicates, which are reported (see `-d`) and removed.
|
||||||
|
* Support GeoJSON input (put identifiers into `id` property).
|
||||||
|
|
||||||
## 1.2.3
|
## 1.2.3
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,8 @@ For a simplest case, run:
|
||||||
|
|
||||||
conflate <profile.py> -o result.osm
|
conflate <profile.py> -o result.osm
|
||||||
|
|
||||||
You might want to add other arguments
|
You might want to add other arguments,
|
||||||
to pass a dataset file or write the resulting osmChange somewhere. Run
|
to pass a dataset file or prepare a preview GeoJSON. Run
|
||||||
``conflate -h`` to see a list of arguments.
|
``conflate -h`` to see a list of arguments.
|
||||||
|
|
||||||
Uploading to OpenStreetMap
|
Uploading to OpenStreetMap
|
||||||
|
|
|
@ -471,11 +471,11 @@ class OsmConflator:
|
||||||
if center is not None:
|
if center is not None:
|
||||||
ways[way.get('id')] = [float(center.get('lat')), float(center.get('lon'))]
|
ways[way.get('id')] = [float(center.get('lat')), float(center.get('lon'))]
|
||||||
else:
|
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]
|
coord = [0, 0]
|
||||||
count = 0
|
count = 0
|
||||||
for nd in way.findall('nd'):
|
for nd in way.findall('nd'):
|
||||||
if nd.get('id') in nodes:
|
if nd.get('ref') in nodes:
|
||||||
count += 1
|
count += 1
|
||||||
for i in range(len(coord)):
|
for i in range(len(coord)):
|
||||||
coord[i] += nodes[nd.get('ref')][i]
|
coord[i] += nodes[nd.get('ref')][i]
|
||||||
|
@ -504,6 +504,7 @@ class OsmConflator:
|
||||||
if center is not None:
|
if center is not None:
|
||||||
coord = [float(center.get('lat')), float(center.get('lon'))]
|
coord = [float(center.get('lat')), float(center.get('lon'))]
|
||||||
else:
|
else:
|
||||||
|
logging.debug('Relation %s does not have a center', el.get('id'))
|
||||||
coord = [0, 0]
|
coord = [0, 0]
|
||||||
count = 0
|
count = 0
|
||||||
for m in el.findall('member'):
|
for m in el.findall('member'):
|
||||||
|
@ -515,13 +516,16 @@ class OsmConflator:
|
||||||
count += 1
|
count += 1
|
||||||
for i in range(len(coord)):
|
for i in range(len(coord)):
|
||||||
coord[i] += ways[m.get('ref')][i]
|
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 = [
|
members = [
|
||||||
(m.get('type'), m.get('ref'), m.get('role'))
|
(m.get('type'), m.get('ref'), m.get('role'))
|
||||||
for m in el.findall('member')
|
for m in el.findall('member')
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
|
if not coord or coord == [0, 0]:
|
||||||
|
continue
|
||||||
pt = OSMPoint(
|
pt = OSMPoint(
|
||||||
el.tag, int(el.get('id')), int(el.get('version')),
|
el.tag, int(el.get('id')), int(el.get('version')),
|
||||||
coord[0], coord[1], tags, categories)
|
coord[0], coord[1], tags, categories)
|
||||||
|
@ -912,8 +916,29 @@ def read_dataset(profile, fileobj):
|
||||||
try:
|
try:
|
||||||
data = []
|
data = []
|
||||||
reader = codecs.getreader('utf-8')
|
reader = codecs.getreader('utf-8')
|
||||||
for item in json.load(reader(fileobj)):
|
json_src = json.load(reader(fileobj))
|
||||||
data.append(SourcePoint(item['id'], item['lat'], item['lon'], item['tags']))
|
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
|
return data
|
||||||
except Exception:
|
except Exception:
|
||||||
logging.error('Failed to parse the source as a JSON')
|
logging.error('Failed to parse the source as a JSON')
|
||||||
|
|
Loading…
Add table
Reference in a new issue