Ejemplo n.º 1
0
DBInt DBGridIF::Value (DBObjRecord *layerRec,DBPosition pos,DBFloat value)

	{
	DBInt j = DimensionVAR.Col * (DimensionVAR.Row - pos.Row - 1) + pos.Col;
	DBObjRecord *dataRec = LayerFLD->Record (layerRec);

	if (pos.Col < 0) return (DBFault);
	if (pos.Row < 0) return (DBFault);
	if (pos.Col >= DimensionVAR.Col) return (DBFault);
	if (pos.Row >= DimensionVAR.Row) return (DBFault);

	switch (ValueTypeVAR)
		{
		case DBTableFieldFloat:
			switch (ValueSizeVAR)
				{
				case sizeof (DBFloat4): ((DBFloat4 *) (dataRec->Data ())) [j] = (DBFloat4) value; break;
				case sizeof (DBFloat):  ((DBFloat *)  (dataRec->Data ())) [j] = value; break;
				}
			break;
		case DBTableFieldInt:
			switch (ValueSizeVAR)
				{
				case sizeof (DBByte):  ((DBByte *)  (dataRec->Data ())) [j] = (DBByte)  value;	break;
				case sizeof (DBShort): ((DBShort *) (dataRec->Data ())) [j] = (DBShort) value;	break;
				case sizeof (DBInt):   ((DBInt *)   (dataRec->Data ())) [j] = (DBInt)   value;	break;
				}
			break;
		}
	return (DBSuccess);
	}
Ejemplo n.º 2
0
DBInt DBGridIF::Value (DBObjRecord *layerRec,DBPosition pos,DBFloat *value) const

	{
	DBInt j;
	DBObjRecord *dataRec = LayerFLD->Record (layerRec);
	DBFloat missingValue = MissingValueFLD->Float (ItemTable->Item (layerRec->RowID ()));

//	if (pos.Col < 0) return (false); No longer possible
//	if (pos.Row < 0) return (false);
	if (pos.Col >= DimensionVAR.Col) return (false);
	if (pos.Row >= DimensionVAR.Row) return (false);

	j = DimensionVAR.Col * (DimensionVAR.Row - pos.Row - 1) + pos.Col;
	switch (ValueTypeVAR)
		{
		case DBTableFieldFloat:
			switch (ValueSizeVAR)
				{
				case sizeof (DBFloat4): *value = (DBFloat) ((DBFloat4 *) (dataRec->Data ())) [j]; break;
				case sizeof (DBFloat):  *value = (DBFloat) ((DBFloat *)  (dataRec->Data ())) [j]; break;
				}
			break;
		case DBTableFieldInt:
			switch (ValueSizeVAR)
				{
				case sizeof (DBByte):  *value = (DBFloat) ((DBByte *)	 (dataRec->Data ())) [j];	break;
				case sizeof (DBShort): *value = (DBFloat) ((DBShort *) (dataRec->Data ())) [j];	break;
				case sizeof (DBInt):   *value = (DBFloat) ((DBInt *)	 (dataRec->Data ())) [j];	break;
				}
			break;
		}
	return (CMmathEqualValues (*value,missingValue) ? false : true);
	}
