DBInt RGlibPointSTNCoordinates(DBObjData *dbData, DBObjTableField *field) { DBInt pointID, ret = DBFault; DBCoordinate coord; DBPosition pos; DBObjData *linkedData = dbData->LinkedData(); DBVPointIF *pntIF; DBNetworkIF *netIF; DBObjRecord *pntRec, *cellRec; if (linkedData == (DBObjData *) NULL) return (DBFault); pntIF = new DBVPointIF(dbData); netIF = new DBNetworkIF(linkedData); for (pointID = 0; pointID < pntIF->ItemNum(); ++pointID) { pntRec = pntIF->Item(pointID); if (DBPause(pointID * 100 / pntIF->ItemNum())) goto Stop; if ((pntRec->Flags () & DBObjectFlagIdle) == DBObjectFlagIdle) continue; coord = pntIF->Coordinate(pntRec); if (netIF->Coord2Pos(coord, pos) == DBFault) continue; netIF->Pos2Coord(pos, coord); if ((field != (DBObjTableField *) NULL) && (!CMmathEqualValues(field->Float(pntRec), field->FloatNoData())) && ((cellRec = netIF->Cell(coord, field->Float(pntRec))) != (DBObjRecord *) NULL)) coord = netIF->Center(cellRec); pntIF->Coordinate(pntRec, coord); } ret = DBSuccess; Stop: delete netIF; delete pntIF; return (ret); }
DBInt RGlibPointSubbasinCenter(DBObjData *pntData, DBObjData *netData) { DBCoordinate massCoord; DBVPointIF *pntIF = new DBVPointIF(pntData); DBObjTable *pointTable = pntData->Table(DBrNItems); DBObjTableField *massCoordXFLD = pointTable->Field(RGlibMassCoordX); DBObjTableField *massCoordYFLD = pointTable->Field(RGlibMassCoordY); DBNetworkIF *netIF = new DBNetworkIF(netData); DBObjRecord *pointRec, *cellRec; if (massCoordXFLD == NULL) { massCoordXFLD = new DBObjTableField(RGlibMassCoordX, DBTableFieldFloat, "%10.3f", sizeof(DBFloat4)); pointTable->AddField(massCoordXFLD); } if (massCoordYFLD == NULL) { massCoordYFLD = new DBObjTableField(RGlibMassCoordY, DBTableFieldFloat, "%10.3f", sizeof(DBFloat4)); pointTable->AddField(massCoordYFLD); } for (pointRec = pntIF->FirstItem(); pointRec != (DBObjRecord *) NULL; pointRec = pntIF->NextItem()) { if ((pointRec->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle) { massCoordXFLD->Float(pointRec, massCoordXFLD->FloatNoData()); massCoordYFLD->Float(pointRec, massCoordYFLD->FloatNoData()); continue; } if (DBPause(pointRec->RowID() * 100 / pntIF->ItemNum())) goto Stop; if ((cellRec = netIF->Cell(pntIF->Coordinate(pointRec))) == (DBObjRecord *) NULL) massCoord = pntIF->Coordinate(pointRec); else { if (netIF->CellBasinCells(cellRec) > 1) { massCoord.X = 0.0; massCoord.Y = 0.0; netIF->UpStreamSearch(cellRec, (DBNetworkACTION) _RGlibSubbasinCenterAction, &massCoord); massCoord.X = massCoord.X / (DBFloat) netIF->CellBasinCells(cellRec); massCoord.Y = massCoord.Y / (DBFloat) netIF->CellBasinCells(cellRec); } else massCoord = netIF->Center(cellRec); } massCoordXFLD->Float(pointRec, massCoord.X); massCoordYFLD->Float(pointRec, massCoord.Y); } Stop: if (pointRec != (DBObjRecord *) NULL) { pointTable->DeleteField(massCoordXFLD); pointTable->DeleteField(massCoordYFLD); return (DBFault); } return (DBSuccess); }
void RGISEditPointAddXYCBK (Widget widget, RGISWorkspace *workspace,XmAnyCallbackStruct *callData) { DBDataset *dataset = UIDataset (); DBObjData *dbData =dataset->Data (); DBVPointIF *pntIF = new DBVPointIF (dbData); DBObjTable *pointTable = dbData->Table (DBrNItems); DBObjTableField *xCoordFLD = pointTable->Field (RGISEditPointXCoord); DBObjTableField *yCoordFLD = pointTable->Field (RGISEditPointYCoord); DBCoordinate coord; DBObjRecord *pointRec; UITable *tableCLS = (UITable *) dbData->Display (UITableName (dbData,pointTable)); widget = widget; workspace = workspace; callData = callData; UIPauseDialogOpen ((char *) "Adding XY Coordinates"); if (xCoordFLD == NULL) { xCoordFLD = new DBObjTableField (RGISEditPointXCoord,DBTableFieldFloat,"%10.3f",sizeof (DBFloat4)); pointTable->AddField (xCoordFLD); if (tableCLS != (UITable *) NULL) tableCLS->AddField (xCoordFLD); UIPause (40); } if (yCoordFLD == NULL) { yCoordFLD = new DBObjTableField (RGISEditPointYCoord,DBTableFieldFloat,"%10.3f",sizeof (DBFloat4)); pointTable->AddField (yCoordFLD); if (tableCLS != (UITable *) NULL) tableCLS->AddField (yCoordFLD); UIPause (80); } for (pointRec = pntIF->FirstItem (); pointRec != (DBObjRecord *) NULL; pointRec = pntIF->NextItem ()) { if (UIPause (80 + pointRec->RowID () * 20 / pntIF->ItemNum ())) goto Stop; coord = pntIF->Coordinate (pointRec); xCoordFLD->Float (pointRec,coord.X); yCoordFLD->Float (pointRec,coord.Y); } Stop: UIPauseDialogClose (); if (tableCLS != (UITable *) NULL) tableCLS->Draw (); }
DBInt DBPointToGrid(DBObjData *pntData, DBObjData *grdData, DBFloat factor) { DBInt startID, pnt0ID, pntID, id, itemNum; double dist, minDist, box, box0, bWidth, bHeight; DBPosition pos; DBCoordinate gCoord, *pCoord; DBObjRecord *grdRec, *pntRec, *symRec; DBObjTable *itemTable, *symTable; DBObjTableField *valField, *symField; DBVPointIF *pntIF; DBGridIF *gridIF; DBMathDistanceFunction distFunc = DBMathGetDistanceFunction(pntData); if (distFunc != DBMathGetDistanceFunction(grdData)) { CMmsgPrint(CMmsgAppError, "Incompatible projections in: %s %d", __FILE__, __LINE__); return (DBFault); } pntIF = new DBVPointIF(pntData); itemNum = pntIF->ItemNum(); if ((pCoord = (DBCoordinate *) calloc(itemNum, sizeof(DBCoordinate))) == (DBCoordinate *) NULL) { CMmsgPrint(CMmsgSysError, "Memory allocation Error in: %s %d", __FILE__, __LINE__); return (DBFault); } gridIF = new DBGridIF(grdData); for (pntID = 0; pntID < itemNum; ++pntID) pCoord[pntID] = pntIF->Coordinate(pntIF->Item(pntID)); if (grdData->Type() == DBTypeGridContinuous) gridIF->RenameLayer(gridIF->Layer((DBInt) 0), (char *) "Distance to Station"); else { gridIF->RenameLayer(gridIF->Layer((DBInt) 0), (char *) "Station grid"); itemTable = grdData->Table(DBrNItems); symTable = grdData->Table(DBrNSymbols); valField = itemTable->Field(DBrNGridValue); symField = itemTable->Field(DBrNSymbol); if ((symRec = symTable->Item(0)) == (DBObjRecord *) NULL) CMmsgPrint(CMmsgAppError, "Total Metal Gebasz in: %s %d", __FILE__, __LINE__); for (pntID = 0; pntID < itemNum; ++pntID) { pntRec = pntIF->Item(pntID); grdRec = itemTable->Add(pntRec->Name()); valField->Int(grdRec, pntID + 1); symField->Record(grdRec, symRec); } } startID = 0; for (pos.Row = 0; pos.Row < gridIF->RowNum(); ++pos.Row) { DBPause(pos.Row * 100 / gridIF->RowNum()); for (pos.Col = 0; pos.Col < gridIF->ColNum(); ++pos.Col) { gridIF->Pos2Coord(pos, gCoord); minDist = box0 = DBHugeVal; pnt0ID = pntID = startID; id = DBFault; do { bWidth = fabs(gCoord.X - pCoord[pntID].X); bHeight = fabs(gCoord.Y - pCoord[pntID].Y); box = bWidth > bHeight ? bWidth : bHeight; if ((box < box0) && ((dist = DBMathCoordinateDistance(distFunc, gCoord, pCoord[pntID])) < minDist)) { minDist = dist; id = startID = pntID; box *= factor; if (box0 > box) box0 = box; } pntID = pntID + 1 < itemNum ? pntID + 1 : 0; } while (pntID != pnt0ID); if (grdData->Type() == DBTypeGridContinuous) gridIF->Value(pos, minDist); else gridIF->Value(pos, id); } } if (grdData->Type() == DBTypeGridContinuous) gridIF->RecalcStats(); else gridIF->DiscreteStats(); delete gridIF; free(pCoord); return (DBSuccess); }
DBInt DBPointToGrid(DBObjData *pntData, DBObjData *netData, DBObjData *grdData) { DBInt i; DBPosition pos; DBObjTable *pntTable = pntData->Table(DBrNItems); DBObjTable *grdTable = grdData->Table(DBrNItems); DBObjTable *symTable = grdData->Table(DBrNSymbols); DBObjectLIST<DBObjTableField> *pntFields = pntTable->Fields(); DBObjTableField *pntFLD; DBObjTableField *grdAttribFLD; DBObjTableField *grdFLD = grdTable->Field(DBrNGridValue); DBObjTableField *symFLD = grdTable->Field(DBrNSymbol); DBObjRecord *cellRec, *toCell, *pntRec, *itemRec; DBObjRecord *symRec = symTable->First(); DBVPointIF *pntIF; DBNetworkIF *netIF; DBGridIF *grdIF; pntIF = new DBVPointIF(pntData); netIF = new DBNetworkIF(netData); grdIF = new DBGridIF(grdData); grdIF->RenameLayer(grdIF->Layer((DBInt) 0), (char *) "Subbasins"); for (pos.Row = 0; pos.Row < grdIF->RowNum(); ++pos.Row) for (pos.Col = 0; pos.Col < grdIF->ColNum(); ++pos.Col) grdIF->Value(pos, DBFault); for (pntFLD = pntFields->First(); pntFLD != (DBObjTableField *) NULL; pntFLD = pntFields->Next()) if (DBTableFieldIsVisible(pntFLD)) grdTable->AddField(new DBObjTableField(*pntFLD)); for (i = 0; i < pntIF->ItemNum(); ++i) { DBPause(i * 100 / pntIF->ItemNum()); pntRec = pntIF->Item(i); if ((pntRec->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle) continue; if ((cellRec = netIF->Cell(pntIF->Coordinate(pntRec))) == (DBObjRecord *) NULL) continue; itemRec = grdTable->Add(pntRec->Name()); grdFLD->Int(itemRec, pntRec->RowID() + 1); symFLD->Record(itemRec, symRec); for (pntFLD = pntFields->First(); pntFLD != (DBObjTableField *) NULL; pntFLD = pntFields->Next()) if ((grdAttribFLD = grdTable->Field(pntFLD->Name())) != (DBObjTableField *) NULL) switch (pntFLD->Type()) { case DBTableFieldString: grdAttribFLD->String(itemRec, pntFLD->String(pntRec)); break; case DBTableFieldInt: grdAttribFLD->Int(itemRec, pntFLD->Int(pntRec)); break; case DBTableFieldFloat: grdAttribFLD->Float(itemRec, pntFLD->Float(pntRec)); break; case DBTableFieldDate: grdAttribFLD->Date(itemRec, pntFLD->Date(pntRec)); break; } grdIF->Value(netIF->CellPosition(cellRec), itemRec->RowID()); } for (i = 0; i < netIF->CellNum(); ++i) { if ((cellRec = netIF->Cell(i)) == (DBObjRecord *) NULL) continue; if ((itemRec = grdIF->GridItem(netIF->CellPosition(cellRec))) != (DBObjRecord *) NULL) continue; if ((toCell = netIF->ToCell(cellRec)) == (DBObjRecord *) NULL) continue; if ((itemRec = grdIF->GridItem(netIF->CellPosition(toCell))) != (DBObjRecord *) NULL) grdIF->Value(netIF->CellPosition(cellRec), itemRec->RowID()); } grdIF->DiscreteStats(); delete pntIF; delete netIF; delete grdIF; return (DBSuccess); }
DBInt RGlibDataStream2RGIS(DBObjData *outData, DBObjData *tmplData, FILE *inFile) { DBInt layerID = 0, itemSize; DBPosition pos; DBFloat val; void *data = (void *) NULL; MFVarHeader_t header; DBObjRecord *record; switch (tmplData->Type()) { case DBTypeVectorPoint: { DBInt itemID; DBDate date; DBObjTable *itemTable = outData->Table(DBrNItems); DBObjTableField *idField = new DBObjTableField("ItemID", DBTableFieldInt, "%6d", sizeof(DBInt), false); DBObjTableField *dateField = new DBObjTableField("Date", DBTableFieldDate, "%s", sizeof(DBDate), false); DBObjTableField *valField; DBVPointIF *pntIF = new DBVPointIF(tmplData); itemTable->AddField(idField); itemTable->AddField(dateField); while (MFVarReadHeader(&header, inFile)) { if (header.ItemNum != pntIF->ItemNum()) { CMmsgPrint(CMmsgUsrError, "Error: Datastream inconsistency %d %d!", header.ItemNum, pntIF->ItemNum()); return (DBFault); } if (data == (void *) NULL) { itemSize = MFVarItemSize(header.DataType); if ((data = (void *) realloc(data, header.ItemNum * itemSize)) == (void *) NULL) { CMmsgPrint(CMmsgSysError, "Memory allocation error in: %s %d", __FILE__, __LINE__); return (DBFault); } switch (header.DataType) { case MFByte: valField = new DBObjTableField("Value", DBTableFieldInt, "%2d", sizeof(char), false); case MFShort: valField = new DBObjTableField("Value", DBTableFieldInt, "%4d", sizeof(DBShort), false); case MFInt: valField = new DBObjTableField("Value", DBTableFieldInt, "%8d", sizeof(DBInt), false); case MFFloat: valField = new DBObjTableField("Value", DBTableFieldFloat, "%8.2f", sizeof(DBFloat4), false); case MFDouble: valField = new DBObjTableField("Value", DBTableFieldFloat, "%8.2f", sizeof(DBFloat), false); } itemTable->AddField(valField); } if ((int) fread(data, itemSize, header.ItemNum, inFile) != header.ItemNum) { CMmsgPrint(CMmsgSysError, "Error: Data stream read in: %s %d", __FILE__, __LINE__); return (DBFault); } for (itemID = 0; itemID < header.ItemNum; ++itemID) { record = itemTable->Add(header.Date); date.Set(header.Date); idField->Int(record, itemID); dateField->Date(record, date); /* decDateField->Float (record,date); */ switch (header.DataType) { case MFByte: valField->Int(record, ((char *) data)[itemID]); break; case MFShort: valField->Int(record, ((short *) data)[itemID]); break; case MFInt: valField->Int(record, ((int *) data)[itemID]); break; case MFFloat: valField->Float(record, ((float *) data)[itemID]); break; case MFDouble: valField->Float(record, ((double *) data)[itemID]); break; } } } delete pntIF; } break; case DBTypeGridContinuous: case DBTypeGridDiscrete: { DBGridIF *gridIF = new DBGridIF(outData); while (MFVarReadHeader(&header, inFile)) { if (header.ItemNum != gridIF->RowNum() * gridIF->ColNum()) { CMmsgPrint(CMmsgUsrError, "Error: Datastream inconsistency!"); return (DBFault); } if (layerID == 0) { itemSize = MFVarItemSize(header.DataType); if ((data = (void *) realloc(data, header.ItemNum * itemSize)) == (void *) NULL) { CMmsgPrint(CMmsgSysError, "Memory allocation error in: %s %d", __FILE__, __LINE__); return (DBFault); } record = gridIF->Layer(layerID); gridIF->RenameLayer(header.Date); } else record = gridIF->AddLayer(header.Date); switch (header.DataType) { case MFByte: case MFShort: case MFInt: gridIF->MissingValue(record, header.Missing.Int); break; case MFFloat: case MFDouble: gridIF->MissingValue(record, header.Missing.Float); break; } if ((int) fread(data, itemSize, header.ItemNum, inFile) != header.ItemNum) { CMmsgPrint(CMmsgSysError, "Error: Data stream read in: %s %d", __FILE__, __LINE__); return (DBFault); } for (pos.Row = 0; pos.Row < gridIF->RowNum(); ++pos.Row) for (pos.Col = 0; pos.Col < gridIF->ColNum(); ++pos.Col) { switch (header.DataType) { case MFByte: val = (DBFloat) (((char *) data)[pos.Row * gridIF->ColNum() + pos.Col]); break; case MFShort: val = (DBFloat) (((short *) data)[pos.Row * gridIF->ColNum() + pos.Col]); break; case MFInt: val = (DBFloat) (((int *) data)[pos.Row * gridIF->ColNum() + pos.Col]); break; case MFFloat: val = (DBFloat) (((float *) data)[pos.Row * gridIF->ColNum() + pos.Col]); break; case MFDouble: val = (DBFloat) (((double *) data)[pos.Row * gridIF->ColNum() + pos.Col]); break; } gridIF->Value(record, pos, val); } layerID++; } gridIF->RecalcStats(); } break; case DBTypeNetwork: { DBInt cellID; DBGridIF *gridIF = new DBGridIF(outData); DBNetworkIF *netIF = new DBNetworkIF(tmplData); while (MFVarReadHeader(&header, inFile)) { if (header.ItemNum != netIF->CellNum()) { CMmsgPrint(CMmsgUsrError, "Error: Datastream inconsistency!"); return (DBFault); } if (layerID == 0) { itemSize = MFVarItemSize(header.DataType); if ((data = (void *) realloc(data, header.ItemNum * itemSize)) == (void *) NULL) { CMmsgPrint(CMmsgSysError, "Memory allocation error in: %s %d", __FILE__, __LINE__); return (DBFault); } record = gridIF->Layer(layerID); gridIF->RenameLayer(header.Date); } else record = gridIF->AddLayer(header.Date); if ((int) fread(data, itemSize, header.ItemNum, inFile) != header.ItemNum) { CMmsgPrint(CMmsgSysError, "Error: Data stream read in: %s %d", __FILE__, __LINE__); delete netIF; return (DBFault); } for (pos.Row = 0; pos.Row < gridIF->RowNum(); ++pos.Row) for (pos.Col = 0; pos.Col < gridIF->ColNum(); ++pos.Col) gridIF->Value(record, pos, gridIF->MissingValue()); for (cellID = 0; cellID < netIF->CellNum(); ++cellID) { pos = netIF->CellPosition(netIF->Cell(cellID)); switch (header.DataType) { case MFByte: val = (DBFloat) (((char *) data)[cellID]); break; case MFShort: val = (DBFloat) (((short *) data)[cellID]); break; case MFInt: val = (DBFloat) (((int *) data)[cellID]); break; case MFFloat: val = (DBFloat) (((float *) data)[cellID]); break; case MFDouble: val = (DBFloat) (((double *) data)[cellID]); break; } gridIF->Value(record, pos, val); } layerID++; } gridIF->RecalcStats(); } break; } return (DBSuccess); }
DBInt RGlibRGIS2DataStream(DBObjData *grdData, DBObjData *tmplData, char *fieldName, FILE *outFile) { DBInt layerID, ret = DBSuccess, itemSize, itemID; DBInt intValue; DBFloat floatValue; void *data; MFVarHeader_t varHeader; DBObjRecord *layerRec, *gridRec; DBObjTableField *fieldPTR = (DBObjTableField *) NULL; DBGridIF *gridIF; DBVPointIF *tmplPntIF = (DBVPointIF *) NULL; DBGridIF *tmplGrdIF = (DBGridIF *) NULL; DBNetworkIF *tmplNetIF = (DBNetworkIF *) NULL; gridIF = new DBGridIF(grdData); varHeader.Swap = 1; if (grdData->Type() == DBTypeGridDiscrete) { DBObjTable *itemTable = grdData->Table(DBrNItems); if (fieldName == (char *) NULL) fieldName = DBrNGridValue; if ((fieldPTR = itemTable->Field(fieldName)) == (DBObjTableField *) NULL) { CMmsgPrint(CMmsgAppError, "Error: Invalid field [%s] in: %s %d", fieldName, __FILE__, __LINE__); return (DBFault); } itemSize = fieldPTR->Length(); switch (fieldPTR->Type()) { case DBTableFieldInt: switch (itemSize) { default: case sizeof(DBByte): varHeader.DataType = MFByte; break; case sizeof(DBShort): varHeader.DataType = MFShort; break; case sizeof(DBInt): varHeader.DataType = MFInt; break; } varHeader.Missing.Int = fieldPTR->IntNoData(); break; case DBTableFieldFloat: switch (itemSize) { default: case sizeof(DBFloat4): varHeader.DataType = MFFloat; break; case sizeof(DBFloat): varHeader.DataType = MFDouble; break; } varHeader.Missing.Float = fieldPTR->FloatNoData(); break; } } else { if (fieldName != (char *) NULL) CMmsgPrint(CMmsgUsrError, "Warning: Fieldname ignored for continuous grid!"); itemSize = gridIF->ValueSize(); switch (gridIF->ValueType()) { case DBVariableInt: switch (itemSize) { case 1: varHeader.DataType = MFByte; break; case 2: varHeader.DataType = MFShort; break; case 4: varHeader.DataType = MFInt; break; } varHeader.Missing.Int = (int) gridIF->MissingValue(); break; case DBVariableFloat: switch (itemSize) { case 4: varHeader.DataType = MFFloat; break; case 8: varHeader.DataType = MFDouble; break; } varHeader.Missing.Float = gridIF->MissingValue(); break; } } if (tmplData == (DBObjData *) NULL) { tmplGrdIF = gridIF; varHeader.ItemNum = gridIF->RowNum() * gridIF->ColNum(); } else { switch (tmplData->Type()) { case DBTypeVectorPoint: tmplPntIF = new DBVPointIF(tmplData); varHeader.ItemNum = tmplPntIF->ItemNum(); break; case DBTypeGridContinuous: case DBTypeGridDiscrete: tmplGrdIF = new DBGridIF(tmplData); varHeader.ItemNum = gridIF->RowNum() * gridIF->ColNum(); break; case DBTypeNetwork: tmplNetIF = new DBNetworkIF(tmplData); varHeader.ItemNum = tmplNetIF->CellNum(); break; default: delete gridIF; return (DBFault); } } if ((data = (void *) calloc(varHeader.ItemNum, itemSize)) == (void *) NULL) { CMmsgPrint(CMmsgSysError, "Error! Allocating %d items of %d size in: %s %d", varHeader.ItemNum, itemSize, __FILE__, __LINE__); return (DBFault); } /************************************************************** * * * Point template * * * **************************************************************/ if (tmplPntIF != (DBVPointIF *) NULL) { DBObjRecord *pntRec; if (fieldPTR == (DBObjTableField *) NULL) { for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) { layerRec = gridIF->Layer(layerID); strncpy(varHeader.Date, layerRec->Name(), MFDateStringLength - 1); for (itemID = 0; itemID < varHeader.ItemNum; ++itemID) { pntRec = tmplPntIF->Item(itemID); if ((varHeader.DataType == MFByte) || (varHeader.DataType == MFShort) || (varHeader.DataType == MFInt)) { if (gridIF->Value(layerRec, tmplPntIF->Coordinate(pntRec), &intValue) == false) intValue = varHeader.Missing.Int; switch (varHeader.DataType) { case MFByte: ((char *) data)[itemID] = (char) intValue; break; case MFShort: ((short *) data)[itemID] = (short) intValue; break; case MFInt: ((int *) data)[itemID] = (short) intValue; break; } } else { if (gridIF->Value(layerRec, tmplPntIF->Coordinate(pntRec), &floatValue) == false) floatValue = varHeader.Missing.Float; switch (varHeader.DataType) { case MFFloat: ((float *) data)[itemID] = (float) floatValue; break; case MFDouble: ((double *) data)[itemID] = (double) floatValue; break; } } } if ((DBInt) fwrite(&varHeader, sizeof(MFVarHeader_t), 1, outFile) != 1) { CMmsgPrint(CMmsgSysError, "Error: Writing record header in: %s %d", __FILE__, __LINE__); ret = DBFault; break; } if ((DBInt) fwrite(data, itemSize, varHeader.ItemNum, outFile) != varHeader.ItemNum) { CMmsgPrint(CMmsgSysError, "Error: Writing data in: %s %d", __FILE__, __LINE__); ret = DBFault; break; } } } else { for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) { layerRec = gridIF->Layer(layerID); strncpy(varHeader.Date, layerRec->Name(), MFDateStringLength - 1); for (itemID = 0; itemID < varHeader.ItemNum; ++itemID) { pntRec = tmplPntIF->Item(itemID); gridRec = gridIF->GridItem(layerRec, tmplPntIF->Coordinate(pntRec)); switch (varHeader.DataType) { case MFByte: ((char *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->IntNoData(); break; case MFShort: ((short *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->IntNoData(); break; case MFInt: ((int *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->IntNoData(); break; case MFFloat: ((float *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->FloatNoData(); break; case MFDouble: ((double *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->FloatNoData(); break; } } if ((DBInt) fwrite(&varHeader, sizeof(MFVarHeader_t), 1, outFile) != 1) { CMmsgPrint(CMmsgSysError, "Error: Writing record header in: %s %d", __FILE__, __LINE__); ret = DBFault; break; } if ((DBInt) fwrite(data, itemSize, varHeader.ItemNum, outFile) != varHeader.ItemNum) { CMmsgPrint(CMmsgSysError, "Error: Writing data in: %s %d", __FILE__, __LINE__); ret = DBFault; break; } } } delete tmplPntIF; } /************************************************************** * * * Grid Template (default when no template coverage is given. * * * **************************************************************/ else if (tmplGrdIF != (DBGridIF *) NULL) { DBPosition pos; DBCoordinate coord; if (fieldPTR == (DBObjTableField *) NULL) { for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) { layerRec = gridIF->Layer(layerID); strncpy(varHeader.Date, layerRec->Name(), MFDateStringLength - 1); for (pos.Row = 0; pos.Row < tmplGrdIF->RowNum(); ++pos.Row) for (pos.Col = 0; pos.Col < tmplGrdIF->ColNum(); ++pos.Col) { itemID = pos.Row * tmplGrdIF->ColNum() + pos.Col; if ((varHeader.DataType == MFByte) || (varHeader.DataType == MFShort) || (varHeader.DataType == MFInt)) { if (tmplGrdIF != gridIF) { tmplGrdIF->Pos2Coord(pos, coord); if (gridIF->Value(layerRec, coord, &intValue) == false) intValue = varHeader.Missing.Int; } else { if (gridIF->Value(layerRec, pos, &intValue) == false) intValue = varHeader.Missing.Int; } switch (varHeader.DataType) { case MFByte: ((char *) data)[itemID] = (char) intValue; break; case MFShort: ((short *) data)[itemID] = (short) intValue; break; case MFInt: ((int *) data)[itemID] = (short) intValue; break; } } else { if (tmplGrdIF != gridIF) { tmplGrdIF->Pos2Coord(pos, coord); if (gridIF->Value(layerRec, coord, &floatValue) == false) floatValue = varHeader.Missing.Float; } else { if (gridIF->Value(layerRec, pos, &floatValue) == false) floatValue = varHeader.Missing.Float; } switch (varHeader.DataType) { case MFFloat: ((float *) data)[itemID] = (float) floatValue; break; case MFDouble: ((double *) data)[itemID] = (double) floatValue; break; } } } if ((DBInt) fwrite(&varHeader, sizeof(MFVarHeader_t), 1, outFile) != 1) { CMmsgPrint(CMmsgSysError, "Error: Writing record header in: %s %d", __FILE__, __LINE__); ret = DBFault; break; } if ((DBInt) fwrite(data, itemSize, varHeader.ItemNum, outFile) != varHeader.ItemNum) { CMmsgPrint(CMmsgSysError, "Error: Writing data in: %s %d", __FILE__, __LINE__); ret = DBFault; break; } } } else { for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) { layerRec = gridIF->Layer(layerID); strncpy(varHeader.Date, layerRec->Name(), MFDateStringLength - 1); for (pos.Row = 0; pos.Row < tmplGrdIF->RowNum(); ++pos.Row) for (pos.Col = 0; pos.Col < tmplGrdIF->ColNum(); ++pos.Col) { itemID = pos.Row * tmplGrdIF->ColNum() + pos.Col; if (tmplGrdIF != gridIF) { tmplGrdIF->Pos2Coord(pos, coord); gridRec = gridIF->GridItem(layerRec, coord); } else gridRec = gridIF->GridItem(layerRec, pos); switch (varHeader.DataType) { case MFByte: ((char *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->IntNoData(); break; case MFShort: ((short *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->IntNoData(); break; case MFInt: ((int *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->IntNoData(); break; case MFFloat: ((float *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->FloatNoData(); break; case MFDouble: ((double *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->FloatNoData(); break; } } if ((DBInt) fwrite(&varHeader, sizeof(MFVarHeader_t), 1, outFile) != 1) { CMmsgPrint(CMmsgSysError, "Error: Writing record header in: %s %d", __FILE__, __LINE__); ret = DBFault; break; } if ((DBInt) fwrite(data, itemSize, varHeader.ItemNum, outFile) != varHeader.ItemNum) { CMmsgPrint(CMmsgSysError, "Error: Writing data in: %s %d", __FILE__, __LINE__); ret = DBFault; break; } } } if (tmplGrdIF != gridIF) delete tmplGrdIF; } /************************************************************** * * * Network Template * * * **************************************************************/ else if (tmplNetIF != (DBNetworkIF *) NULL) { DBObjRecord *cellRec; if (fieldPTR == (DBObjTableField *) NULL) { for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) { layerRec = gridIF->Layer(layerID); strncpy(varHeader.Date, layerRec->Name(), MFDateStringLength - 1); for (itemID = 0; itemID < varHeader.ItemNum; ++itemID) { cellRec = tmplNetIF->Cell(itemID); if ((varHeader.DataType == MFByte) || (varHeader.DataType == MFShort) || (varHeader.DataType == MFInt)) { if (gridIF->Value(layerRec, tmplNetIF->Center(cellRec), &intValue) == false) intValue = varHeader.Missing.Int; switch (varHeader.DataType) { case MFByte: ((char *) data)[itemID] = (char) intValue; break; case MFShort: ((short *) data)[itemID] = (short) intValue; break; case MFInt: ((int *) data)[itemID] = (short) intValue; break; } } else { if (gridIF->Value(layerRec, tmplNetIF->Center(cellRec), &floatValue) == false) floatValue = varHeader.Missing.Float; switch (varHeader.DataType) { case MFFloat: ((float *) data)[itemID] = (float) floatValue; break; case MFDouble: ((double *) data)[itemID] = (double) floatValue; break; } } } if ((DBInt) fwrite(&varHeader, sizeof(MFVarHeader_t), 1, outFile) != 1) { CMmsgPrint(CMmsgSysError, "Error: Writing record header in: %s %d", __FILE__, __LINE__); ret = DBFault; break; } if ((DBInt) fwrite(data, itemSize, varHeader.ItemNum, outFile) != varHeader.ItemNum) { CMmsgPrint(CMmsgSysError, "Error: Writing data in: %s %d", __FILE__, __LINE__); ret = DBFault; break; } } } else { for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) { layerRec = gridIF->Layer(layerID); strncpy(varHeader.Date, layerRec->Name(), MFDateStringLength - 1); for (itemID = 0; itemID < varHeader.ItemNum; ++itemID) { cellRec = tmplNetIF->Cell(itemID); gridRec = gridIF->GridItem(layerRec, tmplNetIF->Center(cellRec)); switch (varHeader.DataType) { case MFByte: ((char *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->IntNoData(); break; case MFShort: ((short *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->IntNoData(); break; case MFInt: ((int *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->IntNoData(); break; case MFFloat: ((float *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Float(gridRec) : fieldPTR->FloatNoData(); break; case MFDouble: ((double *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Float(gridRec) : fieldPTR->FloatNoData(); break; } } if ((DBInt) fwrite(&varHeader, sizeof(MFVarHeader_t), 1, outFile) != 1) { CMmsgPrint(CMmsgSysError, "Error: Writing record header in: %s %d", __FILE__, __LINE__); ret = DBFault; break; } if ((DBInt) fwrite(data, itemSize, varHeader.ItemNum, outFile) != varHeader.ItemNum) { CMmsgPrint(CMmsgSysError, "Error: Writing data in: %s %d", __FILE__, __LINE__); ret = DBFault; break; } } } delete tmplNetIF; } free(data); delete gridIF; return (ret); }
int main (int argc,char *argv []) { FILE *outFile; DBInt argPos, argNum = argc, ret; int objID, size; DBFloat lCorrection = 1.0; MFDomain_t *domain = (MFDomain_t *) NULL; DBCoordinate coord; DBObjRecord *objRec; DBObjData *data; for (argPos = 1;argPos < argNum; ) { if (CMargTest (argv [argPos],"-l","--lengthcorrection")) { if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing length correction!"); return (CMfailed); } if (sscanf (argv [argPos],"%lf", &lCorrection) != 1) { CMmsgPrint (CMmsgUsrError, "Invalid length correction!"); return (CMfailed); } if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest (argv [argPos],"-h","--help")) { CMmsgPrint (CMmsgInfo,"%s [options] <input rgisdata> <output domain>",CMprgName(argv[0])); CMmsgPrint (CMmsgInfo," -l,--lengthcorrection"); CMmsgPrint (CMmsgInfo," -h,--help"); return (DBSuccess); } if ((argv [argPos][0] == '-') && (strlen (argv [argPos]) > 1)) { CMmsgPrint (CMmsgUsrError,"Unknown option: %s!",argv [argPos]); return (CMfailed); } argPos++; } if (argNum > 3) { CMmsgPrint (CMmsgUsrError,"Extra arguments!"); return (CMfailed); } outFile = (argNum > 2) && (strcmp (argv [2],"-") != 0) ? fopen (argv [2],"w") : stdout; if (outFile == (FILE *) NULL) { CMmsgPrint (CMmsgUsrError,"Output file Opening error in: %s",CMprgName(argv[0])); exit (DBFault); } data = new DBObjData (); ret = (argNum > 1) && (strcmp (argv [1],"-") != 0) ? data->Read (argv [1]) : data->Read (stdin); if ((domain = (MFDomain_t *) calloc (1,sizeof (MFDomain_t))) != (MFDomain_t *) NULL) { domain->Objects = (MFObject_t *) NULL; switch (data->Type ()) { case DBTypeVectorPoint: { DBVPointIF *pntIF = new DBVPointIF (data); domain->ObjNum = pntIF->ItemNum (); if ((domain->Objects = (MFObject_t *) calloc (domain->ObjNum,sizeof (MFObject_t))) == (MFObject_t *) NULL) { CMmsgPrint (CMmsgSysError, "Memory Allocation Error in: %s %d",__FILE__,__LINE__); MFDomainFree (domain); goto Stop; } for (objID = 0;objID < domain->ObjNum;++objID) { objRec = pntIF->Item (objID); coord = pntIF->Coordinate (objRec); domain->Objects [objID].ID = objRec->RowID (); domain->Objects [objID].DLinkNum = 0; domain->Objects [objID].ULinkNum = 0; domain->Objects [objID].DLinks = (size_t *) NULL; domain->Objects [objID].ULinks = (size_t *) NULL; domain->Objects [objID].XCoord = domain->Objects [objID].Lon = coord.X; domain->Objects [objID].YCoord = domain->Objects [objID].Lat = coord.Y; domain->Objects [objID].Area = 0.0; domain->Objects [objID].Length = 0.0; } } break; case DBTypeGridContinuous: case DBTypeGridDiscrete: { } break; case DBTypeNetwork: { DBInt dir; DBObjRecord *nextCell; DBNetworkIF *netIF = new DBNetworkIF (data); domain->ObjNum = netIF->CellNum (); if ((domain->Objects = (MFObject_t *) calloc (domain->ObjNum,sizeof (MFObject_t))) == (MFObject_t *) NULL) { CMmsgPrint (CMmsgSysError, "Memory Allocation Error in: %s %d",__FILE__,__LINE__); MFDomainFree (domain); goto Stop; } for (objID = 0;objID < domain->ObjNum;++objID) { domain->Objects [objID].DLinks = (size_t *) NULL; domain->Objects [objID].ULinks = (size_t *) NULL; } for (objID = 0;objID < domain->ObjNum;++objID) { objRec = netIF->Cell (objID); coord = netIF->Center (objRec); domain->Objects [objID].ID = objRec->RowID (); domain->Objects [objID].DLinkNum = 0; domain->Objects [objID].ULinkNum = 0; domain->Objects [objID].XCoord = domain->Objects [objID].Lon = coord.X; domain->Objects [objID].YCoord = domain->Objects [objID].Lat = coord.Y; domain->Objects [objID].Area = netIF->CellArea (objRec); domain->Objects [objID].Length = netIF->CellLength (objRec) *lCorrection; if ((nextCell = netIF->ToCell (objRec)) != (DBObjRecord *) NULL) { size = (domain->Objects [objID].DLinkNum + 1) * sizeof (size_t); if ((domain->Objects [objID].DLinks = (size_t *) realloc (domain->Objects [objID].DLinks,size)) == (size_t *) NULL) { CMmsgPrint (CMmsgSysError, "Memory Allocation Error in: %s %d",__FILE__,__LINE__); MFDomainFree (domain); goto Stop; } domain->Objects [objID].DLinks [domain->Objects [objID].DLinkNum] = nextCell->RowID (); domain->Objects [objID].DLinkNum++; } for (dir = 0;dir < 8;++dir) if ((nextCell = netIF->FromCell (objRec,0x01 << dir)) != (DBObjRecord *) NULL) { size = (domain->Objects [objID].ULinkNum + 1) * sizeof (size_t); if ((domain->Objects [objID].ULinks = (size_t *) realloc (domain->Objects [objID].ULinks,size)) == (size_t *) NULL) { CMmsgPrint (CMmsgSysError, "Memory Allocation Error in: %s %d",__FILE__,__LINE__); MFDomainFree (domain);goto Stop; } domain->Objects [objID].ULinks [domain->Objects [objID].ULinkNum] = nextCell->RowID (); domain->Objects [objID].ULinkNum++; } } } break; } ret = MFDomainWrite (domain,outFile); } Stop: if (outFile != stdout) fclose (outFile); return (ret); }
DBInt RGlibPointSubbasinHist(DBObjData *pntData, DBObjData *netData, DBObjData *grdData, DBObjData *tblData) { DBInt layerID, layerNum = 0, progress = 0, maxProgress; DBObjTable *itemTable = grdData->Table(DBrNItems); DBObjTable *table = tblData->Table(DBrNItems); DBObjTableField *pointIDFLD; DBObjTableField *layerIDFLD; DBObjTableField *layerNameFLD; DBObjTableField *categoryIDFLD; DBObjTableField *categoryFLD; DBObjTableField *percentFLD; DBObjTableField *areaFLD; DBObjTableField *cellNumFLD; DBVPointIF *pntIF; DBNetworkIF *netIF; DBObjRecord *pntRec, *itemRec, *tblRec; DBObjectLIST<DBObjTableField> *fields; _RGlibPointGrdIF = new DBGridIF(grdData); for (layerID = 0; layerID < _RGlibPointGrdIF->LayerNum(); ++layerID) { _RGlibPointGrdLayerRec = _RGlibPointGrdIF->Layer(layerID); if ((_RGlibPointGrdLayerRec->Flags() & DBObjectFlagIdle) != DBObjectFlagIdle) ++layerNum; } if (layerNum < 1) { CMmsgPrint(CMmsgUsrError, "No Layer to Process!"); delete _RGlibPointGrdIF; return (DBFault); } pntIF = new DBVPointIF(pntData); netIF = new DBNetworkIF(netData); table->AddField(pointIDFLD = new DBObjTableField("GHAASPointID", DBTableFieldInt, "%8d", sizeof(DBInt))); table->AddField(layerIDFLD = new DBObjTableField("LayerID", DBTableFieldInt, "%4d", sizeof(DBShort))); table->AddField(layerNameFLD = new DBObjTableField("LayerName", DBTableFieldString, "%s", DBStringLength)); table->AddField(categoryIDFLD = new DBObjTableField(DBrNCategoryID, DBTableFieldInt, "%2d", sizeof(DBShort))); table->AddField(categoryFLD = new DBObjTableField(DBrNCategory, DBTableFieldString, _RGlibPointGrdIF->ValueFormat(), DBStringLength)); table->AddField(cellNumFLD = new DBObjTableField("CellNum", DBTableFieldInt, "%8d", sizeof(DBInt))); table->AddField(areaFLD = new DBObjTableField(DBrNArea, DBTableFieldFloat, "%10.1f", sizeof(DBFloat4))); table->AddField(percentFLD = new DBObjTableField(DBrNPercent, DBTableFieldFloat, "%6.2f", sizeof(DBFloat4))); _RGlibHistogram = (Histogram *) malloc(itemTable->ItemNum() * sizeof(Histogram)); if (_RGlibHistogram == (Histogram *) NULL) { CMmsgPrint(CMmsgAppError, "Memory Allocation Error in: %s %d", __FILE__, __LINE__); return (DBFault); } maxProgress = pntIF->ItemNum() * _RGlibPointGrdIF->LayerNum(); for (layerID = 0; layerID < _RGlibPointGrdIF->LayerNum(); ++layerID) { _RGlibPointGrdLayerRec = _RGlibPointGrdIF->Layer(layerID); if ((_RGlibPointGrdLayerRec->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle) continue; for (pntRec = pntIF->FirstItem(); pntRec != (DBObjRecord *) NULL; pntRec = pntIF->NextItem()) { if (DBPause(progress * 100 / maxProgress)) goto Stop; progress++; if ((pntRec->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle) continue; for (itemRec = itemTable->First(); itemRec != (DBObjRecord *) NULL; itemRec = itemTable->Next()) _RGlibHistogram[itemRec->RowID()].Initialize(); netIF->UpStreamSearch(netIF->Cell(pntIF->Coordinate(pntRec)), (DBNetworkACTION) _RGlibSubbasinCategories); for (itemRec = itemTable->First(); itemRec != (DBObjRecord *) NULL; itemRec = itemTable->Next()) if (_RGlibHistogram[itemRec->RowID()].cellNum > 0) { tblRec = table->Add(pntRec->Name()); pointIDFLD->Int(tblRec, pntRec->RowID() + 1); layerIDFLD->Int(tblRec, _RGlibPointGrdLayerRec->RowID()); layerNameFLD->String(tblRec, _RGlibPointGrdLayerRec->Name()); categoryIDFLD->Int(tblRec, itemRec->RowID() + 1); categoryFLD->String(tblRec, itemRec->Name()); areaFLD->Float(tblRec, _RGlibHistogram[itemRec->RowID()].area); percentFLD->Float(tblRec, _RGlibHistogram[itemRec->RowID()].area / netIF->CellBasinArea(netIF->Cell(pntIF->Coordinate(pntRec))) * 100.0); cellNumFLD->Int(tblRec, _RGlibHistogram[itemRec->RowID()].cellNum); } } } Stop: delete _RGlibPointGrdIF; delete netIF; delete pntIF; free(_RGlibHistogram); if (progress == maxProgress) { fields = new DBObjectLIST<DBObjTableField>("Field List"); fields->Add(new DBObjTableField(*pointIDFLD)); fields->Add(new DBObjTableField(*layerIDFLD)); fields->Add(areaFLD = new DBObjTableField(*areaFLD)); areaFLD->Flags(DBObjectFlagSortReversed, DBSet); table->ListSort(fields); delete fields; return (DBSuccess); } return (DBFault); }
DBInt RGlibPointSubbasinStats(DBObjData *pntData, DBObjData *netData, DBObjData *grdData, DBObjData *tblData) { DBInt layerID, layerNum = 0, progress = 0, maxProgress; DBObjTable *table; DBObjTableField *pointIDFLD; DBObjTableField *layerIDFLD; DBObjTableField *layerNameFLD; DBObjTableField *minimumFLD; DBObjTableField *maximumFLD; DBObjTableField *averageFLD; DBObjTableField *stdDevFLD; DBObjTableField *areaFLD; DBVPointIF *pntIF; DBNetworkIF *netIF; DBObjRecord *pntRec, *tblRec; DBObjectLIST<DBObjTableField> *fields; _RGlibPointGrdIF = new DBGridIF(grdData); for (layerID = 0; layerID < _RGlibPointGrdIF->LayerNum(); ++layerID) { _RGlibPointGrdLayerRec = _RGlibPointGrdIF->Layer(layerID); if ((_RGlibPointGrdLayerRec->Flags() & DBObjectFlagIdle) != DBObjectFlagIdle) ++layerNum; } if (layerNum < 1) { CMmsgPrint(CMmsgUsrError, "No Layer to Process!"); delete _RGlibPointGrdIF; return (DBFault); } table = tblData->Table(DBrNItems); pntIF = new DBVPointIF(pntData); netIF = new DBNetworkIF(netData); table->AddField(pointIDFLD = new DBObjTableField("GHAASPointID", DBTableFieldInt, "%8d", sizeof(DBInt))); table->AddField(layerIDFLD = new DBObjTableField("LayerID", DBTableFieldInt, "%4d", sizeof(DBShort))); table->AddField(layerNameFLD = new DBObjTableField("LayerName", DBTableFieldString, "%s", DBStringLength)); table->AddField(averageFLD = new DBObjTableField(RGlibPointMean, DBTableFieldFloat, _RGlibPointGrdIF->ValueFormat(), sizeof(DBFloat4))); table->AddField(minimumFLD = new DBObjTableField(RGlibPointMin, DBTableFieldFloat, _RGlibPointGrdIF->ValueFormat(), sizeof(DBFloat4))); table->AddField(maximumFLD = new DBObjTableField(RGlibPointMax, DBTableFieldFloat, _RGlibPointGrdIF->ValueFormat(), sizeof(DBFloat4))); table->AddField( stdDevFLD = new DBObjTableField(RGlibPointStdDev, DBTableFieldFloat, _RGlibPointGrdIF->ValueFormat(), sizeof(DBFloat4))); table->AddField(areaFLD = new DBObjTableField(RGlibPointArea, DBTableFieldFloat, _RGlibPointGrdIF->ValueFormat(), sizeof(DBFloat4))); grdData->Flags(DBObjectFlagProcessed, DBSet); maxProgress = pntIF->ItemNum() * _RGlibPointGrdIF->LayerNum(); for (layerID = 0; layerID < _RGlibPointGrdIF->LayerNum(); ++layerID) { _RGlibPointGrdLayerRec = _RGlibPointGrdIF->Layer(layerID); if ((_RGlibPointGrdLayerRec->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle) continue; for (pntRec = pntIF->FirstItem(); pntRec != (DBObjRecord *) NULL; pntRec = pntIF->NextItem()) { if (DBPause(progress * 100 / maxProgress)) goto Stop; progress++; if ((pntRec->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle) continue; tblRec = table->Add(pntRec->Name()); pointIDFLD->Int(tblRec, pntRec->RowID() + 1); layerIDFLD->Int(tblRec, _RGlibPointGrdLayerRec->RowID()); layerNameFLD->String(tblRec, _RGlibPointGrdLayerRec->Name()); _RGlibSubbasinArea = 0.0; _RGlibSubbasinMin = DBHugeVal; _RGlibSubbasinMax = -DBHugeVal; _RGlibSubbasinMean = 0.0; _RGlibSubbasinStdDev = 0.0; netIF->UpStreamSearch(netIF->Cell(pntIF->Coordinate(pntRec)), (DBNetworkACTION) _RGlibSubbasinStatistics); _RGlibSubbasinMean = _RGlibSubbasinMean / _RGlibSubbasinArea; _RGlibSubbasinStdDev = _RGlibSubbasinStdDev / _RGlibSubbasinArea; _RGlibSubbasinStdDev = _RGlibSubbasinStdDev - _RGlibSubbasinMean * _RGlibSubbasinMean; _RGlibSubbasinStdDev = sqrt(_RGlibSubbasinStdDev); minimumFLD->Float(tblRec, _RGlibSubbasinMin); maximumFLD->Float(tblRec, _RGlibSubbasinMax); averageFLD->Float(tblRec, _RGlibSubbasinMean); stdDevFLD->Float(tblRec, _RGlibSubbasinStdDev); areaFLD->Float(tblRec, _RGlibSubbasinArea); } } Stop: delete _RGlibPointGrdIF; delete netIF; delete pntIF; if (progress == maxProgress) { fields = new DBObjectLIST<DBObjTableField>("Field List"); fields->Add(new DBObjTableField(*pointIDFLD)); fields->Add(new DBObjTableField(*layerIDFLD)); table->ListSort(fields); delete fields; return (DBSuccess); } return (DBFault); }