def projectxy(lon, lat, xnum, ynum, dx, dy, toproj, fromproj=None, pos='lowerleft'): """ Get projected x, y coordinates by projection and a given lon, lat coordinate. :param lon: (*float*) Longitude value. :param lat: (*float*) Latitude value. :param xnum: (*int*) X number. :param ynum: (*int*) Y number. :param dx: (*float*) X delta. :param dy: (*float*) Y delta. :param toproj: (*ProjectionInfo*) To projection. :param fromproj: (*ProjectionInfo*) From projection. Default is longlat projection. :param pos: (*string*) ['lowerleft' | 'center'] Lon, lat coordinate position. :returns: (*array_like*, *array_like*) Projected x, y coordinates. """ if fromproj is None: fromproj = KnownCoordinateSystems.geographic.world.WGS1984 x, y = project(lon, lat, toproj, fromproj) if pos == 'lowerleft': xx = np.arange1(x, xnum, dx) yy = np.arange1(y, ynum, dy) else: llx = x - ((xnum - 1) * 0.5 * dx) lly = y - ((ynum - 1) * 0.5 * dy) xx = np.arange1(llx, xnum, dx) yy = np.arange1(lly, ynum, dy) return xx, yy
def __init__(self, proj=projinfo(), x_coord=None, y_coord=None, x_orig=None, x_cell=None, x_num=None, y_orig=None, y_cell=None, y_num=None): """ Grid description. Using ``x_coord`` and ``y_coord`` or using ``x_orig``, ``x_cell``, ``x_num``, ``y_orig``, ``y_cell`` and ``y_num``. :param proj: (*ProjectionInfo*) The projection. :param x_coord: (*array*) X coordinate array. :param y_coord: (*array*) Y coordinate array. :param x_orig: (*float*) X coordinate at grid south-west corner. :param x_cell: (*float*) Grid spacing in x direction. :param x_num: (*int*) The number of grid cell in x direction. :param y_orig: (*float*) Y coordinate at grid. :param y_cell: (*float*) Grid spacing in y direction. :param y_num: (*int*) The number of grid cell in y direction. """ self.proj = proj if x_coord is None: self.__x_orig = x_orig self.__x_cell = x_cell self.__x_num = x_num self.__y_orig = y_orig self.__y_cell = y_cell self.__y_num = y_num self.__x_coord = np.arange1(x_orig, x_num, x_cell) self.__y_coord = np.arange1(y_orig, y_num, y_cell) else: self.__x_coord = x_coord self.__y_coord = y_coord self.__x_orig = x_coord[0] self.__x_cell = x_coord[1] - x_coord[0] self.__x_num = len(x_coord) self.__y_orig = y_coord[0] self.__y_cell = y_coord[1] - y_coord[0] self.__y_num = len(y_coord)