Example #1
0
int mask_raster_array(void *rast, int ncols,
		      int change_null, RASTER_MAP_TYPE data_type)
{
    DCELL x;

    while (ncols-- > 0) {
	x = Rast_get_d_value(rast, data_type);
	if (change_null && Rast_is_null_value(rast, data_type))
	    Rast_set_d_value(rast, new_null, data_type);
	if (mask_d_select(&x, &d_mask))
	    Rast_set_null_value(rast, 1, data_type);
	rast = G_incr_void_ptr(rast, Rast_cell_size(data_type));
    }

    return 0;
}
Example #2
0
static void
modifyNull(char *name, d_Mask * maskRules, int changeNull, double newNullVal)
{
    void *map, *mapOut;
    G3D_Region region;
    int tileX, tileY, tileZ, x, y, z;
    double value;
    int doCompress, doLzw, doRle, precision;
    int cacheSize;

    cacheSize = G3d_cacheSizeEncode(G3D_USE_CACHE_XY, 1);

    if (NULL == G_find_grid3(name, ""))
	G3d_fatalError(_("3D raster map <%s> not found"), name);

    fprintf(stderr, "name %s Mapset %s \n", name, G_mapset());
    map = G3d_openCellOld(name, G_mapset(), G3D_DEFAULT_WINDOW,
			  DCELL_TYPE, cacheSize);

    if (map == NULL)
	G3d_fatalError(_("Unable to open 3D raster map <%s>"), name);

    G3d_getRegionStructMap(map, &region);
    G3d_getTileDimensionsMap(map, &tileX, &tileY, &tileZ);

    G3d_getCompressionMode(&doCompress, &doLzw, &doRle, &precision);

    mapOut = G3d_openNewParam(name, DCELL_TYPE, G3D_USE_CACHE_XY,
			      &region, G3d_fileTypeMap(map),
			      doLzw, doRle, G3d_tilePrecisionMap(map), tileX,
			      tileY, tileZ);
    if (mapOut == NULL)
	G3d_fatalError(_("modifyNull: error opening tmp file"));

    G3d_minUnlocked(map, G3D_USE_CACHE_X);
    G3d_autolockOn(map);
    G3d_unlockAll(map);
    G3d_minUnlocked(mapOut, G3D_USE_CACHE_X);
    G3d_autolockOn(mapOut);
    G3d_unlockAll(mapOut);

     /*AV*/
	/* BEGIN OF ORIGINAL CODE */
	/*
	 * for (z = 0; z < region.depths; z++) {
	 * if ((z % tileZ) == 0) {
	 * G3d_unlockAll (map);
	 * G3d_unlockAll (mapOut);
	 * }
	 * for (y = 0; y < region.cols; y++)
	 * for (x = 0; x < region.rows; x++) {
	 */
	/* END OF ORIGINAL CODE */
	 /*AV*/
	/* BEGIN OF MY CODE */
	for (z = 0; z < region.depths; z++) {
	if ((z % tileZ) == 0) {
	    G3d_unlockAll(map);
	    G3d_unlockAll(mapOut);
	}
	for (y = region.rows - 1; y >= 0; y--)
	    for (x = 0; x < region.cols; x++) {
		/* END OF MY CODE */

		value = G3d_getDoubleRegion(map, x, y, z);

		if (G3d_isNullValueNum(&value, DCELL_TYPE)) {
		    if (changeNull) {
			value = newNullVal;
		    }
		}
		else if (mask_d_select((DCELL *) & value, maskRules)) {
		    G3d_setNullValue(&value, 1, DCELL_TYPE);
		}

		G3d_putDouble(mapOut, x, y, z, value);
	    }
	if ((z % tileZ) == 0) {
	    if (!G3d_flushTilesInCube
		(mapOut, 0, 0, MAX(0, z - tileZ), region.rows - 1,
		 region.cols - 1, z))
		G3d_fatalError(_("modifyNull: error flushing tiles in cube"));
	}
    }


    if (!G3d_flushAllTiles(mapOut))
	G3d_fatalError(_("modifyNull: error flushing all tiles"));

    G3d_autolockOff(map);
    G3d_unlockAll(map);
    G3d_autolockOff(mapOut);
    G3d_unlockAll(mapOut);

    if (!G3d_closeCell(map))
	G3d_fatalError(_("Unable to close raster map"));
    if (!G3d_closeCell(mapOut))
	G3d_fatalError(_("modifyNull: Unable to close tmp file"));
}