Example #1
0
    def get_tin_maxmin(self, map_info):
        """Return"""
        line1 = Line()
        num_areas = GrassVect.Vect_get_num_areas(map_info)
        max_z = 0
        min_z = 100000
        for area_id in range(1, num_areas + 1):

            GrassVect.Vect_get_area_points(map_info, area_id, line1.c_points)

            pto1_z = line1.c_points.contents.z[0]
            pto2_z = line1.c_points.contents.z[1]
            pto3_z = line1.c_points.contents.z[2]

            min_ptos = min(pto1_z, pto2_z, pto3_z)
            max_ptos = max(pto1_z, pto2_z, pto3_z)
            if min_ptos < min_z:
                min_z = min_ptos
            if max_ptos > max_z:
                max_z = max_ptos
        return [int(math.floor(min_z)), int(math.ceil(max_z))]
Example #2
0
 def points(self):
     """Return a Line object with the outer ring"""
     line = Line()
     libvect.Vect_get_area_points(self.c_mapinfo, self.id, line.c_points)
     return line
    def get_rectas(self, map_info):
        """ Return
        """
        line1 = Line()

        max_min = self.get_tin_maxmin(map_info)
        rectas = [[] for p in range(max_min[0], max_min[1] + 1)]
        ptos = [[] for p in range(max_min[0], max_min[1] + 1)]

        num_areas = GrassVect.Vect_get_num_areas(map_info)
        for area_id in range(1, num_areas + 1):

            GrassVect.Vect_get_area_points(map_info, area_id, line1.c_points)

            pto1_x = line1.c_points.contents.x[0]
            pto1_y = line1.c_points.contents.y[0]
            pto1_z = line1.c_points.contents.z[0]
            pto2_x = line1.c_points.contents.x[1]
            pto2_y = line1.c_points.contents.y[1]
            pto2_z = line1.c_points.contents.z[1]
            pto3_x = line1.c_points.contents.x[2]
            pto3_y = line1.c_points.contents.y[2]
            pto3_z = line1.c_points.contents.z[2]

            for i, z_z in enumerate(range(max_min[0], max_min[1] + 1)):

                if pto1_z < z_z and pto2_z < z_z and pto3_z < z_z:
                    continue
                if pto1_z > z_z and pto2_z > z_z and pto3_z > z_z:
                    continue
                if pto1_z == z_z and pto2_z == z_z and pto3_z == z_z:
                    continue

                pts = [[pto1_x, pto1_y, pto1_z], [pto2_x, pto2_y, pto2_z],
                       [pto3_x, pto3_y, pto3_z]]
                inf = [pto for pto in pts if pto[2] < z_z]
                equal = [pto for pto in pts if pto[2] == z_z]
                sup = [pto for pto in pts if pto[2] > z_z]

                if ((len(inf) == 0 and len(sup) == 2)
                        or (len(inf) == 2 and len(sup) == 0)):
                    continue

                if len(equal) == 2:
                    if equal[0] != equal[1]:
                        if equal not in ptos[i] and equal[::-1] not in ptos[i]:
                            rectas[i].append(equal)
                            ptos[i].append(equal)
                    continue

                if len(inf) <= len(sup):
                    inf.extend(equal)
                else:
                    sup.extend(equal)

                if len(inf) < len(sup):
                    pto_a = inf[0]
                    pto_b = sup[0]
                    pto_c = sup[1]
                else:
                    pto_a = sup[0]
                    pto_b = inf[0]
                    pto_c = inf[1]

                t_1 = (z_z - pto_a[2]) / (pto_b[2] - pto_a[2])
                xx1 = pto_a[0] + t_1 * (pto_b[0] - pto_a[0])
                yy1 = pto_a[1] + t_1 * (pto_b[1] - pto_a[1])
                pto_1 = Point(xx1, yy1, z_z)

                t_2 = (z_z - pto_a[2]) / (pto_c[2] - pto_a[2])
                xx2 = pto_a[0] + t_2 * (pto_c[0] - pto_a[0])
                yy2 = pto_a[1] + t_2 * (pto_c[1] - pto_a[1])
                pto_2 = Point(xx2, yy2, z_z)

                rectas[i].append([pto_1, pto_2])

        return rectas