Пример #1
0
    def testTopologyTwoVertices(self):
        topology = TerrainTopology()
        topology.addGeometries([vertices_1, vertices_2])

        self.assertEqual(len(topology.vertices), 5)
        self.assertEqual(len(topology.faces), 2)

        # Make sure no extra vertice is inserted
        self.assertEqual(topology.vertices[1][0], vertices_2[0][0])
        self.assertEqual(topology.vertices[1][1], vertices_2[0][1])
        self.assertEqual(topology.vertices[1][2], vertices_2[0][2])

        self.assertEqual(topology.faces[1][0], 1)
        self.assertEqual(topology.faces[1][1], 3)
        self.assertEqual(topology.faces[1][2], 4)

        self.assertEqual(len(topology.indexData), 6)
        self.assertEqual(len(topology.uVertex), 5)
        self.assertEqual(len(topology.vVertex), 5)
        self.assertEqual(len(topology.hVertex), 5)

        self.assertEqual(topology.minLon, 1.2)
        self.assertEqual(topology.minLat, 1.1)
        self.assertEqual(topology.minHeight, 1.1)
        self.assertEqual(topology.maxLon, 3.2)
        self.assertEqual(topology.maxLat, 3.1)
        self.assertEqual(topology.maxHeight, 4.5)
    def testTopologyTwoVertices(self):
        topology = TerrainTopology()
        topology.addVertices(vertices_1)
        topology.addVertices(vertices_2)
        topology.create()

        self.assertEqual(len(topology.vertices), 5)
        self.assertEqual(len(topology.faces), 2)

        # Make sure no extra vertice is inserted
        self.assertEqual(topology.vertices[1][0], vertices_2[0][0])
        self.assertEqual(topology.vertices[1][1], vertices_2[0][1])
        self.assertEqual(topology.vertices[1][2], vertices_2[0][2])

        self.assertEqual(topology.faces[1][0], 1)
        self.assertEqual(topology.faces[1][1], 3)
        self.assertEqual(topology.faces[1][2], 4)

        self.assertEqual(len(topology.indexData), 6)
        self.assertEqual(len(topology.uVertex), 5)
        self.assertEqual(len(topology.vVertex), 5)
        self.assertEqual(len(topology.hVertex), 5)

        self.assertEqual(topology.minLon, 1.2)
        self.assertEqual(topology.minLat, 1.1)
        self.assertEqual(topology.minHeight, 1.1)
        self.assertEqual(topology.maxLon, 3.2)
        self.assertEqual(topology.maxLat, 3.1)
        self.assertEqual(topology.maxHeight, 4.5)
    def testTopologyOneVertex(self):
        topology = TerrainTopology()
        topology.addVertices(vertices_1)
        topology.create()

        self.assertEqual(len(topology.vertices), 3)
        self.assertEqual(len(topology.faces), 1)

        self.assertEqual(topology.vertices[0][0], vertices_1[0][0])
        self.assertEqual(topology.vertices[0][1], vertices_1[0][1])
        self.assertEqual(topology.vertices[0][2], vertices_1[0][2])

        self.assertEqual(topology.vertices[1][0], vertices_1[1][0])
        self.assertEqual(topology.vertices[1][1], vertices_1[1][1])
        self.assertEqual(topology.vertices[1][2], vertices_1[1][2])
