def __init__(self, iface): self.iface = iface db = PotiTools.setPostGresDataSource("public", "insee_iris", "the_geom", "") layer = QgsVectorLayer(db.uri(), QString.fromUtf8("Insee Iris"), "postgres") PotiTools.displayLayer(layer, "Insee Iris", "../qml/insee_iris.qml")
def __init__(self, iface): self.iface = iface # Récupération de l'adresse du serveur Rails config = ConfigParser.RawConfigParser() config.read(os.path.abspath(currentPath) + "/../Potimart.cfg") srv_rails = config.get("rails", "server") # Récupération fichier XML des indicateurs via un url REST try: self.xmlDoc = minidom.parse(urllib.urlopen('http://' + srv_rails + '/line_indicator_names.xml')) except IOError: QMessageBox.critical(self.iface.mainWindow(), "Connexion au serveur RAILS",\ QString.fromUtf8("Echec de la connexion.\nVérifier que le serveur est lancé et que les paramètres de connexion sont bons (menu Options)."), "Ok") return # Récupération des noeuds des indicateurs self.getIndicators() # create and show the dialog dlg = IndicatorsDialog() # Alimente la combobox du dialogue avec la liste des lignes for line in self.__indicatorList__: dlg.ui.IndicatorsComboBox.addItem(line.name) # show the dialog dlg.show() result = dlg.exec_() # See if OK was pressed if result == 1: # Récupération du fichier .geojson copié en local cleanIndicatorName = dlg.ui.IndicatorsComboBox.currentText().replace(" ","_").replace(":","-").replace("/","-") print "cleanIndicatorName = " + QString.fromUtf8(cleanIndicatorName) distant_geojson_filename = cleanIndicatorName + ".geojson" print "distant_geojson_filename = " + QString.fromUtf8(distant_geojson_filename) local_geojson_filename = os.path.abspath(currentPath) + "/../geojson/" + cleanIndicatorName + '.geojson' print "local_geojson_filename = " + QString.fromUtf8(local_geojson_filename) urlAdress = 'http://' + srv_rails + '/lines_by_indicator/' + str(dlg.ui.IndicatorsComboBox.currentText()) + '.geojson' print "urlAdress = " + QString.fromUtf8(urlAdress) urllib.urlretrieve(urlAdress, QString.fromUtf8(local_geojson_filename)) time.sleep(1) # Envoi de la couche vers QGis : layer = QgsVectorLayer(local_geojson_filename, "LIGNES - " + dlg.ui.IndicatorsComboBox.currentText(), "ogr") PotiTools.displayLayer(layer, "LIGNES - " + dlg.ui.IndicatorsComboBox.currentText(), os.path.abspath(currentPath) + "/../qml/" + dlg.ui.IndicatorsComboBox.currentText() + ".qml")
def displayAllLines(self): # service_links db = PotiTools.setPostGresDataSource("potimart", "service_links", "the_geom", \ "id IN (SELECT DISTINCT service_links.id FROM potimart.service_links)") layer = QgsVectorLayer(db.uri(), QString.fromUtf8("LIGNES"), "postgres") PotiTools.displayLayer(layer, "LIGNES", os.path.abspath(currentPath) + "/../qml/service_links.qml") # Stopareas: tous les arrêts même ceux n'appartenant pas à aucunes lignes (arrêts orphelins) db = PotiTools.setPostGresDataSource("potimart", "stop_area_geos", "the_geom", \ "stoparea_id in (SELECT DISTINCT stop_area_geos.stoparea_id FROM potimart.stop_area_geos)") layer = QgsVectorLayer(db.uri(), QString.fromUtf8("ARRETS"), "postgres") PotiTools.displayLayer(layer, "ARRETS", os.path.abspath(currentPath) + "/../qml/stop_areas.qml")
def displayOneLineAllDirections(self, indexLineToDisplay): # service_links whereClause = "line_id = " + str(self.__lineList__[indexLineToDisplay].id) db = PotiTools.setPostGresDataSource("potimart", "service_links", "the_geom", whereClause) layer = QgsVectorLayer(db.uri(), QString.fromUtf8("LIGNE " + str(self.__lineList__[indexLineToDisplay].number) + " - AR"), "postgres") PotiTools.displayLayer(layer, "LIGNE " + str(self.__lineList__[indexLineToDisplay].number) + " - AR", os.path.abspath(currentPath) + "/../qml/service_links.qml") # Stopareas whereClause = "stoparea_id IN (" whereClause += "SELECT DISTINCT stop_area_geos.stoparea_id " whereClause += "FROM potimart.stop_area_geos, potimart.service_links " whereClause += "WHERE service_links.line_id = " + str(self.__lineList__[indexLineToDisplay].id) + " AND " whereClause += "(stop_area_geos.stoparea_id = service_links.stoparea_start_id OR " whereClause += "stop_area_geos.stoparea_id = service_links.stoparea_arrival_id)" whereClause += ")" db = PotiTools.setPostGresDataSource("potimart", "stop_area_geos", "the_geom", whereClause) layer = QgsVectorLayer(db.uri(), QString.fromUtf8("ARRETS " + str(self.__lineList__[indexLineToDisplay].number) + " - AR"), "postgres") PotiTools.displayLayer(layer, "ARRETS " + str(self.__lineList__[indexLineToDisplay].number) + " - AR", os.path.abspath(currentPath) + "/../qml/stop_areas.qml")
def displaySelectedMission(self, line_id, idMission): print "line_id = " + str(line_id) # service_links whereClause = "journeypattern_id = " + str(idMission) db = PotiTools.setPostGresDataSource("potimart", "service_links", "the_geom", whereClause) layer = QgsVectorLayer(db.uri(), QString.fromUtf8("LIGNE " + line_id + " - Mission " + idMission), "postgres") PotiTools.displayLayer(layer, "LIGNE " + line_id + " - Mission " + idMission, os.path.abspath(currentPath) + "/../qml/missions.qml") # Stopareas whereClause = "stoparea_id IN (" whereClause += "SELECT DISTINCT stop_area_geos.stoparea_id " whereClause += "FROM potimart.stop_area_geos, potimart.service_links " whereClause += "WHERE service_links.journeypattern_id = " + str(idMission) + " AND " whereClause += "(stop_area_geos.stoparea_id = service_links.stoparea_start_id OR " whereClause += "stop_area_geos.stoparea_id = service_links.stoparea_arrival_id)" whereClause += ")" db = PotiTools.setPostGresDataSource("potimart", "stop_area_geos", "the_geom", whereClause) layer = QgsVectorLayer(db.uri(), QString.fromUtf8("ARRETS " + line_id + " - Mission " + idMission), "postgres") PotiTools.displayLayer(layer, "ARRETS " + line_id + " - Mission " + idMission, os.path.abspath(currentPath) + "/../qml/stop_areas.qml")
def displayOneLineOneDirection(self, indexLineToDisplay, sens): # service_links pathlink_query = "SELECT DISTINCT service_links.id " pathlink_query += "FROM potimart.service_links, chouette.route " pathlink_query += "WHERE service_links.route_id = route.id AND " pathlink_query += "route.direction = '" + sens + "' AND " pathlink_query += "line_id = " + str(self.__lineList__[indexLineToDisplay].id) whereClause = "id IN (" + pathlink_query + ")" db = PotiTools.setPostGresDataSource("potimart", "service_links", "the_geom", whereClause) layer = QgsVectorLayer(db.uri(), QString.fromUtf8("LIGNE " + str(self.__lineList__[indexLineToDisplay].number)) + " - " + sens, "postgres") PotiTools.displayLayer(layer, "LIGNE " + str(self.__lineList__[indexLineToDisplay].number) + " - " + sens, os.path.abspath(currentPath) + "/../qml/service_links.qml") # Stopareas stoparea_query = "SELECT DISTINCT stop_area_geos.stoparea_id " stoparea_query += "FROM potimart.stop_area_geos, potimart.service_links, chouette.route " stoparea_query += "WHERE service_links.line_id = " + str(self.__lineList__[indexLineToDisplay].id) + " AND " stoparea_query += "(stop_area_geos.stoparea_id = service_links.stoparea_start_id OR " stoparea_query += "stop_area_geos.stoparea_id = service_links.stoparea_arrival_id) AND " stoparea_query += "service_links.route_id = route.id AND route.direction = '" + sens + "'" whereClause = "stoparea_id IN (" + stoparea_query + ")" db = PotiTools.setPostGresDataSource("potimart", "stop_area_geos", "the_geom", whereClause) layer = QgsVectorLayer(db.uri(), QString.fromUtf8("ARRETS " + str(self.__lineList__[indexLineToDisplay].number) + " - " + sens), "postgres") PotiTools.displayLayer(layer, "ARRETS " + str(self.__lineList__[indexLineToDisplay].number) + " - " + sens, os.path.abspath(currentPath) + "/../qml/stop_areas.qml")
def __init__(self, iface): self.iface = iface db = PotiTools.setPostGresDataSource("public", "insee_communes", "the_geom", "") layer = QgsVectorLayer(db.uri(), QString.fromUtf8("Insee Communes"), "postgres") PotiTools.displayLayer(layer, "Insee Communes", "../qml/insee_communes.qml")
def __init__(self, iface): self.iface = iface # Récupération de l'adresse du serveur Rails config = ConfigParser.RawConfigParser() config.read(os.path.abspath(currentPath) + "/../Potimart.cfg") srv_rails = config.get("rails", "server") # Récupération fichier XML des indicateurs via un url REST try: self.xmlDoc = minidom.parse( urllib.urlopen('http://' + srv_rails + '/line_indicator_names.xml')) except IOError: QMessageBox.critical(self.iface.mainWindow(), "Connexion au serveur RAILS",\ QString.fromUtf8("Echec de la connexion.\nVérifier que le serveur est lancé et que les paramètres de connexion sont bons (menu Options)."), "Ok") return # Récupération des noeuds des indicateurs self.getIndicators() # create and show the dialog dlg = IndicatorsDialog() # Alimente la combobox du dialogue avec la liste des lignes for line in self.__indicatorList__: dlg.ui.IndicatorsComboBox.addItem(line.name) # show the dialog dlg.show() result = dlg.exec_() # See if OK was pressed if result == 1: # Récupération du fichier .geojson copié en local cleanIndicatorName = dlg.ui.IndicatorsComboBox.currentText( ).replace(" ", "_").replace(":", "-").replace("/", "-") print "cleanIndicatorName = " + QString.fromUtf8( cleanIndicatorName) distant_geojson_filename = cleanIndicatorName + ".geojson" print "distant_geojson_filename = " + QString.fromUtf8( distant_geojson_filename) local_geojson_filename = os.path.abspath( currentPath) + "/../geojson/" + cleanIndicatorName + '.geojson' print "local_geojson_filename = " + QString.fromUtf8( local_geojson_filename) urlAdress = 'http://' + srv_rails + '/lines_by_indicator/' + str( dlg.ui.IndicatorsComboBox.currentText()) + '.geojson' print "urlAdress = " + QString.fromUtf8(urlAdress) urllib.urlretrieve(urlAdress, QString.fromUtf8(local_geojson_filename)) time.sleep(1) # Envoi de la couche vers QGis : layer = QgsVectorLayer( local_geojson_filename, "LIGNES - " + dlg.ui.IndicatorsComboBox.currentText(), "ogr") PotiTools.displayLayer( layer, "LIGNES - " + dlg.ui.IndicatorsComboBox.currentText(), os.path.abspath(currentPath) + "/../qml/" + dlg.ui.IndicatorsComboBox.currentText() + ".qml")
def __init__(self, iface): self.iface = iface # Récupération des données de connexion config = ConfigParser.RawConfigParser() config.read(os.path.abspath(currentPath) + "/../Potimart.cfg") self.dbame = config.get("postgres", "dbname") self.host = config.get("postgres", "host") self.port = config.get("postgres", "port") self.user = config.get("postgres", "username") self.password = config.get("postgres", "password") self.srv_rails = config.get("rails", "server") # Connexion à la base de donnée PostgreSQL via psycopg2 try: connect_string = "dbname='" + self.dbame + "' host='" + self.host + "' port='" + self.port + "' user='******' password='******'" print connect_string conn = psycopg2.connect(connect_string) print "Connexion via Psycopg2 : OK" except: print "Impossible de se connecter à la base de donnée." # Création d'un curseur sur la base cur = conn.cursor() # Exécution de la requète try: cur.execute( "" " SELECT DISTINCT stop_area_geos.area_type FROM potimart.stop_area_geos ;" "") except: print "I can't drop our test database, check your isolation level." for areaType in cur.fetchall(): areaTypeName = str(areaType).replace("(", "").replace(")", "").replace( ",", "").replace("'", "") print areaTypeName if areaTypeName == "StopPlace": # Load layer db = PotiTools.setPostGresDataSource( "potimart", "stop_area_geos", "the_geom", "area_type = '" + areaTypeName + "'") layer = QgsVectorLayer(db.uri(), areaTypeName, "postgres") PotiTools.displayLayer( layer, areaTypeName, os.path.abspath(currentPath) + "/../qml/stop_place.qml") elif areaTypeName == "CommercialStopPoint": # Load layer db = PotiTools.setPostGresDataSource( "potimart", "stop_area_geos", "the_geom", "area_type = '" + areaTypeName + "'") layer = QgsVectorLayer(db.uri(), areaTypeName, "postgres") PotiTools.displayLayer( layer, areaTypeName, os.path.abspath(currentPath) + "/../qml/commercial_stop_points.qml") elif areaTypeName == "BoardingPosition": # Load layer db = PotiTools.setPostGresDataSource( "potimart", "stop_area_geos", "the_geom", "area_type = '" + areaTypeName + "'") layer = QgsVectorLayer(db.uri(), areaTypeName, "postgres") PotiTools.displayLayer( layer, areaTypeName, os.path.abspath(currentPath) + "/../qml/boarding_positions.qml") elif areaTypeName == "Quay": # Load layer db = PotiTools.setPostGresDataSource( "potimart", "stop_area_geos", "the_geom", "area_type = '" + areaTypeName + "'") layer = QgsVectorLayer(db.uri(), areaTypeName, "postgres") PotiTools.displayLayer( layer, areaTypeName, os.path.abspath(currentPath) + "/../qml/quay.qml")
def __init__(self, iface): # Save reference to the QGIS interface self.iface = iface # create and show the dialog dlg = JourneyNbDialog() # show the dialog dlg.show() result = dlg.exec_() # See if OK was pressed if result == 1: # Récupération des paramètres saisis the_date = str(dlg.ui.dateEdit.date().toString("yyyy/MM/dd")) starthour = str(dlg.ui.startTimeEdit.time().toString()) endhour = str(dlg.ui.endTimeEdit.time().toString()) #the_date = "2009-08-15"; starthour = "05:00:00"; endhour = "21:00:00"; print the_date + " - " + starthour + " - " + endhour # Récupération des données de connexion config = ConfigParser.RawConfigParser() config.read(os.path.abspath(currentPath) + "/../Potimart.cfg") self.dbame = config.get("postgres", "dbname") self.host = config.get("postgres", "host") self.port = config.get("postgres", "port") self.user = config.get("postgres", "username") self.password = config.get("postgres", "password") self.srv_rails = config.get("rails", "server") # Connexion à la base de donnée PostgreSQL via psycopg2 try: connect_string = "dbname='" + self.dbame + "' host='" + self.host + "' port='" + self.port + "' user='******' password='******'" print connect_string conn = psycopg2.connect(connect_string) print "Connexion via Psycopg2 : OK" except: print "Impossible de se connecter à la base de donnée." # Création d'un curseur sur la base cur = conn.cursor() # Exécution de la requète try: cur.execute("""SELECT potimart.stoparea_journeynb_indicator(%s,%s,%s);""",(the_date, starthour, endhour)) conn.commit() except: print "I can't drop our test database, check your isolation level." # Récupération du fichier .geojson copié en local # Dessertes_du_11-12-2007_entre_05:00:00_et_21:00:00 dispDate = str(dlg.ui.dateEdit.date().toString("dd-MM-yyyy")) ## cleanIndicatorName = dlg.ui.IndicatorsComboBox.currentText().replace(" ","_").replace(":","-").replace("/","-") normalIndicatorName = "Dessertes_du_" + dispDate + "_entre_" + starthour + "_et_" + endhour print "normalIndicatorName = " + QString.fromUtf8(normalIndicatorName) cleanIndicatorName = normalIndicatorName.replace(" ","_").replace(":","-").replace("/","-") print "cleanIndicatorName = " + QString.fromUtf8(cleanIndicatorName) distant_geojson_filename = cleanIndicatorName + '.geojson' print "distant_geojson_filename = " + QString.fromUtf8(distant_geojson_filename) local_geojson_filename = os.path.abspath(currentPath) + "/../geojson/" + cleanIndicatorName + '.geojson' print "local_geojson_filename = " + QString.fromUtf8(local_geojson_filename) urlAdress = 'http://' + self.srv_rails + '/stop_area_geos_by_indicator/' + str(normalIndicatorName) + '.geojson' print "urlAdress = " + QString.fromUtf8(urlAdress) urllib.urlretrieve(urlAdress, QString.fromUtf8(local_geojson_filename)) time.sleep(1) # Envoi de la couche vers QGis : # QgsVectorLayer("/path/to/shapefile/file.shp", "layer_name_you_like", "ogr") layer = QgsVectorLayer(local_geojson_filename, "ARRETS - " + normalIndicatorName, "ogr") # displayLayer(layer, layer_name, qml_file): PotiTools.displayLayer(layer, "ARRETS - " + normalIndicatorName, os.path.abspath(currentPath) + "/../qml/journeynb.qml")
def __init__(self, iface): # Save reference to the QGIS interface self.iface = iface # create and show the dialog dlg = JourneyNbDialog() # show the dialog dlg.show() result = dlg.exec_() # See if OK was pressed if result == 1: # Récupération des paramètres saisis the_date = str(dlg.ui.dateEdit.date().toString("yyyy/MM/dd")) starthour = str(dlg.ui.startTimeEdit.time().toString()) endhour = str(dlg.ui.endTimeEdit.time().toString()) #the_date = "2009-08-15"; starthour = "05:00:00"; endhour = "21:00:00"; print the_date + " - " + starthour + " - " + endhour # Récupération des données de connexion config = ConfigParser.RawConfigParser() config.read(os.path.abspath(currentPath) + "/../Potimart.cfg") self.dbame = config.get("postgres", "dbname") self.host = config.get("postgres", "host") self.port = config.get("postgres", "port") self.user = config.get("postgres", "username") self.password = config.get("postgres", "password") self.srv_rails = config.get("rails", "server") # Connexion à la base de donnée PostgreSQL via psycopg2 try: connect_string = "dbname='" + self.dbame + "' host='" + self.host + "' port='" + self.port + "' user='******' password='******'" print connect_string conn = psycopg2.connect(connect_string) print "Connexion via Psycopg2 : OK" except: print "Impossible de se connecter à la base de donnée." # Création d'un curseur sur la base cur = conn.cursor() # Exécution de la requète try: cur.execute( """SELECT potimart.stoparea_journeynb_indicator(%s,%s,%s);""", (the_date, starthour, endhour)) conn.commit() except: print "I can't drop our test database, check your isolation level." # Récupération du fichier .geojson copié en local # Dessertes_du_11-12-2007_entre_05:00:00_et_21:00:00 dispDate = str(dlg.ui.dateEdit.date().toString("dd-MM-yyyy")) ## cleanIndicatorName = dlg.ui.IndicatorsComboBox.currentText().replace(" ","_").replace(":","-").replace("/","-") normalIndicatorName = "Dessertes_du_" + dispDate + "_entre_" + starthour + "_et_" + endhour print "normalIndicatorName = " + QString.fromUtf8( normalIndicatorName) cleanIndicatorName = normalIndicatorName.replace(" ", "_").replace( ":", "-").replace("/", "-") print "cleanIndicatorName = " + QString.fromUtf8( cleanIndicatorName) distant_geojson_filename = cleanIndicatorName + '.geojson' print "distant_geojson_filename = " + QString.fromUtf8( distant_geojson_filename) local_geojson_filename = os.path.abspath( currentPath) + "/../geojson/" + cleanIndicatorName + '.geojson' print "local_geojson_filename = " + QString.fromUtf8( local_geojson_filename) urlAdress = 'http://' + self.srv_rails + '/stop_area_geos_by_indicator/' + str( normalIndicatorName) + '.geojson' print "urlAdress = " + QString.fromUtf8(urlAdress) urllib.urlretrieve(urlAdress, QString.fromUtf8(local_geojson_filename)) time.sleep(1) # Envoi de la couche vers QGis : # QgsVectorLayer("/path/to/shapefile/file.shp", "layer_name_you_like", "ogr") layer = QgsVectorLayer(local_geojson_filename, "ARRETS - " + normalIndicatorName, "ogr") # displayLayer(layer, layer_name, qml_file): PotiTools.displayLayer( layer, "ARRETS - " + normalIndicatorName, os.path.abspath(currentPath) + "/../qml/journeynb.qml")
def __init__(self, iface): self.iface = iface # Récupération des données de connexion config = ConfigParser.RawConfigParser() config.read(os.path.abspath(currentPath) + "/../Potimart.cfg") self.dbame = config.get("postgres", "dbname") self.host = config.get("postgres", "host") self.port = config.get("postgres", "port") self.user = config.get("postgres", "username") self.password = config.get("postgres", "password") self.srv_rails = config.get("rails", "server") # Connexion à la base de donnée PostgreSQL via psycopg2 try: connect_string = "dbname='" + self.dbame + "' host='" + self.host + "' port='" + self.port + "' user='******' password='******'" print connect_string conn = psycopg2.connect(connect_string) print "Connexion via Psycopg2 : OK" except: print "Impossible de se connecter à la base de donnée." # Création d'un curseur sur la base cur = conn.cursor() # Exécution de la requète try: cur.execute("" " SELECT DISTINCT stop_area_geos.area_type FROM potimart.stop_area_geos ;" "") except: print "I can't drop our test database, check your isolation level." for areaType in cur.fetchall(): areaTypeName = str(areaType).replace("(", "").replace(")", "").replace(",", "").replace("'", "") print areaTypeName if areaTypeName == "StopPlace": # Load layer db = PotiTools.setPostGresDataSource("potimart", "stop_area_geos", "the_geom", "area_type = '" + areaTypeName + "'") layer = QgsVectorLayer(db.uri(), areaTypeName, "postgres") PotiTools.displayLayer(layer, areaTypeName, os.path.abspath(currentPath) + "/../qml/stop_place.qml") elif areaTypeName == "CommercialStopPoint": # Load layer db = PotiTools.setPostGresDataSource("potimart", "stop_area_geos", "the_geom", "area_type = '" + areaTypeName + "'") layer = QgsVectorLayer(db.uri(), areaTypeName, "postgres") PotiTools.displayLayer(layer, areaTypeName, os.path.abspath(currentPath) + "/../qml/commercial_stop_points.qml") elif areaTypeName == "BoardingPosition": # Load layer db = PotiTools.setPostGresDataSource("potimart", "stop_area_geos", "the_geom", "area_type = '" + areaTypeName + "'") layer = QgsVectorLayer(db.uri(), areaTypeName, "postgres") PotiTools.displayLayer(layer, areaTypeName, os.path.abspath(currentPath) + "/../qml/boarding_positions.qml") elif areaTypeName == "Quay": # Load layer db = PotiTools.setPostGresDataSource("potimart", "stop_area_geos", "the_geom", "area_type = '" + areaTypeName + "'") layer = QgsVectorLayer(db.uri(), areaTypeName, "postgres") PotiTools.displayLayer(layer, areaTypeName, os.path.abspath(currentPath) + "/../qml/quay.qml")