Ejemplo n.º 3
0
DBInt DBGridIF::Value (DBObjRecord *layerRec,DBPosition pos,DBInt *value) const

	{
	DBInt j;
	DBObjRecord *dataRec = LayerFLD->Record (layerRec);

	if (pos.Col < 0) return (false);
	if (pos.Row < 0) return (false);
	if (pos.Col >= DimensionVAR.Col) return (false);
	if (pos.Row >= DimensionVAR.Row) return (false);

	j = DimensionVAR.Col * (DimensionVAR.Row - pos.Row - 1) + pos.Col;
	switch (ValueTypeVAR)
		{
		case DBTableFieldFloat:
			switch (ValueSizeVAR)
				{
				case sizeof (DBFloat4): *value = (DBInt) ((DBFloat4 *) (dataRec->Data ())) [j]; break;
				case sizeof (DBFloat):  *value = (DBInt) ((DBFloat *)  (dataRec->Data ())) [j]; break;
				}
			break;
		case DBTableFieldInt:
			switch (ValueSizeVAR)
				{
				case sizeof (DBByte):  *value = (DBInt) ((DBByte *)  (dataRec->Data ())) [j];	break;
				case sizeof (DBShort): *value = (DBInt) ((DBShort *) (dataRec->Data ())) [j];	break;
				case sizeof (DBInt):   *value = (DBInt) ((DBInt *)   (dataRec->Data ())) [j];	break;
				}
			break;
		}
	if (MissingValueFLD != (DBObjTableField *) NULL)
		return (*value == MissingValueFLD->Int (ItemTable->Item (layerRec->RowID ())) ? false : true);
	return (*value == DBFault ? false: true);
	}
Ejemplo n.º 4
0
void DBObjData::Document(const char *docName, const char *string) {
    DBObjRecord *obj = DocsPTR->Item(docName);

    if (obj == (DBObjRecord *) NULL) {
        DocsPTR->Add(obj = new DBObjRecord(docName, sizeof(DBVarString)));
        memset(obj->Data(), 0, sizeof(DBVarString));
        ((DBVarString *) obj->Data())->VString(string);
    }
    else ((DBVarString *) obj->Data())->VString(string);
}
Ejemplo n.º 5
0
int DBObjData::_Write (FILE *file)

	{
	DBInt id, userFlags;
	DBObjRecord *docRec;

	userFlags = Flags () & DBDataFlagUserModeFlags;
	Flags (DBDataFlagUserModeFlags,DBClear);
	if (DBObject::Write (file) == DBFault)		return (DBFault);
	Flags (userFlags,DBSet);
	if (DocsPTR->Write (file) == DBFault)		return (DBFault);
	for (id = 0;id < DocsPTR->ItemNum ();++id)
		{
		if (DocsPTR->WriteItem (file,id) == DBFault) return (DBFault);
		docRec = DocsPTR->Item (id);
		if (((DBVarString *) docRec->Data ())->Write (file) == DBFault) return (DBFault);
		}
	if (ArraysPTR->Write (file) == DBFault)		return (DBFault);
	for (id = 0;id < ArraysPTR->ItemNum ();++id)
		if (ArraysPTR->WriteItem (file,id) == DBFault) return (DBFault);
	TablesPTR->Write (file);
	for (id = 0;id < TablesPTR->ItemNum ();++id)
		if (TablesPTR->WriteItem (file,id) == DBFault) return (DBFault);
	return (BuildFields ());
	}