Пример #4
0
 def testTopologyBadGeoms(self):
     wkt = 'POLYGON Z ((2.1 3.1 3.3, 1.2 1.5 4.2, 3.2 2.2 4.5, 2.5 1.2 1.1,' \
           ' 2.1 3.1 3.3))'
     with self.assertRaises(ValueError):
         TerrainTopology(geometries=[wkt])
     wkt = 'POLYGON ((2.1 3.1, 1.2 1.5, 3.2 2.2, 2.1 3.1))'
     with self.assertRaises(ValueError):
         TerrainTopology(geometries=[wkt])
     wkb = b'\x01\x03\x00\x00\x00\x01\x00\x00\x00\x04\x00\x00\x00\xcd\xcc' \
           b'\xcc\xcc\xcc\xcc\x00@\xcd\xcc\xcc\xcc\xcc\xcc\x08@333333\xf3?' \
           b'\x00\x00\x00\x00\x00\x00\xf8?\x9a\x99\x99\x99\x99\x99\t@\x9a' \
           b'\x99\x99\x99\x99\x99\x01@\xcd\xcc\xcc\xcc\xcc\xcc\x00@\xcd\xcc' \
           b'\xcc\xcc\xcc\xcc\x08@'
     with self.assertRaises(ValueError):
         TerrainTopology(geometries=[wkb])
     wkt = 'POINT (2.1 2.2)'
     with self.assertRaises(ValueError):
         TerrainTopology(geometries=[wkt])
     wktWrong = 'POLYGON Z ((2.1, 3.1 3.3, 1.2 1.5 4.2, 3.2 2.2, 4.5, 2.1 3.1 3.3))'
     with self.assertRaises(ValueError):
         TerrainTopology(geometries=[wktWrong])
Пример #5
0
    def testTopologyWithAutocorrect(self):
        topology = TerrainTopology(geometries=[vertices_1, vertices_2],
                                   autocorrectGeometries=True)
        self.assertEqual(len(topology.faces), 2)

        vertices_3 = [[1.2, 3.2, 5.2], [2.2, 2.1, 3.1], [1.2, 4.1, 3.2],
                      [2.1, 4.7, 2.9]]
        topology = TerrainTopology(geometries=[vertices_1, vertices_3],
                                   autocorrectGeometries=True)
        self.assertEqual(len(topology.faces), 3)

        wkt = 'POLYGON Z ((2.4 3.1 3.3, 1.2 1.9 4.2, 3.2 2.3 4.5, 2.5 1.6 1.1,' \
              ' 2.4 3.1 3.3))'
        topology = TerrainTopology(geometries=[vertices_1, wkt],
                                   autocorrectGeometries=True)
        self.assertEqual(len(topology.faces), 3)

        topology = TerrainTopology(geometries=[wkt],
                                   autocorrectGeometries=True)
        self.assertEqual(len(topology.faces), 2)

        wkt = 'POLYGON Z ((2.1 3.1 3.3, 1.2 1.5 4.2, 3.2 2.2 4.5, 2.5 1.2 1.1,' \
              ' 4.2 2.1 4.8, 2.1 3.1 3.3))'
        topology = TerrainTopology(geometries=[wkt],
                                   autocorrectGeometries=True)
        self.assertEqual(len(topology.faces), 3)

        wkt = 'POLYGON Z ((2.1 3.1 3.3, 1.2 1.5 4.2, 3.2 2.2 4.5, 2.5 1.2 1.1,' \
              ' 4.2 2.1 4.8, 6.2 3.2 1.1, 2.1 3.1 3.3))'
        topology = TerrainTopology(geometries=[wkt],
                                   autocorrectGeometries=True)
        self.assertEqual(len(topology.faces), 4)
    def testGzippedTileCreationFromTopology(self):
        wkts = [
            'POLYGON Z ((0.0 0.0 1.0, 0.0 1.0 1.0, 1.0 1.0 1.0, 0.0 0.0 1.0))',
            'POLYGON Z ((0.0 0.0 1.0, 1.0 0.0 1.0, 1.0 1.0 1.0, 0.0 0.0 1.0))'
        ]
        topology = TerrainTopology(geometries=wkts)
        tile = TerrainTile(topology=topology)

        # Check that the bounds are extracted from the terrain topology
        self.assertEqual(tile._west, 0.0)
        self.assertEqual(tile._south, 0.0)
        self.assertEqual(tile._east, 1.0)
        self.assertEqual(tile._north, 1.0)

        fileLike = tile.toStringIO(gzipped=True)
        self.assertIsInstance(fileLike, cStringIO.OutputType)
    def testTileCreationFromTopology(self):
        wkts = [
            'POLYGON Z ((0.0 0.0 1.0, 0.0 1.0 1.0, 1.0 1.0 1.0, 0.0 0.0 1.0))',
            'POLYGON Z ((0.0 0.0 1.0, 1.0 0.0 1.0, 1.0 1.0 1.0, 0.0 0.0 1.0))'
        ]
        topology = TerrainTopology(geometries=wkts)
        tile = TerrainTile(topology=topology)

        # Check that the bounds are extracted from the terrain topology
        self.assertEqual(tile._west, 0.0)
        self.assertEqual(tile._south, 0.0)
        self.assertEqual(tile._east, 1.0)
        self.assertEqual(tile._north, 1.0)

        fileLike = tile.toBytesIO()
        self.assertIsInstance(fileLike, io.BytesIO)
