Esempio n. 1
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);
}
Esempio n. 2
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);
	}
Esempio n. 3
0
void DBObjData::Type(DBInt type) {
    DBInt realData = true;
    DBDataHeader::Type(type);
    switch (type) {
        case DBTypeVectorPoint: {
            DBObjTable *items, *symbols;
            DBObjTableField *symFLD;
            TablesPTR->Add(symbols = _DBCreateDataBlockSymbols());
            TablesPTR->Add(items = _DBCreateDataBlockPoints());
            symFLD = items->Field(DBrNSymbol);
            symFLD->RecordProp(symbols->RowID());
            break;
        }
        case DBTypeVectorLine: {
            DBObjTable *items, *nodes, *symbols;
            DBObjTableField *symFLD;
            DBObjTableField *fromNodeFLD;
            DBObjTableField *toNodeFLD;

            TablesPTR->Add(symbols = _DBCreateDataBlockSymbols());
            TablesPTR->Add(nodes = _DBCreateDataBlockNodes());
            TablesPTR->Add(items = _DBCreateDataBlockLines());
            symFLD = items->Field(DBrNSymbol);
            symFLD->RecordProp(symbols->RowID());
            fromNodeFLD = items->Field(DBrNFromNode);
            fromNodeFLD->RecordProp(nodes->RowID());
            toNodeFLD = items->Field(DBrNToNode);
            toNodeFLD->RecordProp(nodes->RowID());
            break;
        }
        case DBTypeVectorPolygon: {
            DBObjTable *items, *nodes, *lines, *symbols;
            DBObjTableField *symFLD;
            DBObjTableField *fromNodeFLD;
            DBObjTableField *toNodeFLD;
            DBObjTableField *nextLineFLD;
            DBObjTableField *prevLineFLD;
            DBObjTableField *leftPolyFLD;
            DBObjTableField *rightPolyFLD;
            DBObjTableField *firstLineFLD;

            TablesPTR->Add(symbols = _DBCreateDataBlockSymbols());
            TablesPTR->Add(nodes = _DBCreateDataBlockNodes());
            TablesPTR->Add(lines = _DBCreateDataBlockContours());
            TablesPTR->Add(items = _DBCreateDataBlockPolygons());

            symFLD = items->Field(DBrNSymbol);
            symFLD->RecordProp(symbols->RowID());
            fromNodeFLD = lines->Field(DBrNFromNode);
            fromNodeFLD->RecordProp(nodes->RowID());
            toNodeFLD = lines->Field(DBrNToNode);
            toNodeFLD->RecordProp(nodes->RowID());
            nextLineFLD = lines->Field(DBrNNextLine);
            nextLineFLD->RecordProp(lines->RowID());
            prevLineFLD = lines->Field(DBrNPrevLine);
            prevLineFLD->RecordProp(lines->RowID());
            leftPolyFLD = lines->Field(DBrNLeftPoly);
            leftPolyFLD->RecordProp(items->RowID());
            rightPolyFLD = lines->Field(DBrNRightPoly);
            rightPolyFLD->RecordProp(items->RowID());
            firstLineFLD = items->Field(DBrNFirstLine);
            firstLineFLD->RecordProp(lines->RowID());
            break;
        }
        case DBTypeNetwork: {
            DBObjTable *basins, *symbols;
            DBObjTableField *symField;
            TablesPTR->Add(symbols = _DBCreateDataBlockSymbols());
            TablesPTR->Add(basins = _DBCreateDataBlockNetBasins());
            TablesPTR->Add(_DBCreateDataBlockNetCells());
            TablesPTR->Add(_DBCreateDataBlockGridLayers());
            symField = basins->Field(DBrNSymbol);
            symField->RecordProp(symbols->RowID());
            break;
        }
        case DBTypeGridContinuous: {
            TablesPTR->Add(_DBCreateDataBlockGridLayers());
            TablesPTR->Add(_DBCreateDataBlockGridVariableStats());
            break;
        }
        case DBTypeGridDiscrete: {
            DBObjTable *items, *symbols;
            DBObjTableField *symFLD;

            TablesPTR->Add(symbols = _DBCreateDataBlockSymbols());
            TablesPTR->Add(_DBCreateDataBlockGridLayers());
            TablesPTR->Add(items = _DBCreateDataBlockGridCategoryTable());
            symFLD = items->Field(DBrNSymbol);
            symFLD->RecordProp(symbols->RowID());
            break;
        }
        case    DBTypeTable:
            TablesPTR->Add(new DBObjTable(DBrNItems));
            break;
        default:
            realData = false;
            break;
    }
    if (realData) TablesPTR->Add(_DBCreateDataBlockRelateTable());
}