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 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()