Changeset 9fa6940 in osmose-backend


Ignore:
Timestamp:
Jun 29, 2014 1:20:48 PM (5 years ago)
Author:
Frédéric Rodrigo <fred.rodrigo@…>
Branches:
master
Children:
10335e6
Parents:
dea30cd
git-author:
Frédéric Rodrigo <fred.rodrigo@…> (28/06/2014 18:17:33)
git-committer:
Frédéric Rodrigo <fred.rodrigo@…> (29/06/2014 13:20:48)
Message:

Add support for varying number of objects in error from osmosis analyser

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • analysers/Analyser_Merge.py

    rb39b19b r9fa6940  
    471471            return # Stop, no data 
    472472 
    473         typeGeom = {'n': 'geom', 'w': 'way_locate(linestring)', 'r': 'relation_locate(id)'} 
    474         typeShape = {'n': 'geom', 'w': 'ST_Envelope(linestring)', 'r': 'relation_shape(id)'} 
     473        typeGeom = {'N': 'geom', 'W': 'way_locate(linestring)', 'R': 'relation_locate(id)'} 
     474        typeShape = {'N': 'geom', 'W': 'ST_Envelope(linestring)', 'R': 'relation_shape(id)'} 
    475475        self.logger.log(u"Retrive OSM item") 
    476476        where = "(" + (") OR (".join(map(lambda x: self.where(x), self.mapping.select.tags))) + ")" 
     
    494494                        %(geom)s IS NOT NULL AND""" + (""" 
    495495                        ST_SetSRID(ST_GeomFromText('%(bbox)s'), 4326) && %(geom)s AND""" if bbox else "") + """ 
    496                         %(where)s)""") % {"type":type[0], "ref":self.mapping.osmRef, "geom":typeGeom[type[0]], "shape":typeShape[type[0]], "from":type, "bbox":bbox, "where":where}, 
     496                        %(where)s)""") % {"type":type[0].upper(), "ref":self.mapping.osmRef, "geom":typeGeom[type[0].upper()], "shape":typeShape[type[0].upper()], "from":type, "bbox":bbox, "where":where}, 
    497497                    self.mapping.select.types 
    498498                ) 
     
    530530        self.run(sql20 % {"official": tableOfficial, "joinClause": joinClause}) 
    531531        self.run(sql21) 
    532         typeMapping = {'n': self.node_full, 'w': self.way_full, 'r': self.relation_full} 
    533532        if self.missing_osm: 
    534533            # Missing OSM 
    535534            self.run(sql22, lambda res: { 
    536535                "class": self.missing_osm["class"], 
    537                 "data": [typeMapping[res[1]], None, self.positionAsText] 
     536                "data": [self.typeMapping[res[1]], None, self.positionAsText] 
    538537            } ) 
    539538            # Invalid OSM 
    540539            self.run(sql23 % {"official": tableOfficial, "joinClause": joinClause}, lambda res: { 
    541540                "class": self.missing_osm["class"], 
    542                 "data": [typeMapping[res[1]], None, self.positionAsText] 
     541                "data": [self.typeMapping[res[1]], None, self.positionAsText] 
    543542            } ) 
    544543 
     
    548547                "class": self.possible_merge["class"], 
    549548                "subclass": str(self.stablehash("%s%s"%(res[0],str(res[3])))), 
    550                 "data": [typeMapping[res[1]], None, self.positionAsText], 
     549                "data": [self.typeMapping[res[1]], None, self.positionAsText], 
    551550                "text": self.mapping.generate.text(defaultdict(lambda:None,res[3]), defaultdict(lambda:None,res[4])), 
    552551                "fix": self.mergeTags(res[5], res[3]), 
     
    565564                "class": self.update_official["class"], 
    566565                "subclass": str(self.stablehash("%s%s"%(res[0],str(res[4])))), 
    567                 "data": [typeMapping[res[1]], None, self.positionAsText], 
     566                "data": [self.typeMapping[res[1]], None, self.positionAsText], 
    568567                "text": self.mapping.generate.text(defaultdict(lambda:None,res[3]), defaultdict(lambda:None,res[4])), 
    569568                "fix": self.mergeTags(res[4], res[3]), 
  • analysers/Analyser_Osmosis.py

    ra104b33 r9fa6940  
    4141            self.relation:"relation", self.relation_full:"relation", 
    4242        } 
     43        self.typeMapping = {'N': self.node_full, 'W': self.way_full, 'R': self.relation_full} 
    4344 
    4445    def __enter__(self): 
     
    208209        self.geom["relation"].append(self.apiconn.RelationGet(res)) 
    209210 
     211    def array_full(self, res): 
     212        for type, id in map(lambda r: (r[0], r[1:]), res): 
     213            self.typeMapping[type](int(id)) 
     214 
    210215    def positionAsText(self, res): 
    211216        for loc in self.get_points(res): 
  • osmosis/CreateFunctions.sql

    r1dcd5f7 r9fa6940  
    3131 
    3232CREATE OR REPLACE FUNCTION relation_locate(rid bigint) RETURNS geometry AS $$ 
    33 DECLARE BEGIN 
    34     RETURN 
    35     (SELECT 
     33    SELECT 
    3634        geom 
    3735    FROM 
     
    4543                relation_members.member_type = 'W' 
    4644        WHERE 
    47             relation_members.relation_id = rid 
     45            relation_members.relation_id = $1 
    4846        LIMIT 1 
    4947    ) UNION ( 
     
    5654                relation_members.member_type = 'N' 
    5755        WHERE 
    58             relation_members.relation_id = rid 
     56            relation_members.relation_id = $1 
    5957        LIMIT 1 
    6058    )) AS a 
    61     LIMIT 1); 
    62 END 
    63 $$ LANGUAGE plpgsql; 
     59    LIMIT 1; 
     60$$ LANGUAGE sql; 
     61 
    6462 
    6563CREATE OR REPLACE FUNCTION relation_bbox(rid bigint) RETURNS geometry AS $$ 
     
    136134END 
    137135$$ LANGUAGE plpgsql; 
     136 
     137 
     138CREATE OR REPLACE FUNCTION any_locate(type char(1), aid bigint) RETURNS geometry AS $$ 
     139    SELECT CASE $1 
     140        WHEN 'N' THEN (SELECT geom FROM nodes WHERE nodes.id = $2) 
     141        WHEN 'W' THEN (SELECT way_locate(linestring) FROM ways WHERE ways.id = $2) 
     142        WHEN 'R' THEN relation_locate($2) 
     143    END; 
     144$$ LANGUAGE sql; 
     145 
     146 
     147CREATE OR REPLACE FUNCTION array_locate(many text[]) RETURNS geometry AS $$ 
     148    SELECT CASE 
     149        WHEN $1 IS NULL THEN NULL 
     150        ELSE any_locate(substr($1[1], 1, 1), CAST(substr($1[1], 2) AS bigint)) 
     151    END; 
     152$$ LANGUAGE sql; 
Note: See TracChangeset for help on using the changeset viewer.