Exemple #1
0
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();
}
Exemple #2
0
int DBObjTable::Write(FILE *file) {
    DBInt id;
    DBObjRecord *obj;
    DBObjRecord *record;
    DBObjTableField *field;

    if (DBObjectLIST<DBObjRecord>::Write(file) != DBSuccess) return (DBFault);
    if (FieldPTR->Write(file) != DBSuccess) return (DBFault);
    for (id = 0; id < FieldPTR->ItemNum(); ++id)
        if (FieldPTR->WriteItem(file, id) == DBFault) return (DBFault);

    for (id = 0; id < ItemNum(); ++id) {
        record = Item(id);
        for (field = FieldPTR->First(); field != (DBObjTableField *) NULL; field = FieldPTR->Next())
            switch (field->Type()) {
                case DBTableFieldTableRec:
                case DBTableFieldDataRec:
                    if ((obj = field->Record(record)) != (DBObjRecord *) NULL)
                        field->Record(record, (DBObjRecord *) ((char *) NULL + obj->RowID()));
                    else field->Record(record, (DBObjRecord *) DBFault);
                    break;
            }
        if (WriteItem(file, id) == DBFault) return (DBFault);
    }
    if (MethodPTR->Write(file) != DBSuccess) return (DBFault);
    for (id = 0; id < MethodPTR->ItemNum(); ++id) if (MethodPTR->WriteItem(file, id) == DBFault) return (DBFault);
    return (DBSuccess);
}
Exemple #3
0
int DBObjData::BuildFields() {
    DBInt ret = DBSuccess;
    DBObjTable *table, *refTable;
    DBObjRecord *tableRec;
    DBObjTableField *field;
    DBObjectLIST<DBObjTableField> *tableFLDs;

    for (table = TablesPTR->First(); table != (DBObjTable *) NULL; table = TablesPTR->Next()) {
        tableFLDs = table->Fields();
        for (field = tableFLDs->First(); field != (DBObjTableField *) NULL; field = tableFLDs->Next())
            switch (field->Type()) {
                case DBTableFieldTableRec:
                    if ((refTable = TablesPTR->Item(field->RecordProp())) == (DBObjTable *) NULL) {
                        CMmsgPrint(CMmsgAppError, "Corrupt Dataset in: %s %d", __FILE__, __LINE__);
                        ret = DBFault;
                        continue;
                    }
                    for (tableRec = table->First(); tableRec != (DBObjRecord *) NULL; tableRec = table->Next())
                        if ((DBInt) (field->Record(tableRec) - (DBObjRecord *) NULL) != DBFault)
                            field->Record(tableRec,
                                          refTable->Item((DBInt) ((char *) (field->Record(tableRec)) - (char *) NULL)));
                        else field->Record(tableRec, (DBObjRecord *) NULL);
                    break;
                case DBTableFieldDataRec:
                    for (tableRec = table->First(); tableRec != (DBObjRecord *) NULL; tableRec = table->Next())
                        if ((DBInt) (field->Record(tableRec) - (DBObjRecord *) NULL) != DBFault)
                            field->Record(tableRec, ArraysPTR->Item(
                                    (DBInt) ((char *) (field->Record(tableRec)) - (char *) NULL)));
                        else field->Record(tableRec, (DBObjRecord *) NULL);
                    break;
            }
    }
    return (ret);
}
Exemple #4
0
int RGlibGenFuncSymbolField (DBObjData *data, const char *fieldName)
	{
	DBInt recID;
	char symbolName [DBStringLength + 1];
	DBObjTable *table = data->Table (DBrNItems);
	DBObjTable *symbols = data->Table (DBrNSymbols);
	DBObjRecord *record, *symbolRec;
	DBObjTableField *field;
	DBObjTableField *symbolFLD;
	DBObjTableField *symbolIDFLD;
	DBObjTableField *foregroundFLD;
	DBObjTableField *backgroundFLD;
	DBObjTableField *styleFLD;

	if (table == (DBObjTable *) NULL) return (DBFault);
	if ((field = table->Field (fieldName)) == (DBObjTableField *) NULL)
	{ CMmsgPrint (CMmsgAppError,  "Invalid field name in: %s %d",__FILE__,__LINE__);       return (DBFault); }
	if ((symbolFLD = table->Field (DBrNSymbol)) == (DBObjTableField *) NULL)
	{ CMmsgPrint (CMmsgAppError,  "Missing symbol field in: %s %d",__FILE__,__LINE__);     return (DBFault); }
	if (symbols == (DBObjTable *) NULL)
	{ CMmsgPrint (CMmsgAppError,  "Missing symbol table in: %s %d",__FILE__,__LINE__);     return (DBFault); }
	if ((symbolIDFLD   = symbols->Field (DBrNSymbolID))   == (DBObjTableField *) NULL)
	{ CMmsgPrint (CMmsgAppError,  "Missing symbolID field in: %s %d",__FILE__,__LINE__);   return (DBFault); }
	if ((foregroundFLD = symbols->Field (DBrNForeground)) == (DBObjTableField *) NULL)
	{ CMmsgPrint (CMmsgAppError,  "Missing foreground field in: %s %d",__FILE__,__LINE__); return (DBFault); }
	if ((backgroundFLD = symbols->Field (DBrNBackground)) == (DBObjTableField *) NULL)
	{ CMmsgPrint (CMmsgAppError,  "Missing background field in: %s %d",__FILE__,__LINE__); return (DBFault); }
	if ((styleFLD      = symbols->Field (DBrNStyle))      == (DBObjTableField *) NULL)
	{ CMmsgPrint (CMmsgAppError,  "Missing style field in: %s %d",__FILE__,__LINE__);      return (DBFault); }

	symbols->DeleteAll ();
	for (recID = 0;recID < table->ItemNum (); ++recID)
		{
		record = table->Item (recID);
		DBPause (record->RowID () * 100 / table->ItemNum ());
		
		if (field->Type () == DBTableFieldString) sprintf (symbolName,"%s",field->String (record));
		else	sprintf (symbolName,"Symbol:%03d",field->Int (record));
		if ((symbolRec = (DBObjRecord *) symbols->Item (symbolName)) == (DBObjRecord *) NULL)
			{
			if ((symbolRec = symbols->Add (symbolName)) == NULL)
				{ CMmsgPrint (CMmsgAppError, "Symbol Object Creation Error in: %s %d",__FILE__,__LINE__); return (DBFault); }
			symbolIDFLD->Int (symbolRec,field->Type () == DBTableFieldString ? symbolRec->RowID () : field->Int (record));
			foregroundFLD->Int (symbolRec,1);
			backgroundFLD->Int (symbolRec,0);
			styleFLD->Int (symbolRec,0);
			}
		symbolFLD->Record (record,symbolRec);
		}
	return (DBSuccess);
	}
