Ejemplo n.º 1
0
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);
	}
Ejemplo n.º 2
0
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);
}
Ejemplo n.º 3
0
UIAttribView::UIAttribView (DBObjData *data) : DBObject (data->Name (),sizeof (UIAttribView))

	{
	DBObjTableField *field;
	DBObjectLIST<DBObjTableField> *fields;
	Widget mainForm, scrolledW, rowCol, label;
	XmString string;
	Atom deleteWindowAtom = XmInternAtom(XtDisplay(UITopLevel ()),(char *) "WM_DELETE_WINDOW",FALSE);

	DataPTR = data;
	ItemTable = DataPTR->Table (DBrNItems);
	Name (UIAttribViewSTR);
	DShellWGT = XtVaCreatePopupShell ("UIAttribView",xmDialogShellWidgetClass,UITopLevel (),
								XmNkeyboardFocusPolicy, XmPOINTER,
								XmNtitle,               data->Name (),
								XmNtransient,           False,
								XmNminWidth,            400,
								XmNminHeight,           300,
								NULL);
	XmAddWMProtocolCallback (DShellWGT,deleteWindowAtom,(XtCallbackProc) _UIAttribViewDeleteCBK,(XtPointer) this);
	mainForm = XtVaCreateWidget ("UIAttribViewForm",xmFormWidgetClass,DShellWGT,
								XmNshadowThickness,			0,
								NULL);
	string = XmStringCreate ((char *) "Item:",UICharSetBold);
	label = XtVaCreateManagedWidget ("UIAttribViewNameLabel",xmLabelWidgetClass,mainForm,
								XmNtopAttachment,       XmATTACH_FORM,
								XmNtopOffset,           5,
								XmNleftAttachment,		XmATTACH_FORM,
								XmNleftOffset,          10,
								XmNlabelString,         string,
								XmNrecomputeSize,       False,
								NULL);
	XmStringFree (string);
	string = XmStringCreate ((char *) "",UICharSetNormal);
	ItemNameWGT = XtVaCreateManagedWidget ("UIAttribViewNameText",xmLabelWidgetClass,mainForm,
								XmNtopAttachment,       XmATTACH_FORM,
								XmNtopOffset,           5,
								XmNleftAttachment,      XmATTACH_WIDGET,
								XmNleftWidget,          label,
								XmNleftOffset,          5,
								XmNlabelString,         string,
								NULL);
	XmStringFree (string);
	scrolledW = XtVaCreateManagedWidget ("UIAttribViewScrolledW",xmScrolledWindowWidgetClass,mainForm,
								XmNtopAttachment,       XmATTACH_WIDGET,
								XmNtopWidget,           label,
								XmNtopOffset,           5,
								XmNleftAttachment,      XmATTACH_FORM,
								XmNleftOffset,          5,
								XmNrightAttachment,     XmATTACH_FORM,
								XmNrightOffset,         5,
								XmNbottomAttachment,    XmATTACH_FORM,
								XmNbottomOffset,        5,
								XmNheight,              150,
								XmNvisualPolicy,        XmCONSTANT,
								XmNscrollingPolicy,     XmAUTOMATIC,
								NULL);
	rowCol = XtVaCreateManagedWidget ("UIAttribViewRowColumn",xmRowColumnWidgetClass,scrolledW,
								XmNnumColumns,          2,
								XmNorientation,         XmHORIZONTAL,
								XmNrowColumnType,       XmWORK_AREA,
								NULL);
	NamesRowCol = XtVaCreateManagedWidget ("UIAttribViewNamesRowColumn",xmRowColumnWidgetClass,rowCol,
								XmNorientation,         XmVERTICAL,
								XmNrowColumnType,       XmWORK_AREA,
								XmNpacking,             XmPACK_COLUMN,
								XmNspacing,             0,
								NULL);
	FieldsRowCol = XtVaCreateManagedWidget ("UIAttribViewNamesRowColumn",xmRowColumnWidgetClass,rowCol,
								XmNorientation,         XmVERTICAL,
								XmNrowColumnType,       XmWORK_AREA,
								XmNspacing,             0,
								NULL);

	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)	NewField (field->Name (),field->Format ());
			break;
		case DBTypeGridContinuous:
			{
			DBObjRecord *record;
			DBGridIF *gridIF = new DBGridIF (DataPTR);
			ItemTable = DataPTR->Table (DBrNLayers);
			for (record = ItemTable->First ();record != (DBObjRecord *) NULL;record = ItemTable->Next ())
				NewField (record->Name (),gridIF->ValueFormat ());
			delete gridIF;
			} break;
		case DBTypeNetwork:
			{
			DBObjTable *cellTable = DataPTR->Table (DBrNCells);

			NewField ((char *) "Basin Name",(char *) "%s");
			fields = ItemTable->Fields ();
			for (field = fields->First ();field != (DBObjTableField *) NULL;field = fields->Next ())
				if (DBTableFieldIsVisible (field) == true)	NewField (field->Name (),field->Format ());

			fields =  cellTable->Fields ();
			for (field = fields->First ();field != (DBObjTableField *) NULL;field = fields->Next ())
				if (DBTableFieldIsVisible (field) == true)	NewField (field->Name (),field->Format ());
			} break;
		default:	break;
		}
	XtManageChild (mainForm);
	UILoop ();
	}
Ejemplo n.º 4
0
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;
		}
	}
Ejemplo n.º 5
0
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);
}