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 RGISAnNetworkStreamLinesCBK (Widget widget,RGISWorkspace *workspace,XmAnyCallbackStruct *callData) { char *selection; DBDataset *dataset = UIDataset (); DBObjData *netData = dataset->Data (); DBObjTable *cellTable = netData->Table (DBrNCells); DBObjData *arcData = new DBObjData ("",DBTypeVectorLine); DBNetworkIF *netIF = new DBNetworkIF (netData); static Widget fieldSelect = (Widget) NULL; widget = widget; callData = callData; if (fieldSelect == (Widget) NULL) fieldSelect = UISelectionCreate ((char *) "Select Field"); if ((selection = UISelectObject (fieldSelect,(DBObjectLIST<DBObject> *) cellTable->Fields (),DBTableFieldIsInteger)) == (char *) NULL) return; if ((_RGISAnNetOrderField = cellTable->Field (selection)) == (DBObjTableField *) NULL) { CMmsgPrint (CMmsgAppError, "Field Selection Error in: %s %d",__FILE__,__LINE__); return; } arcData->Document (DBDocGeoDomain,netData->Document (DBDocGeoDomain)); arcData->Document (DBDocSubject,"Stream Lines"); if (UIDataHeaderForm (arcData)) { DBInt cellID; char objName [DBStringLength]; DBVLineIF *lineIF = new DBVLineIF (arcData); DBObjTable *cellTable = netData->Table (DBrNCells); DBObjTable *lineTable = arcData->Table (DBrNItems); DBObjTableField *basinFLD = new DBObjTableField (DBrNBasin,DBTableFieldInt,"%8d",sizeof (DBInt)); DBObjTableField *fieldFLD = new DBObjTableField (_RGISAnNetOrderField->Name (), _RGISAnNetOrderField->Type (), _RGISAnNetOrderField->Format (), _RGISAnNetOrderField->Length ()); DBObjTableField *lengthFLD = new DBObjTableField (RGISNetStreamLength,DBTableFieldFloat,"%10.1f",sizeof (DBFloat4)); DBObjTableField *areaFLD = new DBObjTableField (RGISNetStreamArea,DBTableFieldFloat,"%10.1f",sizeof (DBFloat4)); DBObjTableField *basinAreaFLD = new DBObjTableField (RGISNetBasinArea,DBTableFieldFloat,"%10.1f",sizeof (DBFloat4)); DBObjTableField *nextFLD = new DBObjTableField (RGISNetStreamNext,DBTableFieldInt,"%6d",sizeof (DBInt)); DBObjRecord *cellRec, *toCellRec, *lineRec; arcData->Projection (netData->Projection ()); arcData->Precision (netData->Precision ()); arcData->MaxScale (netData->MaxScale ()); arcData->MinScale (netData->MinScale ()); lineTable->AddField (basinFLD); lineTable->AddField (fieldFLD); lineTable->AddField (lengthFLD); lineTable->AddField (areaFLD); lineTable->AddField (basinAreaFLD); lineTable->AddField (nextFLD); cellTable->AddField (_RGISAnNetStreamIDFLD = new DBObjTableField ("StreamID",DBTableFieldInt,"%8d",sizeof (DBInt))); _RGISAnNetStreamID = 0; UIPauseDialogOpen ((char *) "Creating Stream Lines"); cellID = netIF->CellNum () - 1; cellRec = netIF->Cell (cellID); if (lineIF->NewSymbol ("Default Symbol") == (DBObjRecord *) NULL) { CMmsgPrint (CMmsgAppError, "Symbol Creation Error in: %s %d",__FILE__,__LINE__); return; } for (;cellID >= 0;--cellID) { cellRec = netIF->Cell (cellID); if (((toCellRec = netIF->ToCell (cellRec)) == (DBObjRecord *) NULL) || (_RGISAnNetOrderField->Int (cellRec) != _RGISAnNetOrderField->Int (toCellRec)) || (netIF->CellOrder (cellRec) != netIF->CellOrder (toCellRec))) { if (UIPause ((netIF->CellNum () - cellRec->RowID ()) * 100 / netIF->CellNum ())) goto Stop; sprintf (objName,"Line: %5d",_RGISAnNetStreamID + 1); if ((lineRec = lineIF->NewItem (objName)) == (DBObjRecord *) NULL) { CMmsgPrint (CMmsgAppError, "Line Insertion Error in: %s %d",__FILE__,__LINE__); return; } nextFLD->Int (lineRec,toCellRec == (DBObjRecord *) NULL ? 0 : _RGISAnNetStreamIDFLD->Int (toCellRec) + 1); basinFLD->Int (lineRec,netIF->CellBasinID (cellRec)); fieldFLD->Int (lineRec,_RGISAnNetOrderField->Int (cellRec)); _RGISAnNetVertex = 0; netIF->UpStreamSearch (_RGISAnNetworkCellRec = cellRec,(DBNetworkACTION) _RGISAnNetworkUpStreamAction); lineIF->FromNode (lineRec,lineIF->Node (netIF->Center (_RGISAnNetworkCellRec),true)); lineIF->ToNode (lineRec,lineIF->Node (netIF->Center (cellRec) + netIF->Delta (cellRec),true)); _RGISAnNetArea = netIF->CellArea (_RGISAnNetworkCellRec); if (_RGISAnNetVertex > 1) { if (_RGISAnNetVertexNum < _RGISAnNetVertex - 1) { _RGISAnNetCoord = (DBCoordinate *) realloc (_RGISAnNetCoord,(_RGISAnNetVertex - 1) * sizeof (DBCoordinate)); if (_RGISAnNetCoord == (DBCoordinate *) NULL) { CMmsgPrint (CMmsgSysError, "Memory Allocation Error in: %s %d",__FILE__,__LINE__); return; } } _RGISAnNetVertex = 0; netIF->DownStreamSearch (netIF->ToCell (_RGISAnNetworkCellRec),(DBNetworkACTION) _RGISAnNetworkDownStreamAction); } else _RGISAnNetVertex = 0; lineIF->Vertexes (lineRec,_RGISAnNetCoord,_RGISAnNetVertex); lineIF->ItemSymbol (lineRec,lineIF->Symbol (0)); lengthFLD->Float (lineRec,netIF->CellBasinLength (cellRec)); areaFLD->Float (lineRec,_RGISAnNetArea); basinAreaFLD->Float (lineRec,netIF->CellBasinArea (cellRec)); _RGISAnNetStreamID += 1; } } Stop: UIPauseDialogClose (); if (_RGISAnNetCoord != (DBCoordinate *) NULL) free (_RGISAnNetCoord); delete lineIF; if (cellID >= 0) delete arcData; else workspace->CurrentData (arcData); } else delete arcData; delete netIF; }
void _RGISUserFuncionNetwork (DBObjData *data,UI2DView *view,XEvent *event) { DBInt sX, sY, redraw = false; DBNetworkIF *netIF; DBCoordinate coord; DBObjRecord *cellRec, *basinRec; void _RGISUserFuncionQuery (DBObjData *,UI2DView *,XEvent *); if ((data->Flags () & DBDataFlagUserModeFlags) == DBDataFlagUserModeQuery) { _RGISUserFuncionQuery (data,view,event); return; } if (event->type != ButtonPress) return; if (DBTypeNetwork != data->Type ()) { CMmsgPrint (CMmsgAppError, "Invalid data Type in: %s %d",__FILE__,__LINE__); } sX = event->xbutton.x; sY = event->xbutton.y; view->Window2Map (sX,sY, &coord.X, &coord.Y); netIF = new DBNetworkIF (data); switch (data->Flags () & DBDataFlagUserModeFlags) { case DBDataFlagUserModeSelect: { DBInt basinID, cellID; DBRegion extent; UITable *tableView; if ((cellRec = netIF->Cell (coord)) == (DBObjRecord *) NULL) { UIMessage ((char *) "Cell Does not Exists!"); return; } for (basinID = 0;basinID < netIF->BasinNum ();++basinID) { basinRec = netIF->Basin (basinID); if ((basinRec->Flags () & DBObjectFlagSelected) == DBObjectFlagSelected) { data->SelectObject (basinRec,DBClear); extent.Expand (data->Extent (basinRec)); } } for (cellID = 0;cellID < netIF->CellNum ();++cellID) { cellRec = netIF->Cell (cellID); if ((cellRec->Flags () & DBObjectFlagSelected) == DBObjectFlagSelected) { extent.Expand (netIF->Center (cellRec) + (netIF->CellSize () / 2.0)); extent.Expand (netIF->Center (cellRec) - (netIF->CellSize () / 2.0)); cellRec->Flags (DBObjectFlagSelected,DBClear); } } if ((tableView = (UITable *) data->Display (UITableName (data,data->Table (DBrNItems)))) != (UITable *) NULL) tableView->Draw (); if ((tableView = (UITable *) data->Display (UITableName (data,data->Table (DBrNCells)))) != (UITable *) NULL) tableView->Draw (); UI2DViewRedrawAll (extent); cellRec = netIF->Cell (coord); switch (data->Flags () & DBDataFlagSelectMode) { case DBDataFlagSelectMode: netIF->DownStreamSearch (cellRec, DBNetworkSelect); break; default: netIF->UpStreamSearch (cellRec, DBNetworkSelect); break; } extent.Initialize (); for (cellID = 0;cellID < netIF->CellNum ();++cellID) { cellRec = netIF->Cell (cellID); if ((cellRec->Flags () & DBObjectFlagSelected) == DBObjectFlagSelected) { extent.Expand (netIF->Center (cellRec) + (netIF->CellSize () / 2.0)); extent.Expand (netIF->Center (cellRec) - (netIF->CellSize () / 2.0)); } } UI2DViewRedrawAll (extent); if ((tableView = (UITable *) data->Display (UITableName (data,data->Table (DBrNCells)))) != (UITable *) NULL) tableView->Draw (); } break; case DBDataFlagUserModeAdd: if (netIF->CellAdd (coord) == (DBObjRecord *) NULL) UIMessage ((char *) "Cell Creation Error"); else redraw = true; break; case DBDataFlagUserModeDelete: if (netIF->CellDelete (coord) == DBFault) UIMessage ((char *) "Cell Does not Exists!"); else redraw = true; break; case DBDataFlagUserModeRotate: { DBObjRecord *cellRec = netIF->Cell (coord); if (cellRec != (DBObjRecord *) NULL) { switch (netIF->CellDirection (cellRec)) { case DBNull: netIF->CellDirection (cellRec,DBNetDirN); break; case DBNetDirNW: netIF->CellDirection (cellRec,DBNull); break; default: netIF->CellRotate (cellRec,DBForward); break; } redraw = true; } } break; default: printf ("Unknown Mode %lX",data->Flags () & DBDataFlagUserModeFlags); break; } if (redraw) { DBPosition pos; if (netIF->Coord2Pos (coord,pos) == DBSuccess) { DBRegion extent; DBCoordinate delta (netIF->CellWidth () * 1.25, netIF->CellHeight () * 1.25); netIF->Pos2Coord (pos,coord); coord = coord + delta; extent.Expand (coord); netIF->Pos2Coord (pos,coord); coord = coord - delta; extent.Expand (coord); UI2DViewRedrawAll (extent); } } delete netIF; }
int main (int argc,char *argv []) { int argPos, argNum = argc, ret; bool upStream = true; DBCoordinate coord; DBObjData *data; for (argPos = 1;argPos < argNum; ) { if (CMargTest (argv [argPos],"-c","--coordinates")) { if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing sampling coordinates!"); return (CMfailed); } if (sscanf (argv [argPos],"%lf,%lf", &(coord.X),&(coord.Y)) != 2) { CMmsgPrint (CMmsgUsrError,"Invalid sampling coordinates!"); return (CMfailed); } if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest(argv[argPos],"-d","--direction")) { if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError, "Missing aggregate method!"); return (CMfailed); } else { const char *options [] = { "upstream", "downstream", (char *) NULL }; if ((ret = CMoptLookup (options,argv [argPos],false)) == CMfailed) { CMmsgPrint (CMmsgWarning,"Ignoring illformed direction [%s]!",argv [argPos]); } else upStream = ret == 0 ? true : false; } if ((argNum = CMargShiftLeft(argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest (argv [argPos],"-h","--help")) { CMmsgPrint (CMmsgInfo,"%s [options] <input network> <output list>",CMfileName(argv[0])); CMmsgPrint (CMmsgInfo," -c,--coordinates"); CMmsgPrint (CMmsgInfo," -d,--direction [upstream|downstream]"); 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 > 2) { CMmsgPrint (CMmsgUsrError,"Extra arguments!"); return (CMfailed); } data = new DBObjData (); ret = (argNum > 1) && (strcmp (argv [1],"-") != 0) ? data->Read (argv [1]) : data->Read (stdin); if (data->Type () == DBTypeNetwork) { DBNetworkIF *netIF = new DBNetworkIF (data); DBObjRecord *cellRec = netIF->Cell (coord); if (upStream) netIF->UpStreamSearch (cellRec,_CMDnetCellSearchPrintID); else netIF->DownStreamSearch (cellRec,_CMDnetCellSearchPrintID); delete netIF; } delete data; 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); }