Exemple #5
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);
}
Exemple #6
0
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);
	}
Exemple #7
0
DBNetworkIF::DBNetworkIF (DBObjData *data)
	{
	DBObjTableField *layerFLD;

	DataPTR = data;
	BasinTable	= data->Table (DBrNItems);
	CellTable	= data->Table (DBrNCells);
	LayerTable	= data->Table (DBrNLayers);
	SymbolTable	= data->Table (DBrNSymbols);

	MouthPosFLD		= BasinTable->Field (DBrNMouthPos);
	ColorFLD			= BasinTable->Field (DBrNColor);
	BasinOrderFLD	= BasinTable->Field (DBrNBasinOrder);
	SymbolFLD		= BasinTable->Field (DBrNSymbol);
	BasinLengthFLD	= BasinTable->Field (DBrNBasinLength);
	BasinAreaFLD	= BasinTable->Field (DBrNBasinArea);

	SymbolIDFLD		= SymbolTable->Field (DBrNSymbolID);
	ForegroundFLD	= SymbolTable->Field (DBrNForeground);
	BackgroundFLD	= SymbolTable->Field (DBrNBackground);

	PositionFLD		= CellTable->Field (DBrNPosition);
	ToCellFLD		= CellTable->Field (DBrNToCell);
	FromCellFLD		= CellTable->Field (DBrNFromCell);
	OrderFLD			= CellTable->Field (DBrNOrder);
	MagnitudeFLD	= CellTable->Field (DBrNMagnitude);
	BasinFLD			= CellTable->Field (DBrNBasin);
	BasinCellsFLD	= CellTable->Field (DBrNBasinCells);
	TravelFLD		= CellTable->Field (DBrNTravel);
	UpCellPosFLD	= CellTable->Field (DBrNUpCellPos);
	CellAreaFLD		= CellTable->Field (DBrNCellArea);
	CellLengthFLD	= CellTable->Field (DBrNCellLength);
	DistToMouthFLD		= CellTable->Field (DBrNDistToMouth);
	DistToOceanFLD		= CellTable->Field (DBrNDistToOcean);
	SubbasinLengthFLD	= CellTable->Field (DBrNSubbasinLength);
	SubbasinAreaFLD	= CellTable->Field (DBrNSubbasinArea);

	RowNumFLD		= LayerTable->Field (DBrNRowNum);
	ColNumFLD		= LayerTable->Field (DBrNColNum);
	CellWidthFLD	= LayerTable->Field (DBrNCellWidth);
	CellHeightFLD	= LayerTable->Field (DBrNCellHeight);
	layerFLD			= LayerTable->Field (DBrNLayer);

	if ((LayerRecord = LayerTable->Item (DBrNLookupGrid)) == (DBObjRecord *) NULL)
		{ CMmsgPrint (CMmsgAppError,"Bailing Out like ARC/INFO in: %s %d",__FILE__,__LINE__); exit (-1); }
	if((DataRec	= layerFLD->Record (LayerRecord)) == (DBObjRecord *) NULL)
		{ CMmsgPrint (CMmsgAppError,"Bailing Out in: %s %d",__FILE__,__LINE__); exit (-1); }
	if (CellLengthFLD == (DBObjTableField *) NULL)
		{
		DBInt cellID;
		DBObjRecord *cellRec;
		DBCoordinate coord0, coord1;

		CellLengthFLD = new DBObjTableField (DBrNCellLength,DBTableFieldFloat,"%10.1f",sizeof (DBFloat4),true);
		CellTable->AddField (CellLengthFLD);
		for (cellID = 0;cellID < CellNum ();++cellID)
			{
			cellRec = Cell (cellID);
			coord0 = Center (cellRec);
			coord1 = Center (cellRec) + Delta (cellRec);
			CellLengthFLD->Float (cellRec,DBMathCoordinateDistance (DataPTR->Projection (),coord0,coord1));
			}
		}
	}
