Exemplo n.º 1
0
    def test_tiler_postgis(self):
        config_path = "/tiler-data/test-data/configs/postgis.tiler.json"
        DB_VARS = {
            "DB_HOST": "localhost",  # os.environ["DB_HOST"],
            "DB_NAME": "gis",  # os.environ["DB_NAME"],
            "DB_PORT": 5432,
            "DB_USER": "******",  # os.environ["DB_USER"],
            "DB_PASSWORD": "******"  # os.environ["DB_PASSWORD"]
        }
        try:
            shapefile2postgis("/tiler-data/test-data/states/states.shp",
                              "test_states", DB_VARS)
        except OSError:
            self.fail("Couldn't setup the PostGIS table necessary for test")

        tiles_from_config(config_path)
        self.assertTrue(os.path.isdir(MBTILES_DIR))
        self.assertTrue(os.path.isfile(MBTILES_DIR + "/0/0/0.pbf"))

        try:
            conn_string = "host='{}' dbname='{}' user='******' password='******'".format(
                os.environ["DB_HOST"], os.environ["DB_NAME"],
                os.environ["DB_USER"], os.environ["DB_PASSWORD"])
            conn = psycopg2.connect(conn_string)
            cursor = conn.cursor()
            cursor.execute("DROP TABLE test_states")
            conn.commit()
            conn.close()
        except psycopg2.Error as e:
            print "\n Couldn't tear down PostGIS table test_states"
            print e.pgerror
Exemplo n.º 2
0
    def test_db_insertion(self):
        """Does states.shp data get inserted correctly into database?"""

        config_path = "/tiler-data/test-data/configs/insertDatabase.tiler.json"
        self.assertTrue(os.path.isfile(config_path))

        tiles_from_config(config_path)
        self.assertTrue(
            os.path.isfile("/tiler-data/geojson/test_states.geojson"))
        self.assertTrue(os.path.isdir(MBTILES_DIR))
        self.assertTrue(os.path.isfile(MBTILES_DIR + "/0/0/0.pbf"))
        self.assertFalse(os.path.isfile(MBTILES_DIR + "/5/0/0.pbf"))
        self.assertFalse(os.path.isfile(MBTILES_DIR + "/8/0/0.pbf"))

        try:
            conn = self.get_connection()
            cursor = conn.cursor()
        except:
            self.fail("Couldn't connect to the database")

        try:
            cursor.execute("SELECT * FROM test_states")
            records = cursor.fetchall()
            conn.close()
            self.assertTrue(len(records) == 51)
            self.assertEqual(records[0][2], "Hawaii")
            self.assertEqual(records[50][2], "Alaska")
        except:
            self.fail("Table states contents not successfully fetched")
Exemplo n.º 3
0
    def test_tiler_gml(self):
        config_path = "/tiler-data/test-data/configs/gml.tiler.json"
        self.assertTrue(os.path.isfile(config_path))

        tiles_from_config(config_path)
        self.assertTrue(os.path.isdir(MBTILES_DIR))
        self.assertTrue(os.path.isfile(MBTILES_DIR + "/0/0/0.pbf"))
Exemplo n.º 4
0
    def test_tiler(self):
        config_path = "/tiler-data/test-data/configs/example.tiler.json"
        self.assertTrue(os.path.isfile(config_path))

        tiles_from_config(config_path)
        self.assertTrue(
            os.path.isfile("/tiler-data/geojson/test_states.geojson"))
        self.assertTrue(os.path.isdir(MBTILES_DIR))
        self.assertTrue(os.path.isfile(MBTILES_DIR + "/0/0/0.pbf"))
        self.assertFalse(os.path.isfile(MBTILES_DIR + "/5/0/0.pbf"))
        self.assertFalse(os.path.isfile(MBTILES_DIR + "/8/0/0.pbf"))
Exemplo n.º 5
0
    def test_copy_dir(self):

        config_path_1 = "/tiler-data/test-data/configs/merge1.tiler.json"
        self.assertTrue(os.path.isfile(config_path_1))
        tiles_from_config(config_path_1)
        output_path_1 = "/tiler-data/tiles/test_merge_1"
        self.assertTrue(os.path.isdir(output_path_1))
        num_pbfs_1 = get_num_pbfs(output_path_1)

        output_path_1_copy = "/tiler-data/tiles/test_merge_1_copy"
        copy_dir(output_path_1, output_path_1_copy)
        num_pbfs_1_copy = get_num_pbfs(output_path_1_copy)
        self.assertEqual(num_pbfs_1, num_pbfs_1_copy)
