Exemplo n.º 1
0
def coor2pixel(coord, region):
    """Convert coordinates into a pixel row and col

    >>> reg = Region()
    >>> coor2pixel((reg.west, reg.north), reg)
    (0.0, 0.0)
    >>> coor2pixel((reg.east, reg.south), reg) == (reg.rows, reg.cols)
    True

    """
    (east, north) = coord
    return (libraster.Rast_northing_to_row(north, region.c_region),
            libraster.Rast_easting_to_col(east, region.c_region))
Exemplo n.º 2
0
    def outline(self):
        for cur in range(0, self.npoints):
            x, y = self.coords[cur]
            tmpx = self.view_to_row(y)
            tmpy = self.view_to_col(x)
            tmp_n = self.row_to_northing(tmpy, 0.5)
            tmp_e = self.col_to_easting(tmpx, 0.5)
            self.tempY.append(
                raster.Rast_northing_to_row(tmp_n, byref(self.Band_cellhd)))
            self.tempX.append(
                raster.Rast_easting_to_col(tmp_e, byref(self.Band_cellhd)))

        first = -1
        prev = self.npoints - 1

        for cur in range(0, self.npoints):

            if self.tempY[cur] != self.tempY[prev]:
                first = cur
                break

        skip = 0
        VN = 0
        cur = 0

        if skip == 0:

            self.VX.append(self.tempX[cur])
            self.VY.append(self.tempY[cur])
            VN = VN + 1

        prev = cur
        cur = cur + 1

        if cur >= self.npoints:
            cur = 0
        next = cur + 1
        if next >= self.npoints:
            next = 0

        skip = ((self.tempY[prev] == self.tempY[cur])
                and (self.tempY[next] == self.tempY[cur]))

        while cur != first:
            if skip == 0:

                self.VX.append(self.tempX[cur])
                self.VY.append(self.tempY[cur])
                VN = VN + 1

            cur = cur + 1
            prev = cur
            if cur >= self.npoints:
                cur = 0
            next = cur + 1
            if next >= self.npoints:
                next = 0
            try:
                skip = ((self.tempY[prev] == self.tempY[cur])
                        and (self.tempY[next] == self.tempY[cur]))
            except:
                pass

        np = 0
        prev = VN - 1
        for cur in range(0, self.npoints):
            try:
                np = np + abs(self.VY[prev] - self.VY[cur])
            except:
                pass

        PN = 0
        prev = VN - 1

        cur = 0

        while (cur < VN):
            self.edge(self.VX[prev], self.VY[prev], self.VX[cur], self.VY[cur])

            prev = cur
            cur = cur + 1

        prev = VN - 1
        cur = 0
        ###################################################################
        ###################################################################
        next = cur + 1
        if next >= VN:
            next = 0

        if (((self.VY[prev] < self.VY[cur]) and (self.VY[next] < self.VY[cur]))
                or ((self.VY[prev] > self.VY[cur]) and
                    (self.VY[next] > self.VY[cur]))):
            skip = 1

        elif (
            ((self.VY[prev] < self.VY[cur]) and (self.VY[cur] < self.VY[next]))
                or ((self.VY[prev] > self.VY[cur]) and
                    (self.VY[cur] > self.VY[next]))):
            skip = 0
        else:
            skip = 0
            next += 1
            if next >= VN:
                next = 0

            if (((self.VY[prev] < self.VY[cur]) and
                 (self.VY[next] < self.VY[cur]))
                    or ((self.VY[prev] > self.VY[cur]) and
                        (self.VY[next] > self.VY[cur]))):
                skip = 1

        if skip == 0:
            self.edge_point(self.VX[cur], self.VY[cur])

        cur = next
        prev = cur - 1

        ###################################################################

        while cur != 0:
            next = cur + 1
            if next >= VN:
                next = 0

            if (((self.VY[prev] < self.VY[cur]) and
                 (self.VY[next] < self.VY[cur]))
                    or ((self.VY[prev] > self.VY[cur]) and
                        (self.VY[next] > self.VY[cur]))):
                skip = 1

            elif (((self.VY[prev] < self.VY[cur]) and
                   (self.VY[cur] < self.VY[next]))
                  or ((self.VY[prev] > self.VY[cur]) and
                      (self.VY[cur] > self.VY[next]))):
                skip = 0
            else:
                skip = 0
                next += 1
                if next >= VN:
                    next = 0

                if (((self.VY[prev] < self.VY[cur]) and
                     (self.VY[next] < self.VY[cur]))
                        or ((self.VY[prev] > self.VY[cur]) and
                            (self.VY[next] > self.VY[cur]))):
                    skip = 1

            if skip == 0:
                self.edge_point(self.VX[cur], self.VY[cur])

            cur = next
            prev = cur - 1

        for i in range(0, len(self.perimeterX)):
            a = self.perimeterX[i]
            b = self.perimeterY[i]
            xy = a, b
            self.Region_perimeter.append(xy)

        self.Region_perimeter.sort()