本文整理汇总了C++中DBGridIF::LayerNum方法的典型用法代码示例。如果您正苦于以下问题:C++ DBGridIF::LayerNum方法的具体用法?C++ DBGridIF::LayerNum怎么用?C++ DBGridIF::LayerNum使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBGridIF
的用法示例。
在下文中一共展示了DBGridIF::LayerNum方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DBGridOperationAbs
void DBGridOperationAbs(DBObjData *grdData) {
DBInt layerID;
DBFloat value;
DBPosition pos;
DBObjRecord *layerRec;
DBGridIF *gridIF = new DBGridIF(grdData);
for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) {
layerRec = gridIF->Layer(layerID);
if ((layerRec->Flags() & DBObjectFlagIdle) != DBObjectFlagIdle) break;
}
if (layerID == gridIF->LayerNum()) {
CMmsgPrint(CMmsgAppError, "No Layer to Process in %s %d", __FILE__, __LINE__);
return;
}
for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) {
layerRec = gridIF->Layer(layerID);
if ((layerRec->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle) continue;
for (pos.Row = 0; pos.Row < gridIF->RowNum(); pos.Row++) {
if (DBPause((layerID * gridIF->RowNum() + pos.Row) * 100 / (gridIF->LayerNum() * gridIF->RowNum())))
goto Stop;
for (pos.Col = 0; pos.Col < gridIF->ColNum(); pos.Col++)
if (gridIF->Value(layerRec, pos, &value)) gridIF->Value(layerRec, pos, fabs(value));
}
gridIF->RecalcStats(layerRec);
}
Stop:
return;
}
示例2: return
char *CurrentLayer(DBInt layerID) {
if (layerID == DBFault) LayerRec = GridIF->Layer(0);
else
LayerRec = layerID < GridIF->LayerNum() ? GridIF->Layer(layerID) :
GridIF->Layer(layerID % GridIF->LayerNum());
return (LayerRec->Name());
}
示例3: DBGridOperation
void DBGridOperation(DBObjData *grdData, DBFloat constant, DBInt oper) {
DBInt layerID;
DBFloat value;
DBPosition pos;
DBObjRecord *layerRec;
DBGridIF *gridIF = new DBGridIF(grdData);
for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) {
layerRec = gridIF->Layer(layerID);
if ((layerRec->Flags() & DBObjectFlagIdle) != DBObjectFlagIdle) break;
}
if (layerID == gridIF->LayerNum()) {
CMmsgPrint(CMmsgAppError, "No Layer to Process in %s %d", __FILE__, __LINE__);
return;
}
for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) {
layerRec = gridIF->Layer(layerID);
if ((layerRec->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle) continue;
for (pos.Row = 0; pos.Row < gridIF->RowNum(); pos.Row++) {
if (DBPause((layerID * gridIF->RowNum() + pos.Row) * 100 / (gridIF->LayerNum() * gridIF->RowNum())))
goto Stop;
for (pos.Col = 0; pos.Col < gridIF->ColNum(); pos.Col++) {
if (gridIF->Value(layerRec, pos, &value))
switch (oper) {
case DBMathOperatorAdd:
gridIF->Value(layerRec, pos, value + constant);
break;
case DBMathOperatorSub:
gridIF->Value(layerRec, pos, value - constant);
break;
case DBMathOperatorMul:
gridIF->Value(layerRec, pos, value * constant);
break;
case DBMathOperatorDiv:
gridIF->Value(layerRec, pos, value / constant);
break;
}
}
}
gridIF->RecalcStats(layerRec);
}
Stop:
return;
}
示例4: FindLayer
DBInt FindLayer(char *layerName) {
DBInt layerID, i = 0;
DBObjRecord *layerRec;
char *name;
for (layerID = 0; layerID < GridIF->LayerNum(); ++layerID) {
layerRec = GridIF->Layer(layerID);
name = layerRec->Name();
if (strncmp(name, "XXXX-", 5) == 0) {
i = 5;
if ((strlen(name) - 5) == 0) return (layerID);
}
if (strncmp(name + i, layerName + i, strlen(name) - i) == 0) return (layerID);
}
return (CMfailed);
}
示例5: RGISAnalyseLineMSampleGridCBK
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;
}
示例6: _CMDnetErosion
int _CMDnetErosion(DBObjData *netData, DBObjData *inData, DBObjData *weightData,
DBObjData *outData, DBFloat coeff, DBInt areaMult) {
DBInt ret = DBSuccess, layerID, cellID, progress, maxProgress;
DBFloat inValue, weight, outValue, *sumWeights;
DBPosition pos;
DBNetworkIF *netIF = new DBNetworkIF(netData);
DBGridIF *inIF = new DBGridIF(inData);
DBGridIF *outIF = new DBGridIF(outData);
DBGridIF *weightIF = weightData != (DBObjData *) NULL ? new DBGridIF(weightData) : (DBGridIF *) NULL;
DBObjRecord *inLayerRec, *outLayerRec, *weightLayerRec, *cellRec, *toCell;
if ((sumWeights = (DBFloat *) calloc(netIF->CellNum(), sizeof(DBFloat))) == (DBFloat *) NULL) {
CMmsgPrint(CMmsgSysError, "Memory allocation error in: %s %d", __FILE__, __LINE__);
ret = DBFault;
goto Stop;
}
layerID = 0;
inLayerRec = inIF->Layer(layerID);
outLayerRec = outIF->Layer(layerID);
outIF->RenameLayer(outLayerRec, inLayerRec->Name());
outValue = outIF->MissingValue(outLayerRec);
for (pos.Row = 0; pos.Row < outIF->RowNum(); pos.Row++)
for (pos.Col = 0; pos.Col < outIF->ColNum(); pos.Col++) outIF->Value(outLayerRec, pos, outValue);
for (layerID = 1; layerID < inIF->LayerNum(); ++layerID) {
inLayerRec = inIF->Layer(layerID);
if ((outLayerRec = outIF->AddLayer(inLayerRec->Name())) == (DBObjRecord *) NULL) {
ret = DBFault;
goto Stop;
}
for (pos.Row = 0; pos.Row < outIF->RowNum(); pos.Row++)
for (pos.Col = 0; pos.Col < outIF->ColNum(); pos.Col++) outIF->Value(outLayerRec, pos, outValue);
}
maxProgress = inIF->LayerNum() * netIF->CellNum();
for (layerID = 0; layerID < inIF->LayerNum(); ++layerID) {
inLayerRec = inIF->Layer(layerID);
outLayerRec = outIF->Layer(layerID);
if (weightIF != (DBGridIF *) NULL)
weightLayerRec = weightIF->Layer(layerID % weightIF->LayerNum());
for (cellID = 0; cellID < netIF->CellNum(); cellID++) {
sumWeights[cellID] = 0.0;
cellRec = netIF->Cell(cellID);
if (inIF->Value(inLayerRec, netIF->Center(cellRec), &inValue) == false)
outIF->Value(outLayerRec, netIF->CellPosition(cellRec), 0.0);
else {
if (weightIF != (DBGridIF *) NULL)
weight = weightIF->Value(weightLayerRec, netIF->Center(cellRec), &weight) == false ?
0.0 : weight * coeff;
else weight = coeff;
if (areaMult) weight = weight * netIF->CellArea(cellRec);
sumWeights[cellID] = weight;
outIF->Value(outLayerRec, netIF->CellPosition(cellRec), inValue * weight);
}
}
for (cellID = netIF->CellNum() - 1; cellID >= 0; --cellID) {
progress = layerID * netIF->CellNum() + (netIF->CellNum() - cellID);
if (DBPause(progress * 100 / maxProgress)) goto Stop;
cellRec = netIF->Cell(cellID);
if ((toCell = netIF->ToCell(cellRec)) == (DBObjRecord *) NULL) continue;
if (outIF->Value(outLayerRec, netIF->CellPosition(cellRec), &inValue) == false) continue;
if (outIF->Value(outLayerRec, netIF->CellPosition(toCell), &outValue) == false) continue;
sumWeights[toCell->RowID()] = sumWeights[toCell->RowID()] + weight;
outIF->Value(outLayerRec, netIF->CellPosition(toCell), outValue + inValue);
}
outIF->RecalcStats(outLayerRec);
}
free(sumWeights);
Stop:
delete netIF;
delete inIF;
delete outIF;
if (weightIF != (DBGridIF *) NULL) delete weightIF;
return (ret);
}
示例7: _RGISToolsGridExportARCInfo
int _RGISToolsGridExportARCInfo (DBObjData *data,char *selection)
{
DBInt layerID, i;
FILE *file;
char coverName [11], command [256];
char asciiGrid [FILENAME_MAX];
char attribDef [FILENAME_MAX];
char attribData [FILENAME_MAX];
char amlFile [FILENAME_MAX];
DBGridIF *gridIF = new DBGridIF (data);
DBObjRecord *layerRec;
for (layerID = 0;layerID < gridIF->LayerNum ();++layerID)
{
layerRec = gridIF->Layer (layerID);
sprintf (asciiGrid,"%s/asciigrid%d.tmp",selection,layerID);
if (DBExportARCGridLayer (data,layerRec,asciiGrid) == DBFault) return (DBFault);
}
if (data->Type () == DBTypeGridDiscrete)
{
sprintf (attribDef,"%s/attrib.def",selection);
if (DBExportARCTableDef (data,DBrNItems,attribDef) == DBFault)
{ unlink (asciiGrid); return (DBFault); }
sprintf (attribData,"%s/attrib.dat",selection);
if (DBExportARCTableData (data,DBrNItems,attribData) == DBFault)
{ unlink (asciiGrid); unlink (attribDef); return (DBFault); }
}
sprintf (amlFile,"%s/grdcreate.aml",selection);
if ((file = fopen (amlFile,"w")) == NULL)
{
for (layerID = 0;layerID < gridIF->LayerNum ();++layerID)
{
layerRec = gridIF->Layer (layerID);
sprintf (asciiGrid,"%s/asciigrid%d.tmp",selection,layerID);
unlink (asciiGrid);
}
if (data->Type () == DBTypeGridDiscrete) { unlink (attribDef); unlink (attribData); }
CMmsgPrint (CMmsgAppError, "Aml File Creation Error in: %s %d",__FILE__,__LINE__);
return (DBFault);
}
fprintf (file,"&workspace %s\n",selection);
for (layerID = 0;layerID < gridIF->LayerNum ();++layerID)
{
layerRec = gridIF->Layer (layerID);
strncpy (coverName,layerRec->Name (),sizeof (coverName) - 1);
coverName [sizeof (coverName) - 1] = '\0';
for (i = 0;i < (DBInt) strlen (coverName);++i) if (coverName [i] == '.') coverName [i] = '\0';
for (i = 0;i < (DBInt) strlen (coverName);++i) coverName [i] = tolower (coverName [i]);
sprintf (asciiGrid,"%s/asciigrid%d.tmp",selection,layerID);
if (data->Type () == DBTypeGridContinuous)
fprintf (file,"asciigrid %s g_%s float\n",asciiGrid,coverName);
else
fprintf (file,"asciigrid %s g_%s int\n",asciiGrid,coverName);
if (data->Type () == DBTypeGridDiscrete)
{
fprintf (file,"tables\n");
fprintf (file,"define g_%s.vattr\n",coverName);
fprintf (file,"&r %s\n",attribDef);
fprintf (file,"~\n");
fprintf (file,"alter GridValue\n");
fprintf (file,"value,,,,\n");
fprintf (file,"add\n");
fprintf (file,"&r %s\n",attribData);
fprintf (file,"~\n");
fprintf (file,"q stop\n");
fprintf (file,"joinitem g_%s.vat g_%s.vattr g_%s.vat value count\n",coverName,coverName,coverName);
fprintf (file,"tables\n");
fprintf (file,"select g_%s.vattr\n",coverName);
fprintf (file,"erase g_%s.vattr\ny\n",coverName);
fprintf (file,"q stop\n");
}
}
fclose (file);
if (getenv ("GHAAS_ARC") != NULL)
{
sprintf (command,getenv ("GHAAS_ARC"),amlFile);
system (command);
for (layerID = 0;layerID < gridIF->LayerNum ();++layerID)
{
layerRec = gridIF->Layer (layerID);
sprintf (asciiGrid,"%s/asciigrid%d.tmp",selection,layerID);
unlink (asciiGrid);
}
if (data->Type () == DBTypeGridDiscrete) { unlink (attribDef); unlink (attribData); }
unlink (amlFile);
}
return (DBSuccess);
}
示例8: RGlibRGIS2DataStream
//.........这里部分代码省略.........
tmplPntIF = new DBVPointIF(tmplData);
varHeader.ItemNum = tmplPntIF->ItemNum();
break;
case DBTypeGridContinuous:
case DBTypeGridDiscrete:
tmplGrdIF = new DBGridIF(tmplData);
varHeader.ItemNum = gridIF->RowNum() * gridIF->ColNum();
break;
case DBTypeNetwork:
tmplNetIF = new DBNetworkIF(tmplData);
varHeader.ItemNum = tmplNetIF->CellNum();
break;
default:
delete gridIF;
return (DBFault);
}
}
if ((data = (void *) calloc(varHeader.ItemNum, itemSize)) == (void *) NULL) {
CMmsgPrint(CMmsgSysError, "Error! Allocating %d items of %d size in: %s %d", varHeader.ItemNum, itemSize,
__FILE__, __LINE__);
return (DBFault);
}
/**************************************************************
* *
* Point template *
* *
**************************************************************/
if (tmplPntIF != (DBVPointIF *) NULL) {
DBObjRecord *pntRec;
if (fieldPTR == (DBObjTableField *) NULL) {
for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) {
layerRec = gridIF->Layer(layerID);
strncpy(varHeader.Date, layerRec->Name(), MFDateStringLength - 1);
for (itemID = 0; itemID < varHeader.ItemNum; ++itemID) {
pntRec = tmplPntIF->Item(itemID);
if ((varHeader.DataType == MFByte) || (varHeader.DataType == MFShort) ||
(varHeader.DataType == MFInt)) {
if (gridIF->Value(layerRec, tmplPntIF->Coordinate(pntRec), &intValue) == false)
intValue = varHeader.Missing.Int;
switch (varHeader.DataType) {
case MFByte:
((char *) data)[itemID] = (char) intValue;
break;
case MFShort:
((short *) data)[itemID] = (short) intValue;
break;
case MFInt:
((int *) data)[itemID] = (short) intValue;
break;
}
}
else {
if (gridIF->Value(layerRec, tmplPntIF->Coordinate(pntRec), &floatValue) == false)
floatValue = varHeader.Missing.Float;
switch (varHeader.DataType) {
case MFFloat:
((float *) data)[itemID] = (float) floatValue;
break;
case MFDouble:
((double *) data)[itemID] = (double) floatValue;
break;
}
}
示例9: Write
DBInt Write (FILE *file,DBObjData *data)
{
char *dmRecord;
DBInt layerID, docLen, dbType, intVal;
DBFloat floatVal;
DBPosition pos;
DBObjRecord *layerRec;
DBGridIF *gridIF = new DBGridIF (data);
DMLayerHeader dmLayerHeader;
dbType = gridIF->ValueType ();
switch (dbType)
{
case DBTableFieldFloat: DataType (DMFloat); break;
case DBTableFieldInt:
DataType (gridIF->ValueSize () > 1 ? DMInt : DMByte); break;
}
CellWidth (gridIF->CellWidth ());
CellHeight (gridIF->CellHeight ());
Extent (data->Extent ());
LayerNum (gridIF->LayerNum ());
RowNum (gridIF->RowNum ());
ColNum (gridIF->ColNum ());
dmRecord = (char *) calloc (RowNum () * ColNum (),DataType () != DMByte ? sizeof (int) : sizeof (char));
if (dmRecord == (char *) NULL)
{ CMmsgPrint (CMmsgSysError, "Memory Allocation Error in: %s %d",__FILE__,__LINE__); return (DBFault); }
DMFileHeader::Write (file);
for (layerID = 0;layerID < gridIF->LayerNum ();++layerID)
{
layerRec = gridIF->Layer (layerID);
dmLayerHeader.Description (layerRec->Name ());
dmLayerHeader.Write (file);
}
docLen = strlen (data->Document (DBDocComment));
if (fwrite (&docLen,sizeof (int),1,file) != 1)
{ CMmsgPrint (CMmsgSysError, "File Writing Error in: %s %d",__FILE__,__LINE__); return (DBFault); }
if (docLen > 0)
{
if (fwrite (data->Document (DBDocComment),docLen,1,file) != 1)
{ CMmsgPrint (CMmsgSysError, "File Writing Error in: %s %d",__FILE__,__LINE__); return (DBFault); }
}
for (layerID = 0;layerID < gridIF->LayerNum ();++layerID)
{
layerRec = gridIF->Layer (layerID);
switch (data->Type ())
{
case DBTypeGridContinuous:
layerRec = gridIF->Layer (layerID);
if (dbType == DBTableFieldFloat)
{
for (pos.Row = 0;pos.Row < RowNum ();pos.Row++)
for (pos.Col = 0;pos.Col < ColNum ();pos.Col++)
if (gridIF->Value (layerRec,pos,&floatVal))
((float *) dmRecord) [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = (float) floatVal;
else
((float *) dmRecord) [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = MissingValue ();
}
else
{
for (pos.Row = 0;pos.Row < RowNum ();pos.Row++)
for (pos.Col = 0;pos.Col < ColNum ();pos.Col++)
if (gridIF->Value (layerRec,pos,&intVal))
{
if (DataType () == DMInt)
((int *) dmRecord) [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = (int) intVal;
else
dmRecord [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = intVal;
}
else
{
if (DataType () == DMInt)
((int *) dmRecord) [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = (int) MissingValue ();
else
dmRecord [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = -99;
}
}
break;
case DBTypeGridDiscrete:
for (pos.Row = 0;pos.Row < RowNum ();pos.Row++)
for (pos.Col = 0;pos.Col < ColNum ();pos.Col++)
{
intVal = gridIF->GridValue (layerRec,pos);
if (DataType () == DMInt)
((int *) dmRecord) [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = intVal;
else
dmRecord [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = -99;
}
break;
default:
CMmsgPrint (CMmsgAppError, "Invalid Data Type in: %s %d",__FILE__,__LINE__);
free (dmRecord);
delete gridIF;
return (DBFault);
}
if ((DBInt) fwrite (dmRecord,DataType () == DMByte ? sizeof (char) : sizeof (int),DataPointNum (),file) != DataPointNum ())
{ CMmsgPrint (CMmsgSysError, "File Writing Error in: %s %d",__FILE__,__LINE__); return (DBFault); }
}
//.........这里部分代码省略.........
示例11: DBGridCont2Network
DBInt DBGridCont2Network (DBObjData *gridData,DBObjData *netData, bool downhill)
{
DBInt basinID, layerID, zLayerID, zLayerNum, dir, maxDir, projection = gridData->Projection (), *zones;
DBFloat elev0, elev1, delta, maxDelta, distance;
DBCoordinate coord0, coord1;
DBInt row, col;
DBPosition pos, auxPos;
char nameSTR [DBStringLength];
DBObjTable *basinTable = netData->Table (DBrNItems);
DBObjTable *cellTable = netData->Table (DBrNCells);
DBObjTable *layerTable = netData->Table (DBrNLayers);
DBObjRecord *layerRec, *dataRec, *cellRec, *basinRec;
DBObjTableField *mouthPosFLD = basinTable->Field (DBrNMouthPos);
DBObjTableField *colorFLD = basinTable->Field (DBrNColor);
DBObjTableField *positionFLD = cellTable->Field (DBrNPosition);
DBObjTableField *toCellFLD = cellTable->Field (DBrNToCell);
DBObjTableField *fromCellFLD = cellTable->Field (DBrNFromCell);
DBObjTableField *orderFLD = cellTable->Field (DBrNOrder);
DBObjTableField *basinFLD = cellTable->Field (DBrNBasin);
DBObjTableField *basinCellsFLD= cellTable->Field (DBrNBasinCells);
DBObjTableField *travelFLD = cellTable->Field (DBrNTravel);
DBObjTableField *upCellPosFLD = cellTable->Field (DBrNUpCellPos);
DBObjTableField *cellAreaFLD = cellTable->Field (DBrNCellArea);
DBObjTableField *subbasinLengthFLD = cellTable->Field (DBrNSubbasinLength);
DBObjTableField *subbasinAreaFLD = cellTable->Field (DBrNSubbasinArea);
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);
DBObjData *zGridData = gridData->LinkedData ();
DBGridIF *gridIF = new DBGridIF (gridData), *zGridIF;
DBNetworkIF *netIF;
if ((zGridData != (DBObjData *) NULL) && ((zGridData->Type () == DBTypeGridDiscrete) || (zGridData->Type () == DBTypeGridContinuous)))
{
zGridIF = new DBGridIF (zGridData);
zLayerNum = zGridIF->LayerNum () + 1;
}
else { zGridIF = (DBGridIF *) NULL; zLayerNum = 1; }
if ((zones = (DBInt *) calloc (9 * zLayerNum,sizeof (DBInt))) == (DBInt *) NULL)
{
CMmsgPrint (CMmsgSysError, "Memory Allocation Error in: %s %d",__FILE__,__LINE__);
if (zGridIF != (DBGridIF *) NULL) delete zGridIF;
delete gridIF;
return (DBFault);
}
layerTable->Add (DBrNLookupGrid);
if ((layerRec = layerTable->Item (DBrNLookupGrid)) == (DBObjRecord *) NULL)
{
free (zones);
if (zGridIF != (DBGridIF *) NULL) delete zGridIF;
delete gridIF;
return (DBFault);
}
netData->Projection (projection);
netData->Extent (gridData->Extent ());
cellWidthFLD->Float (layerRec,gridIF->CellWidth ());
cellHeightFLD->Float (layerRec,gridIF->CellHeight ());
valueTypeFLD->Int (layerRec,DBTableFieldInt);
valueSizeFLD->Int (layerRec,sizeof (DBInt));
rowNumFLD->Int (layerRec,gridIF->RowNum ());
colNumFLD->Int (layerRec,gridIF->ColNum ());
dataRec = new DBObjRecord ("NetLookupGridRecord",((size_t) gridIF->RowNum ()) * gridIF->ColNum () * sizeof (DBInt),sizeof (DBInt));
if (dataRec == (DBObjRecord *) NULL)
{
if (zGridIF != (DBGridIF *) NULL) delete zGridIF;
return (DBFault);
}
layerFLD->Record (layerRec,dataRec);
(netData->Arrays ())->Add (dataRec);
for (pos.Row = 0;pos.Row < gridIF->RowNum ();pos.Row++)
for (pos.Col = 0;pos.Col < gridIF->ColNum ();pos.Col++)
((DBInt *) dataRec->Data ()) [pos.Row * gridIF->ColNum () + pos.Col] = DBFault;
for (pos.Row = 0;pos.Row < gridIF->RowNum ();pos.Row++)
{
if (DBPause (10 * pos.Row / gridIF->RowNum ())) goto PauseStop;
for (pos.Col = 0;pos.Col < gridIF->ColNum ();pos.Col++)
{
gridIF->Pos2Coord (pos,coord0);
zLayerID = 0;
if (zGridIF != (DBGridIF *) NULL)
for ( ; zLayerID < zGridIF->LayerNum (); zLayerID++)
{
layerRec = zGridIF->Layer (zLayerID);
if ((layerRec->Flags () & DBObjectFlagIdle) == DBObjectFlagIdle) continue;
for (dir = 0;dir < 8;++dir)
{
row = pos.Row;
col = pos.Col;
//.........这里部分代码省略.........
示例12: _CMDnetTransfer
int _CMDnetTransfer(DBObjData *netData,
DBObjData *inData,
DBObjData *weightData,
DBObjData *outData,
DBFloat coeff,
DBObjData *coeffData,
DBObjData *QData,
DBObjData *HLData,
DBFloat umax,
DBFloat ksat,
DBInt areaMult) {
DBInt ret = DBSuccess, layerID, cellID, progress, maxProgress;
DBFloat inValue, weight, outValue, *sumWeights, kCoeff, q, hl, Conc, Uptake, Vf;
DBPosition pos;
DBNetworkIF *netIF = new DBNetworkIF(netData);
DBGridIF *inIF = new DBGridIF(inData);
DBGridIF *outIF = new DBGridIF(outData);
DBGridIF *weightIF = weightData != (DBObjData *) NULL ? new DBGridIF(weightData) : (DBGridIF *) NULL;
DBGridIF *coeffIF = coeffData != (DBObjData *) NULL ? new DBGridIF(coeffData) : (DBGridIF *) NULL;
DBGridIF *Q_IF = QData != (DBObjData *) NULL ? new DBGridIF(QData) : (DBGridIF *) NULL;
DBGridIF *HL_IF = HLData != (DBObjData *) NULL ? new DBGridIF(HLData) : (DBGridIF *) NULL;
DBObjRecord *inLayerRec, *outLayerRec, *weightLayerRec, *coeffLayerRec, *Q_LayerRec, *HL_LayerRec, *cellRec, *toCell;
DBCoordinate coord;
if ((sumWeights = (DBFloat *) calloc(netIF->CellNum(), sizeof(DBFloat))) == (DBFloat *) NULL) {
CMmsgPrint(CMmsgSysError, "Memory allocation error in: %s %d", __FILE__, __LINE__);
ret = DBFault;
goto Stop;
}
layerID = 0;
inLayerRec = inIF->Layer(layerID);
outLayerRec = outIF->Layer(layerID);
outIF->RenameLayer(outLayerRec, inLayerRec->Name());
outValue = outIF->MissingValue(outLayerRec);
for (pos.Row = 0; pos.Row < outIF->RowNum(); pos.Row++)
for (pos.Col = 0; pos.Col < outIF->ColNum(); pos.Col++) outIF->Value(outLayerRec, pos, outValue);
for (layerID = 1; layerID < inIF->LayerNum(); ++layerID) {
inLayerRec = inIF->Layer(layerID);
if ((outLayerRec = outIF->AddLayer(inLayerRec->Name())) == (DBObjRecord *) NULL) {
ret = DBFault;
goto Stop;
}
for (pos.Row = 0; pos.Row < outIF->RowNum(); pos.Row++)
for (pos.Col = 0; pos.Col < outIF->ColNum(); pos.Col++) outIF->Value(outLayerRec, pos, outValue);
}
maxProgress = inIF->LayerNum() * netIF->CellNum();
for (layerID = 0; layerID < inIF->LayerNum(); ++layerID) {
inLayerRec = inIF->Layer(layerID);
outLayerRec = outIF->Layer(layerID);
if (weightIF != (DBGridIF *) NULL)
weightLayerRec = weightIF->Layer(layerID % weightIF->LayerNum());
if (coeffIF != (DBGridIF *) NULL)
coeffLayerRec = coeffIF->Layer(layerID % coeffIF->LayerNum());
if (Q_IF != (DBGridIF *) NULL)
Q_LayerRec = Q_IF->Layer(layerID % Q_IF->LayerNum());
if (HL_IF != (DBGridIF *) NULL)
HL_LayerRec = HL_IF->Layer(layerID % HL_IF->LayerNum());
for (cellID = 0; cellID < netIF->CellNum(); cellID++) {
sumWeights[cellID] = 0.0;
cellRec = netIF->Cell(cellID);
coord = netIF->Center(cellRec);
if (inIF->Value(inLayerRec, coord, &inValue) == false)
outIF->Value(outLayerRec, netIF->CellPosition(cellRec), 0.0);
else {
if (weightIF != (DBGridIF *) NULL)
weight = weightIF->Value(weightLayerRec, coord, &weight) == false ?
0.0 : weight * coeff;
else weight = coeff;
if (areaMult) weight = weight * netIF->CellArea(cellRec);
sumWeights[cellID] = weight;
outIF->Value(outLayerRec, netIF->CellPosition(cellRec), inValue * weight);
}
}
for (cellID = netIF->CellNum() - 1; cellID >= 0; --cellID) {
progress = layerID * netIF->CellNum() + (netIF->CellNum() - cellID);
if (DBPause(progress * 100 / maxProgress)) goto Stop;
cellRec = netIF->Cell(cellID);
coord = netIF->Center(cellRec);
if ((toCell = netIF->ToCell(cellRec)) == (DBObjRecord *) NULL) continue;
if (outIF->Value(outLayerRec, netIF->CellPosition(cellRec), &inValue) == false) continue;
if (outIF->Value(outLayerRec, netIF->CellPosition(toCell), &outValue) == false) continue;
sumWeights[toCell->RowID()] = sumWeights[toCell->RowID()] + weight;
if (coeffIF != (DBGridIF *) NULL) {
if (coeffIF->Value(coeffLayerRec, netIF->Center(cellRec), &kCoeff) == false) kCoeff = 1.0;
}
else {
if (((Q_IF == (DBGridIF *) NULL) || (Q_IF->Value(Q_LayerRec, netIF->Center(cellRec), &q) == false)) ||
((HL_IF == (DBGridIF *) NULL) ||
(HL_IF->Value(HL_LayerRec, netIF->Center(cellRec), &hl) == false)) ||
(umax == 0) || (ksat == 0))
//.........这里部分代码省略.........
示例13: RGISEditGridDateLayersCBK
//.........这里部分代码省略.........
XmNuserData, &timeStep,
NULL);
XmStringFree (string);
XtAddCallback (button,XmNactivateCallback,(XtCallbackProc) _RGISEditGridLayersYearButtonCBK,(XtPointer) DBTimeStepMinute);
string = XmStringCreate ((char *) "Time Step:",UICharSetBold);
menu = XtVaCreateManagedWidget ("RGISEditGridDateLayersTimeStepMenu",xmRowColumnWidgetClass,mainForm,
XmNtopAttachment, XmATTACH_FORM,
XmNtopOffset, 10,
XmNrightAttachment, XmATTACH_FORM,
XmNrightOffset, 10,
XmNbottomAttachment, XmATTACH_FORM,
XmNbottomOffset, 10,
XmNrowColumnType, XmMENU_OPTION,
XmNlabelString, string,
XmNsubMenuId, menu,
NULL);
XmStringFree (string);
yearTextF = XtVaCreateManagedWidget ("RGISEditGridDateLayersYearTextF",xmTextFieldWidgetClass,mainForm,
XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
XmNtopWidget, menu,
XmNrightAttachment, XmATTACH_WIDGET,
XmNrightWidget, menu,
XmNrightOffset, 10,
XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
XmNbottomWidget, menu,
XmNmaxLength, 4,
XmNcolumns, 4,
NULL);
XtAddCallback (yearTextF,XmNvalueChangedCallback,(XtCallbackProc) _RGISEditGridLayersYearTextCBK,yearText);
string = XmStringCreate ((char *) "Begin Year",UICharSetBold);
XtVaCreateManagedWidget ("RGISEditGridDateLayersYearLabel",xmLabelWidgetClass,mainForm,
XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
XmNtopWidget, menu,
XmNleftAttachment, XmATTACH_FORM,
XmNleftOffset, 10,
XmNrightAttachment, XmATTACH_WIDGET,
XmNrightWidget, yearTextF,
XmNrightOffset, 10,
XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
XmNbottomWidget, menu,
XmNlabelString, string,
NULL);
XmStringFree (string);
XtSetSensitive (UIDialogFormGetOkButton (dShell),true);
XtAddCallback (UIDialogFormGetOkButton (dShell),XmNactivateCallback,(XtCallbackProc) UIAuxSetBooleanTrueCBK,&proc);
}
proc = false;
UIDialogFormPopup (dShell);
while (UILoop ())
{ }
UIDialogFormPopdown (dShell);
if (proc)
{
DBInt layerID, year;
DBDate stepDate;
DBGridIF *gridIF = new DBGridIF (dbData);
DBObjRecord *layerRec;
DBDate date;
switch (timeStep)
{
case DBTimeStepYear: stepDate.Set (1); break;
case DBTimeStepMonth: stepDate.Set (0,1); break;
case DBTimeStepDay: stepDate.Set (0,0,1); break;
case DBTimeStepHour: stepDate.Set (0,0,0,1); break;
case DBTimeStepMinute: stepDate.Set (0,0,0,0,1); break;
}
if (sscanf (yearText,"%d",&year) != 1)
{
year = DBDefaultMissingIntVal;
if (((stepDate.Year () > 0) && (gridIF->LayerNum () > 1)) ||
((stepDate.Month () > 0) && (gridIF->LayerNum () > 12)) ||
((stepDate.Day () > 0) && (gridIF->LayerNum () > 365)) ||
((stepDate.Hour () > 0) && (gridIF->LayerNum () > 365 * 24)) ||
((stepDate.Minute () > 0) && (gridIF->LayerNum () > 365 * 24 * 60)))
{
UIMessage ((char *) "Too Many Layers in Dataset");
}
}
UIPauseDialogOpen ((char *) "Labeling Layers");
date.Set (year);
if (stepDate.Month () > 0) date.Set (year,0);
if (stepDate.Day () > 0) date.Set (year,0,0);
if (stepDate.Hour () > 0) date.Set (year,0,0,0);
if (stepDate.Minute () > 0) date.Set (year,0,0,0,0);
for (layerID = 0;layerID < gridIF->LayerNum ();++layerID)
{
layerRec = gridIF->Layer (layerID);
if (UIPause (layerRec->RowID () * 100 / gridIF->LayerNum ())) goto Stop;
gridIF->RenameLayer (layerRec,date.Get ());
date = date + stepDate;
}
Stop:
UIPauseDialogClose ();
delete gridIF;
}
}
示例14: RGISEditGridNetFilterCBK
void RGISEditGridNetFilterCBK (Widget widget, RGISWorkspace *workspace,XmAnyCallbackStruct *callData)
{
DBInt layerID, cellID, count, ret, kernel, kernelSize, maxProgress, dir;
DBFloat elev, cellElev, prevElev, upElev [5], meanElev, minElev, dElev;
DBDataset *dataset = UIDataset ();
DBObjData *grdData = dataset->Data ();
DBObjData *netData = grdData->LinkedData ();
DBGridIF *gridIF = new DBGridIF (grdData);
DBNetworkIF *netIF = new DBNetworkIF (netData);
DBObjRecord *cellRec, *fromCell, *nextCell, *layerRec;
UIPauseDialogOpen ((char *) "Network Filtering");
maxProgress = netIF->CellNum () * gridIF->LayerNum ();
for (layerID = 0;layerID < gridIF->LayerNum (); ++layerID)
{
layerRec = gridIF->Layer (layerID);
for (cellID = 0;cellID < netIF->CellNum (); ++cellID)
{
if (UIPause (((layerID + 1) * netIF->CellNum () - cellID) * 100 / maxProgress)) goto Stop;
fromCell = netIF->Cell (cellID);
if (netIF->FromCell (fromCell) != (DBObjRecord *) NULL) continue;
while (gridIF->Value (layerRec,netIF->Center (fromCell),&prevElev) == (DBInt) false)
if ((fromCell = netIF->ToCell (fromCell)) == (DBObjRecord *) NULL) break;
if (fromCell == (DBObjRecord *) NULL) continue;
kernelSize = 0;
for (cellRec = netIF->ToCell (fromCell); (cellRec != (DBObjRecord *) NULL) && (netIF->FromCell (cellRec) == fromCell); cellRec = netIF->ToCell (cellRec))
{
dElev = netIF->CellLength (fromCell) * RGlibMinSLOPE;
if ((ret = gridIF->Value (layerRec,netIF->Center (cellRec),&cellElev)) == false) { count = 0; meanElev = 0.0; }
else { count = 1, meanElev = cellElev; }
if (kernelSize + 1 < (int) (sizeof (upElev) / sizeof (upElev [0]))) kernelSize++;
for (kernel = kernelSize - 1;kernel > 0;--kernel) upElev [kernel] = upElev [kernel - 1]; upElev [0] = prevElev;
for (kernel = 0;kernel < kernelSize;++kernel) { meanElev += upElev [kernel]; count++; }
minElev = prevElev;
for (dir = 0; dir < 8;++dir)
if (((fromCell = netIF->FromCell (cellRec,0x01 << dir,true)) != (DBObjRecord *) NULL) &&
(gridIF->Value (layerRec,netIF->Center (fromCell),&elev) == true) && (minElev > elev))
{ minElev = elev; dElev = netIF->CellLength (fromCell) * RGlibMinSLOPE; }
nextCell = netIF->ToCell (cellRec);
for (kernel = 0;(kernel < kernelSize) && (nextCell != (DBObjRecord *) NULL);++kernel)
{
if(gridIF->Value (layerRec,netIF->Center (nextCell),&elev) != (DBInt) false) { meanElev += elev; count++; }
nextCell = netIF->ToCell (nextCell);
}
if (count > 0)
{
meanElev = meanElev / count;
if (meanElev > minElev - dElev) meanElev = minElev - dElev;
gridIF->Value (layerRec,netIF->Center (cellRec),meanElev);
prevElev = meanElev;
}
else gridIF->Value (layerRec,netIF->Center (cellRec),gridIF->MissingValue ());
fromCell = cellRec;
}
}
gridIF->RecalcStats (layerRec);
}
Stop:
UIPauseDialogClose ();
delete gridIF;
delete netIF;
}