Пример #8
0
def write_terrain(fname, xyz, idx):
    """
    mash 三角网写入 terrain 文件,当该文件存在时,直接覆盖
    :param fname: terrain文件名
    :param xyz: 顶点
    :param idx: 索引
    :return: None
    """
    wkts = []
    for _ in range(idx.shape[0]):
        tri = xyz[idx[_]]
        triP = Polygon([(tri[0][0], tri[0][1], tri[0][2])
                           , (tri[1][0], tri[1][1], tri[1][2])
                           , (tri[2][0], tri[2][1], tri[2][2])])
        wkts.append(triP.wkt)
    topology = TerrainTopology(geometries=wkts)
    tile = TerrainTile(topology=topology)
    if not os.path.exists(os.path.dirname(fname)):
        os.makedirs(os.path.dirname(fname))
    if os.path.exists('%s.terrain' %fname):
        os.remove('%s.terrain' %fname)
    tile.toFile('%s.terrain' %fname, gzipped=True)
Пример #9
0
    def testTopologyWithEffectiveBounds(self):
        geometries = []
        with open(
                "/export/data2/Tests_DGM_MERGE/TMS-Samples/14_17381_12506_dgm1.wkt",
                mode='r') as wkt_file:
            for line in wkt_file:
                geometries.append(line)

        bbox = box(10.9533691406, 47.395062446618994, 10.96431255332,
                   47.406005859339)
        effectiveBounds = shapely.affinity.scale(bbox, 0.7, 0.7, 0.7).bounds
        topology = TerrainTopology(geometries=geometries,
                                   effectiveBounds=effectiveBounds)

        with open("/tmp/Faces.wkt", mode='w') as faces_file:
            for face in topology.faces:
                vertices = []
                for v in face:
                    vertex = topology.vertices[v]
                    vertices.append(" ".join(map(str, vertex)))

                faceString = ",".join(vertices) + "," + vertices[0]
                faces_file.write("POLYGON Z (({}))\n".format(faceString))

        with open("/tmp/EffectiveFaces.wkt", mode='w') as effectiveFaces_file:
            for e in topology.effectiveFaces:
                effectiveFace = topology.faces[e]
                vertices = []
                for v in effectiveFace:
                    vertex = topology.vertices[v]
                    vertices.append(" ".join(map(str, vertex)))

                faceString = ",".join(vertices) + "," + vertices[0]
                effectiveFaces_file.write(
                    "POLYGON Z (({}))\n".format(faceString))

        self.assertEqual(len(topology.faces), 3)
