def xy2ij(self, x, y, precise=False): """ Convert easting/northing coordinate pair(s) to array coordinate pairs(s). NOTE: see note at ij2xy() Arguments: x (float): scalar or array of easting coordinates y (float): scalar or array of northing coordinates precise (bool): if true, return fractional array coordinates Returns: i (int, or float): scalar or array of row coordinate index j (int, or float): scalar or array of column coordinate index """ if (rh._test_outside(x, self.easting[0], self.easting[-1]) or rh._test_outside(y, self.northing[0], self.northing[-1])): raise PygaarstRasterError("Coordinates out of bounds") i = (1 - (y - self.northing[0]) / (self.northing[-1] - self.northing[0])) * self.nrow j = ((x - self.easting[0]) / (self.easting[-1] - self.easting[0])) * self.ncol if precise: return i, j else: return int(np.floor(i)), int(np.floor(j))
def ij2xy(self, i, j): """ Converts array index pair(s) to easting/northing coordinate pairs(s). NOTE: array coordinate origin is in the top left corner whereas easting/northing origin is in the bottom left corner. Easting and northing are floating point numbers, and refer to the top-left corner coordinate of the pixel. i runs from 0 to nrow-1, j from 0 to ncol-1. For i=nrow and j=ncol, the bottom-right corner coordinate of the bottom-right pixel will be returned. This is identical to the bottom- right corner. Arguments: i (int): scalar or array of row coordinate index j (int): scalar or array of column coordinate index Returns: x (float): scalar or array of easting coordinates y (float): scalar or array of northing coordinates """ if (rh._test_outside(i, 0, self.nrow) or rh._test_outside(j, 0, self.ncol)): raise PygaarstRasterError("Coordinates %d, %d out of bounds" % (i, j)) x = self.easting[0] + j * self.delx y = self.northing[-1] + i * self.dely return x, y
def ij2xy(self, i, j): """ Converts array index pair(s) to easting/northing coordinate pairs(s). NOTE: array coordinate origin is in the top left corner whereas easting/northing origin is in the bottom left corner. Easting and northing are floating point numbers, and refer to the top-left corner coordinate of the pixel. i runs from 0 to nrow-1, j from 0 to ncol-1. For i=nrow and j=ncol, the bottom-right corner coordinate of the bottom-right pixel will be returned. This is identical to the bottom- right corner. Arguments: i (int): scalar or array of row coordinate index j (int): scalar or array of column coordinate index Returns: x (float): scalar or array of easting coordinates y (float): scalar or array of northing coordinates """ if (rh._test_outside(i, 0, self.nrow) or rh._test_outside(j, 0, self.ncol)): raise PygaarstRasterError( "Coordinates %d, %d out of bounds" % (i, j)) x = self.easting[0] + j * self.delx y = self.northing[-1] + i * self.dely return x, y