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); }
Widget RGISGrpPanel::Load (DBObjData *data) { DBObjTable *groupTable = data->Table (DBrNGroups); XmListDeleteAllItems (GroupListWGT); if (groupTable != (DBObjTable *) NULL) { DBObjTableField *group; GroupLIST = groupTable->Fields (); for (group = GroupLIST->First ();group != (DBObjTableField *) NULL;group = GroupLIST->Next ()) Add (group); XtSetSensitive (DeleteButtonWGT,True); XtSetSensitive (LoadButtonWGT,True); XtSetSensitive (SaveButtonWGT,True); XtVaSetValues (GroupListWGT,XmNuserData, data, NULL); } else { XtSetSensitive (DeleteButtonWGT,False); XtSetSensitive (LoadButtonWGT,False); XtSetSensitive (SaveButtonWGT,False); } return (Form ()); }
DBObjData::DBObjData(DBObjData &data) : DBObject(data), DBDataHeader(data._Header()) { DBObjTable *table; DBObjRecord *record, *obj; DBObjTableField *field; DBObjectLIST<DBObjTableField> *fields; strcpy(FileNameSTR, ""); TablesPTR = new DBObjectLIST<DBObjTable>(*data.TablesPTR); DocsPTR = new DBObjectLIST<DBObjRecord>(*data.DocsPTR); ArraysPTR = new DBObjectLIST<DBObjRecord>(*data.ArraysPTR); DispPTR = new DBObjectLIST<DBObject>("Data Display"); LinkedDataPTR = (DBObjData *) NULL; for (table = TablesPTR->First(); table != (DBObjTable *) NULL; table = TablesPTR->Next()) { fields = table->Fields(); for (record = table->First(); record != (DBObjRecord *) NULL; record = table->Next()) { for (field = fields->First(); field != (DBObjTableField *) NULL; field = fields->Next()) switch (field->Type()) { case DBTableFieldTableRec: case DBTableFieldDataRec: if ((obj = field->Record(record)) != NULL) field->Record(record, (DBObjRecord *) ((char *) NULL + obj->RowID())); else field->Record(record, (DBObjRecord *) DBFault); break; } } } BuildFields(); }
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); }
void RGISAnNetworkToGridCBK (Widget widget,RGISWorkspace *workspace,XmAnyCallbackStruct *callData) { char *selection; DBInt dataType; DBDataset *dataset = UIDataset (); DBObjData *netData = dataset->Data (); DBObjTable *cellTable = netData->Table (DBrNCells); DBObjTableField *field; DBObjData *grdData; static Widget select = NULL; if (select == NULL) select = UISelectionCreate ((char *) "Field Selection"); selection = UISelectObject (select,(DBObjectLIST<DBObject> *) (cellTable->Fields ()),DBTableFieldIsSimple); if (selection == (char *) NULL) return; if ((field = cellTable->Field (selection)) == (DBObjTableField *) NULL) { CMmsgPrint (CMmsgAppError,"Corrupt Network Dataset in: %s %d",__FILE__,__LINE__); return; } if (DBTableFieldIsCategory (field) && DBTableFieldIsNumeric (field)) { DBObjData *tmpData; tmpData = new DBObjData ("",DBTypeGrid); tmpData->Document (DBDocGeoDomain,netData->Document (DBDocGeoDomain)); tmpData->Document (DBDocSubject,field->Name ()); if (UIDataHeaderForm (tmpData)) { grdData = DBNetworkToGrid (netData,tmpData->Type ()); grdData->Name (tmpData->Name ()); grdData->Document (DBDocGeoDomain,tmpData->Document (DBDocGeoDomain)); grdData->Document (DBDocSubject,tmpData->Document (DBDocSubject)); grdData->Document (DBDocVersion,tmpData->Document (DBDocVersion)); grdData->Document (DBDocCitationRef,tmpData->Document (DBDocCitationRef)); grdData->Document (DBDocCitationInst,tmpData->Document (DBDocCitationInst)); grdData->Document (DBDocSourceInst,tmpData->Document (DBDocSourceInst)); grdData->Document (DBDocSourcePerson,tmpData->Document (DBDocSourcePerson)); grdData->Document (DBDocOwnerPerson,tmpData->Document (DBDocOwnerPerson)); grdData->Document (DBDocComment,tmpData->Document (DBDocComment)); delete tmpData; } else { return; } } else { if (DBTableFieldIsCategory (field)) dataType = DBTypeGridDiscrete; else if (DBTableFieldIsNumeric (field)) dataType = DBTypeGridContinuous; else { CMmsgPrint (CMmsgAppError,"Invalid field type in: %s %d",__FILE__,__LINE__); return; } grdData = DBNetworkToGrid (netData,dataType); if (UIDataHeaderForm (grdData) == false) { delete grdData; return; } } UIPauseDialogOpen ((char *) "Converting Network to Grid"); if (RGlibNetworkToGrid (netData,field,grdData) == DBSuccess) workspace->CurrentData (grdData); else delete grdData; UIPauseDialogClose (); }
DBInt Configure(DBObjTable *table, bool flat) { DBInt i; char *dataName; char *fieldName = (char *) NULL; DBObjData *data; dataName = TargetFLD->Name(); if ((dataName = (char *) malloc(strlen(dataName) + 1)) == (char *) NULL) { CMmsgPrint(CMmsgSysError, "Memory allocation error in: %s %d", __FILE__, __LINE__); return (CMfailed); } strcpy(dataName, TargetFLD->Name()); for (i = 0; i < (DBInt) strlen(dataName); ++i) if (dataName[i] == ':') { fieldName = dataName + i + 1; dataName[i] = '\0'; i = 0; break; } data = new DBObjData(); if ((strcmp(dataName, "stdin") == 0 ? data->Read(stdin) : data->Read(dataName)) == DBFault) { CMmsgPrint(CMmsgUsrError, "%s", dataName); return (CMfailed); } if (data->Type() == DBTypeGridDiscrete) { DBObjTable *table = data->Table(DBrNItems); if (fieldName == (char *) NULL) fieldName = DBrNGridValue; if ((SourceFLD = table->Field(fieldName)) == (DBObjTableField *) NULL) { CMmsgPrint(CMmsgUsrError, "Invalid field [%s]!", fieldName); return (CMfailed); } strcpy(dataName, TargetFLD->Name()); delete TargetFLD; TargetFLD = new DBObjTableField(*SourceFLD); TargetFLD->Name(dataName); } else { if (fieldName != (char *) NULL) { CMmsgPrint(CMmsgUsrError, "Continuous grid field is referenced!"); free(dataName); return (CMfailed); } } table->AddField(TargetFLD); GridIF = new DBGridIF(data, flat); free(dataName); return (DBSuccess); }
static void _RGISGridLayerListCBK (Widget widget,void *dummy, XmListCallbackStruct *callData) { int item = 0; DBObjData *data; DBObjTable *layerTable; DBObjRecord *record; XtVaGetValues (widget,XmNuserData, &data, NULL); layerTable = data->Table (DBrNLayers); for (record = layerTable->First ();record != (DBObjRecord *) NULL;record = layerTable->Next ()) if (++item == callData->item_position) layerTable->Item (record->RowID (),true); }
DBInt RGlibPointSubbasinCenter(DBObjData *pntData, DBObjData *netData) { DBCoordinate massCoord; DBVPointIF *pntIF = new DBVPointIF(pntData); DBObjTable *pointTable = pntData->Table(DBrNItems); DBObjTableField *massCoordXFLD = pointTable->Field(RGlibMassCoordX); DBObjTableField *massCoordYFLD = pointTable->Field(RGlibMassCoordY); DBNetworkIF *netIF = new DBNetworkIF(netData); DBObjRecord *pointRec, *cellRec; if (massCoordXFLD == NULL) { massCoordXFLD = new DBObjTableField(RGlibMassCoordX, DBTableFieldFloat, "%10.3f", sizeof(DBFloat4)); pointTable->AddField(massCoordXFLD); } if (massCoordYFLD == NULL) { massCoordYFLD = new DBObjTableField(RGlibMassCoordY, DBTableFieldFloat, "%10.3f", sizeof(DBFloat4)); pointTable->AddField(massCoordYFLD); } for (pointRec = pntIF->FirstItem(); pointRec != (DBObjRecord *) NULL; pointRec = pntIF->NextItem()) { if ((pointRec->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle) { massCoordXFLD->Float(pointRec, massCoordXFLD->FloatNoData()); massCoordYFLD->Float(pointRec, massCoordYFLD->FloatNoData()); continue; } if (DBPause(pointRec->RowID() * 100 / pntIF->ItemNum())) goto Stop; if ((cellRec = netIF->Cell(pntIF->Coordinate(pointRec))) == (DBObjRecord *) NULL) massCoord = pntIF->Coordinate(pointRec); else { if (netIF->CellBasinCells(cellRec) > 1) { massCoord.X = 0.0; massCoord.Y = 0.0; netIF->UpStreamSearch(cellRec, (DBNetworkACTION) _RGlibSubbasinCenterAction, &massCoord); massCoord.X = massCoord.X / (DBFloat) netIF->CellBasinCells(cellRec); massCoord.Y = massCoord.Y / (DBFloat) netIF->CellBasinCells(cellRec); } else massCoord = netIF->Center(cellRec); } massCoordXFLD->Float(pointRec, massCoord.X); massCoordYFLD->Float(pointRec, massCoord.Y); } Stop: if (pointRec != (DBObjRecord *) NULL) { pointTable->DeleteField(massCoordXFLD); pointTable->DeleteField(massCoordYFLD); return (DBFault); } return (DBSuccess); }
DBRegion DBObjData::Extent(DBObjRecord *record) { DBRegion extent; DBCoordinate coord; DBFloat delta; DBObjTable *items; DBObjTableField *field; if (record == (DBObjRecord *) NULL) return (Extent()); switch (Type()) { case DBTypeVectorPoint: delta = pow((double) 10.0, (double) Precision()); items = TablesPTR->Item(DBrNItems); field = items->Field(DBrNCoord); coord = field->Coordinate(record); extent.Expand(coord + delta); extent.Expand(coord - delta); return (extent); case DBTypeVectorLine: case DBTypeVectorPolygon: items = TablesPTR->Item(DBrNItems); field = items->Field(DBrNRegion); return (field->Region(record)); case DBTypeGridDiscrete: case DBTypeGridContinuous: return (Extent()); case DBTypeNetwork: { DBInt cellID, cellNum; DBObjRecord *cellRec; DBNetworkIF *netIF = new DBNetworkIF(this); cellRec = netIF->MouthCell(record); cellNum = netIF->CellBasinCells(cellRec) + cellRec->RowID(); for (cellID = cellRec->RowID(); cellID < cellNum; ++cellID) { cellRec = netIF->Cell(cellID); extent.Expand(netIF->Center(cellRec) + (netIF->CellSize() / 2.0)); extent.Expand(netIF->Center(cellRec) - (netIF->CellSize() / 2.0)); } delete netIF; } return (extent); case DBTypeTable: default: return (extent); } }
static void _RGISGridGroupListCBK (Widget widget,RGISGrpPanel *grpPanel, XmListCallbackStruct *callData) { DBObjData *data; DBObjTable *groupTable; DBObjectLIST<DBObjTableField> *groups; DBObjTableField *group = (DBObjTableField *) NULL; XtVaGetValues (widget,XmNuserData, &data, NULL); if (data == (DBObjData *) NULL) return; if ((groupTable = data->Table (DBrNGroups)) != (DBObjTable *) NULL) { groups = groupTable->Fields (); if ((group = groups->Item (callData->item_position - 1)) != (DBObjTableField *) NULL) grpPanel->Current (group); } }
CMreturn Configure(bool shrink, bool flat, char *expStr) { size_t i; DBInt recID, layerID; DBFloat floatVal; DBObject *obj; DBObjTableField *fieldPTR; Operand = new DBMathOperand(expStr); if (Operand->Expand(Variables) == DBFault) return (CMfailed); CellSize.X = CellSize.Y = DBHugeVal; for (recID = 0; recID < Variables->ItemNum(); ++recID) { obj = Variables->Item(recID); if ((fieldPTR = Table->Field(obj->Name())) != (DBObjTableField *) NULL) continue; if ((GrdVar = (CMDgrdVariable **) realloc(GrdVar, sizeof(CMDgrdVariable *) * (VarNum + 1))) == (CMDgrdVariable **) NULL) { CMmsgPrint(CMmsgSysError, "Memory Allocation Error in: %s %d", __FILE__, __LINE__); return (CMfailed); } GrdVar[VarNum] = new CMDgrdVariable(obj->Name()); if (GrdVar[VarNum]->Configure(Table, flat) == DBFault) { for (i = 0; i <= VarNum; ++i) delete GrdVar[i]; free(GrdVar); return (CMfailed); } Extent.Expand(GrdVar[VarNum]->Extent()); floatVal = GrdVar[VarNum]->CellWidth(); if (CellSize.X > floatVal) CellSize.X = floatVal; floatVal = GrdVar[VarNum]->CellHeight(); if (CellSize.Y > floatVal) CellSize.Y = floatVal; layerID = (GrdVar[VarNum])->LayerNum(); if (LayerNum < layerID) { LayerNum = layerID; MasterVar = VarNum; } VarNum++; } for (i = 0; i < ExpNum; ++i) if (Expressions[i]->Configure(Table) == DBFault) return (CMfailed); Operand->Configure(Table->Fields()); if (shrink) for (i = 0; i < VarNum; ++i) Extent.Shrink(GrdVar[i]->Extent()); return (CMsucceeded); }
void RGISAnalysePointSubbasinCenterCBK (Widget widget, RGISWorkspace *workspace,XmAnyCallbackStruct *callData) { DBDataset *dataset = UIDataset (); DBObjData *pntData =dataset->Data (); DBObjTable *pointTable = pntData->Table (DBrNItems); DBObjTableField *massCoordXFLD = pointTable->Field (RGlibMassCoordX); DBObjTableField *massCoordYFLD = pointTable->Field (RGlibMassCoordY); DBObjData *netData = pntData->LinkedData (); UITable *tableCLS = (UITable *) pntData->Display (UITableName (pntData,pointTable)); UIPauseDialogOpen ((char *) "Subbasin Centers"); if ((RGlibPointSubbasinCenter (pntData, netData) == DBSuccess) && (tableCLS != (UITable *) NULL)) { if (massCoordXFLD == NULL) tableCLS->AddField (pointTable->Field (RGlibMassCoordX)); if (massCoordYFLD == NULL) tableCLS->AddField (pointTable->Field (RGlibMassCoordY)); tableCLS->Draw (); } UIPauseDialogClose (); }
void RGISEditNetAddBasinXYCBK (Widget widget, RGISWorkspace *workspace,XmAnyCallbackStruct *callData) { DBInt basinID; DBDataset *dataset = UIDataset (); DBObjData *dbData =dataset->Data (); DBNetworkIF *netIF = new DBNetworkIF (dbData); DBObjTable *itemTable = dbData->Table (DBrNItems); DBObjTableField *xCoordFLD = itemTable->Field (RGISNetMouthXCoord); DBObjTableField *yCoordFLD = itemTable->Field (RGISNetMouthYCoord); DBCoordinate coord; DBObjRecord *basinRec; UITable *tableCLS = (UITable *) dbData->Display (UITableName (dbData,itemTable)); UIPauseDialogOpen ((char *) "Adding XY Coordinates"); if (xCoordFLD == NULL) { xCoordFLD = new DBObjTableField (RGISNetMouthXCoord,DBTableFieldFloat,(char *) "%10.3f",sizeof (DBFloat4)); itemTable->AddField (xCoordFLD); if (tableCLS != (UITable *) NULL) tableCLS->AddField (xCoordFLD); UIPause (40); } if (yCoordFLD == NULL) { yCoordFLD = new DBObjTableField (RGISNetMouthYCoord,DBTableFieldFloat,(char *) "%10.3f",sizeof (DBFloat4)); itemTable->AddField (yCoordFLD); if (tableCLS != (UITable *) NULL) tableCLS->AddField (yCoordFLD); UIPause (80); } for (basinID = 0;basinID < netIF->BasinNum ();++basinID) { basinRec = netIF->Basin (basinID); if (UIPause (80 + basinID * 20 / netIF->BasinNum ())) goto Stop; coord = netIF->Center (netIF->MouthCell (basinRec)); xCoordFLD->Float (basinRec,coord.X); yCoordFLD->Float (basinRec,coord.Y); } Stop: UIPauseDialogClose (); if (tableCLS != (UITable *) NULL) tableCLS->Draw (); }
DBInt DBObjData::SelectObject(DBObjRecord *record, DBInt select) { DBObjTable *items = TablesPTR->Item(DBrNItems); if (record == (DBObjRecord *) NULL) return (false); if (items->Item(record->RowID()) != record) return (false); record->Flags(DBObjectFlagSelected, select); if (Type() == DBTypeNetwork) { DBInt cellID; DBObjRecord *cellRec; DBNetworkIF *netIF = new DBNetworkIF(this); for (cellID = 0; cellID < netIF->CellNum(); ++cellID) { cellRec = netIF->Cell(cellID); if (netIF->CellBasinID(cellRec) == record->RowID() + 1) cellRec->Flags(DBObjectFlagSelected, select); } delete netIF; } return (DBSuccess); }
void RGISEditPointAddXYCBK (Widget widget, RGISWorkspace *workspace,XmAnyCallbackStruct *callData) { DBDataset *dataset = UIDataset (); DBObjData *dbData =dataset->Data (); DBVPointIF *pntIF = new DBVPointIF (dbData); DBObjTable *pointTable = dbData->Table (DBrNItems); DBObjTableField *xCoordFLD = pointTable->Field (RGISEditPointXCoord); DBObjTableField *yCoordFLD = pointTable->Field (RGISEditPointYCoord); DBCoordinate coord; DBObjRecord *pointRec; UITable *tableCLS = (UITable *) dbData->Display (UITableName (dbData,pointTable)); widget = widget; workspace = workspace; callData = callData; UIPauseDialogOpen ((char *) "Adding XY Coordinates"); if (xCoordFLD == NULL) { xCoordFLD = new DBObjTableField (RGISEditPointXCoord,DBTableFieldFloat,"%10.3f",sizeof (DBFloat4)); pointTable->AddField (xCoordFLD); if (tableCLS != (UITable *) NULL) tableCLS->AddField (xCoordFLD); UIPause (40); } if (yCoordFLD == NULL) { yCoordFLD = new DBObjTableField (RGISEditPointYCoord,DBTableFieldFloat,"%10.3f",sizeof (DBFloat4)); pointTable->AddField (yCoordFLD); if (tableCLS != (UITable *) NULL) tableCLS->AddField (yCoordFLD); UIPause (80); } for (pointRec = pntIF->FirstItem (); pointRec != (DBObjRecord *) NULL; pointRec = pntIF->NextItem ()) { if (UIPause (80 + pointRec->RowID () * 20 / pntIF->ItemNum ())) goto Stop; coord = pntIF->Coordinate (pointRec); xCoordFLD->Float (pointRec,coord.X); yCoordFLD->Float (pointRec,coord.Y); } Stop: UIPauseDialogClose (); if (tableCLS != (UITable *) NULL) tableCLS->Draw (); }
static void _RGISGrpPanelDeleteCBK (Widget widget,RGISGrpPanel *grpPanel,XmAnyCallbackStruct *callData) { DBDataset *dataset = UIDataset (); DBObjData *dbData = dataset->Data (); DBObjTable *groupTable = dbData->Table (DBrNGroups); DBObjTableField *group = grpPanel->Current (); static Widget fieldSelect = (Widget) NULL; if (fieldSelect == (Widget) NULL) fieldSelect = UISelectionCreate ((char *) "Group Selection"); if ((groupTable == (DBObjTable *) NULL) || (group == (DBObjTableField *) NULL)) return; if (groupTable->FieldNum () == 1) grpPanel->Groups ((DBObjectLIST<DBObjTableField> *) NULL); grpPanel->Remove (group); groupTable->DeleteField (group); if (groupTable->FieldNum () == 0) { DBObjectLIST<DBObjTable> *tables = dbData->Tables (); tables->Remove (groupTable); delete groupTable; } }
Widget RGISGrdPanel::Load (DBObjData *data) { int itemPosition = 0; DBObjTable *layerTable = data->Table (DBrNLayers); DBObjRecord *record; XmString string; XmListDeleteAllItems (LayerListWGT); for (record = layerTable->First ();record != (DBObjRecord *) NULL;record = layerTable->Next ()) { string = XmStringCreate (record->Name (),UICharSetNormal); XmListAddItem (LayerListWGT, string, ++itemPosition); XmStringFree (string); } XmListDeselectAllItems (LayerListWGT); record = layerTable->Item (); string = XmStringCreate (record->Name (),UICharSetNormal); XmListSelectItem (LayerListWGT,string,False); XmStringFree (string); XtVaSetValues (LayerListWGT,XmNuserData, data, NULL); return (Form ()); }
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 (); }
void RGISAnalysePointInterStationTSCBK (Widget widget, RGISWorkspace *workspace,XmAnyCallbackStruct *callData) { char *selection; DBDataset *dataset = UIDataset (); DBObjMetaEntry *metaEntry; DBObjData *pntData = dataset->Data (), *tsData; DBObjTable *relateTBL = pntData->Table (DBrNRelations); DBObjRecord *relateRec; DBObjTableField *relDataFLD; DBObjTableField *relateFLD; DBObjTableField *joinFLD; static Widget selectWidget = (Widget) NULL; if (selectWidget == (Widget) NULL) selectWidget = UISelectionCreate ((char *) "Select Time Series"); if ((selection = UISelectObject (selectWidget,(DBObjectLIST<DBObject> *) relateTBL)) == (char *) NULL) return; if ((relateRec = relateTBL->Item (selection)) == (DBObjRecord *) NULL) { CMmsgPrint (CMmsgAppError, "Relate Record Error in: %s %d",__FILE__,__LINE__); return; } relDataFLD = relateTBL->Field (DBrNRelateData); relateFLD = relateTBL->Field (DBrNRelateField); joinFLD = relateTBL->Field (DBrNRelateJoinField); if ((tsData = dataset->Data (relDataFLD->String (relateRec))) == (DBObjData *) NULL) { if ((metaEntry = dataset->Meta (relDataFLD->String (relateRec))) == (DBObjMetaEntry *) NULL) { CMmsgPrint (CMmsgAppError, "Meta Enrty Finding Error in: %s %d",__FILE__,__LINE__); return; } tsData = new DBObjData (); if (tsData->Read (metaEntry->FileName ()) != DBSuccess) return; } workspace->CurrentData (tsData); UIPauseDialogOpen ((char *) "Calculating"); RGlibPointInterStationTS (pntData,tsData,relateFLD->String (relateRec),joinFLD->String (relateRec)); UIPauseDialogClose (); }
CMreturn AddExpression(char *varName, char *exprStr) { DBObjTableField *fieldPTR = new DBObjTableField(varName, DBVariableFloat, "%10.3f", sizeof(DBFloat), false); Table->AddField(fieldPTR); if ((Expressions = (CMDExpression **) realloc(Expressions, (ExpNum + 1) * sizeof(CMDExpression *))) == (CMDExpression **) NULL) { CMmsgPrint(CMmsgSysError, "Memory Allocation error in: %s %d", __FILE__, __LINE__); return (CMfailed); } Expressions[ExpNum] = new CMDExpression(varName, exprStr); if ((Expressions[ExpNum])->Expand(Variables) == DBFault) { CMmsgPrint(CMmsgUsrError, "Invalid Expression!"); return (CMfailed); } ExpNum++; return (CMsucceeded); }
DBVPolyIF::DBVPolyIF(DBObjData *data) : DBVLineIF(data, data->Table(DBrNContours)) { DBObjTable *items = data->Table(DBrNItems); LineTable = data->Table(DBrNContours); DBObjRecord *polyRec; FirstLineFLD = items->Field(DBrNFirstLine); LineNumFLD = items->Field(DBrNLineNum); ExtentFLD = items->Field(DBrNRegion); LeftPolyFLD = LineTable->Field(DBrNLeftPoly); RightPolyFLD = LineTable->Field(DBrNRightPoly); NextLineFLD = LineTable->Field(DBrNNextLine); PrevLineFLD = LineTable->Field(DBrNPrevLine); VertexNumFLD = items->Field(DBrNVertexNum); AreaFLD = items->Field(DBrNArea); MaxVertexNumVAR = 0; for (polyRec = FirstItem(); polyRec != (DBObjRecord *) NULL; polyRec = NextItem()) MaxVertexNumVAR = MaxVertexNumVAR > VertexNum(polyRec) ? MaxVertexNumVAR : VertexNum(polyRec); if ((CoordsPTR = (DBCoordinate *) malloc(MaxVertexNumVAR * sizeof(DBCoordinate))) == (DBCoordinate *) NULL) { CMmsgPrint(CMmsgSysError, "Memory Allocation Error in: %s %d", __FILE__, __LINE__); } }
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); }
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 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; } }
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); }
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 main(int argc, char *argv[]) { int argPos, argNum = argc, ret, verbose = false; DBInt recID; DBObjData *data; char *tableName = (char *) NULL; char *fieldIDName = (char *) NULL; char *fieldXName = (char *) NULL; char *fieldYName = (char *) NULL; DBObjTable *table; DBObjTableField *fieldID, *fieldX, *fieldY; DBObjRecord *record; DBNetworkIF *netIF; DBCoordinate coord; 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", "--IDfield")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing field name!"); return (CMfailed); } fieldIDName = argv[argPos]; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-x", "--Xfield")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing field name!"); return (CMfailed); } fieldXName = argv[argPos]; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-y", "--Yfield")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing field name!"); return (CMfailed); } fieldYName = 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 [ [DBCells] | DBItems ]"); CMmsgPrint(CMmsgInfo, " -f, --IDfield [ [CellID] | BasinID ]"); CMmsgPrint(CMmsgInfo, " -x, --Xfield [ [CellXCoord] | MouthXCoord ]"); CMmsgPrint(CMmsgInfo, " -y, --Yfield [ [CellYCoord] | MouthYCoord ]"); CMmsgPrint(CMmsgInfo, " -V, --verbose"); CMmsgPrint(CMmsgInfo, " -h, --help"); return (DBSuccess); } if ((argv[argPos][0] == '-') && (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]); if (tableName == (char *) NULL) tableName = (char *) "DBCells"; if (fieldIDName == (char *) NULL) fieldIDName = (char *) "CellID"; if (fieldXName == (char *) NULL) fieldXName = (char *) "CellXCoord"; if (fieldYName == (char *) NULL) fieldYName = (char *) "CellYCoord"; data = new DBObjData(); if (((argNum > 1) && (strcmp(argv[1], "-") != 0) ? data->Read(argv[1]) : data->Read(stdin)) == DBFault) { delete data; return (CMfailed); } if ((table = data->Table(tableName)) == (DBObjTable *) NULL) { CMmsgPrint(CMmsgUsrError, "Invalid table: %s!", tableName); delete data; return (CMfailed); } netIF = new DBNetworkIF(data); fieldID = new DBObjTableField(fieldIDName, DBTableFieldInt, (char *) "%8d", sizeof (DBInt)); fieldX = new DBObjTableField (fieldXName, DBTableFieldFloat, (char *) "%10.3f", sizeof (DBFloat4)); fieldY = new DBObjTableField (fieldYName, DBTableFieldFloat, (char *) "%10.3f", sizeof (DBFloat4)); table->AddField(fieldID); table->AddField(fieldX); table->AddField(fieldY); if (strcmp(fieldIDName, "CellID") == 0) { for (recID = 0; recID < table->ItemNum(); ++recID) { record = netIF->Cell(recID); coord = netIF->Center(record); fieldID->Int(record, recID+1); fieldX->Float(record, coord.X); fieldY->Float(record, coord.Y); } } else if (strcmp(fieldIDName, "BasinID") == 0) { for (recID = 0; recID < netIF->BasinNum(); ++recID) { record = netIF->Basin(recID); coord = netIF->Center(netIF->MouthCell(record)); fieldID->Int(record, recID+1); fieldX->Float(record,coord.X); fieldY->Float(record,coord.Y); } } else { CMmsgPrint(CMmsgUsrError, "Invalid field name: %s!", fieldIDName); delete data; return (CMfailed); } ret = (argNum > 2) && (strcmp(argv[2], "-") != 0) ? data->Write(argv[2]) : data->Write(stdout); delete data; if (verbose) RGlibPauseClose(); return (ret); }
int main(int argc, char *argv[]) { int argPos, argNum = argc, ret, verbose = false; DBInt fromSelection = false, selectMode = true, recID; char *tableName = (char *) NULL; char *expr = (char *) NULL; DBMathOperand *operand; DBObjectLIST<DBObject> *variables = new DBObjectLIST<DBObject>("Variables"); DBObjData *data; DBObjTable *table; 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], "-c", "--condition")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing expression!"); return (CMfailed); } if (expr != (char *) NULL) { CMmsgPrint(CMmsgUsrError, "Expression is already set"); return (CMfailed); } expr = argv[argPos]; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-f", "--from")) { int modeCodes[] = {false, true}; const char *modes[] = {"all", "selection", (char *) NULL}; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing selection mode!"); return (CMfailed); } if ((fromSelection = CMoptLookup(modes, argv[argPos], true)) == DBFault) { CMmsgPrint(CMmsgUsrError, "Invalid selection mode!"); return (CMfailed); } fromSelection = modeCodes[fromSelection]; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-m", "--mode")) { int modeCodes[] = {true, false}; const char *modes[] = {"select", "unselect", (char *) NULL}; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing selection mode!"); return (CMfailed); } if ((selectMode = CMoptLookup(modes, argv[argPos], true)) == DBFault) { CMmsgPrint(CMmsgUsrError, "Invalid selection mode!"); return (CMfailed); } selectMode = modeCodes[selectMode]; 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, " -c,--condition [ fieldname expression ]"); CMmsgPrint(CMmsgInfo, " -f,--from [ [all] | selection ]"); CMmsgPrint(CMmsgInfo, " -m,--mode [ [select] | unselect ]"); 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]); if (expr != (char *) NULL) { operand = new DBMathOperand(expr); if (operand->Expand(variables) == DBFault) return (CMfailed); } data = new DBObjData(); if (((argNum > 1) && (strcmp(argv[1], "-") != 0) ? data->Read(argv[1]) : data->Read(stdin)) == DBFault) { delete data; delete operand; return (CMfailed); } if (tableName == (char *) NULL) tableName = DBrNItems; if ((table = data->Table(tableName)) == (DBObjTable *) NULL) { CMmsgPrint(CMmsgUsrError, "Invalid table!"); delete data; delete operand; return (CMfailed); } if (expr != (char *) NULL) { if (operand->Configure(table->Fields()) == DBFault) { delete data; delete operand; return (CMfailed); } for (recID = 0; recID < table->ItemNum(); ++recID) { record = table->Item(recID); if (fromSelection && ((record->Flags() & DBObjectFlagSelected) != DBObjectFlagSelected)) continue; if ((ret = operand->Int(record)) == true) record->Flags(DBObjectFlagSelected, selectMode ? DBSet : DBClear); else if (selectMode) record->Flags(DBObjectFlagSelected, DBClear); } } else { for (recID = 0; recID < table->ItemNum(); ++recID) { record = table->Item(recID); if (fromSelection && ((record->Flags() & DBObjectFlagSelected) != DBObjectFlagSelected)) continue; record->Flags(DBObjectFlagSelected, selectMode ? DBSet : DBClear); } } ret = (argNum > 2) && (strcmp(argv[2], "-") != 0) ? data->Write(argv[2]) : data->Write(stdout); if (expr != (char *) NULL) delete operand; delete data; delete variables; if (verbose) RGlibPauseClose(); return (ret); }
int main (int argc,char *argv []) { int argPos, argNum = argc, ret, i, fieldNum = 0, verbose = false; DBObjData *data; char *tableName = (char *) NULL, **fieldNames; DBObjTable *table; DBObjTableField *field; 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); } fieldNames = fieldNum > 0 ? (char **) realloc (fieldNames,(fieldNum + 1) * sizeof (char *)) : (char **) calloc (1,sizeof (char *)); if (fieldNames == (char **) NULL) { CMmsgPrint (CMmsgSysError, "Memory allocation error in: %s %d",__FILE__,__LINE__); return (CMfailed); } fieldNames [fieldNum++] = 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>",CMprgName(argv[0])); CMmsgPrint (CMmsgInfo," -a,--table [table name]"); CMmsgPrint (CMmsgInfo," -f,--field [field name]"); CMmsgPrint (CMmsgInfo," -V,--verbose"); CMmsgPrint (CMmsgInfo," -h,--help"); return (DBSuccess); } if ((argv [argPos][0] == '-') && (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]); if (tableName == (char *) NULL) tableName = DBrNItems; if (fieldNum < 1) { CMmsgPrint (CMmsgUsrError,"Missing field name!"); return (CMfailed); } data = new DBObjData (); if (((argNum > 1) && (strcmp (argv [1],"-") != 0) ? data->Read (argv [1]) : data->Read (stdin)) == DBFault) { delete data; return (CMfailed); } if ((table = data->Table (tableName)) == (DBObjTable *) NULL) { CMmsgPrint (CMmsgUsrError,"Invalid table: %s!",tableName); delete data; return (CMfailed); } for (i = 0;i < fieldNum;++i) { if ((field = table->Field (fieldNames [i])) == (DBObjTableField *) NULL) { CMmsgPrint (CMmsgUsrError,"Invalid field: %s!",fieldNames [i]); continue; } if (DBTableFieldIsOptional (field) != true) { CMmsgPrint (CMmsgUsrError,"Required field!"); continue; } table->DeleteField (field); } ret = (argNum > 2) && (strcmp (argv [2],"-") != 0) ? data->Write (argv [2]) : data->Write (stdout); free (fieldNames); delete data; if (verbose) RGlibPauseClose (); return (ret); }
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); }