Ejemplo n.º 6
0
char *DBObjData::Document(const char *docName) {
    DBObjRecord *obj = DocsPTR->Item(docName);
    if (obj == (DBObjRecord *) NULL) {
        if ((strcmp(docName, DBDocSubject) == 0) || (strcmp(docName, DBDocGeoDomain) == 0)) {
            Document(docName, (char *) "unspecified");
            return ((char *) "unspecified");
        }
        else return ((char *) "");
    }
    return (((DBVarString *) obj->Data())->VString());
}
Ejemplo n.º 7
0
int DBObjData::_Read(FILE *file, int swap) {
    DBInt id;
    DBObjRecord *docRec;

    if (DBObject::Read(file, swap) == DBFault) return (DBFault);
    if (DocsPTR->Read(file, swap) == DBFault) return (DBFault);
    for (id = 0; id < DocsPTR->ItemNum(); ++id) {
        if (DocsPTR->ReadItem(file, id, swap) == DBFault) return (DBFault);
        docRec = DocsPTR->Item(id);
        if (((DBVarString *) docRec->Data())->Read(file, swap) == DBFault) return (DBFault);
    }
    if (ArraysPTR->Read(file, swap) == DBFault) return (DBFault);
    for (id = 0; id < ArraysPTR->ItemNum(); ++id)
        if (ArraysPTR->ReadItem(file, id, swap) == DBFault) return (DBFault);
    TablesPTR->Read(file, swap);
    for (id = 0; id < TablesPTR->ItemNum(); ++id)
        if (TablesPTR->ReadItem(file, id, swap) == DBFault) return (DBFault);
    return (BuildFields());
}
Ejemplo n.º 8
0
void DBObjTable::DeleteField(DBObjTableField *delField) {
    DBInt i, recID, fieldID;
    DBObjRecord *record;
    DBObjTableField *field;
    unsigned char *data;

    for (fieldID = 0; fieldID < FieldPTR->ItemNum(); ++fieldID) {
        field = FieldPTR->Item(fieldID);
        if (field->StartByte() > delField->StartByte())
            field->StartByte(field->StartByte() - delField->Length());
    }
    for (recID = 0; recID < ItemNum(); ++recID) {
        record = Item(recID);
        data = (unsigned char *) record->Data() + delField->StartByte();
        for (i = 0; i < RecordLengthVAR - delField->StartByte() - delField->Length(); ++i)
            data[i] = data[i + delField->Length()];
        record->Realloc(RecordLengthVAR - delField->Length());
    }
    FieldPTR->Remove(delField);
    RecordLengthVAR -= delField->Length();
    delete delField;
}
Ejemplo n.º 9
0
void DBVLineIF::Vertexes (DBObjRecord *lineRec,DBCoordinate *coord,DBInt vertexNum)

	{
	DBInt vertex;
	DBFloat length = 0;
	DBCoordinate *vertexes, prevCoord;
	DBObjRecord *dataRec = (DBObjRecord *) NULL;
	DBObjectLIST<DBObjRecord> *dataArrays = Data ()->Arrays ();
	DBRegion lineExtent, dataExtent = Data ()->Extent ();
	DBMathDistanceFunction distFunc = DBMathGetDistanceFunction (Data ());

	prevCoord = NodeCoordFLD->Coordinate (FromNodeFLD->Record (lineRec));
	lineExtent.Expand (prevCoord);
	if (vertexNum > 0)
		{
		if ((dataRec = dataArrays->Item (lineRec->RowID ())) == (DBObjRecord *) NULL)
			{
			if ((dataRec = new DBObjRecord (lineRec->Name (),((size_t) vertexNum) * sizeof (DBCoordinate),sizeof (DBFloat))) == (DBObjRecord *) NULL) return;
			dataArrays->Add (dataRec);
			}
		else	dataRec->Realloc (vertexNum * sizeof (DBCoordinate));
		if ((vertexes = (DBCoordinate *) dataRec->Data ()) == NULL)
			{ CMmsgPrint (CMmsgSysError, "Memory Allocation Error in: %s %d",__FILE__,__LINE__); return; }
		for (vertex = 0;vertex < vertexNum;vertex++)
			{
			lineExtent.Expand (vertexes [vertex] = coord [vertex]);
			length += DBMathCoordinateDistance (distFunc,prevCoord,coord [vertex]);
			prevCoord = coord [vertex];
			}
		}
	VertexesFLD->Record (lineRec,dataRec);
	VertexNumFLD->Int (lineRec,vertexNum);
	length += DBMathCoordinateDistance (distFunc,prevCoord,NodeCoordFLD->Coordinate (ToNodeFLD->Record (lineRec)));
	PerimeterFLD->Float (lineRec,length);
	lineExtent.Expand (NodeCoordFLD->Coordinate (ToNodeFLD->Record (lineRec)));
	ExtentFLD->Region (lineRec,lineExtent);
	dataExtent.Expand (lineExtent);
	Data ()->Extent (dataExtent);
	}