Пример #10
0
    def testTopologyOneVertex(self):
        topology = TerrainTopology()
        topology.addGeometries([vertices_1])

        topologyWKT = TerrainTopology()
        topologyWKT.addGeometries([wkt_1])

        topologyWKB = TerrainTopology()
        topologyWKB.addGeometries([wkb_1])

        self.assertIsInstance(topology.__repr__(), str)
        self.assertIsInstance(topology.__repr__(), str)
        self.assertIsInstance(topology.__repr__(), str)

        self.assertEqual(len(topology.vertices), 3)
        self.assertEqual(len(topology.faces), 1)

        self.assertEqual(topology.vertices[0][0], vertices_1[0][0])
        self.assertEqual(topology.vertices[0][1], vertices_1[0][1])
        self.assertEqual(topology.vertices[0][2], vertices_1[0][2])

        self.assertEqual(topology.vertices[1][0], vertices_1[1][0])
        self.assertEqual(topology.vertices[1][1], vertices_1[1][1])
        self.assertEqual(topology.vertices[1][2], vertices_1[1][2])

        # Test if from vertices and from wkt give the same result
        self.assertEqual(topology.vertices[0][0], topologyWKT.vertices[0][0])
        self.assertEqual(topology.vertices[0][1], topologyWKT.vertices[0][1])
        self.assertEqual(topology.vertices[0][2], topologyWKT.vertices[0][2])

        self.assertEqual(topology.vertices[1][0], topologyWKT.vertices[1][0])
        self.assertEqual(topology.vertices[1][1], topologyWKT.vertices[1][1])
        self.assertEqual(topology.vertices[1][2], topologyWKT.vertices[1][2])

        # Test if from wkt and from wkb give the same result
        self.assertEqual(topologyWKT.vertices[0][0],
                         topologyWKB.vertices[0][0])
        self.assertEqual(topologyWKT.vertices[0][1],
                         topologyWKB.vertices[0][1])
        self.assertEqual(topologyWKT.vertices[0][2],
                         topologyWKB.vertices[0][2])

        self.assertEqual(topologyWKT.vertices[1][0],
                         topologyWKB.vertices[1][0])
        self.assertEqual(topologyWKT.vertices[1][1],
                         topologyWKB.vertices[1][1])
        self.assertEqual(topologyWKT.vertices[1][2],
                         topologyWKB.vertices[1][2])
    def testTopologyOneVertex(self):
        topology = TerrainTopology()
        topology.addGeometries([vertices_1])

        topologyWKT = TerrainTopology()
        topologyWKT.addGeometries([wkt_1])

        topologyWKB = TerrainTopology()
        topologyWKB.addGeometries([wkb_1])

        self.assertIsInstance(topology.__repr__(), str)
        self.assertIsInstance(topology.__repr__(), str)
        self.assertIsInstance(topology.__repr__(), str)

        self.assertEqual(len(topology.vertices), 3)
        self.assertEqual(len(topology.faces), 1)

        self.assertEqual(topology.vertices[0][0], vertices_1[0][0])
        self.assertEqual(topology.vertices[0][1], vertices_1[0][1])
        self.assertEqual(topology.vertices[0][2], vertices_1[0][2])

        self.assertEqual(topology.vertices[1][0], vertices_1[1][0])
        self.assertEqual(topology.vertices[1][1], vertices_1[1][1])
        self.assertEqual(topology.vertices[1][2], vertices_1[1][2])

        # Test if from vertices and from wkt give the same result
        self.assertEqual(topology.vertices[0][0], topologyWKT.vertices[0][0])
        self.assertEqual(topology.vertices[0][1], topologyWKT.vertices[0][1])
        self.assertEqual(topology.vertices[0][2], topologyWKT.vertices[0][2])

        self.assertEqual(topology.vertices[1][0], topologyWKT.vertices[1][0])
        self.assertEqual(topology.vertices[1][1], topologyWKT.vertices[1][1])
        self.assertEqual(topology.vertices[1][2], topologyWKT.vertices[1][2])

        # Test if from wkt and from wkb give the same result
        self.assertEqual(topologyWKT.vertices[0][0], topologyWKB.vertices[0][0])
        self.assertEqual(topologyWKT.vertices[0][1], topologyWKB.vertices[0][1])
        self.assertEqual(topologyWKT.vertices[0][2], topologyWKB.vertices[0][2])

        self.assertEqual(topologyWKT.vertices[1][0], topologyWKB.vertices[1][0])
        self.assertEqual(topologyWKT.vertices[1][1], topologyWKB.vertices[1][1])
        self.assertEqual(topologyWKT.vertices[1][2], topologyWKB.vertices[1][2])