Exemplo n.º 6
0
 def test_tiler_url(self):
     config_path = "/tiler-data/test-data/configs/url.tiler.json"
     self.assertTrue(os.path.isfile(config_path))
     PORT = 8080
     SocketServer.TCPServer.allow_reuse_address = True
     server = SocketServer.TCPServer(("", PORT), TestHandler)
     thread = threading.Thread(target=server.serve_forever)
     thread.daemon = True
     thread.start()
     tiles_from_config(config_path)
     server.shutdown()
     server.socket.close()
     self.assertTrue(os.path.isfile("/tiler-data/input/stations.zip"))
     self.assertTrue(os.path.isdir("/tiler-data/input/stations"))
     self.assertTrue(
         os.path.isfile("/tiler-data/input/stations/stations.shp"))
     self.assertTrue(os.path.isfile("/tiler-data/input/states.geojson"))
     self.assertTrue(os.path.isdir(MBTILES_DIR))
Exemplo n.º 7
0
    def test_merge_tile_directories_with_overlap(self):

        config_path_1 = "/tiler-data/test-data/configs/mergeOverlap1.tiler.json"
        self.assertTrue(os.path.isfile(config_path_1))
        tiles_from_config(config_path_1)
        output_path_1 = "/tiler-data/tiles/test_merge_overlap_1"
        self.assertTrue(os.path.isdir(output_path_1))

        config_path_2 = "/tiler-data/test-data/configs/mergeOverlap2.tiler.json"
        self.assertTrue(os.path.isfile(config_path_2))
        tiles_from_config(config_path_2)
        output_path_2 = "/tiler-data/tiles/test_merge_overlap_2"
        self.assertTrue(os.path.isdir(output_path_2))

        out_dir = "/tiler-data/tiles/merge-test-overlap/"
        merge_tile_directories(output_path_1, output_path_2, out_dir)

        with open("/tiler-data/tiles/merge-test-overlap/2/0/1.pbf", 'rb') as f:
            data = f.read()
        overlap_merge = mapbox_vector_tile.decode(data)

        with open("/tiler-data/tiles/test_merge_overlap_1/2/0/1.pbf",
                  'rb') as f:
            data = f.read()
        overlap_1 = mapbox_vector_tile.decode(data)

        with open("/tiler-data/tiles/test_merge_overlap_2/2/0/1.pbf",
                  'rb') as f:
            data = f.read()
        overlap_2 = mapbox_vector_tile.decode(data)

        self.assertTrue(os.path.isdir(out_dir))
        self.assertTrue(get_num_pbfs(out_dir) > 0)
        self.assertTrue(
            str(overlap_merge).find("Pizazz")
            and str(overlap_1).find("Pizazz"))
        self.assertEqual(str(overlap_2).find("Pizazz"), -1)
        self.assertTrue(
            str(overlap_merge).find("Hungry")
            and str(overlap_2).find("Hungry"))
        self.assertEqual(str(overlap_1).find("Hungry"), -1)
Exemplo n.º 8
0
    def test_tiler_shapefile_database(self):
        config_path = "/tiler-data/test-data/configs/example3.tiler.json"
        self.assertTrue(os.path.isfile(config_path))

        tiles_from_config(config_path)
        self.assertTrue(os.path.isdir(MBTILES_DIR))
        self.assertTrue(os.path.isfile(MBTILES_DIR + "/0/0/0.pbf"))
        self.assertFalse(os.path.isfile(MBTILES_DIR + "/5/0/0.pbf"))
        self.assertFalse(os.path.isfile(MBTILES_DIR + "/8/0/0.pbf"))

        try:
            conn_string = "host='{}' dbname='{}' user='******' password='******'".format(
                os.environ["DB_HOST"], os.environ["DB_NAME"],
                os.environ["DB_USER"], os.environ["DB_PASSWORD"])
            conn = psycopg2.connect(conn_string)
            cursor = conn.cursor()
            cursor.execute("DROP TABLE test_states")
            conn.commit()
            conn.close()
        except psycopg2.Error as e:
            print "\n Couldn't tear down PostGIS table test_states"
            print e.pgerror
Exemplo n.º 9
0
    def test_merge_tile_directories(self):

        config_path_1 = "/tiler-data/test-data/configs/merge1.tiler.json"
        self.assertTrue(os.path.isfile(config_path_1))
        tiles_from_config(config_path_1)
        output_path_1 = "/tiler-data/tiles/test_merge_1"
        self.assertTrue(os.path.isdir(output_path_1))
        num_pbfs_1 = get_num_pbfs(output_path_1)

        config_path_2 = "/tiler-data/test-data/configs/merge2.tiler.json"
        self.assertTrue(os.path.isfile(config_path_2))
        tiles_from_config(config_path_2)
        output_path_2 = "/tiler-data/tiles/test_merge_2"
        self.assertTrue(os.path.isdir(output_path_2))
        num_pbfs_2 = get_num_pbfs(output_path_2)

        total = num_pbfs_1 + num_pbfs_2

        out_dir = "/tiler-data/tiles/merge-test/"
        merge_tile_directories(output_path_1, output_path_2, out_dir)
        num_pbfs_total = get_num_pbfs("/tiler-data/tiles/merge-test/")
        self.assertEqual(total, num_pbfs_total)