Ejemplo n.º 10
0
int DBObjTable::Read(FILE *file, int swap) {
    DBInt id;
    DBDate date;
    DBCoordinate coord;
    DBRegion region;
    DBPosition pos;
    DBUShort row, col;
    DBObjRecord *record;
    DBObjTableField *field;

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

    RecordLengthVAR = 0;
    for (field = FieldPTR->First(); field != (DBObjTableField *) NULL; field = FieldPTR->Next())
        RecordLengthVAR = RecordLengthVAR > field->StartByte() + field->Length() ?
                          RecordLengthVAR : field->StartByte() + field->Length();

    for (id = 0; id < ItemNum(); ++id) {
        if (ReadItem(file, id, swap) == DBFault) return (DBFault);
        record = Item(id);
        if (swap == false) continue;
        for (field = FieldPTR->First(); field != (DBObjTableField *) NULL; field = FieldPTR->Next())
            switch (field->Type()) {
                case DBTableFieldInt:
                case DBTableFieldFloat:
                case DBTableFieldTableRec:
                case DBTableFieldDataRec:
                    switch (field->Length()) {
                        case 2:
                            DBByteOrderSwapHalfWord((char *) record->Data() + field->StartByte());
                            break;
                        case 4:
                            DBByteOrderSwapWord((char *) record->Data() + field->StartByte());
                            break;
                        case 8:
                            DBByteOrderSwapLongWord((char *) record->Data() + field->StartByte());
                            break;
                    }
                    break;
                case DBTableFieldDate:
                    date = field->Date(record);
                    date.Swap();
                    field->Date(record, date);
                    break;
                case DBTableFieldCoord:
                    coord = field->Coordinate(record);
                    coord.Swap();
                    field->Coordinate(record, coord);
                    break;
                case DBTableFieldRegion:
                    region = field->Region(record);
                    region.Swap();
                    field->Region(record, region);
                    break;
                case DBTableFieldPosition:
                    pos = field->Position(record);
                    switch (field->Length()) {
                        case sizeof(DBPosition):
                            pos.Swap();
                            break;
                        default:
                            row = pos.Row;
                            col = pos.Col;
                            DBByteOrderSwapHalfWord(&row);
                            DBByteOrderSwapHalfWord(&col);
                            pos.Row = row;
                            pos.Col = col;
                            break;
                    }
                    field->Position(record, pos);
                    break;
                default:
                    break;
            }
    }
    if (MethodPTR->Read(file, swap) != DBSuccess) return (DBFault);
    for (id = 0; id < MethodPTR->ItemNum(); ++id) if (MethodPTR->ReadItem(file, id, swap) == DBFault) return (DBFault);
    return (DBSuccess);
}
Ejemplo n.º 11
0
void _RGISUserFuncionQuery (DBObjData *dbData,UI2DView *view,XEvent *event)

	{
	DBInt sX, sY;
	DBCoordinate coord;
	DBObjData *data = dbData;
	UIAttribView *attribView;

	if (event->type != ButtonPress) return;
	sX = event->xbutton.x;
	sY = event->xbutton.y;
	view->Window2Map  (sX,sY, &(coord.X), &(coord.Y));

	for (data = dbData;
		  (data != (DBObjData *) NULL) && ((data->Flags () & DBObjectFlagProcessed) != DBObjectFlagProcessed);
		  data = data->LinkedData ())
		{
		data->Flags (DBObjectFlagProcessed,DBSet);
		if ((data->Flags () & DBDataFlagUserModeFlags) == DBDataFlagUserModeQuery)
			{
			if ((attribView = (UIAttribView *) data->Display (UIAttribViewSTR)) == (UIAttribView *) NULL)
				data->DispAdd (attribView = new UIAttribView (data));
			switch (data->Type ())
				{
				case DBTypeVectorPoint:
				case DBTypeVectorLine:
				case DBTypeVectorPolygon:
					{
					DBVectorIF *vectorIF = new DBVectorIF (data);
					attribView->Draw (vectorIF->Item (coord));
					} break;
				case DBTypeGridDiscrete:
					{
					DBGridIF *gridIF = new DBGridIF (data);
					attribView->Draw (gridIF->GridItem (coord));
					delete gridIF;
					} break;
				case DBTypeGridContinuous:
					{
					DBPosition pos;
					DBGridIF *gridIF = new DBGridIF (data);
					char nameString [DBStringLength * 2];
					DBObjRecord *record = new DBObjRecord ("Noname",sizeof (DBCoordinate));
					gridIF->Coord2Pos (coord,pos);
					gridIF->Pos2Coord (pos,coord);
					sprintf (nameString,"CellCoordinate %10.2f%10.2f",coord.X,coord.Y);
					record->Name (nameString);
					memcpy (record->Data (),(void *) &coord,sizeof (coord));
					attribView->Draw (record);
					delete record;
					delete gridIF;
					} break;
				case DBTypeNetwork:
					{
					DBNetworkIF *netIF = new DBNetworkIF (data);
					attribView->Draw (netIF->Cell (coord));
					delete netIF;
					} break;
				default:
					CMmsgPrint (CMmsgAppError, "Invalid Data Type in: %s %d",__FILE__,__LINE__); break;
				}
			}
		}
	for (data = dbData;
		  (data != (DBObjData *) NULL) && ((data->Flags () & DBObjectFlagProcessed) == DBObjectFlagProcessed);
		  data = data->LinkedData ())
		data->Flags (DBObjectFlagProcessed,DBClear);
	}
