示例#1
0
    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")
示例#2
0
    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")
示例#3
0
    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")
示例#4
0
    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")
示例#5
0
    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")
示例#6
0
  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")
示例#7
0
    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")