Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New analyser to detect duplicate relation members #2092

Merged
merged 2 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions analysers/analyser_osmosis_relation_duplicate_member.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/usr/bin/env python
#-*- coding: utf-8 -*-

###########################################################################
## ##
## Copyrights Osmose Project 2023 ##
## ##
## 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/>. ##
## ##
###########################################################################

from modules.OsmoseTranslation import T_
from .Analyser_Osmosis import Analyser_Osmosis

sql10 = """
SELECT
id,
ST_AsText(relation_locate(id)),
array_agg(duplicate)
FROM (
SELECT
id,
member_type || member_id || ' (' || COUNT(*) || ')' AS duplicate
Famlam marked this conversation as resolved.
Show resolved Hide resolved
FROM
{0}relations AS relations
JOIN relation_members ON
relations.id = relation_id
WHERE
relations.tags != ''::hstore AND
relations.tags?'type' AND
relations.tags->'type' IN ('multipolygon', 'site', 'waterway', 'enforcement', 'public_transport', 'building')
GROUP BY
id,
member_id,
member_type,
member_role
HAVING
COUNT(*) > 1
) AS t
GROUP BY
id
"""

class Analyser_Osmosis_Relation_Duplicate_Member(Analyser_Osmosis):

def __init__(self, config, logger = None):
Analyser_Osmosis.__init__(self, config, logger)
self.classs_change[3] = self.def_class(item = 1040, level = 1, tags = ['relation', 'fix:chair', 'geom'],
title = T_('Duplicate relation member'),
detail = T_(
'''The relation contains the same member (with the same role) more than once. This is not expected for this type of relations.'''),
fix = T_(
'''Remove the duplicate members until only unique members remain.'''))

self.callback10 = lambda res: {"class": 3, "data": [self.relation, self.positionAsText], "text": {"en": ', '.join(res[2]).lower()}}

def analyser_osmosis_full(self):
self.run(sql10.format(""), self.callback10)

def analyser_osmosis_diff(self):
self.run(sql10.format("touched_"), self.callback10)



###########################################################################

from .Analyser_Osmosis import TestAnalyserOsmosis

class Test(TestAnalyserOsmosis):
@classmethod
def setup_class(cls):
from modules import config
TestAnalyserOsmosis.setup_class()
cls.analyser_conf = cls.load_osm("tests/osmosis_relation_duplicate_member.osm",
config.dir_tmp + "/tests/osmosis_relation_duplicate_member.test.xml", {})

def test_classes(self):
with Analyser_Osmosis_Relation_Duplicate_Member(self.analyser_conf, self.logger) as a:
a.analyser()

self.root_err = self.load_errors()
self.check_err(cl="3", elems=[("relation", "10001")])
self.check_num_err(1)
1 change: 1 addition & 0 deletions osmose_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ def __init__(self, country, polygon_id=None, analyser_options=None, download_url
self.analyser["osmosis_polygon_intersects"] = "xxx"
self.analyser["osmosis_way_angle"] = "xxx"
self.analyser["osmosis_highway_long_crossing"] = "xxx"
self.analyser["osmosis_relation_duplicate_member"] = "xxx"

class default_country_simple(default_simple):
def __init__(self, part, country, polygon_id=None, analyser_options=None,
Expand Down
43 changes: 43 additions & 0 deletions tests/osmosis_relation_duplicate_member.osm
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version='1.0' encoding='UTF-8'?>
<osm version='0.6' generator='JOSM'>
<node id='1' timestamp='2014-03-31T22:00:00Z' version='1' lat='51.84904121444' lon='5.84167543397' />
<node id='2' timestamp='2014-03-31T22:00:00Z' version='1' lat='51.84565606741' lon='5.84194492855' />
<node id='3' timestamp='2014-03-31T22:00:00Z' version='1' lat='51.84571156367' lon='5.84446021135' />
<node id='4' timestamp='2014-03-31T22:00:00Z' version='1' lat='51.84589995006' lon='5.84699939213' />
<node id='5' timestamp='2014-03-31T22:00:00Z' version='1' lat='51.84592769805' lon='5.85045790597' />
<node id='6' timestamp='2014-03-31T22:00:00Z' version='1' lat='51.84914634897' lon='5.84870619117' />
<way id='1000' timestamp='2014-03-31T22:00:00Z' version='1'>
<nd ref='1' />
<nd ref='2' />
<nd ref='3' />
<nd ref='1' />
</way>
<way id='1' timestamp='2014-03-31T22:00:00Z' version='1'>
<nd ref='4' />
<nd ref='5' />
<nd ref='6' />
<nd ref='4' />
</way>
<relation id='10000' timestamp='2014-03-31T22:00:00Z' version='1'>
<member type='way' ref='1000' role='outer' />
<member type='way' ref='1' role='outer' />
<tag k='building' v='yes' />
<tag k='name' v='Proper relation' />
<tag k='type' v='multipolygon' />
</relation>
<relation id='10001' timestamp='2014-03-31T22:00:00Z' version='1'>
<member type='way' ref='1' role='outer' />
<member type='way' ref='1000' role='outer' />
<member type='way' ref='1' role='outer' />
<tag k='building' v='yes' />
<tag k='name' v='Duplicate member' />
<tag k='type' v='multipolygon' />
</relation>
<relation id='10002' timestamp='2014-03-31T22:00:00Z' version='1'>
<member type='way' ref='1' role='outer' />
<member type='node' ref='1' role='outer' />
<tag k='building' v='yes' />
<tag k='name' v='Same id, different object' />
<tag k='type' v='site' />
</relation>
</osm>
Loading