forked from osm-fr/osmose-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyser_merge_street_objects2.py
72 lines (63 loc) · 4.37 KB
/
analyser_merge_street_objects2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python
#-*- coding: utf-8 -*-
###########################################################################
## ##
## Copyrights Frédéric Rodrigo 2020 ##
## ##
## This program is free software: you can redistribute it and/or modify ##
## it under the terms of the GNU General Public License as published by ##
## the Free Software Foundation, either version 3 of the License, or ##
## (at your option) any later version. ##
## ##
## This program is distributed in the hope that it will be useful, ##
## but WITHOUT ANY WARRANTY; without even the implied warranty of ##
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ##
## GNU General Public License for more details. ##
## ##
## You should have received a copy of the GNU General Public License ##
## along with this program. If not, see <http://www.gnu.org/licenses/>. ##
## ##
###########################################################################
import json
from modules.OsmoseTranslation import T_
from .Analyser_Merge_Dynamic import Analyser_Merge_Dynamic, SubAnalyser_Merge_Dynamic
from .Analyser_Merge import CSV, Load, Conflate, Select, Mapping
from .Analyser_Merge_Mapillary import Source_Mapillary
class Analyser_Merge_Street_Objects2(Analyser_Merge_Dynamic):
def __init__(self, config, logger = None):
Analyser_Merge_Dynamic.__init__(self, config, logger)
if "country" not in self.config.options:
return
mapping = 'merge_data/mapillary-street-tags.mapping.json'
mapingfile = json.loads(open(mapping).read())
for r in mapingfile:
self.classFactory(SubAnalyser_Merge_Street_Objects2, r['class'], r['class'], r['level'], r['otype'], r['conflation'], r['title'], r['object'], r['select_tags'], r['generate_tags'], mapping, 'image_detections', 'tags')
class SubAnalyser_Merge_Street_Objects2(SubAnalyser_Merge_Dynamic):
def __init__(self, config, error_file, logger, classs, level, otype, conflation, title, object, selectTags, generateTags, mapping, source, layer):
SubAnalyser_Merge_Dynamic.__init__(self, config, error_file, logger)
self.def_class_missing_official(item = 8360, id = classs, level = level, tags = ['merge', 'leisure', 'fix:survey', 'fix:picture'],
title = T_('Unmapped {0}', T_(title)),
detail = T_('Street object ({1}) detected by Mapillary, but no nearby "{0}" tagging.',
', '.join(map(lambda kv: '{0}={1}'.format(kv[0], kv[1] if kv[1] else '*'), generateTags.items())), T_(title)),
fix = T_('Map the corresponding object if the imagery is up-to-date and object detection is correct.'))
self.init(
"https://www.mapillary.com",
u"Street Objects from Street-level imagery",
CSV(Source_Mapillary(attribution = u"Mapillary Street Objects", country = config.options['country'], polygon_id = config.polygon_id, logger = logger, mapping = mapping, source = source, layer = layer)),
Load("X", "Y",
select = {"value": object}),
Conflate(
select = Select(
types = otype,
tags = selectTags),
conflationDistance = conflation,
subclass_hash = lambda fields: {'image_key': fields['image_key'], 'value': fields['value']},
mapping = Mapping(
static1 = dict(filter(lambda kv: kv[1], generateTags.items())),
static2 = {"source": self.source},
mapping1 = {
"mapillary": "image_key",
"survey:date": lambda res: res["last_seen_at"][0:10]},
text = lambda tags, fields:
T_('Observed between {0} and {1}', fields["first_seen_at"][0:10], fields["last_seen_at"][0:10]) if fields["first_seen_at"][0:10] != fields["last_seen_at"][0:10] else
T_('Observed on {0}', fields["first_seen_at"][0:10]) )))