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); }
DBRegion DBObjData::Extent(DBObjRecord *record) { DBRegion extent; DBCoordinate coord; DBFloat delta; DBObjTable *items; DBObjTableField *field; if (record == (DBObjRecord *) NULL) return (Extent()); switch (Type()) { case DBTypeVectorPoint: delta = pow((double) 10.0, (double) Precision()); items = TablesPTR->Item(DBrNItems); field = items->Field(DBrNCoord); coord = field->Coordinate(record); extent.Expand(coord + delta); extent.Expand(coord - delta); return (extent); case DBTypeVectorLine: case DBTypeVectorPolygon: items = TablesPTR->Item(DBrNItems); field = items->Field(DBrNRegion); return (field->Region(record)); case DBTypeGridDiscrete: case DBTypeGridContinuous: return (Extent()); case DBTypeNetwork: { DBInt cellID, cellNum; DBObjRecord *cellRec; DBNetworkIF *netIF = new DBNetworkIF(this); cellRec = netIF->MouthCell(record); cellNum = netIF->CellBasinCells(cellRec) + cellRec->RowID(); for (cellID = cellRec->RowID(); cellID < cellNum; ++cellID) { cellRec = netIF->Cell(cellID); extent.Expand(netIF->Center(cellRec) + (netIF->CellSize() / 2.0)); extent.Expand(netIF->Center(cellRec) - (netIF->CellSize() / 2.0)); } delete netIF; } return (extent); case DBTypeTable: default: return (extent); } }
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); }