Exemple #8
0
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);
	}
Exemple #9
0
DBObjData *DBNetworkToGrid(DBObjData *netData, DBInt type) {
    DBPosition pos;
    DBObjData *grdData = new DBObjData("", type);
    DBObjRecord *layerRec, *dataRec;
    DBObjTable *layerTable = grdData->Table(DBrNLayers);
    DBObjTable *itemTable = grdData->Table(DBrNItems);
    DBObjTableField *rowNumFLD = layerTable->Field(DBrNRowNum);
    DBObjTableField *colNumFLD = layerTable->Field(DBrNColNum);
    DBObjTableField *cellWidthFLD = layerTable->Field(DBrNCellWidth);
    DBObjTableField *cellHeightFLD = layerTable->Field(DBrNCellHeight);
    DBObjTableField *valueTypeFLD = layerTable->Field(DBrNValueType);
    DBObjTableField *valueSizeFLD = layerTable->Field(DBrNValueSize);
    DBObjTableField *layerFLD = layerTable->Field(DBrNLayer);
    DBNetworkIF *netIF;
    DBGridIF *gridIF;

    grdData->Projection(netData->Projection());
    grdData->Precision(netData->Precision());
    grdData->MaxScale(netData->MaxScale());
    grdData->MinScale(netData->MinScale());
    grdData->Extent(netData->Extent());
    grdData->Document(DBDocGeoDomain, netData->Document(DBDocGeoDomain));

    netIF = new DBNetworkIF(netData);

    layerTable->Add("FirstLayer");
    if ((layerRec = layerTable->Item()) == (DBObjRecord *) NULL) {
        delete netIF;
        return ((DBObjData *) NULL);
    }
    rowNumFLD->Int(layerRec, netIF->RowNum());
    colNumFLD->Int(layerRec, netIF->ColNum());
    cellWidthFLD->Float(layerRec, netIF->CellWidth());
    cellHeightFLD->Float(layerRec, netIF->CellHeight());
    switch (type) {
        case DBTypeGridContinuous:
            valueTypeFLD->Int(layerRec, DBTableFieldFloat);
            valueSizeFLD->Int(layerRec, sizeof(DBFloat));
            break;
        case DBTypeGridDiscrete:
            valueTypeFLD->Int(layerRec, DBTableFieldInt);
            valueSizeFLD->Int(layerRec, sizeof(DBInt));
            break;
        default:
            CMmsgPrint(CMmsgAppError, "Invalid Data Type in: %s %d", __FILE__, __LINE__);
            delete grdData;
            delete netIF;
            return ((DBObjData *) NULL);
    }
    if ((dataRec = new DBObjRecord(layerRec->Name(),
                                   ((size_t) netIF->ColNum()) * netIF->RowNum() * valueSizeFLD->Int(layerRec),
                                   valueSizeFLD->Int(layerRec))) == (DBObjRecord *) NULL) {
        delete netIF;
        return ((DBObjData *) NULL);
    }
    (grdData->Arrays())->Add(dataRec);
    layerFLD->Record(layerRec, dataRec);

    gridIF = new DBGridIF(grdData);
    if (type == DBTypeGridContinuous) {
        itemTable->Add(layerRec->Name());
        DBObjTableField *missingValueFLD = itemTable->Field(DBrNMissingValue);
        missingValueFLD->Float(itemTable->Item(layerRec->Name()), DBDefaultMissingFloatVal);
        for (pos.Row = 0; pos.Row < netIF->RowNum(); pos.Row++)
            for (pos.Col = 0; pos.Col < netIF->ColNum(); pos.Col++)
                gridIF->Value(layerRec, pos, DBDefaultMissingFloatVal);
    }
    else {
        DBObjTable *symbolTable = grdData->Table(DBrNSymbols);
        DBObjTableField *foregroundFLD = symbolTable->Field(DBrNForeground);
        DBObjTableField *backgroundFLD = symbolTable->Field(DBrNBackground);
        DBObjTableField *styleFLD = symbolTable->Field(DBrNStyle);
        DBObjRecord *symbolRec = symbolTable->Add("Default Symbol");

        foregroundFLD->Int(symbolRec, 1);
        backgroundFLD->Int(symbolRec, 0);
        styleFLD->Int(symbolRec, 0);
        for (pos.Row = 0; pos.Row < netIF->RowNum(); pos.Row++)
            for (pos.Col = 0; pos.Col < netIF->ColNum(); pos.Col++)
                gridIF->Value(layerRec, pos, 0);
    }
    delete netIF;
    delete gridIF;
    return (grdData);
}
Exemple #10
0
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;
	}
