DBInt RGlibPointSubbasinCenter(DBObjData *pntData, DBObjData *netData) { DBCoordinate massCoord; DBVPointIF *pntIF = new DBVPointIF(pntData); DBObjTable *pointTable = pntData->Table(DBrNItems); DBObjTableField *massCoordXFLD = pointTable->Field(RGlibMassCoordX); DBObjTableField *massCoordYFLD = pointTable->Field(RGlibMassCoordY); DBNetworkIF *netIF = new DBNetworkIF(netData); DBObjRecord *pointRec, *cellRec; if (massCoordXFLD == NULL) { massCoordXFLD = new DBObjTableField(RGlibMassCoordX, DBTableFieldFloat, "%10.3f", sizeof(DBFloat4)); pointTable->AddField(massCoordXFLD); } if (massCoordYFLD == NULL) { massCoordYFLD = new DBObjTableField(RGlibMassCoordY, DBTableFieldFloat, "%10.3f", sizeof(DBFloat4)); pointTable->AddField(massCoordYFLD); } for (pointRec = pntIF->FirstItem(); pointRec != (DBObjRecord *) NULL; pointRec = pntIF->NextItem()) { if ((pointRec->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle) { massCoordXFLD->Float(pointRec, massCoordXFLD->FloatNoData()); massCoordYFLD->Float(pointRec, massCoordYFLD->FloatNoData()); continue; } if (DBPause(pointRec->RowID() * 100 / pntIF->ItemNum())) goto Stop; if ((cellRec = netIF->Cell(pntIF->Coordinate(pointRec))) == (DBObjRecord *) NULL) massCoord = pntIF->Coordinate(pointRec); else { if (netIF->CellBasinCells(cellRec) > 1) { massCoord.X = 0.0; massCoord.Y = 0.0; netIF->UpStreamSearch(cellRec, (DBNetworkACTION) _RGlibSubbasinCenterAction, &massCoord); massCoord.X = massCoord.X / (DBFloat) netIF->CellBasinCells(cellRec); massCoord.Y = massCoord.Y / (DBFloat) netIF->CellBasinCells(cellRec); } else massCoord = netIF->Center(cellRec); } massCoordXFLD->Float(pointRec, massCoord.X); massCoordYFLD->Float(pointRec, massCoord.Y); } Stop: if (pointRec != (DBObjRecord *) NULL) { pointTable->DeleteField(massCoordXFLD); pointTable->DeleteField(massCoordYFLD); return (DBFault); } return (DBSuccess); }
void RGISEditPointAddXYCBK (Widget widget, RGISWorkspace *workspace,XmAnyCallbackStruct *callData) { DBDataset *dataset = UIDataset (); DBObjData *dbData =dataset->Data (); DBVPointIF *pntIF = new DBVPointIF (dbData); DBObjTable *pointTable = dbData->Table (DBrNItems); DBObjTableField *xCoordFLD = pointTable->Field (RGISEditPointXCoord); DBObjTableField *yCoordFLD = pointTable->Field (RGISEditPointYCoord); DBCoordinate coord; DBObjRecord *pointRec; UITable *tableCLS = (UITable *) dbData->Display (UITableName (dbData,pointTable)); widget = widget; workspace = workspace; callData = callData; UIPauseDialogOpen ((char *) "Adding XY Coordinates"); if (xCoordFLD == NULL) { xCoordFLD = new DBObjTableField (RGISEditPointXCoord,DBTableFieldFloat,"%10.3f",sizeof (DBFloat4)); pointTable->AddField (xCoordFLD); if (tableCLS != (UITable *) NULL) tableCLS->AddField (xCoordFLD); UIPause (40); } if (yCoordFLD == NULL) { yCoordFLD = new DBObjTableField (RGISEditPointYCoord,DBTableFieldFloat,"%10.3f",sizeof (DBFloat4)); pointTable->AddField (yCoordFLD); if (tableCLS != (UITable *) NULL) tableCLS->AddField (yCoordFLD); UIPause (80); } for (pointRec = pntIF->FirstItem (); pointRec != (DBObjRecord *) NULL; pointRec = pntIF->NextItem ()) { if (UIPause (80 + pointRec->RowID () * 20 / pntIF->ItemNum ())) goto Stop; coord = pntIF->Coordinate (pointRec); xCoordFLD->Float (pointRec,coord.X); yCoordFLD->Float (pointRec,coord.Y); } Stop: UIPauseDialogClose (); if (tableCLS != (UITable *) NULL) tableCLS->Draw (); }
DBInt 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); }