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; }
DBObjData *DBNetworkToGrid(DBObjData *netData, DBInt type) { DBPosition pos; DBObjData *grdData = new DBObjData("", type); DBObjRecord *layerRec, *dataRec; DBObjTable *layerTable = grdData->Table(DBrNLayers); DBObjTable *itemTable = grdData->Table(DBrNItems); DBObjTableField *rowNumFLD = layerTable->Field(DBrNRowNum); DBObjTableField *colNumFLD = layerTable->Field(DBrNColNum); DBObjTableField *cellWidthFLD = layerTable->Field(DBrNCellWidth); DBObjTableField *cellHeightFLD = layerTable->Field(DBrNCellHeight); DBObjTableField *valueTypeFLD = layerTable->Field(DBrNValueType); DBObjTableField *valueSizeFLD = layerTable->Field(DBrNValueSize); DBObjTableField *layerFLD = layerTable->Field(DBrNLayer); DBNetworkIF *netIF; DBGridIF *gridIF; grdData->Projection(netData->Projection()); grdData->Precision(netData->Precision()); grdData->MaxScale(netData->MaxScale()); grdData->MinScale(netData->MinScale()); grdData->Extent(netData->Extent()); grdData->Document(DBDocGeoDomain, netData->Document(DBDocGeoDomain)); netIF = new DBNetworkIF(netData); layerTable->Add("FirstLayer"); if ((layerRec = layerTable->Item()) == (DBObjRecord *) NULL) { delete netIF; return ((DBObjData *) NULL); } rowNumFLD->Int(layerRec, netIF->RowNum()); colNumFLD->Int(layerRec, netIF->ColNum()); cellWidthFLD->Float(layerRec, netIF->CellWidth()); cellHeightFLD->Float(layerRec, netIF->CellHeight()); switch (type) { case DBTypeGridContinuous: valueTypeFLD->Int(layerRec, DBTableFieldFloat); valueSizeFLD->Int(layerRec, sizeof(DBFloat)); break; case DBTypeGridDiscrete: valueTypeFLD->Int(layerRec, DBTableFieldInt); valueSizeFLD->Int(layerRec, sizeof(DBInt)); break; default: CMmsgPrint(CMmsgAppError, "Invalid Data Type in: %s %d", __FILE__, __LINE__); delete grdData; delete netIF; return ((DBObjData *) NULL); } if ((dataRec = new DBObjRecord(layerRec->Name(), ((size_t) netIF->ColNum()) * netIF->RowNum() * valueSizeFLD->Int(layerRec), valueSizeFLD->Int(layerRec))) == (DBObjRecord *) NULL) { delete netIF; return ((DBObjData *) NULL); } (grdData->Arrays())->Add(dataRec); layerFLD->Record(layerRec, dataRec); gridIF = new DBGridIF(grdData); if (type == DBTypeGridContinuous) { itemTable->Add(layerRec->Name()); DBObjTableField *missingValueFLD = itemTable->Field(DBrNMissingValue); missingValueFLD->Float(itemTable->Item(layerRec->Name()), DBDefaultMissingFloatVal); for (pos.Row = 0; pos.Row < netIF->RowNum(); pos.Row++) for (pos.Col = 0; pos.Col < netIF->ColNum(); pos.Col++) gridIF->Value(layerRec, pos, DBDefaultMissingFloatVal); } else { DBObjTable *symbolTable = grdData->Table(DBrNSymbols); DBObjTableField *foregroundFLD = symbolTable->Field(DBrNForeground); DBObjTableField *backgroundFLD = symbolTable->Field(DBrNBackground); DBObjTableField *styleFLD = symbolTable->Field(DBrNStyle); DBObjRecord *symbolRec = symbolTable->Add("Default Symbol"); foregroundFLD->Int(symbolRec, 1); backgroundFLD->Int(symbolRec, 0); styleFLD->Int(symbolRec, 0); for (pos.Row = 0; pos.Row < netIF->RowNum(); pos.Row++) for (pos.Col = 0; pos.Col < netIF->ColNum(); pos.Col++) gridIF->Value(layerRec, pos, 0); } delete netIF; delete gridIF; return (grdData); }