Exemple #11
0
		DBInt Read (FILE *file,DBObjData *data)
			{
			DBInt i, layer, swap, valueType, valueSize, docLength;
			DMLayerHeader dmLayerHeader;
			DBObjRecord *layerRec, *dataRec;
			DBObjTable *layerTable = data->Table (DBrNLayers);
			DBObjTable *itemTable	 = data->Table (DBrNItems);
			DBObjTableField *rowNumFLD = layerTable->Field (DBrNRowNum);
			DBObjTableField *colNumFLD = layerTable->Field (DBrNColNum);
			DBObjTableField *cellWidthFLD = layerTable->Field (DBrNCellWidth);
			DBObjTableField *cellHeightFLD = layerTable->Field (DBrNCellHeight);
			DBObjTableField *valueTypeFLD = layerTable->Field (DBrNValueType);
			DBObjTableField *valueSizeFLD = layerTable->Field (DBrNValueSize);
			DBObjTableField *layerFLD = layerTable->Field (DBrNLayer);
			DBGridIF *gridIF;

			if ((swap = DMFileHeader::Read (file)) == DBFault) return (DBFault);
         data->Extent (Extent ());
         data->Projection (DBMathGuessProjection (data->Extent ()));
         data->Precision  (DBMathGuessPrecision  (data->Extent ()));
			if (FileType () != DMMatrix)
				{ CMmsgPrint (CMmsgAppError, "Wrong File Type in: %s %d",__FILE__,__LINE__); return (DBFault); }
			switch (DataType ())
				{
				case DMFloat:	valueType = DBTableFieldFloat;	valueSize = sizeof (DBFloat4);break;
				case DMInt:		valueType = DBTableFieldInt;		valueSize = sizeof (DBInt);	break;
				case DMByte:	valueType = DBTableFieldInt;		valueSize = sizeof (DBByte);	break;
				default: CMmsgPrint (CMmsgAppError, "Wrong Data Value Type in: %s %d",__FILE__,__LINE__); return (DBFault);
				}
			for (layer = 0;layer < LayerNum ();++layer)
				{
				if (dmLayerHeader.Read (file,swap) == DBFault) return (DBFault);
				if (strlen (dmLayerHeader.Description ()) > 0) layerName = dmLayerHeader.Description ();
				else { sprintf (layerNameSTR,"GHAASLayer%4d",layer + 1); layerName = layerNameSTR; }
				layerTable->Add (layerName);
				if ((layerRec = layerTable->Item ()) == (DBObjRecord *) NULL) return (DBFault);
				rowNumFLD->Int (layerRec,RowNum ());
				colNumFLD->Int (layerRec,ColNum ());
				cellWidthFLD->Float (layerRec,CellWidth ());
				cellHeightFLD->Float (layerRec,CellHeight ());
				valueTypeFLD->Int (layerRec,((DBInt) DBTypeGridDiscrete) == data->Type () ? DBTableFieldInt : valueType);
				valueSizeFLD->Int (layerRec,valueSize);
				if ((dataRec = new DBObjRecord (layerName,((size_t) ColNum ()) * RowNum () * valueSize,valueSize)) == (DBObjRecord *) NULL)
					return (DBFault);
				(data->Arrays ())->Add (dataRec);
				layerFLD->Record (layerRec,dataRec);
				}
			if (fread (&docLength,sizeof (int),1,file) != 1)
				{ CMmsgPrint (CMmsgSysError, "File Reading Error in: %s %d",__FILE__,__LINE__); return (DBFault); }
			if (swap) DBByteOrderSwapWord (&docLength);
			if (docLength > 0)
				{
				char *docString;
				if ((docString = (char *) calloc (docLength,sizeof (char))) == (char *) NULL)
					{ CMmsgPrint (CMmsgSysError, "Memory Allocation Error in: %s %d",__FILE__,__LINE__); return (DBFault); }
				if (fread (docString,docLength,1,file) != 1)
					{ CMmsgPrint (CMmsgSysError, "File Reading Error in: %s %d",__FILE__,__LINE__); return (DBFault); }
				data->Document (DBDocComment,docString);
				free (docString);
				}
			for (dataRec = (data->Arrays ())->First ();dataRec != (DBObjRecord *) NULL;dataRec = (data->Arrays ())->Next ())
				if (fread (dataRec->Data (),ColNum () * valueSize * RowNum (),1,file) != 1)
					{ CMmsgPrint (CMmsgSysError, "File Reading Error in: %s %d",__FILE__,__LINE__); return (DBFault); }
			if (swap && valueSize > 1)
				{
				int i;
				void (*swapFunc) (void *);
				switch (valueSize)
					{
					case 2: swapFunc = DBByteOrderSwapHalfWord; break;
					case 4: swapFunc = DBByteOrderSwapWord; break;
					case 8: swapFunc = DBByteOrderSwapLongWord; break;
					default: CMmsgPrint (CMmsgAppError, "Wrong Data Value Size in: %s %d",__FILE__,__LINE__); return (DBFault);
					}
				for (dataRec = (data->Arrays ())->First ();dataRec != (DBObjRecord *) NULL;dataRec = (data->Arrays ())->Next ())
					for (i = 0;i < ColNum () * RowNum ();++i) (*swapFunc) ((char *) dataRec->Data () + i * valueSize);
				}
			switch (data->Type ())
				{
				case DBTypeGridDiscrete:
					{
					DBInt value;
					char nameStr [DBStringLength];
					DBObjRecord *symRec = (data->Table (DBrNSymbols))->Add ("Default Symbol");
					DBObjRecord *itemRec;
					DBObjTableField *gridValueFLD  = itemTable->Field (DBrNGridValue);
					DBObjTableField *gridSymbolFLD = itemTable->Field (DBrNSymbol);
					DBObjTableField *symbolIDFLD	 = (data->Table (DBrNSymbols))->Field (DBrNSymbolID);
					DBObjTableField *foregroundFLD = (data->Table (DBrNSymbols))->Field (DBrNForeground);
					DBObjTableField *backgroundFLD = (data->Table (DBrNSymbols))->Field (DBrNBackground);
					DBObjTableField *styleFLD = (data->Table (DBrNSymbols))->Field (DBrNStyle);

					symbolIDFLD->Int (symRec,0);
					foregroundFLD->Int (symRec,1);
					backgroundFLD->Int (symRec,0);
					styleFLD->Int (symRec,0);
					for (dataRec = (data->Arrays ())->First ();dataRec != (DBObjRecord *) NULL;dataRec = (data->Arrays ())->Next ())
						{
						for (i = 0;i < ColNum () * RowNum ();++i)
							{
							switch (valueType)
								{
								case DBTableFieldFloat: value = (DBInt) rint (*((float *) ((char *) dataRec->Data () + i * valueSize))); break;
								case DBTableFieldInt:
									switch (valueSize)
										{
										case sizeof (DBByte):  value = (DBInt) (*((DBByte *)  ((char *) dataRec->Data () + i * valueSize))); break;
										case sizeof (DBShort): value = (DBInt) (*((DBShort *) ((char *) dataRec->Data () + i * valueSize))); break;
										case sizeof (DBInt):	  value = (DBInt) (*((DBInt *)	((char *) dataRec->Data () + i * valueSize))); break;
										default: CMmsgPrint (CMmsgAppError, "Wrong Data Size in: %s %d",__FILE__,__LINE__); return (DBFault);
										}
									break;
								default: CMmsgPrint (CMmsgAppError, "Wrong Data Type in: %s %d",__FILE__,__LINE__); return (DBFault);
								}
							sprintf (nameStr,"Category%04d",value);
							if ((itemRec = itemTable->Item (nameStr)) == (DBObjRecord *) NULL)
								{
								if ((itemRec = itemTable->Add (nameStr)) == (DBObjRecord *) NULL)
									{ CMmsgPrint (CMmsgAppError, "Item Object Creation Error in: %s %d",__FILE__,__LINE__); return (DBFault); }
								gridValueFLD->Int (itemRec,value);
								gridSymbolFLD->Record (itemRec,symRec);
								}
							value = itemRec->RowID ();
							switch (valueSize)
								{
								case sizeof (DBByte):  *((DBByte *)  ((char *) dataRec->Data () + i * valueSize)) = value; break;
								case sizeof (DBShort): *((DBShort *) ((char *) dataRec->Data () + i * valueSize)) = value; break;
								case sizeof (DBInt):	  *((DBInt *)	 ((char *) dataRec->Data () + i * valueSize)) = value; break;
								default: CMmsgPrint (CMmsgAppError, "Wrong Data Size in: %s %d",__FILE__,__LINE__); return (DBFault);
								}
							}
						}
					itemTable->ListSort (gridValueFLD);
					for (dataRec = (data->Arrays ())->First ();dataRec != (DBObjRecord *) NULL;dataRec = (data->Arrays ())->Next ())
						{
						for (i = 0;i < ColNum () * RowNum ();++i)
							{
							switch (valueSize)
								{
								case sizeof (DBByte):  value = (DBInt) (*((DBByte *)  ((char *) dataRec->Data () + i * valueSize))); break;
								case sizeof (DBShort): value = (DBInt) (*((DBShort *) ((char *) dataRec->Data () + i * valueSize))); break;
								case sizeof (DBInt):	  value = (DBInt) (*((DBInt *)	((char *) dataRec->Data () + i * valueSize))); break;
								default: CMmsgPrint (CMmsgAppError, "Wrong Data Size in: %s %d",__FILE__,__LINE__); return (DBFault);
								}
							itemRec = itemTable->Item (value);
							value = itemRec->ListPos ();
							switch (valueSize)
								{
								case sizeof (DBByte):  *((DBByte *)  ((char *) dataRec->Data () + i * valueSize)) = value; break;
								case sizeof (DBShort): *((DBShort *) ((char *) dataRec->Data () + i * valueSize)) = value; break;
								case sizeof (DBInt):	  *((DBInt *)	 ((char *) dataRec->Data () + i * valueSize)) = value; break;
								default: CMmsgPrint (CMmsgAppError, "Wrong Data Size in: %s %d",__FILE__,__LINE__); return (DBFault);
								}
							}
						}
					itemTable->ItemSort ();
					gridIF = new DBGridIF (data);
					gridIF->DiscreteStats ();
					delete gridIF;
					} break;
				case DBTypeGridContinuous:
					{
					DBObjTableField *missingValueFLD		= itemTable->Field (DBrNMissingValue);

					for (dataRec = (data->Arrays ())->First ();dataRec != (DBObjRecord *) NULL;dataRec = (data->Arrays ())->Next ())
						{
						itemTable->Add (dataRec->Name ());
						missingValueFLD->Float (itemTable->Item (),MissingValue ());
						}
					gridIF = new DBGridIF (data);
					gridIF->RecalcStats ();
					delete gridIF;
					data->Flags (DBDataFlagDispModeContBlueRed,DBSet);
					break;
					}
				default: break;
				}
			return (DBSuccess);
			}
