def analyser(self): ## result file outxml = OsmSax.OsmSaxWriter(open(self.config.dst, "w"), "UTF-8") outxml.startDocument() outxml.startElement( "analyser", {"timestamp": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())}) outxml.startElement("class", {"id": "1", "item": "0"}) outxml.Element( "classtext", { "lang": "fr", "title": "TEST : Plusieurs nœuds à la même position", "menu": "test : plusieurs nœuds" }) outxml.endElement("class") ## loop on results conn = psycopg2.connect(self.config.db_string) curs = conn.cursor() curs.execute( "SELECT node_accum(id,tags),lat,lon FROM france_nodes GROUP BY lat,lon HAVING count(*) <> 1;" ) while True: all = curs.fetchmany(1000) if not all: break for res in all: outxml.startElement("error", {"class": "1"}) outxml.Element( "location", { "lat": str(float(res["lat"]) / 1000000), "lon": str(float(res["lon"]) / 1000000) }) for i in range(len(res[0]) / 2): if res[0][2 * i] == "#new#": if i: outxml.endElement("node") outxml.startElement("node", {"id": res[0][2 * i + 1]}) else: outxml.Element("tag", { "k": res[0][2 * i], "v": res[0][2 * i + 1] }) outxml.endElement("node") outxml.endElement("error") outxml.endElement("analyser") outxml._out.close() ## update front-end #if config.updt: # logger.log("update front-end") # urllib.urlretrieve(config.updt, "/dev/null") ## close database connections curs.close() conn.close()
def analyser(self): apiconn = OsmGis.OsmGis(self.config.db_string, self.config.db_schema) ## result file outxml = OsmSax.OsmSaxWriter(open(self.config.dst, "w"), "UTF-8") outxml.startDocument() outxml.startElement( "analyser", {"timestamp": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())}) outxml.startElement("class", {"id": "1", "item": "0"}) outxml.Element("classtext", { "lang": "en", "title": "Building intersection" }) outxml.endElement("class") ## gis connection gisconn = psycopg2.connect(self.config.db_string) giscurs = gisconn.cursor() ## sql querries sql1 = "CREATE TEMP TABLE %s_building AS SELECT osm_id, way FROM %s_polygon WHERE st_isvalid(way)='t' AND st_issimple(way)='t' AND building='yes';" % ( self.config.db_schema, self.config.dbp) sql2 = "CREATE INDEX %s_building_idx ON %s_building USING gist(way);" % ( self.config.db_schema, self.config.dbp) sql3 = "SELECT b1.osm_id AS id1, b2.osm_id AS id2, astext(st_transform(st_pointonsurface(ST_Intersection(b1.way, b2.way)), 4020)) FROM %s_building AS b1, %s_building AS b2 WHERE b1.osm_id>b2.osm_id AND st_intersects(b1.way, b2.way)='t' AND st_area(ST_Intersection(b1.way, b2.way))<>0;" % ( self.config.db_schema, self.config.dbp) sql4 = "DROP TABLE %s_building;" % (self.config.db_schema) ## gis querries self.logger.log(u"create building table") giscurs.execute(sql1) self.logger.log(u"create building index") giscurs.execute(sql2) self.logger.log(u"analyse overlap") giscurs.execute(sql3) ## format results to outxml self.logger.log(u"generate xml") while True: many = giscurs.fetchmany(1000) if not many: break for res in many: outxml.startElement("error", {"class": "1"}) for loc in self.get_points(res[2]): outxml.Element("location", loc) #outxml.WayCreate(apiconn.WayGet(res[0])) #outxml.WayCreate(apiconn.WayGet(res[1])) outxml.WayCreate({"id": res[0], "nd": [], "tag": {}}) outxml.WayCreate({"id": res[1], "nd": [], "tag": {}}) outxml.endElement("error") giscurs.close() outxml.endElement("analyser") outxml._out.close()
def analyser(self): apiconn = OsmGis.OsmGis(self.config.db_string, self.config.db_schema) ## result file outxml = OsmSax.OsmSaxWriter(open(self.config.dst, "w"), "UTF-8") outxml.startDocument() outxml.startElement( "analyser", {"timestamp": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())}) outxml.startElement("class", {"id": "1", "item": "1050"}) outxml.Element( "classtext", { "lang": "fr", "title": "Rond-point à l'envers", "menu": "rond-point à l'envers" }) outxml.Element( "classtext", { "lang": "en", "title": "Reverse roundabout", "menu": "reverse roundabout" }) outxml.endElement("class") ## sql querry sql = """ select osm_id, astext(st_transform(st_centroid(way),4020)) as center from %s_line where junction = 'roundabout' and (st_isclosed(way) and st_isring(way)) and ((st_azimuth(st_centroid(way),ST_PointN(way,1))-st_azimuth(st_centroid(way),ST_PointN(way,2)))::numeric)%%((pi()*2)::numeric) between pi() and pi()*2 ; """ % self.config.db_schema gisconn = psycopg2.connect(self.config.db_string) giscurs = gisconn.cursor() giscurs.execute(sql) ## format results to outxml for res in giscurs.fetchall(): outxml.startElement("error", {"class": "1"}) for loc in self.get_points(res[1]): outxml.Element("location", loc) #outxml.Element("text", {"lang":"en", "value":get_error_text(res[0])}) if res[0] < 0: outxml.RelationCreate(apiconn.RelationGet(-res[0])) else: outxml.WayCreate(apiconn.WayGet(res[0])) outxml.endElement("error") outxml.endElement("analyser") outxml._out.close()
def _osm_changeset(tags, id='0'): out = io.StringIO() o = OsmSax.OsmSaxWriter(out, "UTF-8") o.startDocument() o.startElement('osm', {"version": "0.6", "generator": u"Osmose"}) o.startElement('changeset', {"id": id, "open": "false"}) for (k, v) in tags.items(): o.Element('tag', {'k': k, 'v': v}) o.endElement('changeset') o.endElement('osm') return out.getvalue()
def analyser(self): apiconn = OsmGis.OsmGis(self.config.db_string, self.config.db_schema) ## result file outxml = OsmSax.OsmSaxWriter(open(self.config.dst, "w"), "UTF-8") outxml.startDocument() outxml.startElement("analyser", {"timestamp":time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())}) outxml.startElement("class", {"id":"1", "item":"1060"}) outxml.Element("classtext", {"lang":"fr", "title":"Croisement de frontières", "menu":"boundary intersect"}) outxml.Element("classtext", {"lang":"en", "title":"Boundary intersection", "menu":"boundary intersect"}) outxml.endElement("class") ## sql querry sql = """ select ligne1.osm_id, ligne2.osm_id, astext(st_transform(st_intersection(ligne1.way, ligne2.way),4020)) from %s_roads as ligne1, %s_roads as ligne2 where st_crosses(ligne1.way,ligne2.way) = 't' and ST_touches(ligne1.way,ligne2.way) = 'f' and ligne1.boundary='administrative' and ligne2.boundary='administrative' and ligne1.osm_id > 0 and ligne2.osm_id > 0 and ligne1.osm_id > ligne2.osm_id ; """ % (self.config.db_schema, self.config.dbp) gisconn = psycopg2.connect(self.config.db_string) giscurs = gisconn.cursor() giscurs.execute(sql) ## format results to outxml while True: many = giscurs.fetchmany(1000) if not many: break for res in many: outxml.startElement("error", {"class":"1"}) for loc in self.get_points(res[2]): outxml.Element("location", loc) outxml.WayCreate(apiconn.WayGet(res[0])) outxml.WayCreate(apiconn.WayGet(res[1])) outxml.endElement("error") outxml.endElement("analyser") outxml._out.close()
def analyser(self): ## result file outxml = OsmSax.OsmSaxWriter(open(self.config.dst, "w"), "UTF-8") outxml.startDocument() outxml.startElement( "analyser", {"timestamp": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())}) outxml.startElement("class", {"id": "1", "item": "1040"}) outxml.Element( "classtext", { "lang": "fr", "title": "Polygone non valide (analyse gis)", "menu": "polygone non valide" }) outxml.Element( "classtext", { "lang": "en", "title": "Invalid polygon (gis analysis)", "menu": "invalid polygon" }) outxml.endElement("class") ## sql querry sql = """ SELECT osm_id, name, astext(st_transform(selfinter,4020)) AS selfinter, astext(st_transform(way,4020)) AS way FROM ( SELECT osm_id,name, st_difference( st_endpoint( st_union( st_exteriorring(way), st_endpoint(st_exteriorring(way)) ) ), st_endpoint(st_exteriorring(way)) ) AS selfinter, way FROM %s_polygon WHERE st_isvalid(way)='f' ) AS tmp WHERE st_isempty(selfinter)='f' ; """ % self.config.db_schema gisconn = psycopg2.connect(self.config.db_string) giscurs = gisconn.cursor() giscurs.execute(sql) apiconn = OsmGis.OsmGis(self.config.db_string, self.config.db_schema) ## format results to outxml while True: many = giscurs.fetchmany(1000) if not many: break for res in many: outxml.startElement("error", {"class": "1"}) for loc in self.get_points(res[2]): outxml.Element("location", loc) #outxml.Element("text", {"lang":"en", "value":get_error_text(res[0])}) if res[0] < 0: outxml.RelationCreate(apiconn.RelationGet(-res[0])) else: outxml.WayCreate(apiconn.WayGet(res[0])) outxml.endElement("error") outxml.endElement("analyser") outxml._out.close()
def save(db, lang): json = request.json if 'tag' not in json: abort(422) # Changeset tags tags = json['tag'] if 'comment' not in tags or tags['comment'].strip() == '': tags['comment'] = u'Fixed with Osmose' if 'source' not in tags or tags['source'].strip() == '': tags['source'] = u'Osmose' if 'type' not in tags or tags['type'].strip() == '': tags['type'] = u'fix' tags['created_by'] = u'Osmose Editor' reuse_changeset = json.get('reuse_changeset', True) != False # Get an open changeset changeset = request.session.get('changeset') if changeset and not reuse_changeset: try: _changeset_close(changeset) except: pass changeset = None del request.session['changeset'] request.session.save() elif changeset: try: _changeset_update(changeset, tags) except: changeset = None request.session['changeset'] = changeset request.session.save() if not changeset: changeset = _changeset_create(tags) request.session['changeset'] = changeset request.session.save() # OsmChange out = io.StringIO() o = OsmSax.OsmSaxWriter(out, "UTF-8") o.startDocument() o.startElement('osmChange', {"version": "0.6", "generator": "OsmSax"}) methode = { 'node': o.NodeCreate, 'way': o.WayCreate, 'relation': o.RelationCreate } for action in ('modify', 'delete'): if action in json and len(json[action]) > 0: o.startElement(action, {}) for e in json[action]: try: ee = utils.fetch_osm_elem(e['type'], e["id"]) except: ee = None if ee and ee['version'] == int(e['version']): ee[u'changeset'] = changeset ee['tag'] = e['tags'] methode[e['type']](ee) else: # FIXME reject pass o.endElement(action) o.endElement('osmChange') osmchange = out.getvalue() # Fire the changeset _changeset_upload(changeset, osmchange)