void UIAttribView::Draw (DBObjRecord *record) { DBObjTableField *field; DBObjectLIST<DBObjTableField> *fields; UIXYGraphShell *graphCLS; if (record == (DBObjRecord *) NULL) { Cardinal i, numChildren; WidgetList rowCols; UIAuxSetLabelString (ItemNameWGT,(char *) ""); XtVaGetValues (FieldsRowCol,XmNchildren, &rowCols, XmNnumChildren, &numChildren,NULL); for (i = 0;i < numChildren; ++i) XmTextFieldSetString (XtNameToWidget (rowCols [i],"UIAttribViewTextField"),(char *) ""); return; } UIAuxSetLabelString (ItemNameWGT,record->Name ()); switch (DataPTR->Type ()) { case DBTypeVectorPoint: case DBTypeVectorLine: case DBTypeVectorPolygon: case DBTypeGridDiscrete: fields = ItemTable->Fields (); for (field = fields->First ();field != (DBObjTableField *) NULL;field = fields->Next ()) if (DBTableFieldIsVisible (field) == true) DrawField (field->Name (),field->String (record)); break; case DBTypeGridContinuous: { DBCoordinate coord = *((DBCoordinate *) (record->Data ())); DBGridIF *gridIF = new DBGridIF (DataPTR); for (record = ItemTable->First ();record != (DBObjRecord *) NULL;record = ItemTable->Next ()) DrawField (record->Name (),gridIF->ValueString (record,coord)); delete gridIF; } break; case DBTypeNetwork: { DBObjTable *cellTable = DataPTR->Table (DBrNCells); DBObjTableField *basinFLD = cellTable->Field (DBrNBasin); DBObjRecord *basinRec; if ((basinRec = ItemTable->Item (basinFLD->Int (record) - 1)) == (DBObjRecord *) NULL) { CMmsgPrint (CMmsgAppError, "BasinID Error in:%s %d",__FILE__,__LINE__); return; } DrawField ((char *) "Basin Name",basinRec->Name ()); fields = ItemTable->Fields (); for (field = fields->First ();field != (DBObjTableField *) NULL;field = fields->Next ()) if (DBTableFieldIsVisible (field) == true) DrawField (field->Name (),field->String (basinRec)); fields = cellTable->Fields (); for (field = fields->First ();field != (DBObjTableField *) NULL;field = fields->Next ()) if (DBTableFieldIsVisible (field) == true) DrawField (field->Name (),field->String (record)); } break; default: break; } if ((graphCLS = (UIXYGraphShell *) DataPTR->Display (UIXYGraphShellStr)) != (UIXYGraphShell *) NULL) graphCLS->Configure (record); }
void GetVariable(DBObjRecord *record, DBCoordinate coord) { switch ((GridIF->Data())->Type()) { case DBTypeGridContinuous: { DBFloat value; if (GridIF->Value(LayerRec, coord, &value)) TargetFLD->Float(record, value); else TargetFLD->Float(record, TargetFLD->FloatNoData()); } break; case DBTypeGridDiscrete: { DBObjRecord *grdRec; if ((grdRec = GridIF->GridItem(LayerRec, coord)) != (DBObjRecord *) NULL) switch (SourceFLD->Type()) { case DBVariableString: TargetFLD->String(record, SourceFLD->String(grdRec)); break; case DBVariableInt: TargetFLD->Int(record, SourceFLD->Int(grdRec)); break; case DBVariableFloat: TargetFLD->Float(record, SourceFLD->Float(grdRec)); break; default: break; } else switch (SourceFLD->Type()) { case DBVariableString: TargetFLD->String(record, ""); break; case DBVariableInt: TargetFLD->Int(record, SourceFLD->IntNoData()); break; case DBVariableFloat: TargetFLD->Float(record, SourceFLD->FloatNoData()); break; default: break; } } break; default: CMmsgPrint(CMmsgUsrError, "Invalid grid type in: CMDgrdVariable:GetVariable ()"); break; } }
static int _DBObjTableListSort(const DBObjRecord **obj0, const DBObjRecord **obj1) { DBInt ret = 0; DBObjTableField *field; DBDate date0, date1; for (field = _DBObjTableSortFields->First(); field != (DBObjTableField *) NULL; field = _DBObjTableSortFields->Next()) { switch (field->Type()) { case DBTableFieldString: ret = strcmp(field->String(*obj0), field->String(*obj1)); break; case DBTableFieldInt: ret = field->Int(*obj0) - field->Int(*obj1); break; case DBTableFieldFloat: if (field->Float(*obj0) - field->Float(*obj1) > 0.0) ret = 1; else if (field->Float(*obj0) - field->Float(*obj1) < 0.0) ret = -1; else ret = 0; break; case DBTableFieldDate: date0 = field->Date(*obj0); date1 = field->Date(*obj1); if (date0 > date1) ret = 1; else if (date0 < date1) ret = -1; else ret = 0; break; case DBTableFieldTableRec: ret = strcmp((*obj0)->Name(), (*obj1)->Name()); break; case DBTableFieldDataRec: ret = (*obj0)->RowID() - (*obj1)->RowID(); break; } if ((field->Flags() & DBObjectFlagSortReversed) == DBObjectFlagSortReversed) ret *= -1; if (ret != 0) return (ret); } if (ret == 0) ret = (*obj0)->ListPos() - (*obj1)->ListPos(); return (ret); }
int RGlibGenFuncSymbolField (DBObjData *data, const char *fieldName) { DBInt recID; char symbolName [DBStringLength + 1]; DBObjTable *table = data->Table (DBrNItems); DBObjTable *symbols = data->Table (DBrNSymbols); DBObjRecord *record, *symbolRec; DBObjTableField *field; DBObjTableField *symbolFLD; DBObjTableField *symbolIDFLD; DBObjTableField *foregroundFLD; DBObjTableField *backgroundFLD; DBObjTableField *styleFLD; if (table == (DBObjTable *) NULL) return (DBFault); if ((field = table->Field (fieldName)) == (DBObjTableField *) NULL) { CMmsgPrint (CMmsgAppError, "Invalid field name in: %s %d",__FILE__,__LINE__); return (DBFault); } if ((symbolFLD = table->Field (DBrNSymbol)) == (DBObjTableField *) NULL) { CMmsgPrint (CMmsgAppError, "Missing symbol field in: %s %d",__FILE__,__LINE__); return (DBFault); } if (symbols == (DBObjTable *) NULL) { CMmsgPrint (CMmsgAppError, "Missing symbol table in: %s %d",__FILE__,__LINE__); return (DBFault); } if ((symbolIDFLD = symbols->Field (DBrNSymbolID)) == (DBObjTableField *) NULL) { CMmsgPrint (CMmsgAppError, "Missing symbolID field in: %s %d",__FILE__,__LINE__); return (DBFault); } if ((foregroundFLD = symbols->Field (DBrNForeground)) == (DBObjTableField *) NULL) { CMmsgPrint (CMmsgAppError, "Missing foreground field in: %s %d",__FILE__,__LINE__); return (DBFault); } if ((backgroundFLD = symbols->Field (DBrNBackground)) == (DBObjTableField *) NULL) { CMmsgPrint (CMmsgAppError, "Missing background field in: %s %d",__FILE__,__LINE__); return (DBFault); } if ((styleFLD = symbols->Field (DBrNStyle)) == (DBObjTableField *) NULL) { CMmsgPrint (CMmsgAppError, "Missing style field in: %s %d",__FILE__,__LINE__); return (DBFault); } symbols->DeleteAll (); for (recID = 0;recID < table->ItemNum (); ++recID) { record = table->Item (recID); DBPause (record->RowID () * 100 / table->ItemNum ()); if (field->Type () == DBTableFieldString) sprintf (symbolName,"%s",field->String (record)); else sprintf (symbolName,"Symbol:%03d",field->Int (record)); if ((symbolRec = (DBObjRecord *) symbols->Item (symbolName)) == (DBObjRecord *) NULL) { if ((symbolRec = symbols->Add (symbolName)) == NULL) { CMmsgPrint (CMmsgAppError, "Symbol Object Creation Error in: %s %d",__FILE__,__LINE__); return (DBFault); } symbolIDFLD->Int (symbolRec,field->Type () == DBTableFieldString ? symbolRec->RowID () : field->Int (record)); foregroundFLD->Int (symbolRec,1); backgroundFLD->Int (symbolRec,0); styleFLD->Int (symbolRec,0); } symbolFLD->Record (record,symbolRec); } return (DBSuccess); }
void RGISAnalysePointInterStationTSCBK (Widget widget, RGISWorkspace *workspace,XmAnyCallbackStruct *callData) { char *selection; DBDataset *dataset = UIDataset (); DBObjMetaEntry *metaEntry; DBObjData *pntData = dataset->Data (), *tsData; DBObjTable *relateTBL = pntData->Table (DBrNRelations); DBObjRecord *relateRec; DBObjTableField *relDataFLD; DBObjTableField *relateFLD; DBObjTableField *joinFLD; static Widget selectWidget = (Widget) NULL; if (selectWidget == (Widget) NULL) selectWidget = UISelectionCreate ((char *) "Select Time Series"); if ((selection = UISelectObject (selectWidget,(DBObjectLIST<DBObject> *) relateTBL)) == (char *) NULL) return; if ((relateRec = relateTBL->Item (selection)) == (DBObjRecord *) NULL) { CMmsgPrint (CMmsgAppError, "Relate Record Error in: %s %d",__FILE__,__LINE__); return; } relDataFLD = relateTBL->Field (DBrNRelateData); relateFLD = relateTBL->Field (DBrNRelateField); joinFLD = relateTBL->Field (DBrNRelateJoinField); if ((tsData = dataset->Data (relDataFLD->String (relateRec))) == (DBObjData *) NULL) { if ((metaEntry = dataset->Meta (relDataFLD->String (relateRec))) == (DBObjMetaEntry *) NULL) { CMmsgPrint (CMmsgAppError, "Meta Enrty Finding Error in: %s %d",__FILE__,__LINE__); return; } tsData = new DBObjData (); if (tsData->Read (metaEntry->FileName ()) != DBSuccess) return; } workspace->CurrentData (tsData); UIPauseDialogOpen ((char *) "Calculating"); RGlibPointInterStationTS (pntData,tsData,relateFLD->String (relateRec),joinFLD->String (relateRec)); UIPauseDialogClose (); }
void RGISAnalyseLineMSampleGridCBK (Widget widget, RGISWorkspace *workspace,XmAnyCallbackStruct *callData) { DBInt layerID, layerNum; DBCoordinate coord; DBFloat realValue; DBDataset *dataset = UIDataset (); DBObjData *dbData = dataset->Data (); DBObjData *grdData = dbData->LinkedData (); DBObjData *tblData; DBObjTable *table, *itemTable = dbData->Table (DBrNItems); DBObjTableField *lineIDFLD; DBObjTableField *layerIDFLD; DBObjTableField *layerNameFLD; DBObjTableField *fromValueFLD = (DBObjTableField *) NULL; DBObjTableField *toValueFLD = (DBObjTableField *) NULL; DBVLineIF *lineIF = (DBVLineIF *) NULL; DBGridIF *gridIF; DBObjRecord *record, *layerRec, *tblRec; DBObjectLIST<DBObjTableField> *fields; widget = widget; callData = callData; gridIF = new DBGridIF (grdData); for (layerID = 0;layerID < gridIF->LayerNum ();++layerID) { layerRec = gridIF->Layer (layerID); if ((layerRec->Flags () & DBObjectFlagIdle) != DBObjectFlagIdle) ++layerNum; } if (layerNum < 1) { CMmsgPrint (CMmsgAppError, "No Layer to Process in: %s %d",__FILE__,__LINE__); delete gridIF; return; } tblData = new DBObjData ("",DBTypeTable); tblData->Document (DBDocGeoDomain,dbData->Document (DBDocGeoDomain)); tblData->Document (DBDocSubject,grdData->Document (DBDocSubject)); if (UIDataHeaderForm (tblData) == false) { delete gridIF; delete tblData; return; } table = tblData->Table (DBrNItems); lineIF = new DBVLineIF (dbData); table->AddField (lineIDFLD = 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 (fromValueFLD = new DBObjTableField (RGISLineFromNodeValue,DBTableFieldFloat,gridIF->ValueFormat (),sizeof (DBFloat4))); table->AddField (toValueFLD = new DBObjTableField (RGISLineToNodeValue,DBTableFieldFloat,gridIF->ValueFormat (),sizeof (DBFloat4))); grdData->Flags (DBObjectFlagProcessed,DBSet); UIPauseDialogOpen ((char *) "Sampling Grid(s)"); for (layerID = 0;layerID < gridIF->LayerNum ();++layerID) { layerRec = gridIF->Layer (layerID); if ((layerRec->Flags () & DBObjectFlagIdle) == DBObjectFlagIdle) continue; for (record = itemTable->First ();record != (DBObjRecord *) NULL;record = itemTable->Next ()) { if (UIPause ((layerRec->RowID () * itemTable->ItemNum () + record->RowID ()) * 100 / (itemTable->ItemNum () * gridIF->LayerNum ()))) goto Stop; if ((record->Flags () & DBObjectFlagIdle) == DBObjectFlagIdle) continue; tblRec = table->Add (record->Name ()); lineIDFLD->Int (tblRec,record->RowID () + 1); layerIDFLD->Int (tblRec,layerRec->RowID ()); layerNameFLD->String (tblRec,layerRec->Name ()); coord = lineIF->FromCoord (record); if (gridIF->Value (layerRec,coord,&realValue)) fromValueFLD->Float (tblRec,realValue); coord = lineIF->ToCoord (record); if (gridIF->Value (layerRec,coord,&realValue)) toValueFLD->Float (tblRec,realValue); } } Stop: UIPauseDialogClose (); delete gridIF; delete lineIF; fields = new DBObjectLIST<DBObjTableField> ("Field List"); fields->Add (new DBObjTableField (*lineIDFLD)); fields->Add (new DBObjTableField (*layerIDFLD)); table->ListSort (fields); workspace->CurrentData (tblData); delete fields; }
int main (int argc,char *argv []) { int argPos, argNum = argc, ret, verbose = false; DBInt recID; bool padding = false; char *tableName = (char *) NULL; char *fieldName = (char *) NULL; char *yearFieldName = (char *) NULL; char *monthFieldName = (char *) NULL; char *dayFieldName = (char *) NULL; char *hourFieldName = (char *) NULL; char *minFieldName = (char *) NULL; char *tmp = (char *) NULL; DBObjData *data; DBObjTable *table; DBObjTableField *srcField; DBObjTableField *yearField = (DBObjTableField *) NULL; DBObjTableField *monthField= (DBObjTableField *) NULL; DBObjTableField *dayField = (DBObjTableField *) NULL; DBObjTableField *hourField = (DBObjTableField *) NULL; DBObjTableField *minField = (DBObjTableField *) NULL; DBInt dbInputType = DBTableFieldInt; DBInt dbInputSize = sizeof(DBShort); DBDate date; DBObjRecord *record; for (argPos = 1;argPos < argNum; ) { if (CMargTest (argv [argPos],"-a","--table")) { if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing table name!"); return (CMfailed); } tableName = argv [argPos]; if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest (argv [argPos],"-f","--field")) { if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing field name!"); return (CMfailed); } fieldName = argv [argPos]; if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest (argv [argPos],"-y","--year")) { if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing year field name!"); return (CMfailed); } yearFieldName = argv [argPos]; if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest (argv [argPos],"-m","--month")) { if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing month field name!"); return (CMfailed); } monthFieldName = argv [argPos]; if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest (argv [argPos],"-d","--day")) { if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing day field name!"); return (CMfailed); } dayFieldName = argv [argPos]; if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest (argv [argPos],"-o","--hour")) { if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing hour field name!"); return (CMfailed); } hourFieldName = argv [argPos]; if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest (argv [argPos],"-i","--minute")) { if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing minute field name!"); return (CMfailed); } minFieldName = argv [argPos]; if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest (argv [argPos],"-p","--padding")) { padding = true; dbInputType = DBTableFieldString; dbInputSize = sizeof(DBByte) * 3; if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest (argv [argPos],"-V","--verbose")) { verbose = true; if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest (argv [argPos],"-h","--help")) { CMmsgPrint (CMmsgInfo,"%s [options] <input file> <output file>",CMfileName(argv[0])); CMmsgPrint (CMmsgInfo," -a,--table [table name]"); CMmsgPrint (CMmsgInfo," -f,--field [field name]"); CMmsgPrint (CMmsgInfo," -y,--year [year field]"); CMmsgPrint (CMmsgInfo," -m,--month [month field]"); CMmsgPrint (CMmsgInfo," -d,--day [day field]"); CMmsgPrint (CMmsgInfo," -o,--hour [hour field]"); CMmsgPrint (CMmsgInfo," -i,--minute [minute field]"); CMmsgPrint (CMmsgInfo," -p,--padding"); CMmsgPrint (CMmsgInfo," -V,--verbose"); CMmsgPrint (CMmsgInfo," -h,--help"); return (DBSuccess); } if ((argv [argPos][0] == '-') && ((int) strlen (argv [argPos]) > 1)) { CMmsgPrint (CMmsgUsrError,"Unknown option: %s!",argv [argPos]); return (CMfailed); } argPos++; } if (argNum > 3) { CMmsgPrint (CMmsgUsrError,"Extra arguments!"); return (CMfailed); } if (verbose) RGlibPauseOpen (argv[0]); data = new DBObjData (); if (((argNum > 1) && (strcmp (argv [1],"-") != 0) ? data->Read (argv [1]) : data->Read (stdin)) == DBFault) { delete data; return (CMfailed); } if (tableName == (char *) NULL) tableName = DBrNItems; if ((table = data->Table (tableName)) == (DBObjTable *) NULL) { CMmsgPrint (CMmsgUsrError,"Invalid table!"); delete data; return (CMfailed); } if (fieldName == (char *) NULL) fieldName = (char *) "Date"; if ((srcField = table->Field (fieldName)) == (DBObjTableField *) NULL) { CMmsgPrint (CMmsgUsrError,"Missing date field!"); delete data; return (CMfailed); } if ((srcField->Type () != DBTableFieldString) && (srcField->Type () != DBTableFieldDate)) { CMmsgPrint (CMmsgUsrError,"Invalid date field!"); delete data; return (CMfailed); } if (yearFieldName != (char *) NULL) { if ((yearField = table->Field (yearFieldName)) == (DBObjTableField *) NULL) { yearField = new DBObjTableField (yearFieldName,DBTableFieldInt,"%4d",sizeof(DBShort),false); table->AddField (yearField); } } if (monthFieldName != (char *) NULL) { if ((monthField = table->Field (monthFieldName)) == (DBObjTableField *) NULL) { monthField = new DBObjTableField (monthFieldName,dbInputType,"%2d",dbInputSize,false); table->AddField (monthField); } } if (dayFieldName != (char *) NULL) { if (monthField == (DBObjTableField *) NULL) { CMmsgPrint (CMmsgUsrError,"Month field is not set!"); delete data; return (CMfailed); } if ((dayField = table->Field (dayFieldName)) == (DBObjTableField *) NULL) { dayField = new DBObjTableField (dayFieldName,dbInputType,"%2d",dbInputSize,false); table->AddField (dayField); } } if (hourFieldName != (char *) NULL) { if (dayField == (DBObjTableField *) NULL) { CMmsgPrint (CMmsgUsrError,"Day field is not set!"); delete data; return (CMfailed); } if ((hourField = table->Field (hourFieldName)) == (DBObjTableField *) NULL) { hourField = new DBObjTableField (hourFieldName,dbInputType,"%2d",dbInputSize,false); table->AddField (hourField); } } if (minFieldName != (char *) NULL) { if (hourField == (DBObjTableField *) NULL) { CMmsgPrint (CMmsgUsrError,"Hour field is not set!"); delete data; return (CMfailed); } if ((minField = table->Field (minFieldName)) == (DBObjTableField *) NULL) { minField = new DBObjTableField (minFieldName,dbInputType,"%2d",dbInputSize,false); table->AddField (minField); } } for (recID = 0;recID < table->ItemNum ();++recID) { record = table->Item (recID); if (srcField->Type () == DBTableFieldString) date.Set (srcField->String (record)); else date = srcField->Date (record); if (yearField != (DBObjTableField *) NULL) yearField->Int(record,date.Year ()); if(padding) { if (monthField != (DBObjTableField *) NULL) { if (date.Month() != DBDefaultMissingIntVal) monthField->String (record,tmp = _CMDpadit(date.Month() + 1,false)); else monthField->String (record,tmp = _CMDpadit(date.Month(),false)); free(tmp); } if (dayField != (DBObjTableField *) NULL) { dayField->String (record,tmp = _CMDpadit(date.Day(),false)); free(tmp); } if (hourField != (DBObjTableField *) NULL) { hourField->String (record,tmp = _CMDpadit(date.Hour(),false)); free(tmp); } if (minField != (DBObjTableField *) NULL) { minField->String (record,tmp = _CMDpadit(date.Minute(),false)); free(tmp); } } else { if (monthField != (DBObjTableField *) NULL) { if (date.Month() != DBDefaultMissingIntVal) monthField->Int(record,date.Month () + 1); else monthField->Int (record,DBDefaultMissingIntVal); } if (dayField != (DBObjTableField *) NULL) dayField->Int (record,date.Day ()); if (hourField != (DBObjTableField *) NULL) hourField->Int(record,date.Hour ()); if (minField != (DBObjTableField *) NULL) minField->Int (record,date.Minute ()); } } ret = (argNum > 2) && (strcmp (argv [2],"-") != 0) ? data->Write (argv [2]) : data->Write (stdout); delete data; if (verbose) RGlibPauseClose (); return (ret); }
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); }
int DBImportARCVector (DBObjData *vecData,const char *arcCov,const char *nameFieldStr,const char *symbolFieldStr) { char symbolName [DBStringLength + 1]; DBObjTable *items = vecData->Table (DBrNItems); DBObjTable *symbols = vecData->Table (DBrNSymbols); DBObjTableField *nameFLD = NULL, *symbolResFLD, *symbolFLD = NULL; DBObjTableField *symbolIDFLD = symbols->Field (DBrNSymbolID); DBObjTableField *foregroundFLD = symbols->Field (DBrNForeground); DBObjTableField *backgroundFLD = symbols->Field (DBrNBackground); DBObjTableField *styleFLD = symbols->Field (DBrNStyle); DBObjRecord *record; DBObjRecord *symbolRec; if (DBInfoGetFields (items,DBInfoFileName (arcCov,vecData->Type ())) == DBSuccess) if (DBInfoGetTable (items,DBInfoFileName (arcCov,vecData->Type ())) == DBFault) return (DBFault); switch (vecData->Type ()) { case DBTypeVectorPoint: if (DBImportARCPoint (vecData,arcCov) == DBFault) return (DBFault); else break; case DBTypeVectorLine: if (DBImportARCLine (vecData,arcCov) == DBFault) return (DBFault); else break; case DBTypeVectorPolygon: if (DBImportARCPoly (vecData,arcCov) == DBFault) return (DBFault); else break; default: return (DBFault); } nameFLD = nameFieldStr != NULL ? items->Field (nameFieldStr) : (DBObjTableField *) NULL; symbolFLD = symbolFieldStr != NULL ? items->Field (symbolFieldStr) : (DBObjTableField *) NULL; symbolResFLD = items->Field (DBrNSymbol); if (symbolFLD != NULL) { for (record = items->First ();record != (DBObjRecord *) NULL;record = items->Next ()) { switch (symbolFLD->Type ()) { case DBTableFieldString: if ((symbolRec = (DBObjRecord *) symbols->Item (symbolFLD->String (record))) == NULL) { if ((symbolRec = symbols->Add (symbolFLD->String (record))) == NULL) { CMmsgPrint (CMmsgAppError,"Symbol Object Creation Error in: %s %d",__FILE__,__LINE__); return (DBFault); } symbolIDFLD->Int (symbolRec,symbolRec->RowID ()); foregroundFLD->Int (symbolRec,1); backgroundFLD->Int (symbolRec,0); styleFLD->Int (symbolRec,0); } break; case DBTableFieldInt: sprintf (symbolName,"Symbol:%5d",symbolFLD->Int (record)); if ((symbolRec = (DBObjRecord *) symbols->Item (symbolName)) == NULL) { if ((symbolRec = symbols->Add (symbolName)) == NULL) { CMmsgPrint (CMmsgAppError, "Symbol Object Creation Error in: %s %d",__FILE__,__LINE__); return (DBFault); } symbolIDFLD->Int (symbolRec,symbolFLD->Int (record)); foregroundFLD->Int (symbolRec,1); backgroundFLD->Int (symbolRec,0); styleFLD->Int (symbolRec,0); } break; default: CMmsgPrint (CMmsgAppError, "Invalid Field Type in: %s %d",__FILE__,__LINE__); break; } symbolResFLD->Record (record,symbolRec); } } else { symbols->Add ("Default Symbol"); if ((symbolRec = (DBObjRecord *) symbols->Item ()) == (DBObjRecord *) NULL) { CMmsgPrint (CMmsgAppError, "Symbol Object Creation Error in: %s %d",__FILE__,__LINE__); return (DBFault); } symbolIDFLD->Int (symbolRec,0); foregroundFLD->Int (symbolRec,1); backgroundFLD->Int (symbolRec,0); styleFLD->Int (symbolRec,0); for (record = items->First ();record != (DBObjRecord *) NULL;record = items->Next ()) symbolResFLD->Record (record,symbolRec); } if (nameFLD != NULL) for (record = items->First ();record != (DBObjRecord *) NULL;record = items->Next ()) record->Name (nameFLD->String (record)); return (DBSuccess); }
int main(int argc, char *argv[]) { int argPos, argNum = argc, ret, verbose = false; DBInt recID, i, deg, min, sec, strLen; DBFloat coord; char crdStr[DBStringLength]; char *minStr, *secStr; char *tableName = (char *) NULL; char *srcFieldName = (char *) NULL; char *dstFieldName = (char *) NULL; DBObjData *data; DBObjTable *table; DBObjTableField *srcField; DBObjTableField *dstField; DBObjRecord *record; for (argPos = 1; argPos < argNum;) { if (CMargTest (argv[argPos], "-a", "--table")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing table name!"); return (CMfailed); } tableName = argv[argPos]; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-f", "--field")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing field name!"); return (CMfailed); } srcFieldName = argv[argPos]; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-r", "--rename")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing second field name!"); return (CMfailed); } dstFieldName = argv[argPos]; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-V", "--verbose")) { verbose = true; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-h", "--help")) { CMmsgPrint(CMmsgInfo, "%s [options] <input file> <output file>", CMfileName(argv[0])); CMmsgPrint(CMmsgInfo, " -a,--table [table name]"); CMmsgPrint(CMmsgInfo, " -f,--field [coord field name]"); CMmsgPrint(CMmsgInfo, " -r,--rename [output field]"); CMmsgPrint(CMmsgInfo, " -V,--verbose"); CMmsgPrint(CMmsgInfo, " -h,--help"); return (DBSuccess); } if ((argv[argPos][0] == '-') && ((int) strlen(argv[argPos]) > 1)) { CMmsgPrint(CMmsgUsrError, "Unknown option: %s!", argv[argPos]); return (CMfailed); } argPos++; } if (argNum > 3) { CMmsgPrint(CMmsgUsrError, "Extra arguments!"); return (CMfailed); } if (verbose) RGlibPauseOpen(argv[0]); if (srcFieldName == (char *) NULL) { CMmsgPrint(CMmsgUsrError, "Coordinate field is not set!"); return (CMfailed); } data = new DBObjData(); if (((argNum > 1) && (strcmp(argv[1], "-") != 0) ? data->Read(argv[1]) : data->Read(stdin)) == DBFault) { delete data; return (CMfailed); } if (tableName == (char *) NULL) tableName = DBrNItems; if ((table = data->Table(tableName)) == (DBObjTable *) NULL) { CMmsgPrint(CMmsgUsrError, "Invalid table!"); delete data; return (CMfailed); } if ((srcField = table->Field(srcFieldName)) == (DBObjTableField *) NULL) { CMmsgPrint(CMmsgUsrError, "Invalid coordinate field [%s]!", srcFieldName); delete data; return (CMfailed); } if (dstFieldName == (char *) NULL) dstFieldName = (char *) "DecimalCoord"; { if ((dstField = table->Field(dstFieldName)) == (DBObjTableField *) NULL) { dstField = new DBObjTableField(dstFieldName, DBVariableFloat, "%10.3f", sizeof(DBFloat4), false); table->AddField(dstField); } else { if (dstField->Type() != DBVariableFloat) { CMmsgPrint(CMmsgUsrError, "Invalid coordinate field type!"); delete data; return (CMfailed); } } } for (recID = 0; recID < table->ItemNum(); ++recID) { record = table->Item(recID); strncpy(crdStr, srcField->String(record), sizeof(crdStr) - 1); if ((strLen = strlen(crdStr)) > 0) { minStr = secStr = (char *) NULL; for (i = 0; i < strLen; ++i) if (crdStr[i] == ':') minStr = crdStr + i + 1; else if (crdStr[i] == '\'') secStr = crdStr + i + 1; else if (crdStr[i] == '\"') crdStr[i] = '\0'; if (sscanf(crdStr, "%d", °) != 1) continue; coord = (float) deg; if ((minStr != (char *) NULL) && (sscanf(minStr, "%d", &min) == 1)) { coord = coord + (deg > 0 ? 1.0 : -1.0) * (DBFloat) min / 60.0; if ((secStr != (char *) NULL) && (sscanf(secStr, "%d", &sec) == 1)) coord = coord + (deg > 0 ? 1.0 : -1.0) * (DBFloat) sec / 3600.0; } dstField->Float(record, coord); } } ret = (argNum > 2) && (strcmp(argv[2], "-") != 0) ? data->Write(argv[2]) : data->Write(stdout); delete data; if (verbose) RGlibPauseClose(); return (ret); }
int main(int argc, char *argv[]) { int argPos, argNum = argc, ret, verbose = false; DBInt recID, mode = DBTimeStepYear; char *tableName = (char *) NULL; char *srcName = (char *) NULL; char *dstName = (char *) NULL; DBObjData *data; DBObjTable *table; DBObjTableField *srcField; DBObjTableField *dstField = (DBObjTableField *) NULL; DBDate date; DBObjRecord *record; for (argPos = 1; argPos < argNum;) { if (CMargTest (argv[argPos], "-a", "--table")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing table name!"); return (CMfailed); } tableName = argv[argPos]; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-f", "--field")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing field name!"); return (CMfailed); } srcName = argv[argPos]; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-o", "--outfield")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing output field name!"); return (CMfailed); } dstName = argv[argPos]; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-m", "--mode")) { int optCodes[] = {DBTimeStepYear, DBTimeStepMonth}; const char *optStrs[] = {"year", "month", (char *) NULL}; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing mode!"); return (CMfailed); } if ((mode = CMoptLookup(optStrs, argv[argPos], true)) == DBFault) { CMmsgPrint(CMmsgUsrError, "Invalid decimal date method!"); return (CMfailed); } mode = optCodes[mode]; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-V", "--verbose")) { verbose = true; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-h", "--help")) { CMmsgPrint(CMmsgInfo, "%s [options] <input file> <output file>", CMfileName(argv[0])); CMmsgPrint(CMmsgInfo, " -a,--table [table name]"); CMmsgPrint(CMmsgInfo, " -f,--field [field name]"); CMmsgPrint(CMmsgInfo, " -o,--outfield [output field]"); CMmsgPrint(CMmsgInfo, " -m,--mode [year|month]"); CMmsgPrint(CMmsgInfo, " -V,--verbose"); CMmsgPrint(CMmsgInfo, " -h,--help"); return (DBSuccess); } if ((argv[argPos][0] == '-') && ((int) strlen(argv[argPos]) > 1)) { CMmsgPrint(CMmsgUsrError, "Unknown option: %s!", argv[argPos]); return (CMfailed); } argPos++; } if (argNum > 3) { CMmsgPrint(CMmsgUsrError, "Extra arguments!"); return (CMfailed); } if (verbose) RGlibPauseOpen(argv[0]); data = new DBObjData(); if (((argNum > 1) && (strcmp(argv[1], "-") != 0) ? data->Read(argv[1]) : data->Read(stdin)) == DBFault) { delete data; return (CMfailed); } if (tableName == (char *) NULL) tableName = DBrNItems; if ((table = data->Table(tableName)) == (DBObjTable *) NULL) { CMmsgPrint(CMmsgUsrError, "Invalid table!"); delete data; return (CMfailed); } if (srcName == (char *) NULL) srcName = (char *) "Date"; if ((srcField = table->Field(srcName)) == (DBObjTableField *) NULL) { CMmsgPrint(CMmsgUsrError, "Missing date field!"); delete data; return (CMfailed); } if ((srcField->Type() != DBTableFieldString) && (srcField->Type() != DBTableFieldDate)) { CMmsgPrint(CMmsgUsrError, "Invalid date field!"); delete data; return (CMfailed); } if (dstName == (char *) NULL) switch (mode) { case DBTimeStepYear: dstName = (char *) "Decimal Year"; break; case DBTimeStepMonth: dstName = (char *) "Decimal Month"; break; } if ((dstField = table->Field(dstName)) == (DBObjTableField *) NULL) { dstField = new DBObjTableField(dstName, DBTableFieldFloat, (char *) "%8.2f", sizeof(DBFloat4), false); table->AddField(dstField); } for (recID = 0; recID < table->ItemNum(); ++recID) { record = table->Item(recID); if (srcField->Type() == DBTableFieldString) date.Set(srcField->String(record)); else date = srcField->Date(record); switch (mode) { case DBTimeStepYear: dstField->Float(record, date.DecimalYear()); break; case DBTimeStepMonth: dstField->Float(record, date.DecimalMonth()); break; } } ret = (argNum > 2) && (strcmp(argv[2], "-") != 0) ? data->Write(argv[2]) : data->Write(stdout); delete data; if (verbose) RGlibPauseClose(); return (ret); }
int main(int argc, char *argv[]) { int argPos, argNum = argc, ret, verbose = false; DBInt recID; int deg, min, sec; char coordStr[DBStringLength]; char *tableName = (char *) NULL; char *fieldName = (char *) NULL; char *degFieldName = (char *) NULL; char *minFieldName = (char *) NULL; char *secFieldName = (char *) NULL; DBObjData *data; DBObjTable *table; DBObjTableField *dstField; DBObjTableField *degField = (DBObjTableField *) NULL; DBObjTableField *minField = (DBObjTableField *) NULL; DBObjTableField *secField = (DBObjTableField *) NULL; DBObjRecord *record; for (argPos = 1; argPos < argNum;) { if (CMargTest (argv[argPos], "-a", "--table")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing table name!"); return (CMfailed); } tableName = argv[argPos]; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-f", "--field")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing field name!"); return (CMfailed); } fieldName = argv[argPos]; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-d", "--degree")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing degree field name!"); return (CMfailed); } degFieldName = argv[argPos]; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-m", "--minute")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing minutefield name!"); return (CMfailed); } minFieldName = argv[argPos]; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-s", "--second")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing second field name!"); return (CMfailed); } secFieldName = argv[argPos]; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-V", "--verbose")) { verbose = true; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-h", "--help")) { CMmsgPrint(CMmsgInfo, "%s [options] <input file> <output file>", CMfileName(argv[0])); CMmsgPrint(CMmsgInfo, " -a,--table [table name]"); CMmsgPrint(CMmsgInfo, " -f,--field [field name]"); CMmsgPrint(CMmsgInfo, " -d,--degree [degree field]"); CMmsgPrint(CMmsgInfo, " -m,--minute [minute field]"); CMmsgPrint(CMmsgInfo, " -s,--second [secon field]"); CMmsgPrint(CMmsgInfo, " -V,--verbose"); CMmsgPrint(CMmsgInfo, " -h,--help"); return (DBSuccess); } if ((argv[argPos][0] == '-') && ((int) strlen(argv[argPos]) > 1)) { CMmsgPrint(CMmsgUsrError, "Unknown option: %s!", argv[argPos]); return (CMfailed); } argPos++; } if (argNum > 3) { CMmsgPrint(CMmsgUsrError, "Extra arguments!"); return (CMfailed); } if (verbose) RGlibPauseOpen(argv[0]); data = new DBObjData(); if (((argNum > 1) && (strcmp(argv[1], "-") != 0) ? data->Read(argv[1]) : data->Read(stdin)) == DBFault) { delete data; return (CMfailed); } if (tableName == (char *) NULL) tableName = DBrNItems; if ((table = data->Table(tableName)) == (DBObjTable *) NULL) { CMmsgPrint(CMmsgUsrError, "Invalid table!"); delete data; return (CMfailed); } if (degFieldName != (char *) NULL) { if ((degField = table->Field(degFieldName)) == (DBObjTableField *) NULL) { CMmsgPrint(CMmsgUsrError, "Invalid degree field [%s]!", degFieldName); delete data; return (CMfailed); } } if (minFieldName != (char *) NULL) { if ((minField = table->Field(minFieldName)) == (DBObjTableField *) NULL) { CMmsgPrint(CMmsgUsrError, "Invalid min field [%s]!", minFieldName); delete data; return (CMfailed); } } if (secFieldName != (char *) NULL) { if (minField == (DBObjTableField *) NULL) { CMmsgPrint(CMmsgUsrError, "Minute field is not set!"); delete data; return (CMfailed); } if ((secField = table->Field(secFieldName)) == (DBObjTableField *) NULL) { CMmsgPrint(CMmsgUsrError, "Invalid second field [%s]", secFieldName); delete data; return (CMfailed); } } if (fieldName == (char *) NULL) fieldName = (char *) "Coord[ddd:mm\'ss\"]"; if ((dstField = table->Field(fieldName)) == (DBObjTableField *) NULL) { dstField = new DBObjTableField(fieldName, DBTableFieldString, "%s", 16, false); table->AddField(dstField); } for (recID = 0; recID < table->ItemNum(); ++recID) { record = table->Item(recID); if ((degField == (DBObjTableField *) NULL) || ((deg = degField->Int(record)) == degField->IntNoData())) strcpy(coordStr, ""); else if ((minField == (DBObjTableField *) NULL) || ((min = minField->Int(record)) == minField->IntNoData())) sprintf(coordStr, "%4d", deg); else if ((secField == (DBObjTableField *) NULL) || ((sec = secField->Int(record)) == secField->IntNoData())) sprintf(coordStr, "%4d:%02d", deg, min); else sprintf(coordStr, "%4d:%02d\'%02d\"", deg, min, sec); dstField->String(record, coordStr); } ret = (argNum > 2) && (strcmp(argv[2], "-") != 0) ? data->Write(argv[2]) : data->Write(stdout); delete data; if (verbose) RGlibPauseClose(); return (ret); }
DBInt RGlibPointSTNCharacteristics(DBObjData *dbData) { DBInt i, pointID, dPointID, cellID, mouthID, basinID, color, ret = DBFault, dir; DBVPointIF *pntIF; DBObjTable *pointTable, *cellTable; DBObjTableField *cellIDFLD; DBObjTableField *basinFLD; DBObjTableField *basinNameFLD; DBObjTableField *orderFLD; DBObjTableField *colorFLD; DBObjTableField *basinCellsFLD; DBObjTableField *basinLengthFLD; DBObjTableField *basinAreaFLD; DBObjTableField *interAreaFLD; DBObjTableField *nextStationFLD; DBObjData *netData; DBNetworkIF *netIF; DBObjRecord *pointRec, *dPointRec, *cellRec, *fromCell, *basinRec; if ((netData = dbData->LinkedData()) == (DBObjData *) NULL) return (DBFault); pointTable = dbData->Table(DBrNItems); pntIF = new DBVPointIF(dbData); netIF = new DBNetworkIF(netData); cellTable = netData->Table(DBrNCells); if ((cellIDFLD = pointTable->Field(RGlibCellID)) == NULL) { cellIDFLD = new DBObjTableField(RGlibCellID, DBTableFieldInt, "%8d", sizeof(DBInt)); pointTable->AddField(cellIDFLD); DBPause(1); } if ((basinFLD = pointTable->Field(DBrNBasin)) == NULL) { basinFLD = new DBObjTableField(DBrNBasin, DBTableFieldInt, "%8d", sizeof(DBInt)); pointTable->AddField(basinFLD); DBPause(2); } if ((basinNameFLD = pointTable->Field(RGlibBasinName)) == NULL) { basinNameFLD = new DBObjTableField(RGlibBasinName, DBTableFieldString, "%32s", DBStringLength); pointTable->AddField(basinNameFLD); DBPause(3); } if ((orderFLD = pointTable->Field(DBrNOrder)) == NULL) { orderFLD = new DBObjTableField(DBrNOrder, DBTableFieldInt, "%3d", sizeof(DBByte)); pointTable->AddField(orderFLD); DBPause(4); } if ((colorFLD = pointTable->Field(RGlibColor)) == NULL) { colorFLD = new DBObjTableField(RGlibColor, DBTableFieldInt, "%2d", sizeof(DBShort)); pointTable->AddField(colorFLD); DBPause(5); } if ((basinCellsFLD = pointTable->Field(RGlibCellNum)) == NULL) { basinCellsFLD = new DBObjTableField(RGlibCellNum, DBTableFieldInt, "%8d", sizeof(DBInt)); pointTable->AddField(basinCellsFLD); DBPause(6); } if ((basinLengthFLD = pointTable->Field(RGlibLength)) == NULL) { basinLengthFLD = new DBObjTableField(RGlibLength, DBTableFieldFloat, "%10.1f", sizeof(DBFloat4)); pointTable->AddField(basinLengthFLD); DBPause(7); } if ((basinAreaFLD = pointTable->Field(RGlibArea)) == NULL) { basinAreaFLD = new DBObjTableField(RGlibArea, DBTableFieldFloat, "%10.1f", sizeof(DBFloat4)); pointTable->AddField(basinAreaFLD); DBPause(8); } if ((interAreaFLD = pointTable->Field(RGlibInterStation)) == NULL) { interAreaFLD = new DBObjTableField(RGlibInterStation, DBTableFieldFloat, "%10.1f", sizeof(DBFloat4)); pointTable->AddField(interAreaFLD); DBPause(9); } if ((nextStationFLD = pointTable->Field(RGlibNextStation)) == NULL) { nextStationFLD = new DBObjTableField(RGlibNextStation, DBTableFieldInt, "%8d", sizeof(DBInt)); pointTable->AddField(nextStationFLD); DBPause(10); } if ((_RGlibTEMPPointIDFLD = cellTable->Field(RGlibTEMPPointID)) == NULL) { _RGlibTEMPPointIDFLD = new DBObjTableField(RGlibTEMPPointID, DBTableFieldInt, "%8d", sizeof(DBInt)); cellTable->AddField(_RGlibTEMPPointIDFLD); } for (pointID = 0; pointID < pointTable->ItemNum(); pointID++) { pointRec = pointTable->Item(pointID); if (DBPause(10 + pointID * 10 / pointTable->ItemNum())) goto Stop; if ((pointRec->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle) { cellIDFLD->Int(pointRec, cellIDFLD->IntNoData()); basinFLD->Int(pointRec, basinFLD->IntNoData()); basinNameFLD->String(pointRec, ""); orderFLD->Int(pointRec, orderFLD->IntNoData()); colorFLD->Int(pointRec, colorFLD->IntNoData()); basinCellsFLD->Int(pointRec, basinCellsFLD->IntNoData()); basinAreaFLD->Float(pointRec, basinAreaFLD->FloatNoData()); interAreaFLD->Float(pointRec, interAreaFLD->FloatNoData()); continue; } if ((cellRec = netIF->Cell(pntIF->Coordinate(pointRec))) == (DBObjRecord *) NULL) { cellIDFLD->Int(pointRec, 0); basinFLD->Int(pointRec, 0); basinNameFLD->String(pointRec, "Water"); orderFLD->Int(pointRec, colorFLD->IntNoData()); colorFLD->Int(pointRec, colorFLD->IntNoData()); basinCellsFLD->Int(pointRec, 0); basinAreaFLD->Float(pointRec, 0.0); interAreaFLD->Float(pointRec, 0.0); } else { cellIDFLD->Int(pointRec, cellRec->RowID() + 1); basinRec = netIF->Basin(cellRec); basinFLD->Int(pointRec, basinRec->RowID() + 1); basinNameFLD->String(pointRec, basinRec->Name()); orderFLD->Int(pointRec, netIF->CellOrder(cellRec)); colorFLD->Int(pointRec, 0); basinCellsFLD->Int(pointRec, netIF->CellBasinCells(cellRec)); basinLengthFLD->Float(pointRec, netIF->CellBasinLength(cellRec)); basinAreaFLD->Float(pointRec, netIF->CellBasinArea(cellRec)); interAreaFLD->Float(pointRec, netIF->CellBasinArea(cellRec)); } nextStationFLD->Int(pointRec, 0); } for (cellID = 0; cellID < cellTable->ItemNum(); ++cellID) { if (DBPause(20 + cellID * 20 / cellTable->ItemNum())) goto Stop; cellRec = cellTable->Item(cellID); _RGlibTEMPPointIDFLD->Int(cellRec, DBFault); } pointTable->ListSort(basinAreaFLD); for (pointRec = pointTable->Last(); pointRec != (DBObjRecord *) NULL; pointRec = pointTable->Next(DBBackward)) { if ((pointRec->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle) continue; if (DBPause(40 + pointID * 20 / pointTable->ItemNum())) goto Stop; cellRec = netIF->Cell(pntIF->Coordinate(pointRec)); netIF->UpStreamSearch(cellRec, (DBNetworkACTION) _RGlibSetPointID, (void *) ((char *) NULL + pointRec->RowID())); } for (pointID = 0; pointID < pointTable->ItemNum(); pointID++) { pointRec = pointTable->Item(pointID); if ((pointRec->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle) continue; if (DBPause(60 + pointID * 20 / pointTable->ItemNum())) goto Stop; if ((cellRec = netIF->Cell(pntIF->Coordinate(pointRec))) != (DBObjRecord *) NULL) { if ((cellRec = netIF->ToCell(cellRec)) == (DBObjRecord *) NULL) continue; if ((dPointID = _RGlibTEMPPointIDFLD->Int(cellRec)) != DBFault) { dPointRec = pointTable->Item(dPointID); nextStationFLD->Int(pointRec, dPointRec->RowID() + 1); interAreaFLD->Float(dPointRec, interAreaFLD->Float(dPointRec) - basinAreaFLD->Float(pointRec)); } } } pointTable->ListSort(interAreaFLD); i = 0; for (pointRec = pointTable->Last(); pointRec != (DBObjRecord *) NULL; pointRec = pointTable->Next(DBBackward)) { if (DBPause(80 + (i++) * 20 / pointTable->ItemNum())) goto Stop; pointID = pointRec->RowID(); if ((pointRec->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle) continue; if ((basinID = basinFLD->Int(pointRec)) == 0) continue; cellRec = netIF->Cell(pntIF->Coordinate(pointRec)); mouthID = cellRec->RowID(); color = 1; Start: for (cellID = mouthID; cellID < cellTable->ItemNum(); ++cellID) { cellRec = cellTable->Item(cellID); if (netIF->CellBasinID(cellRec) != basinID) break; if (_RGlibTEMPPointIDFLD->Int(cellRec) != pointID) continue; for (dir = 0; dir < 8; ++dir) { if ((fromCell = netIF->FromCell(cellRec, 0x01 << dir, false)) == (DBObjRecord *) NULL) continue; if ((dPointID = _RGlibTEMPPointIDFLD->Int(fromCell)) == pointID) continue; if (dPointID == DBFault) continue; dPointRec = pointTable->Item(dPointID); if (colorFLD->Int(dPointRec) == color) { color++; goto Start; } } } colorFLD->Int(pointRec, color); } ret = DBSuccess; Stop: pointTable->ListSort(); cellTable->DeleteField(_RGlibTEMPPointIDFLD); delete pntIF; delete netIF; 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); }