Exemple #12
0
DBInt DBGridCont2Network (DBObjData *gridData,DBObjData *netData, bool downhill)

	{
	DBInt basinID, layerID, zLayerID, zLayerNum, dir, maxDir, projection = gridData->Projection (), *zones;
	DBFloat elev0, elev1, delta, maxDelta, distance;
	DBCoordinate coord0, coord1;
	DBInt row, col;
	DBPosition pos, auxPos;
	char nameSTR [DBStringLength];
	DBObjTable *basinTable = netData->Table (DBrNItems);
	DBObjTable *cellTable  = netData->Table (DBrNCells);
	DBObjTable *layerTable = netData->Table (DBrNLayers);
	DBObjRecord *layerRec, *dataRec, *cellRec, *basinRec;

	DBObjTableField *mouthPosFLD = basinTable->Field (DBrNMouthPos);
	DBObjTableField *colorFLD		= basinTable->Field (DBrNColor);

	DBObjTableField *positionFLD	= cellTable->Field (DBrNPosition);
	DBObjTableField *toCellFLD		= cellTable->Field (DBrNToCell);
	DBObjTableField *fromCellFLD	= cellTable->Field (DBrNFromCell);
	DBObjTableField *orderFLD		= cellTable->Field (DBrNOrder);
	DBObjTableField *basinFLD		= cellTable->Field (DBrNBasin);
	DBObjTableField *basinCellsFLD= cellTable->Field (DBrNBasinCells);
	DBObjTableField *travelFLD		= cellTable->Field (DBrNTravel);
	DBObjTableField *upCellPosFLD	= cellTable->Field (DBrNUpCellPos);
	DBObjTableField *cellAreaFLD	= cellTable->Field (DBrNCellArea);
	DBObjTableField *subbasinLengthFLD = cellTable->Field (DBrNSubbasinLength);
	DBObjTableField *subbasinAreaFLD = cellTable->Field (DBrNSubbasinArea);

	DBObjTableField *rowNumFLD = layerTable->Field (DBrNRowNum);
	DBObjTableField *colNumFLD = layerTable->Field (DBrNColNum);
	DBObjTableField *cellWidthFLD = layerTable->Field (DBrNCellWidth);
	DBObjTableField *cellHeightFLD = layerTable->Field (DBrNCellHeight);
	DBObjTableField *valueTypeFLD = layerTable->Field (DBrNValueType);
	DBObjTableField *valueSizeFLD = layerTable->Field (DBrNValueSize);
	DBObjTableField *layerFLD = layerTable->Field (DBrNLayer);
	DBObjData *zGridData = gridData->LinkedData ();
	DBGridIF *gridIF = new DBGridIF (gridData), *zGridIF;
	DBNetworkIF *netIF;

	if ((zGridData != (DBObjData *) NULL) && ((zGridData->Type () == DBTypeGridDiscrete) || (zGridData->Type () == DBTypeGridContinuous)))
		{
		zGridIF = new DBGridIF (zGridData);
		zLayerNum = zGridIF->LayerNum () + 1;
		}
	else { zGridIF = (DBGridIF *) NULL; zLayerNum = 1; }

	if ((zones = (DBInt *) calloc (9 * zLayerNum,sizeof (DBInt))) == (DBInt *) NULL)
		{
		CMmsgPrint (CMmsgSysError, "Memory Allocation Error in: %s %d",__FILE__,__LINE__);
		if (zGridIF != (DBGridIF *) NULL) delete zGridIF;
		delete gridIF;
		return (DBFault);
		}
	layerTable->Add (DBrNLookupGrid);
	if ((layerRec = layerTable->Item (DBrNLookupGrid)) == (DBObjRecord *) NULL)
		{
		free (zones);
		if (zGridIF != (DBGridIF *) NULL) delete zGridIF;
		delete gridIF;
		return (DBFault);
		}

	netData->Projection (projection);
	netData->Extent (gridData->Extent ());
	cellWidthFLD->Float  (layerRec,gridIF->CellWidth ());
	cellHeightFLD->Float (layerRec,gridIF->CellHeight ());
	valueTypeFLD->Int (layerRec,DBTableFieldInt);
	valueSizeFLD->Int (layerRec,sizeof (DBInt));
	rowNumFLD->Int (layerRec,gridIF->RowNum ());
	colNumFLD->Int (layerRec,gridIF->ColNum ());

	dataRec = new DBObjRecord ("NetLookupGridRecord",((size_t) gridIF->RowNum ()) * gridIF->ColNum () * sizeof (DBInt),sizeof (DBInt));
	if (dataRec == (DBObjRecord *) NULL)
		{
		if (zGridIF != (DBGridIF *) NULL) delete zGridIF;
		return (DBFault);
		}
	layerFLD->Record (layerRec,dataRec);
	(netData->Arrays ())->Add (dataRec);
	for (pos.Row = 0;pos.Row < gridIF->RowNum ();pos.Row++)
		for (pos.Col = 0;pos.Col < gridIF->ColNum ();pos.Col++)
			((DBInt *) dataRec->Data ()) [pos.Row * gridIF->ColNum () + pos.Col] = DBFault;

	for (pos.Row = 0;pos.Row < gridIF->RowNum ();pos.Row++)
		{
		if (DBPause (10 * pos.Row / gridIF->RowNum ())) goto PauseStop;
		for (pos.Col = 0;pos.Col < gridIF->ColNum ();pos.Col++)
			{
			gridIF->Pos2Coord (pos,coord0);
			zLayerID = 0;
			if (zGridIF != (DBGridIF *) NULL)
				for ( ; zLayerID < zGridIF->LayerNum (); zLayerID++)
					{
					layerRec = zGridIF->Layer (zLayerID);
					if ((layerRec->Flags () & DBObjectFlagIdle) == DBObjectFlagIdle) continue;
					for (dir = 0;dir < 8;++dir)
						{
						row = pos.Row;
						col = pos.Col;
						if (((0x01 << dir) == DBNetDirNW) || ((0x01 << dir) == DBNetDirN) || ((0x01 << dir) == DBNetDirNE)) row++;
						if (((0x01 << dir) == DBNetDirSE) || ((0x01 << dir) == DBNetDirS) || ((0x01 << dir) == DBNetDirSW)) row--;
						if (((0x01 << dir) == DBNetDirNE) || ((0x01 << dir) == DBNetDirE) || ((0x01 << dir) == DBNetDirSE)) col++;
						if (((0x01 << dir) == DBNetDirNW) || ((0x01 << dir) == DBNetDirW) || ((0x01 << dir) == DBNetDirSW)) col--;
						if (row < 0) continue;
						if (col < 0) continue;
						if (row >= gridIF->RowNum ()) continue;
						if (col >= gridIF->ColNum ()) continue;
						auxPos.Row = row;
						auxPos.Col = col;
						gridIF->Pos2Coord (auxPos,coord1);
						switch (zGridData->Type ())
							{
							case DBTypeGridDiscrete:	basinID = zGridIF->GridValue (layerRec,coord1);	break;
							case DBTypeGridContinuous:	zGridIF->Value (layerRec,coord1,&basinID);		break;
							}
						zones [zLayerID * 9 + dir] = basinID;
						}
					switch (zGridData->Type ())
						{
						case DBTypeGridDiscrete:	basinID = zGridIF->GridValue (layerRec,coord0);	break;
						case DBTypeGridContinuous: zGridIF->Value (layerRec,coord0,&basinID);		break;
						}
					zones [zLayerID * 9 + 8] = basinID;
					}
			for (dir = 0;dir < 9;++dir) zones [zLayerID * 9 + dir] = 0;

			maxDir = DBFault;
			for (layerID = 0;layerID < gridIF->LayerNum ();++layerID)
				{
				layerRec = gridIF->Layer (layerID);
				if ((layerRec->Flags () & DBObjectFlagIdle) == DBObjectFlagIdle) continue;
				if (gridIF->Value (layerRec,pos,&elev0))
					{
					maxDelta = (DBFloat) 0.0;
					maxDir   = 0;

					for (zLayerID = 0;zLayerID < zLayerNum;++zLayerID)
						{
						for (dir = 0;dir < 8;++dir)
							{
							row = pos.Row;
							col = pos.Col;
							if (((0x01 << dir) == DBNetDirNW) || ((0x01 << dir) == DBNetDirN) || ((0x01 << dir) == DBNetDirNE)) row++;
							if (((0x01 << dir) == DBNetDirSE) || ((0x01 << dir) == DBNetDirS) || ((0x01 << dir) == DBNetDirSW)) row--;
							if (((0x01 << dir) == DBNetDirNE) || ((0x01 << dir) == DBNetDirE) || ((0x01 << dir) == DBNetDirSE)) col++;
							if (((0x01 << dir) == DBNetDirNW) || ((0x01 << dir) == DBNetDirW) || ((0x01 << dir) == DBNetDirSW)) col--;
							if (col < 0) continue;
							if (row < 0) continue;
							if (col >= gridIF->ColNum ()) continue;
							if (row >= gridIF->RowNum ()) continue;
							auxPos.Row = row;
							auxPos.Col = col;
							gridIF->Pos2Coord (auxPos,coord1);
							distance = DBMathCoordinateDistance (projection,coord0,coord1);
							if ((zones [zLayerID * 9 + dir] == zones [zLayerID * 9 + 8]) && (gridIF->Value (layerRec,auxPos,&elev1)))
								{
								delta = (downhill ? (elev1 - elev0) : (elev0 - elev1)) / distance;
								if (maxDelta > delta) { maxDelta = delta; maxDir = (0x01 << dir); }
								}
							}
						if (maxDir != 0) goto SlopeStop;
						}
					}
				}
SlopeStop:
			if (maxDir != DBFault)
				{
				sprintf (nameSTR,"GHAASCell:%d",cellTable->ItemNum ());
				cellRec = cellTable->Add (nameSTR);
				positionFLD->Position(cellRec,pos);
				toCellFLD->Int			(cellRec,(DBInt) maxDir);
				fromCellFLD->Int		(cellRec,(DBInt) 0);
				orderFLD->Int			(cellRec,(DBInt) 0);
				basinFLD->Int			(cellRec,(DBInt) 0);
				basinCellsFLD->Int	(cellRec,(DBInt) 0);
				travelFLD->Int			(cellRec,(DBInt) 0);
				upCellPosFLD->Position	(cellRec,pos);
				cellAreaFLD->Float	(cellRec,(DBFloat) 0.0);
				subbasinLengthFLD->Float(cellRec,(DBFloat) 0.0);
				subbasinAreaFLD->Float	(cellRec,(DBFloat) 0.0);
				((DBInt *) dataRec->Data ()) [pos.Row * gridIF->ColNum () + pos.Col] = cellRec->RowID ();
				}
			}
		}
PauseStop:
	if (pos.Row < gridIF->RowNum ())	return (DBFault);
	sprintf (nameSTR,"GHAASBasin%d",(DBInt) 0);
	basinRec = basinTable->Add (nameSTR);
	mouthPosFLD->Position	(basinRec,positionFLD->Position (cellTable->Item (0)));
	colorFLD->Int				(basinRec,0);

	free (zones);
	delete gridIF;
	if (zGridIF != (DBGridIF *) NULL) delete zGridIF;

	netData->Precision (DBMathMin (gridIF->CellWidth (),gridIF->CellHeight ()) / 25.0);
	netIF = new DBNetworkIF (netData);
	netIF->Build ();
	delete netIF;
	return (DBSuccess);
	}
Exemple #13
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;
		}
	}
Exemple #14
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);
}