DBInt IsChanged() { if (Foreground() != ForegroundFLD->Int(OrigREC)) return (true); if (Background() != BackgroundFLD->Int(OrigREC)) return (true); if (Style() != StyleFLD->Int(OrigREC)) return (true); if (strcmp(Name(), OrigREC->Name()) != 0) return (true); return (false); }
static void _RGISGrpPanelNewCBK (Widget widget,RGISGrpPanel *grpPanel,XmAnyCallbackStruct *callData) { char *groupName; DBDataset *dataset = UIDataset (); DBObjData *dbData = dataset->Data (); DBObjTable *groupTable = dbData->Table (DBrNGroups); DBObjTableField *group; DBObjRecord *record; if ((groupName = UIGetString ((char *) "Group Name",16)) == (char *) NULL) return; if (groupTable == (DBObjTable *) NULL) { DBObjTable *items = dbData->Table (DBrNItems); DBObjectLIST<DBObjTable> *tables = dbData->Tables (); DBTableFieldDefinition fieldDefs [] = { DBTableFieldDefinition (groupName, DBTableFieldInt,(char *) "%1d",sizeof (DBByte)), DBTableFieldDefinition () }; tables->Add (groupTable = new DBObjTable (DBrNGroups,fieldDefs)); grpPanel->Groups (groupTable->Fields ()); group = groupTable->Field (groupName); for (record = items->First ();record != (DBObjRecord *) NULL;record = items->Next ()) group->Int (groupTable->Add (record->Name ()),true); } else { groupTable->AddField (group = new DBObjTableField (groupName,DBTableFieldInt,"%1d",sizeof (DBByte))); for (record = groupTable->First ();record != (DBObjRecord *) NULL;record = groupTable->Next ()) group->Int (record,true); } grpPanel->Add (group); }
DBObjRecord *DBGridIF::AddLayer (char *layerName) { DBInt index; DBObjRecord *firstLayer, *layerRec, *dataRec; 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); firstLayer = LayerTable->First (&index); LayerTable->Add (layerName); if ((layerRec = LayerTable->Item ()) == (DBObjRecord *) NULL) return ((DBObjRecord *) NULL); rowNumFLD->Int (layerRec,rowNumFLD->Int (firstLayer)); colNumFLD->Int (layerRec,colNumFLD->Int (firstLayer)); cellWidthFLD->Float (layerRec,cellWidthFLD->Float (firstLayer)); cellHeightFLD->Float (layerRec,cellHeightFLD->Float (firstLayer)); valueTypeFLD->Int (layerRec,valueTypeFLD->Int (firstLayer)); valueSizeFLD->Int (layerRec,valueSizeFLD->Int (firstLayer)); if ((dataRec = new DBObjRecord (layerName,((size_t) rowNumFLD->Int (firstLayer)) * colNumFLD->Int (firstLayer) * valueSizeFLD->Int (firstLayer),valueSizeFLD->Int (firstLayer))) == (DBObjRecord *) NULL) { return ((DBObjRecord *) NULL); } LayerFLD->Record (layerRec,dataRec); ((Data ())->Arrays ())->Add (dataRec); if (DataPTR->Type () == DBTypeGridContinuous) { ItemTable->Add (layerName); MissingValueFLD->Float (ItemTable->Item (),MissingValueFLD->Float (ItemTable->First (&index))); } return (layerRec); }
void Update () { ForegroundFLD->Int (OrigREC,Foreground ()); BackgroundFLD->Int (OrigREC,Background ()); StyleFLD->Int (OrigREC,Style ()); OrigREC->Name (Name ()); }
int RGlibGenFuncSymbolField (DBObjData *data, const char *fieldName) { DBInt recID; char symbolName [DBStringLength + 1]; DBObjTable *table = data->Table (DBrNItems); DBObjTable *symbols = data->Table (DBrNSymbols); DBObjRecord *record, *symbolRec; DBObjTableField *field; DBObjTableField *symbolFLD; DBObjTableField *symbolIDFLD; DBObjTableField *foregroundFLD; DBObjTableField *backgroundFLD; DBObjTableField *styleFLD; if (table == (DBObjTable *) NULL) return (DBFault); if ((field = table->Field (fieldName)) == (DBObjTableField *) NULL) { CMmsgPrint (CMmsgAppError, "Invalid field name in: %s %d",__FILE__,__LINE__); return (DBFault); } if ((symbolFLD = table->Field (DBrNSymbol)) == (DBObjTableField *) NULL) { CMmsgPrint (CMmsgAppError, "Missing symbol field in: %s %d",__FILE__,__LINE__); return (DBFault); } if (symbols == (DBObjTable *) NULL) { CMmsgPrint (CMmsgAppError, "Missing symbol table in: %s %d",__FILE__,__LINE__); return (DBFault); } if ((symbolIDFLD = symbols->Field (DBrNSymbolID)) == (DBObjTableField *) NULL) { CMmsgPrint (CMmsgAppError, "Missing symbolID field in: %s %d",__FILE__,__LINE__); return (DBFault); } if ((foregroundFLD = symbols->Field (DBrNForeground)) == (DBObjTableField *) NULL) { CMmsgPrint (CMmsgAppError, "Missing foreground field in: %s %d",__FILE__,__LINE__); return (DBFault); } if ((backgroundFLD = symbols->Field (DBrNBackground)) == (DBObjTableField *) NULL) { CMmsgPrint (CMmsgAppError, "Missing background field in: %s %d",__FILE__,__LINE__); return (DBFault); } if ((styleFLD = symbols->Field (DBrNStyle)) == (DBObjTableField *) NULL) { CMmsgPrint (CMmsgAppError, "Missing style field in: %s %d",__FILE__,__LINE__); return (DBFault); } symbols->DeleteAll (); for (recID = 0;recID < table->ItemNum (); ++recID) { record = table->Item (recID); DBPause (record->RowID () * 100 / table->ItemNum ()); if (field->Type () == DBTableFieldString) sprintf (symbolName,"%s",field->String (record)); else sprintf (symbolName,"Symbol:%03d",field->Int (record)); if ((symbolRec = (DBObjRecord *) symbols->Item (symbolName)) == (DBObjRecord *) NULL) { if ((symbolRec = symbols->Add (symbolName)) == NULL) { CMmsgPrint (CMmsgAppError, "Symbol Object Creation Error in: %s %d",__FILE__,__LINE__); return (DBFault); } symbolIDFLD->Int (symbolRec,field->Type () == DBTableFieldString ? symbolRec->RowID () : field->Int (record)); foregroundFLD->Int (symbolRec,1); backgroundFLD->Int (symbolRec,0); styleFLD->Int (symbolRec,0); } symbolFLD->Record (record,symbolRec); } return (DBSuccess); }
void UIAttribView::Draw (DBObjRecord *record) { DBObjTableField *field; DBObjectLIST<DBObjTableField> *fields; UIXYGraphShell *graphCLS; if (record == (DBObjRecord *) NULL) { Cardinal i, numChildren; WidgetList rowCols; UIAuxSetLabelString (ItemNameWGT,(char *) ""); XtVaGetValues (FieldsRowCol,XmNchildren, &rowCols, XmNnumChildren, &numChildren,NULL); for (i = 0;i < numChildren; ++i) XmTextFieldSetString (XtNameToWidget (rowCols [i],"UIAttribViewTextField"),(char *) ""); return; } UIAuxSetLabelString (ItemNameWGT,record->Name ()); switch (DataPTR->Type ()) { case DBTypeVectorPoint: case DBTypeVectorLine: case DBTypeVectorPolygon: case DBTypeGridDiscrete: fields = ItemTable->Fields (); for (field = fields->First ();field != (DBObjTableField *) NULL;field = fields->Next ()) if (DBTableFieldIsVisible (field) == true) DrawField (field->Name (),field->String (record)); break; case DBTypeGridContinuous: { DBCoordinate coord = *((DBCoordinate *) (record->Data ())); DBGridIF *gridIF = new DBGridIF (DataPTR); for (record = ItemTable->First ();record != (DBObjRecord *) NULL;record = ItemTable->Next ()) DrawField (record->Name (),gridIF->ValueString (record,coord)); delete gridIF; } break; case DBTypeNetwork: { DBObjTable *cellTable = DataPTR->Table (DBrNCells); DBObjTableField *basinFLD = cellTable->Field (DBrNBasin); DBObjRecord *basinRec; if ((basinRec = ItemTable->Item (basinFLD->Int (record) - 1)) == (DBObjRecord *) NULL) { CMmsgPrint (CMmsgAppError, "BasinID Error in:%s %d",__FILE__,__LINE__); return; } DrawField ((char *) "Basin Name",basinRec->Name ()); fields = ItemTable->Fields (); for (field = fields->First ();field != (DBObjTableField *) NULL;field = fields->Next ()) if (DBTableFieldIsVisible (field) == true) DrawField (field->Name (),field->String (basinRec)); fields = cellTable->Fields (); for (field = fields->First ();field != (DBObjTableField *) NULL;field = fields->Next ()) if (DBTableFieldIsVisible (field) == true) DrawField (field->Name (),field->String (record)); } break; default: break; } if ((graphCLS = (UIXYGraphShell *) DataPTR->Display (UIXYGraphShellStr)) != (UIXYGraphShell *) NULL) graphCLS->Configure (record); }
void GetVariable(DBObjRecord *record, DBCoordinate coord) { switch ((GridIF->Data())->Type()) { case DBTypeGridContinuous: { DBFloat value; if (GridIF->Value(LayerRec, coord, &value)) TargetFLD->Float(record, value); else TargetFLD->Float(record, TargetFLD->FloatNoData()); } break; case DBTypeGridDiscrete: { DBObjRecord *grdRec; if ((grdRec = GridIF->GridItem(LayerRec, coord)) != (DBObjRecord *) NULL) switch (SourceFLD->Type()) { case DBVariableString: TargetFLD->String(record, SourceFLD->String(grdRec)); break; case DBVariableInt: TargetFLD->Int(record, SourceFLD->Int(grdRec)); break; case DBVariableFloat: TargetFLD->Float(record, SourceFLD->Float(grdRec)); break; default: break; } else switch (SourceFLD->Type()) { case DBVariableString: TargetFLD->String(record, ""); break; case DBVariableInt: TargetFLD->Int(record, SourceFLD->IntNoData()); break; case DBVariableFloat: TargetFLD->Float(record, SourceFLD->FloatNoData()); break; default: break; } } break; default: CMmsgPrint(CMmsgUsrError, "Invalid grid type in: CMDgrdVariable:GetVariable ()"); break; } }
static int _DBObjTableListSort(const DBObjRecord **obj0, const DBObjRecord **obj1) { DBInt ret = 0; DBObjTableField *field; DBDate date0, date1; for (field = _DBObjTableSortFields->First(); field != (DBObjTableField *) NULL; field = _DBObjTableSortFields->Next()) { switch (field->Type()) { case DBTableFieldString: ret = strcmp(field->String(*obj0), field->String(*obj1)); break; case DBTableFieldInt: ret = field->Int(*obj0) - field->Int(*obj1); break; case DBTableFieldFloat: if (field->Float(*obj0) - field->Float(*obj1) > 0.0) ret = 1; else if (field->Float(*obj0) - field->Float(*obj1) < 0.0) ret = -1; else ret = 0; break; case DBTableFieldDate: date0 = field->Date(*obj0); date1 = field->Date(*obj1); if (date0 > date1) ret = 1; else if (date0 < date1) ret = -1; else ret = 0; break; case DBTableFieldTableRec: ret = strcmp((*obj0)->Name(), (*obj1)->Name()); break; case DBTableFieldDataRec: ret = (*obj0)->RowID() - (*obj1)->RowID(); break; } if ((field->Flags() & DBObjectFlagSortReversed) == DBObjectFlagSortReversed) ret *= -1; if (ret != 0) return (ret); } if (ret == 0) ret = (*obj0)->ListPos() - (*obj1)->ListPos(); return (ret); }
static void _RGISGrpPanelSaveCBK (Widget widget,RGISGrpPanel *grpPanel,XmAnyCallbackStruct *callData) { DBInt rowID; DBDataset *dataset= UIDataset (); DBObjData *dbData = dataset->Data (); DBObjTable *itemTable = dbData->Table (DBrNItems); DBObjTable *groupTable = dbData->Table (DBrNGroups); DBObjTableField *group; DBObjRecord *itemRec, *groupRec; UITable *tableCLS; if (groupTable == (DBObjTable *) NULL) return; group = grpPanel->Current (); for (rowID = 0;rowID < groupTable->ItemNum ();++rowID) { groupRec = groupTable->Item (rowID); itemRec = itemTable->Item (rowID); group->Int (groupRec,(itemRec->Flags () & DBObjectFlagSelected) == DBObjectFlagSelected ? true : false); } if ((tableCLS = (UITable *) dbData->Display (UITableName (dbData,groupTable))) != (UITable *) NULL) tableCLS->Draw (); }
int DBImportARCPoly (DBObjData *vecData,const char *arcCov) { DBInt polyNum = 0, line, lineNum, vertexNum, polyDir; DBObjTable *items = vecData->Table (DBrNItems); DBObjTable *lines = vecData->Table (DBrNContours); DBObjTableField *firstLineFLD = items->Field (DBrNFirstLine); DBObjTableField *lineNumFLD = items->Field (DBrNLineNum); DBObjTableField *polyVertexNumFLD = items->Field (DBrNVertexNum); DBObjTableField *polyExtentFLD = items->Field (DBrNRegion); DBObjTableField *leftPolyFLD = lines->Field (DBrNLeftPoly); DBObjTableField *rightPolyFLD = lines->Field (DBrNRightPoly); DBObjTableField *nextLineFLD = lines->Field (DBrNNextLine); DBObjTableField *prevLineFLD = lines->Field (DBrNPrevLine); DBObjTableField *fromNodeFLD = lines->Field (DBrNFromNode); DBObjTableField *toNodeFLD = lines->Field (DBrNToNode); DBObjTableField *lineVertextNumFLD = lines->Field (DBrNVertexNum); DBObjTableField *lineExtentFLD = lines->Field (DBrNRegion); DBObjRecord *polyRec, *lineRec, *firstNodeRec, *nodeRec, **lineRecArray; DBRegion extent, initRegion; if (DBImportARCLine (vecData,arcCov) == DBFault) return (DBFault); items->Delete (0); for (polyRec = items->First ();polyRec != (DBObjRecord *) NULL;polyRec = items->Next ()) lineNumFLD->Int (polyRec,0); for (lineRec = lines->First ();lineRec != (DBObjRecord *) NULL;lineRec = lines->Next ()) { rightPolyFLD->Record (lineRec,items->Item ((DBInt) (rightPolyFLD->Record(lineRec) - (DBObjRecord *) NULL))); leftPolyFLD->Record (lineRec,items->Item ((DBInt) (leftPolyFLD->Record (lineRec) - (DBObjRecord *) NULL))); nextLineFLD->Record (lineRec,(DBObjRecord *) NULL); prevLineFLD->Record (lineRec,(DBObjRecord *) NULL); } if ((lineRecArray = (DBObjRecord **) calloc (lines->ItemNum (),sizeof (DBObjRecord *))) == (DBObjRecord **) NULL) { CMmsgPrint (CMmsgSysError, "Memory Allocation Error in: %s %d",__FILE__,__LINE__); return (DBFault); } for (polyRec = items->First ();polyRec != (DBObjRecord *) NULL;polyRec = items->Next ()) { DBPause ((++polyNum * 100) / items->ItemNum ()); lineNum = vertexNum = 0; extent = initRegion; for (lineRec = lines->First ();lineRec != (DBObjRecord *) NULL;lineRec = lines->Next ()) if ((rightPolyFLD->Record (lineRec) == polyRec) || (leftPolyFLD->Record (lineRec) == polyRec)) { lineRecArray [lineNum++] = lineRec; vertexNum += lineVertextNumFLD->Int (lineRec); extent.Expand (lineExtentFLD->Region (lineRec)); } lineNumFLD->Int (polyRec,lineNum); polyExtentFLD->Region (polyRec,extent); firstLineFLD->Record (polyRec,lineRecArray [0]); firstNodeRec = (rightPolyFLD->Record (lineRecArray [0]) == polyRec) ? fromNodeFLD->Record (lineRecArray [0]) : toNodeFLD->Record(lineRecArray [0]); for (lineNum = 1;lineNum < lineNumFLD->Int (polyRec);++lineNum) { polyDir = (rightPolyFLD->Record (lineRecArray [lineNum - 1]) == polyRec); nodeRec = polyDir ? toNodeFLD->Record (lineRecArray [lineNum - 1]) : fromNodeFLD->Record(lineRecArray [lineNum - 1]); for (line = lineNum;line < lineNumFLD->Int (polyRec); ++line) if ((nodeRec == fromNodeFLD->Record (lineRecArray [line])) || (nodeRec == toNodeFLD->Record (lineRecArray [line]))) break; if (line < lineNumFLD->Int (polyRec)) { lineRec = lineRecArray [lineNum]; lineRecArray [lineNum] = lineRecArray [line]; lineRecArray [line] = lineRec; } else { vertexNum += 1; if (nodeRec != firstNodeRec) vertexNum += 1; } } polyDir = (rightPolyFLD->Record (lineRecArray [lineNum - 1]) == polyRec); nodeRec = polyDir ? toNodeFLD->Record (lineRecArray [lineNum - 1]) : fromNodeFLD->Record(lineRecArray [lineNum - 1]); polyVertexNumFLD->Int (polyRec,vertexNum + lineNum + 1 + (nodeRec != firstNodeRec ? 1 : 0)); for (lineNum = 1;lineNum < lineNumFLD->Int (polyRec);++lineNum) { if (rightPolyFLD->Record (lineRecArray [lineNum - 1]) == polyRec) nextLineFLD->Record (lineRecArray [lineNum - 1],lineRecArray [lineNum]); else prevLineFLD->Record (lineRecArray [lineNum - 1],lineRecArray [lineNum]); } if (rightPolyFLD->Record (lineRecArray [lineNum - 1]) == polyRec) nextLineFLD->Record (lineRecArray [lineNum - 1],lineRecArray [0]); else prevLineFLD->Record (lineRecArray [lineNum - 1],lineRecArray [0]); } free (lineRecArray); return (DBSuccess); }
int DBImportARCVector (DBObjData *vecData,const char *arcCov,const char *nameFieldStr,const char *symbolFieldStr) { char symbolName [DBStringLength + 1]; DBObjTable *items = vecData->Table (DBrNItems); DBObjTable *symbols = vecData->Table (DBrNSymbols); DBObjTableField *nameFLD = NULL, *symbolResFLD, *symbolFLD = NULL; DBObjTableField *symbolIDFLD = symbols->Field (DBrNSymbolID); DBObjTableField *foregroundFLD = symbols->Field (DBrNForeground); DBObjTableField *backgroundFLD = symbols->Field (DBrNBackground); DBObjTableField *styleFLD = symbols->Field (DBrNStyle); DBObjRecord *record; DBObjRecord *symbolRec; if (DBInfoGetFields (items,DBInfoFileName (arcCov,vecData->Type ())) == DBSuccess) if (DBInfoGetTable (items,DBInfoFileName (arcCov,vecData->Type ())) == DBFault) return (DBFault); switch (vecData->Type ()) { case DBTypeVectorPoint: if (DBImportARCPoint (vecData,arcCov) == DBFault) return (DBFault); else break; case DBTypeVectorLine: if (DBImportARCLine (vecData,arcCov) == DBFault) return (DBFault); else break; case DBTypeVectorPolygon: if (DBImportARCPoly (vecData,arcCov) == DBFault) return (DBFault); else break; default: return (DBFault); } nameFLD = nameFieldStr != NULL ? items->Field (nameFieldStr) : (DBObjTableField *) NULL; symbolFLD = symbolFieldStr != NULL ? items->Field (symbolFieldStr) : (DBObjTableField *) NULL; symbolResFLD = items->Field (DBrNSymbol); if (symbolFLD != NULL) { for (record = items->First ();record != (DBObjRecord *) NULL;record = items->Next ()) { switch (symbolFLD->Type ()) { case DBTableFieldString: if ((symbolRec = (DBObjRecord *) symbols->Item (symbolFLD->String (record))) == NULL) { if ((symbolRec = symbols->Add (symbolFLD->String (record))) == NULL) { CMmsgPrint (CMmsgAppError,"Symbol Object Creation Error in: %s %d",__FILE__,__LINE__); return (DBFault); } symbolIDFLD->Int (symbolRec,symbolRec->RowID ()); foregroundFLD->Int (symbolRec,1); backgroundFLD->Int (symbolRec,0); styleFLD->Int (symbolRec,0); } break; case DBTableFieldInt: sprintf (symbolName,"Symbol:%5d",symbolFLD->Int (record)); if ((symbolRec = (DBObjRecord *) symbols->Item (symbolName)) == NULL) { if ((symbolRec = symbols->Add (symbolName)) == NULL) { CMmsgPrint (CMmsgAppError, "Symbol Object Creation Error in: %s %d",__FILE__,__LINE__); return (DBFault); } symbolIDFLD->Int (symbolRec,symbolFLD->Int (record)); foregroundFLD->Int (symbolRec,1); backgroundFLD->Int (symbolRec,0); styleFLD->Int (symbolRec,0); } break; default: CMmsgPrint (CMmsgAppError, "Invalid Field Type in: %s %d",__FILE__,__LINE__); break; } symbolResFLD->Record (record,symbolRec); } } else { symbols->Add ("Default Symbol"); if ((symbolRec = (DBObjRecord *) symbols->Item ()) == (DBObjRecord *) NULL) { CMmsgPrint (CMmsgAppError, "Symbol Object Creation Error in: %s %d",__FILE__,__LINE__); return (DBFault); } symbolIDFLD->Int (symbolRec,0); foregroundFLD->Int (symbolRec,1); backgroundFLD->Int (symbolRec,0); styleFLD->Int (symbolRec,0); for (record = items->First ();record != (DBObjRecord *) NULL;record = items->Next ()) symbolResFLD->Record (record,symbolRec); } if (nameFLD != NULL) for (record = items->First ();record != (DBObjRecord *) NULL;record = items->Next ()) record->Name (nameFLD->String (record)); return (DBSuccess); }
int main(int argc, char *argv[]) { int argPos, argNum = argc, ret, verbose = false; DBInt recID; int deg, min, sec; char coordStr[DBStringLength]; char *tableName = (char *) NULL; char *fieldName = (char *) NULL; char *degFieldName = (char *) NULL; char *minFieldName = (char *) NULL; char *secFieldName = (char *) NULL; DBObjData *data; DBObjTable *table; DBObjTableField *dstField; DBObjTableField *degField = (DBObjTableField *) NULL; DBObjTableField *minField = (DBObjTableField *) NULL; DBObjTableField *secField = (DBObjTableField *) NULL; DBObjRecord *record; for (argPos = 1; argPos < argNum;) { if (CMargTest (argv[argPos], "-a", "--table")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing table name!"); return (CMfailed); } tableName = argv[argPos]; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-f", "--field")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing field name!"); return (CMfailed); } fieldName = argv[argPos]; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-d", "--degree")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing degree field name!"); return (CMfailed); } degFieldName = argv[argPos]; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-m", "--minute")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing minutefield name!"); return (CMfailed); } minFieldName = argv[argPos]; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-s", "--second")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing second field name!"); return (CMfailed); } secFieldName = argv[argPos]; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-V", "--verbose")) { verbose = true; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-h", "--help")) { CMmsgPrint(CMmsgInfo, "%s [options] <input file> <output file>", CMfileName(argv[0])); CMmsgPrint(CMmsgInfo, " -a,--table [table name]"); CMmsgPrint(CMmsgInfo, " -f,--field [field name]"); CMmsgPrint(CMmsgInfo, " -d,--degree [degree field]"); CMmsgPrint(CMmsgInfo, " -m,--minute [minute field]"); CMmsgPrint(CMmsgInfo, " -s,--second [secon field]"); CMmsgPrint(CMmsgInfo, " -V,--verbose"); CMmsgPrint(CMmsgInfo, " -h,--help"); return (DBSuccess); } if ((argv[argPos][0] == '-') && ((int) strlen(argv[argPos]) > 1)) { CMmsgPrint(CMmsgUsrError, "Unknown option: %s!", argv[argPos]); return (CMfailed); } argPos++; } if (argNum > 3) { CMmsgPrint(CMmsgUsrError, "Extra arguments!"); return (CMfailed); } if (verbose) RGlibPauseOpen(argv[0]); data = new DBObjData(); if (((argNum > 1) && (strcmp(argv[1], "-") != 0) ? data->Read(argv[1]) : data->Read(stdin)) == DBFault) { delete data; return (CMfailed); } if (tableName == (char *) NULL) tableName = DBrNItems; if ((table = data->Table(tableName)) == (DBObjTable *) NULL) { CMmsgPrint(CMmsgUsrError, "Invalid table!"); delete data; return (CMfailed); } if (degFieldName != (char *) NULL) { if ((degField = table->Field(degFieldName)) == (DBObjTableField *) NULL) { CMmsgPrint(CMmsgUsrError, "Invalid degree field [%s]!", degFieldName); delete data; return (CMfailed); } } if (minFieldName != (char *) NULL) { if ((minField = table->Field(minFieldName)) == (DBObjTableField *) NULL) { CMmsgPrint(CMmsgUsrError, "Invalid min field [%s]!", minFieldName); delete data; return (CMfailed); } } if (secFieldName != (char *) NULL) { if (minField == (DBObjTableField *) NULL) { CMmsgPrint(CMmsgUsrError, "Minute field is not set!"); delete data; return (CMfailed); } if ((secField = table->Field(secFieldName)) == (DBObjTableField *) NULL) { CMmsgPrint(CMmsgUsrError, "Invalid second field [%s]", secFieldName); delete data; return (CMfailed); } } if (fieldName == (char *) NULL) fieldName = (char *) "Coord[ddd:mm\'ss\"]"; if ((dstField = table->Field(fieldName)) == (DBObjTableField *) NULL) { dstField = new DBObjTableField(fieldName, DBTableFieldString, "%s", 16, false); table->AddField(dstField); } for (recID = 0; recID < table->ItemNum(); ++recID) { record = table->Item(recID); if ((degField == (DBObjTableField *) NULL) || ((deg = degField->Int(record)) == degField->IntNoData())) strcpy(coordStr, ""); else if ((minField == (DBObjTableField *) NULL) || ((min = minField->Int(record)) == minField->IntNoData())) sprintf(coordStr, "%4d", deg); else if ((secField == (DBObjTableField *) NULL) || ((sec = secField->Int(record)) == secField->IntNoData())) sprintf(coordStr, "%4d:%02d", deg, min); else sprintf(coordStr, "%4d:%02d\'%02d\"", deg, min, sec); dstField->String(record, coordStr); } ret = (argNum > 2) && (strcmp(argv[2], "-") != 0) ? data->Write(argv[2]) : data->Write(stdout); delete data; if (verbose) RGlibPauseClose(); return (ret); }
void DBGridIF::Initialize(DBObjData *data, bool flat) { DBObjTableField *rowNumFLD; DBObjTableField *colNumFLD; DBObjTableField *cellWidthFLD; DBObjTableField *cellHeightFLD; DBObjTableField *valueTypeFLD; DBObjTableField *valueSizeFLD; DBObjRecord *layerRec; DataPTR = data; ItemTable = data->Table(DBrNItems); switch (data->Type()) { case DBTypeGridDiscrete: SymbolTable = data->Table(DBrNSymbols); AverageFLD = (DBObjTableField *) NULL; StdDevFLD = (DBObjTableField *) NULL; MinimumFLD = (DBObjTableField *) NULL; MaximumFLD = (DBObjTableField *) NULL; MissingValueFLD = (DBObjTableField *) NULL; GridValueFLD = ItemTable->Field(DBrNGridValue); SymbolFLD = ItemTable->Field(DBrNSymbol); SymbolIDFLD = SymbolTable->Field(DBrNSymbolID); ForegroundFLD = SymbolTable->Field(DBrNForeground); BackgroundFLD = SymbolTable->Field(DBrNBackground); StyleFLD = SymbolTable->Field(DBrNStyle); break; case DBTypeGridContinuous: SymbolTable = (DBObjTable *) NULL; AverageFLD = ItemTable->Field(DBrNAverage); StdDevFLD = ItemTable->Field(DBrNStdDev); MinimumFLD = ItemTable->Field(DBrNMinimum); MaximumFLD = ItemTable->Field(DBrNMaximum); MissingValueFLD = ItemTable->Field(DBrNMissingValue); SymbolFLD = (DBObjTableField *) NULL; SymbolIDFLD = (DBObjTableField *) NULL; ForegroundFLD = (DBObjTableField *) NULL; BackgroundFLD = (DBObjTableField *) NULL; StyleFLD = (DBObjTableField *) NULL; break; default: CMmsgPrint(CMmsgAppError, "Invalid Data Type in: %s %d", __FILE__, __LINE__); break; } LayerTable = data->Table(DBrNLayers); LayerFLD = LayerTable->Field(DBrNLayer); rowNumFLD = LayerTable->Field(DBrNRowNum); colNumFLD = LayerTable->Field(DBrNColNum); cellWidthFLD = LayerTable->Field(DBrNCellWidth); cellHeightFLD = LayerTable->Field(DBrNCellHeight); valueTypeFLD = LayerTable->Field(DBrNValueType); valueSizeFLD = LayerTable->Field(DBrNValueSize); layerRec = LayerTable->Item(); DimensionVAR.Row = rowNumFLD->Int(layerRec); DimensionVAR.Col = colNumFLD->Int(layerRec); CellWidthVAR = cellWidthFLD->Float(layerRec); CellHeightVAR = cellHeightFLD->Float(layerRec); ValueTypeVAR = valueTypeFLD->Int(layerRec); ValueSizeVAR = valueSizeFLD->Int(layerRec); Flat = flat; }
DBInt Foreground () const { return (ForegroundFLD->Int ((DBObjRecord *) this)); }
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 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; }
void Style (DBInt style) { StyleFLD->Int ((DBObjRecord *) this,style); }
DBInt Style () const { return (StyleFLD->Int ((DBObjRecord *) this)); }
void Background (DBInt color) { BackgroundFLD->Int ((DBObjRecord *) this,color); }
DBInt Background () const { return (BackgroundFLD->Int ((DBObjRecord *) this)); }
void Foreground (DBInt color) { ForegroundFLD->Int ((DBObjRecord *) this,color); }
int DBImportARCLine (DBObjData *vecData,const char *arcCov) { FILE *inFile; DBInt arcNum, vertex, swap = DBByteOrder (DBByteOrderLITTLE), floatCov; char fileName [DBDataFileNameLen], objName [DBStringLength]; short infoHeader [50]; DBARCRecord arcRecord; DBObjTable *lines; DBObjTable *nodes; DBObjectLIST<DBObjRecord> *data; DBObjRecord *lineRec, *nodeRec, *dataRec; DBRegion dataExtent = vecData->Extent (), itemExtent; DBObjTableField *fromNodeFLD; DBObjTableField *toNodeFLD; DBObjTableField *leftPolyFLD; DBObjTableField *rightPolyFLD; DBObjTableField *vertexesFLD; DBObjTableField *vertexNumFLD; DBObjTableField *extentFLD; DBObjTableField *coordFLD; DBObjTableField *linkNumFLD; DBCoordinate *vertexes, nodeCoord; DBFloat4 floatVAR [2]; switch (vecData->Type ()) { case DBTypeVectorLine: lines = vecData->Table (DBrNItems); break; case DBTypeVectorPolygon: lines = vecData->Table (DBrNContours); break; default: CMmsgPrint (CMmsgAppError, "Invalide Vector Data Type in: %s %d",__FILE__,__LINE__); return (DBFault); } fromNodeFLD = lines->Field (DBrNFromNode); toNodeFLD = lines->Field (DBrNToNode); leftPolyFLD = lines->Field (DBrNLeftPoly); rightPolyFLD= lines->Field (DBrNRightPoly); vertexesFLD = lines->Field (DBrNVertexes); vertexNumFLD= lines->Field (DBrNVertexNum); extentFLD = lines->Field (DBrNRegion); nodes = vecData->Table (DBrNNodes); coordFLD = nodes->Field (DBrNCoord); linkNumFLD = nodes->Field (DBrNLinkNum); data = vecData->Arrays (); sprintf (fileName,"%s/arc",arcCov); if (access (fileName,R_OK) == DBFault) sprintf (fileName,"%s/arc.adf",arcCov); if ((inFile = fopen (fileName,"r")) == NULL) { CMmsgPrint (CMmsgSysError, "File Opening Error in: %s %d",__FILE__,__LINE__); return (DBFault); } if (fread (infoHeader,sizeof (short),50,inFile) != 50) { CMmsgPrint (CMmsgSysError, "File Reading Error in: %s %d",__FILE__,__LINE__); return (DBFault); } arcNum = 0; for (lineRec = lines->First ();arcRecord.Read (inFile,swap) != DBFault;lineRec = lines->Next ()) { if (lineRec == NULL) { sprintf (objName,"Line: %5d",arcRecord.ID () + 1); if ((lineRec = lines->Add (objName)) == (DBObjRecord *) NULL) return (DBFault); } else DBPause ((++arcNum * 100) / lines->ItemNum ()); floatCov = arcRecord.RecordLength () - 12 == arcRecord.NumOfPnts () * (DBInt) sizeof (float) ? true : false; while (arcRecord.FromNode () > nodes->ItemNum ()) { sprintf (objName,"Node: %5d",nodes->ItemNum () + 1); nodes->Add (objName); if ((nodeRec = nodes->Item ()) == NULL) return (DBFault); linkNumFLD->Int (nodeRec,0); } if ((nodeRec = nodes->Item (arcRecord.FromNode () - 1)) == (DBObjRecord *) NULL) { CMmsgPrint (CMmsgAppError, "Node Not Found in: %s %d",__FILE__,__LINE__); return (DBFault); } if (floatCov) { if (fread (floatVAR,sizeof (floatVAR),1,inFile) != 1) { CMmsgPrint (CMmsgSysError, "File Reading Error in: %s %d",__FILE__,__LINE__); return (DBFault); } if (swap) { DBByteOrderSwapWord (floatVAR); DBByteOrderSwapWord (floatVAR + 1); } nodeCoord.X = (DBFloat) floatVAR [0]; nodeCoord.Y = (DBFloat) floatVAR [1]; } else { if (fread (&nodeCoord,sizeof (DBCoordinate),1,inFile) != 1) { CMmsgPrint (CMmsgSysError, "File Reading Error in: %s %d",__FILE__,__LINE__); return (DBFault); } if (swap) nodeCoord.Swap (); } coordFLD->Coordinate (nodeRec,nodeCoord); fromNodeFLD->Record (lineRec,nodeRec); if (leftPolyFLD != (DBObjTableField *) NULL) leftPolyFLD->Record (lineRec,arcRecord.LeftPoly ()); if (rightPolyFLD != (DBObjTableField *) NULL) rightPolyFLD->Record (lineRec,arcRecord.RightPoly ()); itemExtent.LowerLeft = nodeCoord; itemExtent.UpperRight = nodeCoord; linkNumFLD->Int (nodeRec,linkNumFLD->Int (nodeRec) + 1); if (arcRecord.NumOfPnts () > 2) { if ((dataRec = data->Item (lineRec->RowID ())) == (DBObjRecord *) NULL) { if ((dataRec = new DBObjRecord ("LineData",0,sizeof (DBFloat))) == (DBObjRecord *) NULL) return (DBFault); data->Add (dataRec); } dataRec->Realloc ((arcRecord.NumOfPnts () - 2) * sizeof (DBCoordinate)); if ((vertexes = (DBCoordinate *) dataRec->Data ()) == NULL) { CMmsgPrint (CMmsgSysError, "Memory Allocation Error in: %s %d",__FILE__,__LINE__); return (DBFault); } if (floatCov) for (vertex = 0;vertex < arcRecord.NumOfPnts () - 2;++vertex) { if (fread (floatVAR,sizeof (floatVAR),1,inFile) != 1) { CMmsgPrint (CMmsgSysError, "File Reading Error in: %s %d",__FILE__,__LINE__); return (DBFault); } if (swap) { DBByteOrderSwapWord (floatVAR); DBByteOrderSwapWord (floatVAR + 1); } vertexes [vertex].X = (DBFloat) floatVAR [0]; vertexes [vertex].Y = (DBFloat) floatVAR [1]; dataExtent.Expand (vertexes [vertex]); itemExtent.Expand (vertexes [vertex]); } else for (vertex = 0;vertex < arcRecord.NumOfPnts () - 2;++vertex) { if (fread (vertexes + vertex,sizeof (DBCoordinate),1,inFile) != 1) { CMmsgPrint (CMmsgSysError, "File Reading Error in: %s %d",__FILE__,__LINE__); return (DBFault); } if (swap) vertexes [vertex].Swap (); dataExtent.Expand (vertexes [vertex]); itemExtent.Expand (vertexes [vertex]); } vertexesFLD->Record (lineRec,dataRec); } else vertexesFLD->Record (lineRec,(DBObjRecord *) NULL); vertexNumFLD->Int (lineRec,arcRecord.NumOfPnts () - 2); while (arcRecord.ToNode () > nodes->ItemNum ()) { sprintf (objName,"Node: %5d",nodes->ItemNum () + 1); nodes->Add (objName); if ((nodeRec = nodes->Item ()) == NULL) return (DBFault); linkNumFLD->Int (nodeRec,0); } if ((nodeRec = nodes->Item (arcRecord.ToNode () - 1)) == (DBObjRecord *) NULL) { CMmsgPrint (CMmsgAppError, "Node Not Found in: %s %d",__FILE__,__LINE__); return (DBFault); } if (floatCov) { if (fread (floatVAR,sizeof (floatVAR),1,inFile) != 1) { CMmsgPrint (CMmsgAppError, "File Reading Error in: %s %d",__FILE__,__LINE__); return (DBFault); } if (swap) { DBByteOrderSwapWord (floatVAR); DBByteOrderSwapWord (floatVAR + 1); } nodeCoord.X = (DBFloat) floatVAR [0]; nodeCoord.Y = (DBFloat) floatVAR [1]; } else { if (fread (&nodeCoord,sizeof (DBCoordinate),1,inFile) != 1) { CMmsgPrint (CMmsgAppError, "File Reading Error in: %s %d",__FILE__,__LINE__); return (DBFault); } if (swap) nodeCoord.Swap (); } itemExtent.Expand (nodeCoord); coordFLD->Coordinate (nodeRec,nodeCoord); linkNumFLD->Int (nodeRec,linkNumFLD->Int (nodeRec) + 1); toNodeFLD->Record (lineRec,nodeRec); extentFLD->Region (lineRec,itemExtent); } fclose (inFile); vertexesFLD->RecordProp ((DBInt) sizeof (DBFloat)); vecData->Extent (dataExtent); vecData->Projection (DBMathGuessProjection (dataExtent)); return (DBSuccess); }
static void _RGISToolsNetBasinMouthCBK (Widget widget,RGISWorkspace *workspace,XmAnyCallbackStruct *callData) { DBDataset *dataset = UIDataset (); DBObjData *netData = dataset->Data (), *pntData; DBNetworkIF *netIF; widget = widget; callData = callData; if (netData == (DBObjData *) NULL) { CMmsgPrint (CMmsgAppError, "Null Data in: %s %d",__FILE__,__LINE__); return; } netIF = new DBNetworkIF (netData); if (UIDataHeaderForm (pntData = new DBObjData ("",DBTypeVectorPoint))) { char symName [DBStringLength]; DBInt basinID, order; DBCoordinate coord; DBObjTable *items = pntData->Table (DBrNItems); DBObjTable *symbols = pntData->Table (DBrNSymbols); DBObjTableField *coordField = items->Field (DBrNCoord); DBObjTableField *symbolFLD = items->Field (DBrNSymbol); DBObjTableField *orderFLD = new DBObjTableField (DBrNOrder,DBTableFieldInt,"%3d",sizeof (DBByte)); DBObjTableField *subbasinLengthFLD = new DBObjTableField (DBrNSubbasinLength,DBTableFieldFloat,"%10.1f",sizeof (float)); DBObjTableField *subbasinAreaFLD = new DBObjTableField (DBrNSubbasinArea,DBTableFieldFloat,"%10.1f",sizeof (float)); DBObjTableField *foregroundFLD = symbols->Field (DBrNForeground); DBObjTableField *backgroundFLD = symbols->Field (DBrNBackground); DBObjTableField *styleFLD = symbols->Field (DBrNStyle); DBObjRecord *pntRec, *symRec, *cellRec, *basinRec; DBRegion dataExtent; items->AddField (orderFLD); items->AddField (subbasinLengthFLD); items->AddField (subbasinAreaFLD); cellRec = netIF->Cell ((DBInt) 0); for (order = 0;order <= netIF->CellOrder (cellRec);++order) { sprintf (symName,"Strahler Order:%2d",order); symRec = symbols->Add (symName); styleFLD->Int (symRec,0); foregroundFLD->Int (symRec,1); backgroundFLD->Int (symRec,0); } UIPauseDialogOpen ((char *) "Creating Basin Mouth"); for (basinID = 0;basinID < netIF->BasinNum ();++basinID) { basinRec = netIF->Basin (basinID); if (UIPause (basinID * 100 / netIF->BasinNum ())) goto Stop; symRec = symbols->Item (netIF->CellOrder (cellRec)); cellRec = netIF->MouthCell (basinRec); pntRec = items->Add (basinRec->Name ()); coord = netIF->Center (cellRec); coordField->Coordinate (pntRec,coord); symbolFLD->Record (pntRec,symRec); orderFLD->Int (pntRec,netIF->CellOrder (cellRec)); subbasinLengthFLD->Float (pntRec,netIF->CellBasinLength (cellRec)); subbasinAreaFLD->Float (pntRec,netIF->CellBasinArea (cellRec)); dataExtent.Expand (coord); } Stop: UIPauseDialogClose (); pntData->Extent (dataExtent); workspace->CurrentData (pntData); } else delete pntData; delete netIF; }
DBInt RGlibRGIS2DataStream(DBObjData *grdData, DBObjData *tmplData, char *fieldName, FILE *outFile) { DBInt layerID, ret = DBSuccess, itemSize, itemID; DBInt intValue; DBFloat floatValue; void *data; MFVarHeader_t varHeader; DBObjRecord *layerRec, *gridRec; DBObjTableField *fieldPTR = (DBObjTableField *) NULL; DBGridIF *gridIF; DBVPointIF *tmplPntIF = (DBVPointIF *) NULL; DBGridIF *tmplGrdIF = (DBGridIF *) NULL; DBNetworkIF *tmplNetIF = (DBNetworkIF *) NULL; gridIF = new DBGridIF(grdData); varHeader.Swap = 1; if (grdData->Type() == DBTypeGridDiscrete) { DBObjTable *itemTable = grdData->Table(DBrNItems); if (fieldName == (char *) NULL) fieldName = DBrNGridValue; if ((fieldPTR = itemTable->Field(fieldName)) == (DBObjTableField *) NULL) { CMmsgPrint(CMmsgAppError, "Error: Invalid field [%s] in: %s %d", fieldName, __FILE__, __LINE__); return (DBFault); } itemSize = fieldPTR->Length(); switch (fieldPTR->Type()) { case DBTableFieldInt: switch (itemSize) { default: case sizeof(DBByte): varHeader.DataType = MFByte; break; case sizeof(DBShort): varHeader.DataType = MFShort; break; case sizeof(DBInt): varHeader.DataType = MFInt; break; } varHeader.Missing.Int = fieldPTR->IntNoData(); break; case DBTableFieldFloat: switch (itemSize) { default: case sizeof(DBFloat4): varHeader.DataType = MFFloat; break; case sizeof(DBFloat): varHeader.DataType = MFDouble; break; } varHeader.Missing.Float = fieldPTR->FloatNoData(); break; } } else { if (fieldName != (char *) NULL) CMmsgPrint(CMmsgUsrError, "Warning: Fieldname ignored for continuous grid!"); itemSize = gridIF->ValueSize(); switch (gridIF->ValueType()) { case DBVariableInt: switch (itemSize) { case 1: varHeader.DataType = MFByte; break; case 2: varHeader.DataType = MFShort; break; case 4: varHeader.DataType = MFInt; break; } varHeader.Missing.Int = (int) gridIF->MissingValue(); break; case DBVariableFloat: switch (itemSize) { case 4: varHeader.DataType = MFFloat; break; case 8: varHeader.DataType = MFDouble; break; } varHeader.Missing.Float = gridIF->MissingValue(); break; } } if (tmplData == (DBObjData *) NULL) { tmplGrdIF = gridIF; varHeader.ItemNum = gridIF->RowNum() * gridIF->ColNum(); } else { switch (tmplData->Type()) { case DBTypeVectorPoint: 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; } } } if ((DBInt) fwrite(&varHeader, sizeof(MFVarHeader_t), 1, outFile) != 1) { CMmsgPrint(CMmsgSysError, "Error: Writing record header in: %s %d", __FILE__, __LINE__); ret = DBFault; break; } if ((DBInt) fwrite(data, itemSize, varHeader.ItemNum, outFile) != varHeader.ItemNum) { CMmsgPrint(CMmsgSysError, "Error: Writing data in: %s %d", __FILE__, __LINE__); ret = DBFault; break; } } } else { 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); gridRec = gridIF->GridItem(layerRec, tmplPntIF->Coordinate(pntRec)); switch (varHeader.DataType) { case MFByte: ((char *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->IntNoData(); break; case MFShort: ((short *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->IntNoData(); break; case MFInt: ((int *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->IntNoData(); break; case MFFloat: ((float *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->FloatNoData(); break; case MFDouble: ((double *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->FloatNoData(); break; } } if ((DBInt) fwrite(&varHeader, sizeof(MFVarHeader_t), 1, outFile) != 1) { CMmsgPrint(CMmsgSysError, "Error: Writing record header in: %s %d", __FILE__, __LINE__); ret = DBFault; break; } if ((DBInt) fwrite(data, itemSize, varHeader.ItemNum, outFile) != varHeader.ItemNum) { CMmsgPrint(CMmsgSysError, "Error: Writing data in: %s %d", __FILE__, __LINE__); ret = DBFault; break; } } } delete tmplPntIF; } /************************************************************** * * * Grid Template (default when no template coverage is given. * * * **************************************************************/ else if (tmplGrdIF != (DBGridIF *) NULL) { DBPosition pos; DBCoordinate coord; if (fieldPTR == (DBObjTableField *) NULL) { for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) { layerRec = gridIF->Layer(layerID); strncpy(varHeader.Date, layerRec->Name(), MFDateStringLength - 1); for (pos.Row = 0; pos.Row < tmplGrdIF->RowNum(); ++pos.Row) for (pos.Col = 0; pos.Col < tmplGrdIF->ColNum(); ++pos.Col) { itemID = pos.Row * tmplGrdIF->ColNum() + pos.Col; if ((varHeader.DataType == MFByte) || (varHeader.DataType == MFShort) || (varHeader.DataType == MFInt)) { if (tmplGrdIF != gridIF) { tmplGrdIF->Pos2Coord(pos, coord); if (gridIF->Value(layerRec, coord, &intValue) == false) intValue = varHeader.Missing.Int; } else { if (gridIF->Value(layerRec, pos, &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 (tmplGrdIF != gridIF) { tmplGrdIF->Pos2Coord(pos, coord); if (gridIF->Value(layerRec, coord, &floatValue) == false) floatValue = varHeader.Missing.Float; } else { if (gridIF->Value(layerRec, pos, &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; } } } if ((DBInt) fwrite(&varHeader, sizeof(MFVarHeader_t), 1, outFile) != 1) { CMmsgPrint(CMmsgSysError, "Error: Writing record header in: %s %d", __FILE__, __LINE__); ret = DBFault; break; } if ((DBInt) fwrite(data, itemSize, varHeader.ItemNum, outFile) != varHeader.ItemNum) { CMmsgPrint(CMmsgSysError, "Error: Writing data in: %s %d", __FILE__, __LINE__); ret = DBFault; break; } } } else { for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) { layerRec = gridIF->Layer(layerID); strncpy(varHeader.Date, layerRec->Name(), MFDateStringLength - 1); for (pos.Row = 0; pos.Row < tmplGrdIF->RowNum(); ++pos.Row) for (pos.Col = 0; pos.Col < tmplGrdIF->ColNum(); ++pos.Col) { itemID = pos.Row * tmplGrdIF->ColNum() + pos.Col; if (tmplGrdIF != gridIF) { tmplGrdIF->Pos2Coord(pos, coord); gridRec = gridIF->GridItem(layerRec, coord); } else gridRec = gridIF->GridItem(layerRec, pos); switch (varHeader.DataType) { case MFByte: ((char *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->IntNoData(); break; case MFShort: ((short *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->IntNoData(); break; case MFInt: ((int *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->IntNoData(); break; case MFFloat: ((float *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->FloatNoData(); break; case MFDouble: ((double *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->FloatNoData(); break; } } if ((DBInt) fwrite(&varHeader, sizeof(MFVarHeader_t), 1, outFile) != 1) { CMmsgPrint(CMmsgSysError, "Error: Writing record header in: %s %d", __FILE__, __LINE__); ret = DBFault; break; } if ((DBInt) fwrite(data, itemSize, varHeader.ItemNum, outFile) != varHeader.ItemNum) { CMmsgPrint(CMmsgSysError, "Error: Writing data in: %s %d", __FILE__, __LINE__); ret = DBFault; break; } } } if (tmplGrdIF != gridIF) delete tmplGrdIF; } /************************************************************** * * * Network Template * * * **************************************************************/ else if (tmplNetIF != (DBNetworkIF *) NULL) { DBObjRecord *cellRec; 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) { cellRec = tmplNetIF->Cell(itemID); if ((varHeader.DataType == MFByte) || (varHeader.DataType == MFShort) || (varHeader.DataType == MFInt)) { if (gridIF->Value(layerRec, tmplNetIF->Center(cellRec), &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, tmplNetIF->Center(cellRec), &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; } } } if ((DBInt) fwrite(&varHeader, sizeof(MFVarHeader_t), 1, outFile) != 1) { CMmsgPrint(CMmsgSysError, "Error: Writing record header in: %s %d", __FILE__, __LINE__); ret = DBFault; break; } if ((DBInt) fwrite(data, itemSize, varHeader.ItemNum, outFile) != varHeader.ItemNum) { CMmsgPrint(CMmsgSysError, "Error: Writing data in: %s %d", __FILE__, __LINE__); ret = DBFault; break; } } } else { 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) { cellRec = tmplNetIF->Cell(itemID); gridRec = gridIF->GridItem(layerRec, tmplNetIF->Center(cellRec)); switch (varHeader.DataType) { case MFByte: ((char *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->IntNoData(); break; case MFShort: ((short *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->IntNoData(); break; case MFInt: ((int *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->IntNoData(); break; case MFFloat: ((float *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Float(gridRec) : fieldPTR->FloatNoData(); break; case MFDouble: ((double *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Float(gridRec) : fieldPTR->FloatNoData(); break; } } if ((DBInt) fwrite(&varHeader, sizeof(MFVarHeader_t), 1, outFile) != 1) { CMmsgPrint(CMmsgSysError, "Error: Writing record header in: %s %d", __FILE__, __LINE__); ret = DBFault; break; } if ((DBInt) fwrite(data, itemSize, varHeader.ItemNum, outFile) != varHeader.ItemNum) { CMmsgPrint(CMmsgSysError, "Error: Writing data in: %s %d", __FILE__, __LINE__); ret = DBFault; break; } } } delete tmplNetIF; } free(data); delete gridIF; return (ret); }
DBInt DBPointToGrid(DBObjData *pntData, DBObjData *netData, DBObjData *grdData) { DBInt i; DBPosition pos; DBObjTable *pntTable = pntData->Table(DBrNItems); DBObjTable *grdTable = grdData->Table(DBrNItems); DBObjTable *symTable = grdData->Table(DBrNSymbols); DBObjectLIST<DBObjTableField> *pntFields = pntTable->Fields(); DBObjTableField *pntFLD; DBObjTableField *grdAttribFLD; DBObjTableField *grdFLD = grdTable->Field(DBrNGridValue); DBObjTableField *symFLD = grdTable->Field(DBrNSymbol); DBObjRecord *cellRec, *toCell, *pntRec, *itemRec; DBObjRecord *symRec = symTable->First(); DBVPointIF *pntIF; DBNetworkIF *netIF; DBGridIF *grdIF; pntIF = new DBVPointIF(pntData); netIF = new DBNetworkIF(netData); grdIF = new DBGridIF(grdData); grdIF->RenameLayer(grdIF->Layer((DBInt) 0), (char *) "Subbasins"); for (pos.Row = 0; pos.Row < grdIF->RowNum(); ++pos.Row) for (pos.Col = 0; pos.Col < grdIF->ColNum(); ++pos.Col) grdIF->Value(pos, DBFault); for (pntFLD = pntFields->First(); pntFLD != (DBObjTableField *) NULL; pntFLD = pntFields->Next()) if (DBTableFieldIsVisible(pntFLD)) grdTable->AddField(new DBObjTableField(*pntFLD)); for (i = 0; i < pntIF->ItemNum(); ++i) { DBPause(i * 100 / pntIF->ItemNum()); pntRec = pntIF->Item(i); if ((pntRec->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle) continue; if ((cellRec = netIF->Cell(pntIF->Coordinate(pntRec))) == (DBObjRecord *) NULL) continue; itemRec = grdTable->Add(pntRec->Name()); grdFLD->Int(itemRec, pntRec->RowID() + 1); symFLD->Record(itemRec, symRec); for (pntFLD = pntFields->First(); pntFLD != (DBObjTableField *) NULL; pntFLD = pntFields->Next()) if ((grdAttribFLD = grdTable->Field(pntFLD->Name())) != (DBObjTableField *) NULL) switch (pntFLD->Type()) { case DBTableFieldString: grdAttribFLD->String(itemRec, pntFLD->String(pntRec)); break; case DBTableFieldInt: grdAttribFLD->Int(itemRec, pntFLD->Int(pntRec)); break; case DBTableFieldFloat: grdAttribFLD->Float(itemRec, pntFLD->Float(pntRec)); break; case DBTableFieldDate: grdAttribFLD->Date(itemRec, pntFLD->Date(pntRec)); break; } grdIF->Value(netIF->CellPosition(cellRec), itemRec->RowID()); } for (i = 0; i < netIF->CellNum(); ++i) { if ((cellRec = netIF->Cell(i)) == (DBObjRecord *) NULL) continue; if ((itemRec = grdIF->GridItem(netIF->CellPosition(cellRec))) != (DBObjRecord *) NULL) continue; if ((toCell = netIF->ToCell(cellRec)) == (DBObjRecord *) NULL) continue; if ((itemRec = grdIF->GridItem(netIF->CellPosition(toCell))) != (DBObjRecord *) NULL) grdIF->Value(netIF->CellPosition(cellRec), itemRec->RowID()); } grdIF->DiscreteStats(); delete pntIF; delete netIF; delete grdIF; return (DBSuccess); }
DBInt RGlibDataStream2RGIS(DBObjData *outData, DBObjData *tmplData, FILE *inFile) { DBInt layerID = 0, itemSize; DBPosition pos; DBFloat val; void *data = (void *) NULL; MFVarHeader_t header; DBObjRecord *record; switch (tmplData->Type()) { case DBTypeVectorPoint: { DBInt itemID; DBDate date; DBObjTable *itemTable = outData->Table(DBrNItems); DBObjTableField *idField = new DBObjTableField("ItemID", DBTableFieldInt, "%6d", sizeof(DBInt), false); DBObjTableField *dateField = new DBObjTableField("Date", DBTableFieldDate, "%s", sizeof(DBDate), false); DBObjTableField *valField; DBVPointIF *pntIF = new DBVPointIF(tmplData); itemTable->AddField(idField); itemTable->AddField(dateField); while (MFVarReadHeader(&header, inFile)) { if (header.ItemNum != pntIF->ItemNum()) { CMmsgPrint(CMmsgUsrError, "Error: Datastream inconsistency %d %d!", header.ItemNum, pntIF->ItemNum()); return (DBFault); } if (data == (void *) NULL) { itemSize = MFVarItemSize(header.DataType); if ((data = (void *) realloc(data, header.ItemNum * itemSize)) == (void *) NULL) { CMmsgPrint(CMmsgSysError, "Memory allocation error in: %s %d", __FILE__, __LINE__); return (DBFault); } switch (header.DataType) { case MFByte: valField = new DBObjTableField("Value", DBTableFieldInt, "%2d", sizeof(char), false); case MFShort: valField = new DBObjTableField("Value", DBTableFieldInt, "%4d", sizeof(DBShort), false); case MFInt: valField = new DBObjTableField("Value", DBTableFieldInt, "%8d", sizeof(DBInt), false); case MFFloat: valField = new DBObjTableField("Value", DBTableFieldFloat, "%8.2f", sizeof(DBFloat4), false); case MFDouble: valField = new DBObjTableField("Value", DBTableFieldFloat, "%8.2f", sizeof(DBFloat), false); } itemTable->AddField(valField); } if ((int) fread(data, itemSize, header.ItemNum, inFile) != header.ItemNum) { CMmsgPrint(CMmsgSysError, "Error: Data stream read in: %s %d", __FILE__, __LINE__); return (DBFault); } for (itemID = 0; itemID < header.ItemNum; ++itemID) { record = itemTable->Add(header.Date); date.Set(header.Date); idField->Int(record, itemID); dateField->Date(record, date); /* decDateField->Float (record,date); */ switch (header.DataType) { case MFByte: valField->Int(record, ((char *) data)[itemID]); break; case MFShort: valField->Int(record, ((short *) data)[itemID]); break; case MFInt: valField->Int(record, ((int *) data)[itemID]); break; case MFFloat: valField->Float(record, ((float *) data)[itemID]); break; case MFDouble: valField->Float(record, ((double *) data)[itemID]); break; } } } delete pntIF; } break; case DBTypeGridContinuous: case DBTypeGridDiscrete: { DBGridIF *gridIF = new DBGridIF(outData); while (MFVarReadHeader(&header, inFile)) { if (header.ItemNum != gridIF->RowNum() * gridIF->ColNum()) { CMmsgPrint(CMmsgUsrError, "Error: Datastream inconsistency!"); return (DBFault); } if (layerID == 0) { itemSize = MFVarItemSize(header.DataType); if ((data = (void *) realloc(data, header.ItemNum * itemSize)) == (void *) NULL) { CMmsgPrint(CMmsgSysError, "Memory allocation error in: %s %d", __FILE__, __LINE__); return (DBFault); } record = gridIF->Layer(layerID); gridIF->RenameLayer(header.Date); } else record = gridIF->AddLayer(header.Date); switch (header.DataType) { case MFByte: case MFShort: case MFInt: gridIF->MissingValue(record, header.Missing.Int); break; case MFFloat: case MFDouble: gridIF->MissingValue(record, header.Missing.Float); break; } if ((int) fread(data, itemSize, header.ItemNum, inFile) != header.ItemNum) { CMmsgPrint(CMmsgSysError, "Error: Data stream read in: %s %d", __FILE__, __LINE__); return (DBFault); } for (pos.Row = 0; pos.Row < gridIF->RowNum(); ++pos.Row) for (pos.Col = 0; pos.Col < gridIF->ColNum(); ++pos.Col) { switch (header.DataType) { case MFByte: val = (DBFloat) (((char *) data)[pos.Row * gridIF->ColNum() + pos.Col]); break; case MFShort: val = (DBFloat) (((short *) data)[pos.Row * gridIF->ColNum() + pos.Col]); break; case MFInt: val = (DBFloat) (((int *) data)[pos.Row * gridIF->ColNum() + pos.Col]); break; case MFFloat: val = (DBFloat) (((float *) data)[pos.Row * gridIF->ColNum() + pos.Col]); break; case MFDouble: val = (DBFloat) (((double *) data)[pos.Row * gridIF->ColNum() + pos.Col]); break; } gridIF->Value(record, pos, val); } layerID++; } gridIF->RecalcStats(); } break; case DBTypeNetwork: { DBInt cellID; DBGridIF *gridIF = new DBGridIF(outData); DBNetworkIF *netIF = new DBNetworkIF(tmplData); while (MFVarReadHeader(&header, inFile)) { if (header.ItemNum != netIF->CellNum()) { CMmsgPrint(CMmsgUsrError, "Error: Datastream inconsistency!"); return (DBFault); } if (layerID == 0) { itemSize = MFVarItemSize(header.DataType); if ((data = (void *) realloc(data, header.ItemNum * itemSize)) == (void *) NULL) { CMmsgPrint(CMmsgSysError, "Memory allocation error in: %s %d", __FILE__, __LINE__); return (DBFault); } record = gridIF->Layer(layerID); gridIF->RenameLayer(header.Date); } else record = gridIF->AddLayer(header.Date); if ((int) fread(data, itemSize, header.ItemNum, inFile) != header.ItemNum) { CMmsgPrint(CMmsgSysError, "Error: Data stream read in: %s %d", __FILE__, __LINE__); delete netIF; return (DBFault); } for (pos.Row = 0; pos.Row < gridIF->RowNum(); ++pos.Row) for (pos.Col = 0; pos.Col < gridIF->ColNum(); ++pos.Col) gridIF->Value(record, pos, gridIF->MissingValue()); for (cellID = 0; cellID < netIF->CellNum(); ++cellID) { pos = netIF->CellPosition(netIF->Cell(cellID)); switch (header.DataType) { case MFByte: val = (DBFloat) (((char *) data)[cellID]); break; case MFShort: val = (DBFloat) (((short *) data)[cellID]); break; case MFInt: val = (DBFloat) (((int *) data)[cellID]); break; case MFFloat: val = (DBFloat) (((float *) data)[cellID]); break; case MFDouble: val = (DBFloat) (((double *) data)[cellID]); break; } gridIF->Value(record, pos, val); } layerID++; } gridIF->RecalcStats(); } break; } return (DBSuccess); }
int main (int argc,char *argv []) { int argPos, argNum = argc, ret, verbose = false; DBInt recID; bool padding = false; char *tableName = (char *) NULL; char *fieldName = (char *) NULL; char *yearFieldName = (char *) NULL; char *monthFieldName = (char *) NULL; char *dayFieldName = (char *) NULL; char *hourFieldName = (char *) NULL; char *minFieldName = (char *) NULL; char *tmp = (char *) NULL; DBObjData *data; DBObjTable *table; DBObjTableField *srcField; DBObjTableField *yearField = (DBObjTableField *) NULL; DBObjTableField *monthField= (DBObjTableField *) NULL; DBObjTableField *dayField = (DBObjTableField *) NULL; DBObjTableField *hourField = (DBObjTableField *) NULL; DBObjTableField *minField = (DBObjTableField *) NULL; DBInt dbInputType = DBTableFieldInt; DBInt dbInputSize = sizeof(DBShort); DBDate date; DBObjRecord *record; for (argPos = 1;argPos < argNum; ) { if (CMargTest (argv [argPos],"-a","--table")) { if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing table name!"); return (CMfailed); } tableName = argv [argPos]; if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest (argv [argPos],"-f","--field")) { if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing field name!"); return (CMfailed); } fieldName = argv [argPos]; if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest (argv [argPos],"-y","--year")) { if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing year field name!"); return (CMfailed); } yearFieldName = argv [argPos]; if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest (argv [argPos],"-m","--month")) { if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing month field name!"); return (CMfailed); } monthFieldName = argv [argPos]; if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest (argv [argPos],"-d","--day")) { if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing day field name!"); return (CMfailed); } dayFieldName = argv [argPos]; if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest (argv [argPos],"-o","--hour")) { if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing hour field name!"); return (CMfailed); } hourFieldName = argv [argPos]; if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest (argv [argPos],"-i","--minute")) { if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing minute field name!"); return (CMfailed); } minFieldName = argv [argPos]; if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest (argv [argPos],"-p","--padding")) { padding = true; dbInputType = DBTableFieldString; dbInputSize = sizeof(DBByte) * 3; if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest (argv [argPos],"-V","--verbose")) { verbose = true; if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest (argv [argPos],"-h","--help")) { CMmsgPrint (CMmsgInfo,"%s [options] <input file> <output file>",CMfileName(argv[0])); CMmsgPrint (CMmsgInfo," -a,--table [table name]"); CMmsgPrint (CMmsgInfo," -f,--field [field name]"); CMmsgPrint (CMmsgInfo," -y,--year [year field]"); CMmsgPrint (CMmsgInfo," -m,--month [month field]"); CMmsgPrint (CMmsgInfo," -d,--day [day field]"); CMmsgPrint (CMmsgInfo," -o,--hour [hour field]"); CMmsgPrint (CMmsgInfo," -i,--minute [minute field]"); CMmsgPrint (CMmsgInfo," -p,--padding"); CMmsgPrint (CMmsgInfo," -V,--verbose"); CMmsgPrint (CMmsgInfo," -h,--help"); return (DBSuccess); } if ((argv [argPos][0] == '-') && ((int) strlen (argv [argPos]) > 1)) { CMmsgPrint (CMmsgUsrError,"Unknown option: %s!",argv [argPos]); return (CMfailed); } argPos++; } if (argNum > 3) { CMmsgPrint (CMmsgUsrError,"Extra arguments!"); return (CMfailed); } if (verbose) RGlibPauseOpen (argv[0]); data = new DBObjData (); if (((argNum > 1) && (strcmp (argv [1],"-") != 0) ? data->Read (argv [1]) : data->Read (stdin)) == DBFault) { delete data; return (CMfailed); } if (tableName == (char *) NULL) tableName = DBrNItems; if ((table = data->Table (tableName)) == (DBObjTable *) NULL) { CMmsgPrint (CMmsgUsrError,"Invalid table!"); delete data; return (CMfailed); } if (fieldName == (char *) NULL) fieldName = (char *) "Date"; if ((srcField = table->Field (fieldName)) == (DBObjTableField *) NULL) { CMmsgPrint (CMmsgUsrError,"Missing date field!"); delete data; return (CMfailed); } if ((srcField->Type () != DBTableFieldString) && (srcField->Type () != DBTableFieldDate)) { CMmsgPrint (CMmsgUsrError,"Invalid date field!"); delete data; return (CMfailed); } if (yearFieldName != (char *) NULL) { if ((yearField = table->Field (yearFieldName)) == (DBObjTableField *) NULL) { yearField = new DBObjTableField (yearFieldName,DBTableFieldInt,"%4d",sizeof(DBShort),false); table->AddField (yearField); } } if (monthFieldName != (char *) NULL) { if ((monthField = table->Field (monthFieldName)) == (DBObjTableField *) NULL) { monthField = new DBObjTableField (monthFieldName,dbInputType,"%2d",dbInputSize,false); table->AddField (monthField); } } if (dayFieldName != (char *) NULL) { if (monthField == (DBObjTableField *) NULL) { CMmsgPrint (CMmsgUsrError,"Month field is not set!"); delete data; return (CMfailed); } if ((dayField = table->Field (dayFieldName)) == (DBObjTableField *) NULL) { dayField = new DBObjTableField (dayFieldName,dbInputType,"%2d",dbInputSize,false); table->AddField (dayField); } } if (hourFieldName != (char *) NULL) { if (dayField == (DBObjTableField *) NULL) { CMmsgPrint (CMmsgUsrError,"Day field is not set!"); delete data; return (CMfailed); } if ((hourField = table->Field (hourFieldName)) == (DBObjTableField *) NULL) { hourField = new DBObjTableField (hourFieldName,dbInputType,"%2d",dbInputSize,false); table->AddField (hourField); } } if (minFieldName != (char *) NULL) { if (hourField == (DBObjTableField *) NULL) { CMmsgPrint (CMmsgUsrError,"Hour field is not set!"); delete data; return (CMfailed); } if ((minField = table->Field (minFieldName)) == (DBObjTableField *) NULL) { minField = new DBObjTableField (minFieldName,dbInputType,"%2d",dbInputSize,false); table->AddField (minField); } } for (recID = 0;recID < table->ItemNum ();++recID) { record = table->Item (recID); if (srcField->Type () == DBTableFieldString) date.Set (srcField->String (record)); else date = srcField->Date (record); if (yearField != (DBObjTableField *) NULL) yearField->Int(record,date.Year ()); if(padding) { if (monthField != (DBObjTableField *) NULL) { if (date.Month() != DBDefaultMissingIntVal) monthField->String (record,tmp = _CMDpadit(date.Month() + 1,false)); else monthField->String (record,tmp = _CMDpadit(date.Month(),false)); free(tmp); } if (dayField != (DBObjTableField *) NULL) { dayField->String (record,tmp = _CMDpadit(date.Day(),false)); free(tmp); } if (hourField != (DBObjTableField *) NULL) { hourField->String (record,tmp = _CMDpadit(date.Hour(),false)); free(tmp); } if (minField != (DBObjTableField *) NULL) { minField->String (record,tmp = _CMDpadit(date.Minute(),false)); free(tmp); } } else { if (monthField != (DBObjTableField *) NULL) { if (date.Month() != DBDefaultMissingIntVal) monthField->Int(record,date.Month () + 1); else monthField->Int (record,DBDefaultMissingIntVal); } if (dayField != (DBObjTableField *) NULL) dayField->Int (record,date.Day ()); if (hourField != (DBObjTableField *) NULL) hourField->Int(record,date.Hour ()); if (minField != (DBObjTableField *) NULL) minField->Int (record,date.Minute ()); } } ret = (argNum > 2) && (strcmp (argv [2],"-") != 0) ? data->Write (argv [2]) : data->Write (stdout); delete data; if (verbose) RGlibPauseClose (); return (ret); }
DBInt SymbolID () const { return (SymbolIDFLD->Int ((DBObjRecord *) this)); }
void RGISAnalyseLineSSampleGridCBK (Widget widget, RGISWorkspace *workspace,XmAnyCallbackStruct *callData) { char *fText; int allowOk; static int sample; DBDataset *dataset = UIDataset (); DBObjData *dbData = dataset->Data (), *grdData = dbData->LinkedData (); DBObjTable *itemTable = dbData->Table (DBrNItems); static Widget dShell = (Widget) NULL, mainForm; static Widget fromNameTextF, toNameTextF; XmString string; widget = widget; workspace = workspace; callData = callData; _RGISAnLineSampleGridFields = itemTable->Fields (); if (dShell == (Widget) NULL) { Widget button; dShell = UIDialogForm ((char *) "Single Layer Grid Sampling",false); mainForm = UIDialogFormGetMainForm (dShell); string = XmStringCreate ((char *) "Select",UICharSetBold); button = XtVaCreateManagedWidget ("RGISAnalyseLineSSampleNameButton",xmPushButtonWidgetClass,mainForm, XmNtopAttachment, XmATTACH_FORM, XmNtopOffset, 10, XmNrightAttachment, XmATTACH_FORM, XmNrightOffset, 10, XmNmarginHeight, 5, XmNtraversalOn, False, XmNlabelString, string, XmNuserData, grdData->Type () == DBTypeGridContinuous ? DBTableFieldIsNumeric : DBTableFieldIsCategory, NULL); XmStringFree (string); fromNameTextF = XtVaCreateManagedWidget ("RGISAnalyseLineSSampleNameTextF",xmTextFieldWidgetClass,mainForm, XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET, XmNtopWidget, button, XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, button, XmNrightOffset, 10, XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET, XmNbottomWidget, button, XmNmaxLength, DBStringLength, XmNcolumns, DBStringLength / 2, NULL); XtAddCallback (button,XmNactivateCallback,(XtCallbackProc) _RGIAnalyseLineSSampleGridSSelectCBK,fromNameTextF); string = XmStringCreate ((char *) "From Field:",UICharSetBold); XtVaCreateManagedWidget ("RGISAnalyseLineSSampleNameLabel",xmLabelWidgetClass,mainForm, XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET, XmNtopWidget, button, XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, 10, XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, fromNameTextF, XmNrightOffset, 10, XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET, XmNbottomWidget, button, XmNlabelString, string, NULL); XmStringFree (string); string = XmStringCreate ((char *) "Select",UICharSetBold); button = XtVaCreateManagedWidget ("RGISAnalyseLineSSampleNameButton",xmPushButtonWidgetClass,mainForm, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, button, XmNtopOffset, 10, XmNrightAttachment, XmATTACH_FORM, XmNrightOffset, 10, XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, 10, XmNmarginHeight, 5, XmNtraversalOn, False, XmNlabelString, string, XmNuserData, grdData->Type () == DBTypeGridContinuous ? DBTableFieldIsNumeric : DBTableFieldIsCategory, NULL); XmStringFree (string); toNameTextF = XtVaCreateManagedWidget ("RGISAnalyseLineSSampleNameTextF",xmTextFieldWidgetClass,mainForm, XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET, XmNtopWidget, button, XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, button, XmNrightOffset, 10, XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET, XmNbottomWidget, button, XmNmaxLength, DBStringLength, XmNcolumns, DBStringLength / 2, NULL); XtAddCallback (button,XmNactivateCallback,(XtCallbackProc) _RGIAnalyseLineSSampleGridSSelectCBK,toNameTextF); string = XmStringCreate ((char *) "To Field:",UICharSetBold); XtVaCreateManagedWidget ("RGISAnalyseLineSSampleNameLabel",xmLabelWidgetClass,mainForm, XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET, XmNtopWidget, button, XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, 10, XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, toNameTextF, XmNrightOffset, 10, XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET, XmNbottomWidget, button, XmNlabelString, string, NULL); XmStringFree (string); XtAddCallback (UIDialogFormGetOkButton (dShell),XmNactivateCallback,(XtCallbackProc) UIAuxSetBooleanTrueCBK,&sample); } sample = false; UIDialogFormPopup (dShell); while (UILoop ()) { allowOk = false; fText = XmTextFieldGetString (fromNameTextF); if (strlen (fText) > 0) allowOk = true; XtFree (fText); fText = XmTextFieldGetString (toNameTextF); if (strlen (fText) > 0) allowOk = true; XtFree (fText); XtSetSensitive (UIDialogFormGetOkButton (dShell),allowOk); } UIDialogFormPopdown (dShell); if (sample) { DBInt ret; DBFloat value; DBCoordinate coord; DBGridIF *gridIF = new DBGridIF (grdData); DBVLineIF *lineIF = new DBVLineIF (dbData); DBObjTableField *fromField; DBObjTableField *toField; DBObjRecord *record; fText = XmTextFieldGetString (fromNameTextF); if (strlen (fText) > 0) { if ((fromField = itemTable->Field (fText)) == (DBObjTableField *) NULL) itemTable->AddField (fromField = new DBObjTableField (fText,DBTableFieldFloat,"%10.3f",sizeof (DBFloat4))); } else fromField = (DBObjTableField *) NULL; XtFree (fText); fText = XmTextFieldGetString (toNameTextF); if (strlen (fText) > 0) { if ((toField = itemTable->Field (fText)) == (DBObjTableField *) NULL) itemTable->AddField (toField = new DBObjTableField (fText,DBTableFieldFloat,"%10.3f",sizeof (DBFloat4))); } else toField = (DBObjTableField *) NULL; XtFree (fText); UIPauseDialogOpen ((char *) "Sampling Grid"); for (record = itemTable->First ();record != (DBObjRecord *) NULL;record = itemTable->Next ()) { if (UIPause (record->RowID () * 100 / itemTable->ItemNum ())) goto Stop; if (fromField != (DBObjTableField *) NULL) { coord = lineIF->FromCoord (record); ret = gridIF->Value (coord,&value); if (fromField->Type () == DBTableFieldFloat) { if (ret) fromField->Float (record,value); else fromField->Float (record,fromField->FloatNoData ()); } else { if (ret) fromField->Int (record,(DBInt) value); else fromField->Int (record,fromField->IntNoData ()); } } if (toField != (DBObjTableField *) NULL) { coord = lineIF->ToCoord (record); ret = gridIF->Value (coord,&value); if (toField->Type () == DBTableFieldFloat) { if (ret) toField->Float (record,value); else toField->Float (record,toField->FloatNoData ()); } else { if (ret) toField->Int (record,(DBInt) value); else toField->Int (record,toField->IntNoData ()); } } } Stop: UIPauseDialogClose (); delete lineIF; delete gridIF; } }
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); }