/* create a new map by cloning another one * Rdup creates a new empty map from the specifications of another map. * No cell values are copied. It uses a call to Rcreate to create the * map. See Rcreate for legal values of the args cellRepr and valueScale. * returns the map handle of the newly created map or NULL in case of an * error * * Merrno * NOT_RASTER plus the Merrno codes of Rcreate * * EXAMPLE * .so examples/dupbool.tr */ MAP *Rdup( const char *toFile, /* file name of map to be created */ const MAP *from, /* map to clone from */ CSF_CR cellRepr, /* cell representation of new map */ CSF_VS dataType) /* datatype/valuescale of new map */ { MAP *newMap = NULL; /* set NULL for goto error */ CHECKHANDLE_GOTO(from, error); /* check if mapType is T_RASTER */ if (from->main.mapType != T_RASTER) { M_ERROR(NOT_RASTER); goto error; } newMap = Rcreate(toFile, (size_t)from->raster.nrRows, (size_t)from->raster.nrCols, cellRepr, dataType, from->main.projection, from->raster.xUL, from->raster.yUL, from->raster.angle, from->raster.cellSize); error: return newMap ; }
/* compare 2 maps for their location attributes * Rcompare compares 2 maps for all location attributes: * * projection, * * xUL, yUL, angle, * * cell size and * * number of rows and columns * * returns 0 if one of these attributes differ or in case of an error, 1 * if they are all equal. * * Merrno * NOT_RASTER */ int Rcompare( const MAP *m1, /* map handle 1 */ const MAP *m2) /* map handle 2 */ { CHECKHANDLE_GOTO(m1, error); /* check if mapType is T_RASTER */ if ((m1->main.mapType != T_RASTER) || (m2->main.mapType != T_RASTER)) { M_ERROR(NOT_RASTER); goto error; } if ( MgetProjection(m1) == MgetProjection(m2) && m1->raster.xUL == m2->raster.xUL && m1->raster.yUL == m2->raster.yUL && m1->raster.cellSize == m2->raster.cellSize && m1->raster.cellSizeDupl == m2->raster.cellSizeDupl && m1->raster.angle == m2->raster.angle && m1->raster.nrRows == m2->raster.nrRows && m1->raster.nrCols == m2->raster.nrCols ) return(1); error: return(0); }
int RgetLocationAttributes( CSF_RASTER_LOCATION_ATTRIBUTES *l, /* fill in this struct */ const MAP *m) /* map handle to copy from */ { CHECKHANDLE_GOTO(m, error); *l = m->raster; return 1; error: return 0; }
/* change the x value of upper left co-ordinate * RputXUL changes the x value of upper left co-ordinate. * returns the new x value of upper left co-ordinate or 0 * case of an error. * * Merrno * NOACCESS */ REAL8 RputXUL( MAP *map, /* map handle */ REAL8 xUL) /* new x value of top left co-ordinate */ { CHECKHANDLE_GOTO(map, error); if(! WRITE_ENABLE(map)) { M_ERROR(NOACCESS); goto error; } map->raster.xUL = xUL; return(xUL); error: return(0); }
/* change projection type of map * MputProjection type changes the projection type of a map. * In version 2, projections are simplified. We only discern between * a projection with y increasing (PT_YINCT2B=0) and decreasing (PT_YDECT2B=1) * from top to bottom. * All old constants that denote a projection with y decreasing are nonzero. * And the old constant that denote a projection with y decreasing (PT_XY) is 0. * returns the new projection (PT_YINCT2B or PT_YDECT2B) or MV_UINT2 if an * error occurred. * * Merrno * NOACCESS */ CSF_PT MputProjection( MAP *map, /* map handle */ CSF_PT p) /* projection type, all nonzero values are mapped to * 1 (PT_YDECT2B) */ { CHECKHANDLE_GOTO(map, error); if(! WRITE_ENABLE(map)) { M_ERROR(NOACCESS); goto error; } map->main.projection = (p) ? PT_YDECT2B : PT_YINCT2B; return map->main.projection; error: return(MV_UINT2); }
/* make all cells missing value in map * RputAllMV writes a missing values to all the cells in a * map. For this is allocates a buffer to hold one row at a * time. * returns 1 if succesfull, 0 in case of an error */ int RputAllMV( MAP *m) { size_t i,nc,nr; void *buffer; CSF_CR cr; CHECKHANDLE_GOTO(m, error); if(! WRITE_ENABLE(m)) { M_ERROR(NOACCESS); goto error; } cr = RgetCellRepr(m); nc = RgetNrCols(m); buffer = Rmalloc(m,nc); if(buffer == NULL) { M_ERROR(NOCORE); goto error; } /* Fill buffer with determined Missingvalue*/ SetMemMV(buffer, nc, cr); nr = RgetNrRows(m); for(i = 0 ; i < nr; i++) if (RputRow(m, i, buffer) != nc) { M_ERROR(WRITE_ERROR); goto error_f; } CSF_FREE(buffer); CsfSetVarTypeMV( &(m->raster.minVal), cr); CsfSetVarTypeMV( &(m->raster.maxVal), cr); return(1); error_f: CSF_FREE(buffer); error: return(0); }
/* put cell size * returns the new cell size or -1 * in case of an error. * * Merrno * ILLHANDLE * NOACCESS * ILL_CELLSIZE */ REAL8 RputCellSize( MAP *map, /* map handle */ REAL8 cellSize) /* new cell size */ { CHECKHANDLE_GOTO(map, error); if(! WRITE_ENABLE(map)) { M_ERROR(NOACCESS); goto error; } if (cellSize <= 0.0) { M_ERROR(ILL_CELLSIZE); goto error; } map->raster.cellSize = cellSize; map->raster.cellSizeDupl = cellSize; return(cellSize); error: return(-1.0); }
/* read an attribute (LIBRARY_INTERNAL) * MgetAttribute reads an attribute if it is available. * Be aware that you can't pass a simple pointer to some * (array of) structure(s) due to alignment en endian problems. * At some time there will be a separate get function for each attribute * returns 0 if the attribute is not found, arg id if * the attribute is found. */ CSF_ATTR_ID CsfGetAttribute( MAP *m, /* map handle */ CSF_ATTR_ID id, /* id of attribute to be read */ size_t elSize, /* size of each data-element */ size_t *nmemb, /* write-only. How many elSize members are read. */ void *attr) /* write-only. buffer where attribute is read in. * Must be big enough to hold buffer. */ { ATTR_CNTRL_BLOCK b; CSF_FADDR pos; PRECOND(CsfValidSize(elSize)); CHECKHANDLE_GOTO(m, error); if (! READ_ENABLE(m)) { M_ERROR(NOACCESS); goto error; } if (CsfGetAttrBlock(m, id, &b) != 0) { int i = CsfGetAttrIndex(id, &b); *nmemb = b.attrs[i].attrSize; POSTCOND( ((*nmemb) % elSize) == 0); *nmemb /= elSize; POSTCOND( (*nmemb) > 0); pos = b.attrs[i].attrOffset; (void)fseek(m->fp, (long)pos, SEEK_SET); m->read(attr,elSize, (size_t)(*nmemb),m->fp); return(id); } else *nmemb = 0; error: return(0); /* not available or an error */ } /* MgetAttribute */