DBRegion Extent() const { DBCoordinate coord; DBRegion extent; coord.X = EastVAR + CellWidthVAR / 2.0; coord.Y = NorthVAR + CellHeightVAR / 2.0; extent.Expand(coord); coord.X = WestVAR - CellWidthVAR / 2.0; coord.Y = SouthVAR - CellHeightVAR / 2.0; extent.Expand(coord); return (extent); }
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); } }
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 DBObjData::RecalcExtent() { DBRegion extent; switch (Type()) { case DBTypeVectorPoint: case DBTypeVectorLine: case DBTypeVectorPolygon: { DBVectorIF *vectorIF = new DBVectorIF(this); DBInt recordID; for (recordID = 0; recordID < vectorIF->ItemNum(); ++recordID) extent.Expand(Extent(vectorIF->Item(recordID))); delete vectorIF; } break; case DBTypeGridDiscrete: case DBTypeGridContinuous: { DBGridIF *gridIF = new DBGridIF(this); extent.LowerLeft = Extent().LowerLeft; extent.UpperRight.X = extent.LowerLeft.X + gridIF->ColNum() * gridIF->CellWidth(); extent.UpperRight.Y = extent.LowerLeft.Y + gridIF->RowNum() * gridIF->CellHeight(); delete gridIF; } break; case DBTypeNetwork: { DBNetworkIF *netIF = new DBNetworkIF(this); extent.LowerLeft = Extent().LowerLeft; extent.UpperRight.X = extent.LowerLeft.X + netIF->ColNum() * netIF->CellWidth(); extent.UpperRight.Y = extent.LowerLeft.Y + netIF->RowNum() * netIF->CellHeight(); delete netIF; } break; case DBTypeTable: default: return; } Extent(extent); }
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); }
void _RGISUserFuncionNetwork (DBObjData *data,UI2DView *view,XEvent *event) { DBInt sX, sY, redraw = false; DBNetworkIF *netIF; DBCoordinate coord; DBObjRecord *cellRec, *basinRec; void _RGISUserFuncionQuery (DBObjData *,UI2DView *,XEvent *); if ((data->Flags () & DBDataFlagUserModeFlags) == DBDataFlagUserModeQuery) { _RGISUserFuncionQuery (data,view,event); return; } if (event->type != ButtonPress) return; if (DBTypeNetwork != data->Type ()) { CMmsgPrint (CMmsgAppError, "Invalid data Type in: %s %d",__FILE__,__LINE__); } sX = event->xbutton.x; sY = event->xbutton.y; view->Window2Map (sX,sY, &coord.X, &coord.Y); netIF = new DBNetworkIF (data); switch (data->Flags () & DBDataFlagUserModeFlags) { case DBDataFlagUserModeSelect: { DBInt basinID, cellID; DBRegion extent; UITable *tableView; if ((cellRec = netIF->Cell (coord)) == (DBObjRecord *) NULL) { UIMessage ((char *) "Cell Does not Exists!"); return; } for (basinID = 0;basinID < netIF->BasinNum ();++basinID) { basinRec = netIF->Basin (basinID); if ((basinRec->Flags () & DBObjectFlagSelected) == DBObjectFlagSelected) { data->SelectObject (basinRec,DBClear); extent.Expand (data->Extent (basinRec)); } } for (cellID = 0;cellID < netIF->CellNum ();++cellID) { cellRec = netIF->Cell (cellID); if ((cellRec->Flags () & DBObjectFlagSelected) == DBObjectFlagSelected) { extent.Expand (netIF->Center (cellRec) + (netIF->CellSize () / 2.0)); extent.Expand (netIF->Center (cellRec) - (netIF->CellSize () / 2.0)); cellRec->Flags (DBObjectFlagSelected,DBClear); } } if ((tableView = (UITable *) data->Display (UITableName (data,data->Table (DBrNItems)))) != (UITable *) NULL) tableView->Draw (); if ((tableView = (UITable *) data->Display (UITableName (data,data->Table (DBrNCells)))) != (UITable *) NULL) tableView->Draw (); UI2DViewRedrawAll (extent); cellRec = netIF->Cell (coord); switch (data->Flags () & DBDataFlagSelectMode) { case DBDataFlagSelectMode: netIF->DownStreamSearch (cellRec, DBNetworkSelect); break; default: netIF->UpStreamSearch (cellRec, DBNetworkSelect); break; } extent.Initialize (); for (cellID = 0;cellID < netIF->CellNum ();++cellID) { cellRec = netIF->Cell (cellID); if ((cellRec->Flags () & DBObjectFlagSelected) == DBObjectFlagSelected) { extent.Expand (netIF->Center (cellRec) + (netIF->CellSize () / 2.0)); extent.Expand (netIF->Center (cellRec) - (netIF->CellSize () / 2.0)); } } UI2DViewRedrawAll (extent); if ((tableView = (UITable *) data->Display (UITableName (data,data->Table (DBrNCells)))) != (UITable *) NULL) tableView->Draw (); } break; case DBDataFlagUserModeAdd: if (netIF->CellAdd (coord) == (DBObjRecord *) NULL) UIMessage ((char *) "Cell Creation Error"); else redraw = true; break; case DBDataFlagUserModeDelete: if (netIF->CellDelete (coord) == DBFault) UIMessage ((char *) "Cell Does not Exists!"); else redraw = true; break; case DBDataFlagUserModeRotate: { DBObjRecord *cellRec = netIF->Cell (coord); if (cellRec != (DBObjRecord *) NULL) { switch (netIF->CellDirection (cellRec)) { case DBNull: netIF->CellDirection (cellRec,DBNetDirN); break; case DBNetDirNW: netIF->CellDirection (cellRec,DBNull); break; default: netIF->CellRotate (cellRec,DBForward); break; } redraw = true; } } break; default: printf ("Unknown Mode %lX",data->Flags () & DBDataFlagUserModeFlags); break; } if (redraw) { DBPosition pos; if (netIF->Coord2Pos (coord,pos) == DBSuccess) { DBRegion extent; DBCoordinate delta (netIF->CellWidth () * 1.25, netIF->CellHeight () * 1.25); netIF->Pos2Coord (pos,coord); coord = coord + delta; extent.Expand (coord); netIF->Pos2Coord (pos,coord); coord = coord - delta; extent.Expand (coord); UI2DViewRedrawAll (extent); } } delete netIF; }
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; }
void RGISToolsConvertToPointCBK (Widget widget,RGISWorkspace *workspace,XmAnyCallbackStruct *callData) { char *nText, *xText, *yText, *selection; int allowOk; static int convert; DBDataset *dataset = UIDataset (); DBObjData *dbData = dataset->Data (); DBObjTable *itemTable; static Widget tableSelect = (Widget) NULL; static Widget dShell = (Widget) NULL, mainForm; static Widget nameTextF, xCoordTextF, yCoordTextF; XmString string; if (tableSelect == (Widget) NULL) tableSelect = UISelectionCreate ((char *) "Table Selection"); selection = UISelectObject (tableSelect,(DBObjectLIST<DBObject> *) dbData->Tables ()); if (selection == (char *) NULL) return; if ((itemTable = dbData->Table (selection)) == (DBObjTable *) NULL) { CMmsgPrint (CMmsgAppError, "Invalid Table in: %s %d",__FILE__,__LINE__); return; } _RGISToolsConvertToPointFields = itemTable->Fields (); if (dShell == (Widget) NULL) { Widget button; dShell = UIDialogForm ((char *) "Convert Table To Point",false); mainForm = UIDialogFormGetMainForm (dShell); string = XmStringCreate ((char *) "Select",UICharSetBold); button = XtVaCreateManagedWidget ("RGISToolsConvertToPointNameButton",xmPushButtonWidgetClass,mainForm, XmNtopAttachment, XmATTACH_FORM, XmNtopOffset, 10, XmNrightAttachment, XmATTACH_FORM, XmNrightOffset, 10, XmNmarginHeight, 5, XmNtraversalOn, False, XmNlabelString, string, XmNuserData, DBTableFieldIsString, NULL); XmStringFree (string); nameTextF = XtVaCreateManagedWidget ("RGISToolsConvertToPointNameTextF",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) _RGISToolsConvertToPointSelectCBK,nameTextF); string = XmStringCreate ((char *) "Name Field:",UICharSetBold); XtVaCreateManagedWidget ("RGISToolsConvertToPointNameLabel",xmLabelWidgetClass,mainForm, XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET, XmNtopWidget, button, XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, 10, XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, nameTextF, XmNrightOffset, 10, XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET, XmNbottomWidget, button, XmNlabelString, string, NULL); XmStringFree (string); string = XmStringCreate ((char *) "Select",UICharSetBold); button = XtVaCreateManagedWidget ("RGISToolsConvertToPointXCoordButton",xmPushButtonWidgetClass,mainForm, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, button, XmNtopOffset, 10, XmNrightAttachment, XmATTACH_FORM, XmNrightOffset, 10, XmNmarginHeight, 5, XmNtraversalOn, False, XmNlabelString, string, XmNuserData, DBTableFieldIsNumeric, NULL); XmStringFree (string); xCoordTextF = XtVaCreateManagedWidget ("RGISToolsConvertToPointXCoordTextF",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) _RGISToolsConvertToPointSelectCBK,xCoordTextF); string = XmStringCreate ((char *) "X Coordinate:",UICharSetBold); XtVaCreateManagedWidget ("RGISToolsConvertToPointXCoordLabel",xmLabelWidgetClass,mainForm, XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET, XmNtopWidget, button, XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, 10, XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, nameTextF, XmNrightOffset, 10, XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET, XmNbottomWidget, button, XmNlabelString, string, NULL); XmStringFree (string); string = XmStringCreate ((char *) "Select",UICharSetBold); button = XtVaCreateManagedWidget ("RGISToolsConvertToPointYCoordButton",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, DBTableFieldIsNumeric, NULL); XmStringFree (string); yCoordTextF = XtVaCreateManagedWidget ("RGISToolsConvertToPointYCoordTextF",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) _RGISToolsConvertToPointSelectCBK,yCoordTextF); string = XmStringCreate ((char *) "Y Coordinate:",UICharSetBold); XtVaCreateManagedWidget ("RGISToolsConvertToPointYCoordLabel",xmLabelWidgetClass,mainForm, XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET, XmNtopWidget, button, XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, 10, XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, nameTextF, XmNrightOffset, 10, XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET, XmNbottomWidget, button, XmNlabelString, string, NULL); XmStringFree (string); XtAddCallback (UIDialogFormGetOkButton (dShell),XmNactivateCallback,(XtCallbackProc) UIAuxSetBooleanTrueCBK,&convert); } convert = false; UIDialogFormPopup (dShell); while (UILoop ()) { xText = XmTextFieldGetString (xCoordTextF); yText = XmTextFieldGetString (yCoordTextF); allowOk = (strlen (xText) > 0) && (strlen (yText) > 0); XtFree (xText); XtFree (yText); XtSetSensitive (UIDialogFormGetOkButton (dShell),allowOk); } UIDialogFormPopdown (dShell); if (convert) { DBObjData *pntData = new DBObjData ("",DBTypeVectorPoint); pntData->Name (dbData->Name ()); pntData->Document (DBDocSubject,dbData->Document (DBDocSubject)); pntData->Document (DBDocGeoDomain,dbData->Document (DBDocGeoDomain)); if (UIDataHeaderForm (pntData)) { DBCoordinate coord; DBObjTableField *nField, *xField, *yField, *tblFLD, *pntFLD; DBObjRecord *tblRec, *pntRec, *symRec; DBObjTable *pntTable = pntData->Table (DBrNItems); DBObjTable *symbols = pntData->Table (DBrNSymbols); DBObjTableField *symbolIDFLD = symbols->Field (DBrNSymbolID); DBObjTableField *fgFLD = symbols->Field (DBrNForeground); DBObjTableField *bgFLD = symbols->Field (DBrNBackground); DBObjTableField *stFLD = symbols->Field (DBrNStyle); DBObjTableField *coordFLD = pntTable->Field (DBrNCoord); DBObjTableField *symbolFLD = pntTable->Field (DBrNSymbol); DBRegion extent; symRec = symbols->Add ("Default Symbol"); symbolIDFLD->Int (symRec,0); fgFLD->Int (symRec,1); bgFLD->Int (symRec,2); stFLD->Int (symRec,0); nText = XmTextFieldGetString (nameTextF); xText = XmTextFieldGetString (xCoordTextF); yText = XmTextFieldGetString (yCoordTextF); nField = _RGISToolsConvertToPointFields->Item (nText); xField = _RGISToolsConvertToPointFields->Item (xText); yField = _RGISToolsConvertToPointFields->Item (yText); XtFree (nText); XtFree (xText); XtFree (yText); for (tblRec = itemTable->First ();tblRec != (DBObjRecord *) NULL;tblRec = itemTable->Next ()) { if (CMmathEqualValues (coord.X = xField->Float (tblRec),xField->FloatNoData ())) continue; if (CMmathEqualValues (coord.Y = yField->Float (tblRec),yField->FloatNoData ())) continue; if (nField == (DBObjTableField *) NULL) pntRec = pntTable->Add (tblRec->Name ()); else pntRec = pntTable->Add (nField->String (tblRec)); coordFLD->Coordinate (pntRec,coord); symbolFLD->Record (pntRec,symRec); extent.Expand (coord); } pntData->Extent (extent); pntData->Projection (DBMathGuessProjection (extent)); pntData->Precision (DBMathGuessPrecision (extent)); for (tblFLD = _RGISToolsConvertToPointFields->First ();tblFLD != (DBObjTableField *) NULL;tblFLD = _RGISToolsConvertToPointFields->Next ()) if ((tblFLD != nField) && (tblFLD != xField) && (tblFLD != yField) && DBTableFieldIsVisible (tblFLD)) { pntTable->AddField (pntFLD = new DBObjTableField (*tblFLD)); pntFLD->Required (false); pntRec = pntTable->First (); for (tblRec = itemTable->First ();tblRec != (DBObjRecord *) NULL;tblRec = itemTable->Next ()) { if (CMmathEqualValues (coord.X = xField->Float (tblRec),xField->FloatNoData ())) continue; if (CMmathEqualValues (coord.Y = yField->Float (tblRec),yField->FloatNoData ())) continue; switch (tblFLD->Type ()) { case DBTableFieldString: pntFLD->String (pntRec,tblFLD->String (tblRec)); break; case DBTableFieldInt: pntFLD->Int (pntRec,tblFLD->Int (tblRec)); break; case DBTableFieldFloat: pntFLD->Float (pntRec,tblFLD->Float (tblRec)); break; case DBTableFieldDate: pntFLD->Date (pntRec,tblFLD->Date (tblRec)); break; default: CMmsgPrint (CMmsgAppError, "Invalid Field Type in: %s %d",__FILE__,__LINE__); break; } pntRec = pntTable->Next (); } } workspace->CurrentData (pntData); } else delete pntData; } }
int main(int argc, char *argv[]) { int argPos, argNum = argc, ret, verbose = false; char *tableName = DBrNItems; char *nameSTR = (char *) NULL; char *xcoordSTR = (char *) "XCoord"; char *ycoordSTR = (char *) "YCoord"; char *title = (char *) NULL, *subject = (char *) NULL; char *domain = (char *) NULL, *version = (char *) NULL; DBObjData *data, *pntData; DBObjTable *table; DBCoordinate coord; DBObjTableField *nField, *xField, *yField, *tblFLD, *pntFLD; DBObjRecord *tblRec, *pntRec, *symRec; DBObjTable *pntTable; DBObjTable *symbols; DBObjTableField *symbolIDFLD; DBObjTableField *fgFLD; DBObjTableField *bgFLD; DBObjTableField *stFLD; DBObjTableField *coordFLD; DBObjTableField *symbolFLD; DBRegion extent; 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], "-n", "--name")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing next field name!"); return (CMfailed); } nameSTR = argv[argPos]; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-x", "--xcoord")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing source field name!"); return (CMfailed); } xcoordSTR = argv[argPos]; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-y", "--ycoord")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing target field name!"); return (CMfailed); } ycoordSTR = argv[argPos]; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-t", "--title")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing title!"); return (CMfailed); } title = argv[argPos]; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-u", "--subject")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing subject!"); return (CMfailed); } subject = argv[argPos]; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-d", "--domain")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing domain!"); return (CMfailed); } domain = 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, " -n,--name [name field]"); CMmsgPrint(CMmsgInfo, " -x,--xcoord [xcoord field]"); CMmsgPrint(CMmsgInfo, " -y,--ycoord [ycoord field]"); CMmsgPrint(CMmsgInfo, " -t,--title [dataset title]"); CMmsgPrint(CMmsgInfo, " -u,--subject [subject]"); CMmsgPrint(CMmsgInfo, " -d,--domain [domain]"); 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 (tableName == (char *) NULL) tableName = DBrNItems; 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; if (argNum > 1) printf("File error in: %s", argv[1]); return (DBFault); } if ((table = data->Table(tableName)) == (DBObjTable *) NULL) { CMmsgPrint(CMmsgUsrError, "Invalid table!"); delete data; return (CMfailed); } if (nameSTR == (char *) NULL) nField = (DBObjTableField *) NULL; else if ((nField = table->Field(nameSTR)) == ((DBObjTableField *) NULL)) { CMmsgPrint(CMmsgUsrError, "Name field!"); delete data; return (CMfailed); } if ((xField = table->Field(xcoordSTR)) == (DBObjTableField *) NULL) { CMmsgPrint(CMmsgUsrError, "XCoord field!"); delete data; return (CMfailed); } if ((yField = table->Field(ycoordSTR)) == (DBObjTableField *) NULL) { CMmsgPrint(CMmsgUsrError, "YCoord field!"); delete data; return (CMfailed); } pntData = new DBObjData("", DBTypeVectorPoint); if (title == (char *) NULL) title = (char *) "Converted Point coverage"; if (subject == (char *) NULL) subject = (char *) "Points"; if (domain == (char *) NULL) domain = data->Document(DBDocGeoDomain); if (version == (char *) NULL) version = (char *) "0.01pre"; pntData->Name(title); pntData->Document(DBDocSubject, subject); pntData->Document(DBDocGeoDomain, domain); pntData->Document(DBDocVersion, version); pntTable = pntData->Table(DBrNItems); symbols = pntData->Table(DBrNSymbols); symbolIDFLD = symbols->Field(DBrNSymbolID); fgFLD = symbols->Field(DBrNForeground); bgFLD = symbols->Field(DBrNBackground); stFLD = symbols->Field(DBrNStyle); coordFLD = pntTable->Field(DBrNCoord); symbolFLD = pntTable->Field(DBrNSymbol); symRec = symbols->Add("Default Symbol"); symbolIDFLD->Int(symRec, 0); fgFLD->Int(symRec, 1); bgFLD->Int(symRec, 2); stFLD->Int(symRec, 0); for (tblRec = table->First(); tblRec != (DBObjRecord *) NULL; tblRec = table->Next()) { if (CMmathEqualValues(coord.X = xField->Float(tblRec), xField->FloatNoData())) continue; if (CMmathEqualValues(coord.Y = yField->Float(tblRec), yField->FloatNoData())) continue; if (nField == (DBObjTableField *) NULL) pntRec = pntTable->Add(tblRec->Name()); else pntRec = pntTable->Add(nField->String(tblRec)); coordFLD->Coordinate(pntRec, coord); symbolFLD->Record(pntRec, symRec); extent.Expand(coord); } pntData->Extent(extent); pntData->Projection(DBMathGuessProjection(extent)); pntData->Precision(DBMathGuessPrecision(extent)); for (tblFLD = table->Fields()->First(); tblFLD != (DBObjTableField *) NULL; tblFLD = table->Fields()->Next()) if ((tblFLD != nField) && (tblFLD != xField) && (tblFLD != yField) && DBTableFieldIsVisible(tblFLD)) { pntTable->AddField(pntFLD = new DBObjTableField(*tblFLD)); pntFLD->Required(false); pntRec = pntTable->First(); for (tblRec = table->First(); tblRec != (DBObjRecord *) NULL; tblRec = table->Next()) { if (CMmathEqualValues(coord.X = xField->Float(tblRec), xField->FloatNoData())) continue; if (CMmathEqualValues(coord.Y = yField->Float(tblRec), yField->FloatNoData())) continue; switch (tblFLD->Type()) { case DBTableFieldString: pntFLD->String(pntRec, tblFLD->String(tblRec)); break; case DBTableFieldInt: pntFLD->Int(pntRec, tblFLD->Int(tblRec)); break; case DBTableFieldFloat: pntFLD->Float(pntRec, tblFLD->Float(tblRec)); break; case DBTableFieldDate: pntFLD->Date(pntRec, tblFLD->Date(tblRec)); break; default: CMmsgPrint(CMmsgAppError, "Invalid Field Type in: %s %d", __FILE__, __LINE__); break; } pntRec = pntTable->Next(); } } ret = (argNum > 2) && (strcmp(argv[2], "-") != 0) ? pntData->Write(argv[2]) : pntData->Write(stdout); delete data; delete pntData; if (verbose) RGlibPauseClose(); return (ret); }