Ejemplo n.º 12
0
DBInt DBGridIF::Value(DBObjRecord *layerRec, DBCoordinate coord, DBFloat *value) const {
    DBInt i, j, pointNum;
    DBInt row[9], col[9];
    DBPosition pos;
    DBCoordinate cellCoord;
    DBPosition cellPos;
    DBFloat precision, dist, wAvg, sumWeight, retVal;
    DBObjRecord *dataRec = LayerFLD->Record(layerRec);
    DBFloat missingValue = MissingValueFLD->Float(ItemTable->Item());
    DBMathDistanceFunction distFunc = DBMathGetDistanceFunction(DataPTR);

    if (DataPTR->Extent().InRegion(coord) == false) return (false);
    precision = pow((double) 10.0, (double) DataPTR->Precision());
    Coord2Pos(coord, cellPos);
    Pos2Coord(cellPos, cellCoord);
    if (Flat ||
        ((fabs(coord.X - cellCoord.X) < precision) &&
         (fabs(coord.Y - cellCoord.Y) < precision))) {
        j = DimensionVAR.Col * (DimensionVAR.Row - cellPos.Row - 1) + cellPos.Col;
        switch (ValueTypeVAR) {
            case DBTableFieldFloat:
                switch (ValueSizeVAR) {
                    case sizeof(DBFloat4):
                        retVal = (DBFloat) ((DBFloat4 *) (dataRec->Data()))[j];
                        break;
                    case sizeof(DBFloat):
                        retVal = (DBFloat) ((DBFloat *) (dataRec->Data()))[j];
                        break;
                }
                break;
            case DBTableFieldInt:
                switch (ValueSizeVAR) {
                    case sizeof(DBByte):
                        retVal = (DBFloat) ((DBByte *) (dataRec->Data()))[j];
                        break;
                    case sizeof(DBShort):
                        retVal = (DBFloat) ((DBShort *) (dataRec->Data()))[j];
                        break;
                    case sizeof(DBInt):
                        retVal = (DBFloat) ((DBInt *) (dataRec->Data()))[j];
                        break;
                }
                break;
        }
        if (!CMmathEqualValues(retVal, missingValue)) {
            *value = retVal;
            return (true);
        }
    }
    col[0] = cellPos.Col;
    row[0] = cellPos.Row;
    if (coord.X < cellCoord.X) col[0] -= 1;
    if (coord.Y < cellCoord.Y) row[0] -= 1;
    col[1] = col[0] + 1;
    row[1] = row[0];
    col[2] = col[0] + 1;
    row[2] = row[0] + 1;
    col[3] = col[0];
    row[3] = row[0] + 1;

    pos.Col = col[0];
    pos.Row = row[0];
    Pos2Coord(pos, cellCoord);
    if ((coord.X - cellCoord.X) > (3.0 * CellWidth() / 4.0)) i = 1;
    else if ((coord.X - cellCoord.X) > (CellWidth() / 4.0)) i = 0;
    else i = -1;
    if ((coord.Y - cellCoord.Y) > (3.0 * CellHeight() / 4.0)) j = 1;
    else if ((coord.Y - cellCoord.Y) > (CellHeight() / 4.0)) j = 0;
    else j = -1;

    if ((i != 0) || (j != 0)) {
        if (i == 0) {
            row[4] = row[5] = j > 0 ? row[2] + 1 : row[0] - 1;
            col[4] = col[0];
            col[5] = col[2];
            pointNum = 6;
        }
        else if (j == 0) {
            row[4] = row[0];
            row[5] = row[2];
            col[4] = col[5] = i > 0 ? col[2] + 1 : col[0] - 1;
            pointNum = 6;
        }
        else {
            row[7] = row[0];
            row[8] = row[2];
            if (j > 0)
                row[4] = row[5] = row[6] = row[2] + 1;
            else
                row[4] = row[5] = row[6] = row[0] - 1;

            if (i > 0) {
                col[4] = col[0];
                col[5] = col[2];
                col[6] = col[7] = col[8] = col[2] + 1;
            }
            else {
                col[5] = col[0];
                col[6] = col[2];
                col[4] = col[7] = col[8] = col[0] - 1;
            }
            pointNum = 9;
        }
    }
    else pointNum = 4;

    wAvg = sumWeight = 0.0;
    for (i = 0; i < pointNum; ++i) {
        if (col[i] < 0) continue;
        if (row[i] < 0) continue;
        if (col[i] >= DimensionVAR.Col) continue;
        if (row[i] >= DimensionVAR.Row) continue;

        j = DimensionVAR.Col * (DimensionVAR.Row - row[i] - 1) + col[i];
        switch (ValueTypeVAR) {
            case DBTableFieldFloat:
                switch (ValueSizeVAR) {
                    case sizeof(DBFloat4):
                        retVal = (DBFloat) ((DBFloat4 *) (dataRec->Data()))[j];
                        break;
                    case sizeof(DBFloat):
                        retVal = (DBFloat) ((DBFloat *) (dataRec->Data()))[j];
                        break;
                }
                break;
            case DBTableFieldInt:
                switch (ValueSizeVAR) {
                    case sizeof(DBByte):
                        retVal = (DBFloat) ((DBByte *) (dataRec->Data()))[j];
                        break;
                    case sizeof(DBShort):
                        retVal = (DBFloat) ((DBShort *) (dataRec->Data()))[j];
                        break;
                    case sizeof(DBInt):
                        retVal = (DBFloat) ((DBInt *) (dataRec->Data()))[j];
                        break;
                }
                break;
        }
        if (CMmathEqualValues(retVal, missingValue)) {
            if ((col[i] == cellPos.Col) && (row[i] == cellPos.Row)) return (false);
            else continue;
        }
        pos.Row = (DBUShort) row[i];
        pos.Col = (DBUShort) col[i];
        Pos2Coord(pos, cellCoord);
        if (pointNum > 1) {
            dist = DBMathCoordinateDistance(distFunc, coord, cellCoord);
            dist *= dist;
        }
        else dist = 1.0;
        wAvg = wAvg + retVal / dist;
        sumWeight = sumWeight + 1.0 / dist;
    }
    if (sumWeight > 0) {
        *value = wAvg / sumWeight;
        return (true);
    }
    else {
        *value = missingValue;
        return (false);
    }
}