Exemplo n.º 1
0
 char *CurrentLayer(DBInt layerID) {
     if (layerID == DBFault) LayerRec = GridIF->Layer(0);
     else
         LayerRec = layerID < GridIF->LayerNum() ? GridIF->Layer(layerID) :
                    GridIF->Layer(layerID % GridIF->LayerNum());
     return (LayerRec->Name());
 }
Exemplo n.º 2
0
void UIAttribView::Draw (DBObjRecord *record)

	{
	DBObjTableField *field;
	DBObjectLIST<DBObjTableField> *fields;
	UIXYGraphShell *graphCLS;

	if (record == (DBObjRecord *) NULL)
		{
		Cardinal i, numChildren;
		WidgetList rowCols;

		UIAuxSetLabelString (ItemNameWGT,(char *) "");
		XtVaGetValues (FieldsRowCol,XmNchildren,	&rowCols, XmNnumChildren,	&numChildren,NULL);
		for (i = 0;i < numChildren; ++i)
			XmTextFieldSetString (XtNameToWidget (rowCols [i],"UIAttribViewTextField"),(char *) "");
		return;
		}

	UIAuxSetLabelString (ItemNameWGT,record->Name ());
	switch (DataPTR->Type ())
		{
		case DBTypeVectorPoint:
		case DBTypeVectorLine:
		case DBTypeVectorPolygon:
		case DBTypeGridDiscrete:
			fields = ItemTable->Fields ();
			for (field = fields->First ();field != (DBObjTableField *) NULL;field = fields->Next ())
				if (DBTableFieldIsVisible (field) == true)	DrawField (field->Name (),field->String (record));
			break;
		case DBTypeGridContinuous:
			{
			DBCoordinate coord = *((DBCoordinate *) (record->Data ()));
			DBGridIF *gridIF = new DBGridIF (DataPTR);
			for (record = ItemTable->First ();record != (DBObjRecord *) NULL;record = ItemTable->Next ())
				DrawField (record->Name (),gridIF->ValueString (record,coord));
			delete gridIF;
			} break;
		case DBTypeNetwork:
			{
			DBObjTable *cellTable = DataPTR->Table (DBrNCells);
			DBObjTableField *basinFLD = cellTable->Field (DBrNBasin);
			DBObjRecord *basinRec;

			if ((basinRec =  ItemTable->Item (basinFLD->Int (record) - 1)) == (DBObjRecord *) NULL)
				{ CMmsgPrint (CMmsgAppError, "BasinID Error in:%s %d",__FILE__,__LINE__); return; }
			DrawField ((char *) "Basin Name",basinRec->Name ());
			fields = ItemTable->Fields ();
			for (field = fields->First ();field != (DBObjTableField *) NULL;field = fields->Next ())
				if (DBTableFieldIsVisible (field) == true)	DrawField (field->Name (),field->String (basinRec));

			fields = cellTable->Fields ();
			for (field = fields->First ();field != (DBObjTableField *) NULL;field = fields->Next ())
				if (DBTableFieldIsVisible (field) == true)	DrawField (field->Name (),field->String (record));
			} break;
		default:	break;
		}
	if ((graphCLS = (UIXYGraphShell *) DataPTR->Display (UIXYGraphShellStr)) != (UIXYGraphShell *) NULL)
		graphCLS->Configure (record);
	}
Exemplo n.º 3
0
void RGISEditGridStatsCBK (Widget widget, RGISWorkspace *workspace,XmAnyCallbackStruct *callData)

	{
	DBDataset *dataset = UIDataset ();
	DBObjData *dbData = dataset->Data ();
	DBGridIF *gridIF = new DBGridIF (dbData);
	UITable *tableCLS = (UITable *) dbData->Display (UITableName (dbData,dbData->Table (DBrNItems)));

	if (dbData->Type () == DBTypeGridContinuous)
			gridIF->RecalcStats ();
	else	gridIF->DiscreteStats ();
	if (tableCLS != (UITable *) NULL) tableCLS->Draw ();
	}
Exemplo n.º 4
0
    void ComputeTask(DBObjRecord *record, size_t taskId) {
        size_t i;
        DBPosition pos;
        DBCoordinate coord;

        pos.Row = taskId / GridIF->ColNum();
        pos.Col = taskId % GridIF->ColNum();

        GridIF->Pos2Coord(pos, coord);
        for (i = 0; i < VarNum; ++i) GrdVar[i]->GetVariable(record, coord);
        for (i = 0; i < ExpNum; ++i) Expressions[i]->Evaluate(record);
        GridIF->Value(LayerRec, pos, Operand->Float(record));
    }
Exemplo n.º 5
0
void RGISEditGridRenameLayerCBK (Widget widget, RGISWorkspace *workspace,XmAnyCallbackStruct *callData)

	{
	char *layerName;
	DBDataset *dataset = UIDataset ();
	DBObjData *dbData = dataset->Data ();
	DBGridIF *gridIF;

	if ((layerName = UIGetString ((char *) "Layer Name",DBStringLength)) == (char *) NULL) return;
	gridIF= new DBGridIF (dbData);
	gridIF->RenameLayer (layerName);
	delete gridIF;
	workspace->CurrentData (dbData);
	}
Exemplo n.º 6
0
    DBInt FindLayer(char *layerName) {
        DBInt layerID, i = 0;
        DBObjRecord *layerRec;
        char *name;

        for (layerID = 0; layerID < GridIF->LayerNum(); ++layerID) {
            layerRec = GridIF->Layer(layerID);

            name = layerRec->Name();
            if (strncmp(name, "XXXX-", 5) == 0) {
                i = 5;
                if ((strlen(name) - 5) == 0) return (layerID);
            }
            if (strncmp(name + i, layerName + i, strlen(name) - i) == 0) return (layerID);
        }
        return (CMfailed);
    }
Exemplo n.º 7
0
 void GetVariable(DBObjRecord *record, DBCoordinate coord) {
     switch ((GridIF->Data())->Type()) {
         case DBTypeGridContinuous: {
             DBFloat value;
             if (GridIF->Value(LayerRec, coord, &value))
                 TargetFLD->Float(record, value);
             else TargetFLD->Float(record, TargetFLD->FloatNoData());
         }
             break;
         case DBTypeGridDiscrete: {
             DBObjRecord *grdRec;
             if ((grdRec = GridIF->GridItem(LayerRec, coord)) != (DBObjRecord *) NULL)
                 switch (SourceFLD->Type()) {
                     case DBVariableString:
                         TargetFLD->String(record, SourceFLD->String(grdRec));
                         break;
                     case DBVariableInt:
                         TargetFLD->Int(record, SourceFLD->Int(grdRec));
                         break;
                     case DBVariableFloat:
                         TargetFLD->Float(record, SourceFLD->Float(grdRec));
                         break;
                     default:
                         break;
                 }
             else
                 switch (SourceFLD->Type()) {
                     case DBVariableString:
                         TargetFLD->String(record, "");
                         break;
                     case DBVariableInt:
                         TargetFLD->Int(record, SourceFLD->IntNoData());
                         break;
                     case DBVariableFloat:
                         TargetFLD->Float(record, SourceFLD->FloatNoData());
                         break;
                     default:
                         break;
                 }
         }
             break;
         default:
             CMmsgPrint(CMmsgUsrError, "Invalid grid type in: CMDgrdVariable:GetVariable ()");
             break;
     }
 }
Exemplo n.º 8
0
 DBInt LayerIsDated(DBInt layerID) {
     DBObjRecord *layerRec;
     DBDate date;
     layerRec = GridIF->Layer(layerID);
     date.Set(layerRec->Name());
     if (date.Year() != DBDefaultMissingIntVal) return (true);
     return (date.Month() != DBDefaultMissingIntVal ? true : false);
 }
Exemplo n.º 9
0
    ~CMDgrdVariable() {
        DBObjData *data;

        if (GridIF != (DBGridIF *) NULL) {
            data = GridIF->Data();
            delete GridIF;
            delete data;
        }
    }
Exemplo n.º 10
0
void DBObjData::RecalcExtent() {
    DBRegion extent;

    switch (Type()) {
        case DBTypeVectorPoint:
        case DBTypeVectorLine:
        case DBTypeVectorPolygon: {
            DBVectorIF *vectorIF = new DBVectorIF(this);
            DBInt recordID;
            for (recordID = 0; recordID < vectorIF->ItemNum(); ++recordID)
                extent.Expand(Extent(vectorIF->Item(recordID)));
            delete vectorIF;
        }
            break;
        case DBTypeGridDiscrete:
        case DBTypeGridContinuous: {
            DBGridIF *gridIF = new DBGridIF(this);
            extent.LowerLeft = Extent().LowerLeft;
            extent.UpperRight.X = extent.LowerLeft.X + gridIF->ColNum() * gridIF->CellWidth();
            extent.UpperRight.Y = extent.LowerLeft.Y + gridIF->RowNum() * gridIF->CellHeight();
            delete gridIF;
        }
            break;
        case DBTypeNetwork: {
            DBNetworkIF *netIF = new DBNetworkIF(this);
            extent.LowerLeft = Extent().LowerLeft;
            extent.UpperRight.X = extent.LowerLeft.X + netIF->ColNum() * netIF->CellWidth();
            extent.UpperRight.Y = extent.LowerLeft.Y + netIF->RowNum() * netIF->CellHeight();
            delete netIF;
        }
            break;
        case DBTypeTable:
        default:
            return;
    }
    Extent(extent);
}
Exemplo n.º 11
0
void RGISEditLineDirectionCBK (Widget widget, RGISWorkspace *workspace,XmAnyCallbackStruct *callData)

	{
	DBFloat elev0, elev1;
	DBCoordinate coord;
	DBObjRecord *lineRec;
	DBDataset *dataset = UIDataset ();
	DBObjData *lineData = dataset->Data ();
	DBObjData *gridData = lineData->LinkedData ();
	DBVLineIF *lineIF = new DBVLineIF (lineData);
	DBGridIF *gridIF = new DBGridIF (gridData);

	UIPauseDialogOpen ((char *) "Changing Directionality");
	for (lineRec = lineIF->FirstItem ();lineRec != (DBObjRecord *) NULL;lineRec = lineIF->NextItem ())
		{
		DBPause (lineRec->RowID () * 100 / lineIF->ItemNum ());
		coord = lineIF->FromCoord (lineRec);
		if (gridIF->Value (coord,&elev0) == false) continue;
		coord = lineIF->ToCoord (lineRec);
		if (gridIF->Value (coord,&elev1) == false) continue;
		if (elev0 < elev1) lineIF->Flip (lineRec);
		}
	UIPauseDialogClose ();
	}
Exemplo n.º 12
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);
}
Exemplo n.º 13
0
DBInt DBPointToGrid(DBObjData *pntData, DBObjData *grdData, DBFloat factor) {
    DBInt startID, pnt0ID, pntID, id, itemNum;
    double dist, minDist, box, box0, bWidth, bHeight;
    DBPosition pos;
    DBCoordinate gCoord, *pCoord;
    DBObjRecord *grdRec, *pntRec, *symRec;
    DBObjTable *itemTable, *symTable;
    DBObjTableField *valField, *symField;
    DBVPointIF *pntIF;
    DBGridIF *gridIF;
    DBMathDistanceFunction distFunc = DBMathGetDistanceFunction(pntData);

    if (distFunc != DBMathGetDistanceFunction(grdData)) {
        CMmsgPrint(CMmsgAppError, "Incompatible projections in: %s %d", __FILE__, __LINE__);
        return (DBFault);
    }

    pntIF = new DBVPointIF(pntData);
    itemNum = pntIF->ItemNum();
    if ((pCoord = (DBCoordinate *) calloc(itemNum, sizeof(DBCoordinate))) == (DBCoordinate *) NULL) {
        CMmsgPrint(CMmsgSysError, "Memory allocation Error in: %s %d", __FILE__, __LINE__);
        return (DBFault);
    }

    gridIF = new DBGridIF(grdData);
    for (pntID = 0; pntID < itemNum; ++pntID) pCoord[pntID] = pntIF->Coordinate(pntIF->Item(pntID));

    if (grdData->Type() == DBTypeGridContinuous)
        gridIF->RenameLayer(gridIF->Layer((DBInt) 0), (char *) "Distance to Station");
    else {
        gridIF->RenameLayer(gridIF->Layer((DBInt) 0), (char *) "Station grid");
        itemTable = grdData->Table(DBrNItems);
        symTable = grdData->Table(DBrNSymbols);
        valField = itemTable->Field(DBrNGridValue);
        symField = itemTable->Field(DBrNSymbol);
        if ((symRec = symTable->Item(0)) == (DBObjRecord *) NULL)
            CMmsgPrint(CMmsgAppError, "Total Metal Gebasz in: %s %d", __FILE__, __LINE__);
        for (pntID = 0; pntID < itemNum; ++pntID) {
            pntRec = pntIF->Item(pntID);
            grdRec = itemTable->Add(pntRec->Name());
            valField->Int(grdRec, pntID + 1);
            symField->Record(grdRec, symRec);
        }
    }

    startID = 0;
    for (pos.Row = 0; pos.Row < gridIF->RowNum(); ++pos.Row) {
        DBPause(pos.Row * 100 / gridIF->RowNum());
        for (pos.Col = 0; pos.Col < gridIF->ColNum(); ++pos.Col) {
            gridIF->Pos2Coord(pos, gCoord);
            minDist = box0 = DBHugeVal;
            pnt0ID = pntID = startID;
            id = DBFault;
            do {
                bWidth = fabs(gCoord.X - pCoord[pntID].X);
                bHeight = fabs(gCoord.Y - pCoord[pntID].Y);
                box = bWidth > bHeight ? bWidth : bHeight;
                if ((box < box0) && ((dist = DBMathCoordinateDistance(distFunc, gCoord, pCoord[pntID])) < minDist)) {
                    minDist = dist;
                    id = startID = pntID;
                    box *= factor;
                    if (box0 > box) box0 = box;
                }
                pntID = pntID + 1 < itemNum ? pntID + 1 : 0;
            } while (pntID != pnt0ID);
            if (grdData->Type() == DBTypeGridContinuous) gridIF->Value(pos, minDist); else gridIF->Value(pos, id);
        }
    }
    if (grdData->Type() == DBTypeGridContinuous) gridIF->RecalcStats(); else gridIF->DiscreteStats();
    delete gridIF;
    free(pCoord);
    return (DBSuccess);
}
Exemplo n.º 14
0
DBInt RGPDrawGridContinuous (DBInt mode, DBInt *entryNum, DBObjData *grdData)

	{
	DBInt r, g, b;
	DBInt ret, shadeNum, colorNum, scaleMode = 0;
	DBPosition pos;
	char charBuffer [RGPBufferSIZE], errorMsg [RGPBufferSIZE];
	const char *colorMaps [] = { "default", "grey", "blue", "red", "blue-red", "elevation", "custom", NULL };
	char colorMap;
	const char *scaleModes [] = { "linear", "logarithmic", "square-root", NULL };
	RGPColorMapEntry *customColors;
	DBFloat value;
	float *array, translation [6], min, max, unit = 1.0;
	DBRegion extent = grdData->Extent ();
	DBObjRecord *layerRec;
	DBGridIF *gridIF = new DBGridIF (grdData);

	do {
		RGPPrintMessage (mode,entryNum,"Grid Layer:");
		if (fgets (charBuffer,sizeof (charBuffer) - 2,stdin) == (char *) NULL) { ret = DBFault; goto Stop; }
		if ((strlen (charBuffer) > 0) && (charBuffer [strlen (charBuffer) - 1] == '\n'))
			charBuffer [strlen (charBuffer) - 1] = '\0';
		if ((layerRec = gridIF->Layer (charBuffer)) != NULL) break;
		sprintf (errorMsg,"Invalid grid layer [%s]",charBuffer);
		if (RGPPrintError (mode,*entryNum,errorMsg)) { ret = DBFault; goto Stop;}
 		} while (true);

	do	{
		RGPPrintMessage (mode,entryNum,"Colormap [default|grey|blue|red-blue|elevation|custom]:");
		if (fgets (charBuffer,sizeof (charBuffer) - 2,stdin) == (char *) NULL) { ret = DBFault; goto Stop; }
		if ((strlen (charBuffer) > 0) && (charBuffer [strlen (charBuffer) - 1] == '\n'))
			charBuffer [strlen (charBuffer) - 1] = '\0';
		if ((colorMap = CMoptLookup (colorMaps,charBuffer,true)) != DBFault) break;
		sprintf (errorMsg,"Invalid colormap [%s]",charBuffer);
		if (RGPPrintError (mode,*entryNum,errorMsg)) { ret = DBFault; goto Stop; }
		} while (true);
	switch (colorMap)
		{
		default:
		case 0:
			switch (grdData->Flags () & DBDataFlagDispModeFlags)
				{
				case DBDataFlagDispModeContStandard:
				case DBDataFlagDispModeContGreyScale:
					shadeNum = RGPSetColorMap (_RGPGreyColors,		RGPColorNum (_RGPGreyColors));		break;
				case DBDataFlagDispModeContBlueScale:
					shadeNum = RGPSetColorMap	(_RGPBlueColors,		RGPColorNum (_RGPBlueColors));		break;
				case DBDataFlagDispModeContBlueRed:
					shadeNum = RGPSetColorMap (_RGPBlueRedColors,	RGPColorNum (_RGPBlueRedColors));	break;
				case DBDataFlagDispModeContElevation:
					shadeNum = RGPSetColorMap (_RGPElevationColors,	RGPColorNum (_RGPElevationColors));	break;
				}
			break;
		case 1:	shadeNum = RGPSetColorMap (_RGPGreyColors,		RGPColorNum (_RGPGreyColors));		break;
		case 2:	shadeNum = RGPSetColorMap (_RGPBlueColors,		RGPColorNum (_RGPBlueColors));		break;
		case 3:	shadeNum = RGPSetColorMap (_RGPRedColors,			RGPColorNum (_RGPRedColors));			break;
		case 4:	shadeNum = RGPSetColorMap (_RGPBlueRedColors,	RGPColorNum (_RGPBlueRedColors));	break;
		case 5:	shadeNum = RGPSetColorMap (_RGPElevationColors,	RGPColorNum (_RGPElevationColors));	break;
		case 6:
			colorNum = 0;
			if ((customColors = (RGPColorMapEntry *) calloc (1,sizeof (RGPColorMapEntry))) == (RGPColorMapEntry *) NULL)
				{ CMmsgPrint (CMmsgSysError, "Memory Allocation Error in: %s %d",__FILE__,__LINE__); delete gridIF; return (DBFault); }
			do	{
				RGPPrintMessage (mode,entryNum,"Background Shade [red,green,blue]:");
				if (fgets (charBuffer,sizeof (charBuffer) - 2,stdin) == (char *) NULL) { ret = DBFault; goto Stop; }
				if (sscanf (charBuffer,"%d,%d,%d",&r,&g,&b) == 3)
					{
					customColors [colorNum].Red = r;
					customColors [colorNum].Green = g;
					customColors [colorNum].Blue = b;
					colorNum++;
					break;
					}
				else	if (RGPPrintError (mode,*entryNum,"Background Color Entry Error")) { ret = DBFault; goto Stop; }
				} while (true);
			do	{
				RGPPrintMessage (mode,entryNum,"Color Shade [red,green,blue]:");
				if (fgets (charBuffer,sizeof (charBuffer) - 2,stdin) == (char *) NULL) { ret = DBFault; goto Stop; }
				if (sscanf (charBuffer,"%d,%d,%d",&r,&g,&b) == 3)
					{
					if ((customColors = (RGPColorMapEntry *) realloc (customColors,(colorNum + 1) * sizeof (RGPColorMapEntry))) == (RGPColorMapEntry *) NULL)
						{ CMmsgPrint (CMmsgSysError, "Memory Allocation Error in: %s %d",__FILE__,__LINE__); delete gridIF; return (DBFault); }
					customColors [colorNum].Red = r;
					customColors [colorNum].Green = g;
					customColors [colorNum].Blue = b;
					colorNum++;
					}
				else
					{
					if (colorNum < 3)
						{ if (RGPPrintError (mode,*entryNum,"Color Shade Entry Error")) { ret = DBFault; goto Stop; }}
					else	break;
					}
				} while (true);
			shadeNum = RGPSetColorMap (customColors,colorNum);
			free (customColors);
			break;
		}
	if (shadeNum == DBFault)	{ RGPPrintError (mode,*entryNum,"Colormap Initialization Error") ; ret = DBFault; goto Stop; }
	do	{
		RGPPrintMessage (mode,entryNum,"Scale mode [linear|logarithmic]:");
		if (fgets (charBuffer,sizeof (charBuffer) - 2,stdin) == (char *) NULL) { ret = DBFault; goto Stop; }
		if ((strlen (charBuffer) > 0) && (charBuffer [strlen (charBuffer) - 1] == '\n'))
			charBuffer [strlen (charBuffer) - 1] = '\0';
		if ((scaleMode = CMoptLookup (scaleModes,charBuffer,true)) != DBFault) break;
		sprintf (errorMsg,"Invalid scale mode [%s]",charBuffer);
		if (RGPPrintError (mode,*entryNum,errorMsg)) { ret = DBFault; goto Stop; }
		} while (true);
	do	{
		RGPPrintMessage (mode,entryNum,"Value range [minimum,maximum]:");
		if (fgets (charBuffer,sizeof (charBuffer) - 2,stdin) == (char *) NULL) { ret = DBFault; goto Stop; }
		if (sscanf (charBuffer,"%f,%f",&min,&max) == 2)	break;
		else	if (RGPPrintError (mode,*entryNum,"Value range input error")) { ret = DBFault; goto Stop; }
		} while (true);
	if ((array = (float *) calloc (gridIF->RowNum () * gridIF->ColNum (),sizeof (float))) == (float *) NULL)
		{ CMmsgPrint (CMmsgSysError, "Memory allocation error in: %s %d",__FILE__,__LINE__); ret = DBFault; goto Stop; }
	for (pos.Row = 0;pos.Row < gridIF->RowNum ();++pos.Row)
		for (pos.Col = 0;pos.Col < gridIF->ColNum ();++pos.Col)
			if (gridIF->Value (layerRec,pos,&value))
					{
					value = value > min ? value : min;
					value = value < max ? value : max;
					switch (scaleMode)
						{
						default:
						case 0:	array [pos.Row * gridIF->ColNum () + pos.Col] = value; break;
						case 1:	array [pos.Row * gridIF->ColNum () + pos.Col] = log10 (value); break;
						case 2:	array [pos.Row * gridIF->ColNum () + pos.Col] = sqrt (value); break;
						}
					}
			else 	array [pos.Row * gridIF->ColNum () + pos.Col] = min - (max - min) / (float) shadeNum;

	translation [0] = extent.LowerLeft.X - gridIF->CellWidth () / 2.0;
	translation [1] = gridIF->CellWidth ();
	translation [2] = 0.0;
	translation [3] = extent.LowerLeft.Y - gridIF->CellHeight () / 2.0;
	translation [4] = 0.0;
	translation [5] = gridIF->CellHeight ();
	RGPPrintMessage (mode,entryNum,"Unit:");
	if ((fgets (charBuffer,sizeof (charBuffer) - 2,stdin) == (char *) NULL) || (sscanf (charBuffer,"%f",&unit) != 1))
		{ RGPPrintError (mode,*entryNum,"Unit input error"), ret = DBFault; goto Stop; }

	RGPPrintMessage (mode,entryNum,"Unit label:");
	if (fgets (charBuffer,sizeof (charBuffer) - 2,stdin) == (char *) NULL)
		{ RGPPrintError (mode,*entryNum,"Unit label input error"); ret = DBFault; goto Stop; }
	if ((strlen (charBuffer) > 0) && (charBuffer [strlen (charBuffer) - 1] == '\n'))
			charBuffer [strlen (charBuffer) - 1] = '\0';

/*	cpgsitf (scaleMode); */
	switch (scaleMode)
		{
		default:
		case 0:
			min = min - (max - min) / (float) shadeNum;
			max = max + (max - min) / (float) shadeNum;
			cpgwedg ("BI",0.0,5.0,min * unit,max * unit,charBuffer);
			cpgimag (array,pos.Col,pos.Row,1,pos.Col,1,pos.Row,min,max,translation);
			break;
		case 1:
			cpgwedg ("BI",0.0,5.0,log10 (min * unit),log10 (max * unit),charBuffer);
			cpgimag (array,pos.Col,pos.Row,1,pos.Col,1,pos.Row,log10 (min),log10 (max),translation);
			break;
		case 2:
			cpgwedg ("BI",0.0,5.0,sqrt (min * unit),sqrt (max * unit),charBuffer);
			cpgimag (array,pos.Col,pos.Row,1,pos.Col,1,pos.Row,sqrt (min),sqrt (max),translation);
			break;
		}

Stop:
	delete gridIF;
	return (ret);
	}
Exemplo n.º 15
0
int _RGISToolsGridExportARCInfo (DBObjData *data,char *selection)

	{
	DBInt layerID, i;
	FILE *file;
	char coverName	[11], command    [256]; 
	char asciiGrid   		[FILENAME_MAX];
	char attribDef   		[FILENAME_MAX];
	char attribData   	[FILENAME_MAX];
	char amlFile    [FILENAME_MAX];
	DBGridIF *gridIF = new DBGridIF (data);
	DBObjRecord *layerRec;

	for (layerID = 0;layerID < gridIF->LayerNum ();++layerID)
		{
		layerRec = gridIF->Layer (layerID);
		sprintf (asciiGrid,"%s/asciigrid%d.tmp",selection,layerID);
		if (DBExportARCGridLayer (data,layerRec,asciiGrid) == DBFault) return (DBFault);
		}
	if (data->Type () == DBTypeGridDiscrete)
		{
		sprintf (attribDef,"%s/attrib.def",selection);
		if (DBExportARCTableDef (data,DBrNItems,attribDef) == DBFault)
			{ unlink (asciiGrid); return (DBFault); }
		sprintf (attribData,"%s/attrib.dat",selection);
		if (DBExportARCTableData (data,DBrNItems,attribData) == DBFault)
			{ unlink (asciiGrid); unlink (attribDef); return (DBFault); }
		}
	
	sprintf (amlFile,"%s/grdcreate.aml",selection);
	if ((file = fopen (amlFile,"w")) == NULL)
		{
		for (layerID = 0;layerID < gridIF->LayerNum ();++layerID)
			{
			layerRec = gridIF->Layer (layerID);
			sprintf (asciiGrid,"%s/asciigrid%d.tmp",selection,layerID);
			unlink (asciiGrid);
			}
		if (data->Type () == DBTypeGridDiscrete) { unlink (attribDef); unlink (attribData); }
		CMmsgPrint (CMmsgAppError, "Aml File Creation Error in: %s %d",__FILE__,__LINE__);
		return (DBFault);
		}
	fprintf (file,"&workspace %s\n",selection);
	for (layerID = 0;layerID < gridIF->LayerNum ();++layerID)
		{
		layerRec = gridIF->Layer (layerID);
		strncpy (coverName,layerRec->Name (),sizeof (coverName) - 1);
		coverName	[sizeof (coverName) - 1] = '\0';
		for (i = 0;i < (DBInt) strlen (coverName);++i) if (coverName [i] == '.') coverName [i] = '\0';
		for (i = 0;i < (DBInt) strlen (coverName);++i) coverName [i] = tolower (coverName [i]);
		sprintf (asciiGrid,"%s/asciigrid%d.tmp",selection,layerID);
		if (data->Type () == DBTypeGridContinuous)
			fprintf (file,"asciigrid %s g_%s float\n",asciiGrid,coverName);
		else
			fprintf (file,"asciigrid %s g_%s int\n",asciiGrid,coverName);
		if (data->Type () == DBTypeGridDiscrete)
			{
			fprintf (file,"tables\n");
			fprintf (file,"define g_%s.vattr\n",coverName);
			fprintf (file,"&r %s\n",attribDef);
			fprintf (file,"~\n");
			fprintf (file,"alter GridValue\n");
			fprintf (file,"value,,,,\n");
			fprintf (file,"add\n");
			fprintf (file,"&r %s\n",attribData);
			fprintf (file,"~\n");
			fprintf (file,"q stop\n");
			fprintf (file,"joinitem g_%s.vat g_%s.vattr g_%s.vat value count\n",coverName,coverName,coverName);
			fprintf (file,"tables\n");
			fprintf (file,"select g_%s.vattr\n",coverName);
			fprintf (file,"erase g_%s.vattr\ny\n",coverName);
			fprintf (file,"q stop\n");
			}
		}
	fclose (file);

	if (getenv ("GHAAS_ARC") != NULL)
		{
		sprintf (command,getenv ("GHAAS_ARC"),amlFile);

		system (command);
		for (layerID = 0;layerID < gridIF->LayerNum ();++layerID)
			{
			layerRec = gridIF->Layer (layerID);
			sprintf (asciiGrid,"%s/asciigrid%d.tmp",selection,layerID);
			unlink (asciiGrid);
			}
		if (data->Type () == DBTypeGridDiscrete) { unlink (attribDef); unlink (attribData); }
		unlink (amlFile);
		}
	return (DBSuccess);
	}
Exemplo n.º 16
0
void DBGridOperation(DBObjData *grdData, DBFloat constant, DBInt oper) {
    DBInt layerID;
    DBFloat value;
    DBPosition pos;
    DBObjRecord *layerRec;
    DBGridIF *gridIF = new DBGridIF(grdData);

    for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) {
        layerRec = gridIF->Layer(layerID);
        if ((layerRec->Flags() & DBObjectFlagIdle) != DBObjectFlagIdle) break;
    }
    if (layerID == gridIF->LayerNum()) {
        CMmsgPrint(CMmsgAppError, "No Layer to Process in %s %d", __FILE__, __LINE__);
        return;
    }

    for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) {
        layerRec = gridIF->Layer(layerID);
        if ((layerRec->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle) continue;

        for (pos.Row = 0; pos.Row < gridIF->RowNum(); pos.Row++) {
            if (DBPause((layerID * gridIF->RowNum() + pos.Row) * 100 / (gridIF->LayerNum() * gridIF->RowNum())))
                goto Stop;
            for (pos.Col = 0; pos.Col < gridIF->ColNum(); pos.Col++) {
                if (gridIF->Value(layerRec, pos, &value))
                    switch (oper) {
                        case DBMathOperatorAdd:
                            gridIF->Value(layerRec, pos, value + constant);
                            break;
                        case DBMathOperatorSub:
                            gridIF->Value(layerRec, pos, value - constant);
                            break;
                        case DBMathOperatorMul:
                            gridIF->Value(layerRec, pos, value * constant);
                            break;
                        case DBMathOperatorDiv:
                            gridIF->Value(layerRec, pos, value / constant);
                            break;
                    }
            }
        }
        gridIF->RecalcStats(layerRec);
    }
    Stop:
    return;
}
Exemplo n.º 17
0
void DBGridOperationAbs(DBObjData *grdData) {
    DBInt layerID;
    DBFloat value;
    DBPosition pos;
    DBObjRecord *layerRec;
    DBGridIF *gridIF = new DBGridIF(grdData);

    for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) {
        layerRec = gridIF->Layer(layerID);
        if ((layerRec->Flags() & DBObjectFlagIdle) != DBObjectFlagIdle) break;
    }
    if (layerID == gridIF->LayerNum()) {
        CMmsgPrint(CMmsgAppError, "No Layer to Process in %s %d", __FILE__, __LINE__);
        return;
    }

    for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) {
        layerRec = gridIF->Layer(layerID);
        if ((layerRec->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle) continue;

        for (pos.Row = 0; pos.Row < gridIF->RowNum(); pos.Row++) {
            if (DBPause((layerID * gridIF->RowNum() + pos.Row) * 100 / (gridIF->LayerNum() * gridIF->RowNum())))
                goto Stop;
            for (pos.Col = 0; pos.Col < gridIF->ColNum(); pos.Col++)
                if (gridIF->Value(layerRec, pos, &value)) gridIF->Value(layerRec, pos, fabs(value));
        }
        gridIF->RecalcStats(layerRec);
    }
    Stop:
    return;
}
Exemplo n.º 18
0
int main(int argc, char* argv[])

	{
	int argPos, argNum = argc, ret, verbose = false;
	int layerID;
	int shadeSet        = DBDataFlagDispModeContGreyScale;
	bool changeShadeSet = false;
	DBObjData *dbData;
	DBGridIF *gridIF;
	class RenameCLS
		{
		public:
			DBInt LayerID;
			char *LayerName;
			RenameCLS *Next;
			RenameCLS (DBInt layerID, char * layerName)
				{ LayerID = layerID; LayerName = layerName; Next = (RenameCLS *) NULL; }
			void AddLink (RenameCLS *renameCLS)
				{
				if (Next == (RenameCLS *) NULL)	Next = renameCLS;
				else Next->AddLink (renameCLS);
				}
			void DeleteLink ()
				{
				if (Next != (RenameCLS *) NULL) { Next->DeleteLink (); delete Next; }
				}
			void RenameLayer (DBGridIF *gridIF)
				{
				DBObjRecord *layerRec;
				if ((layerRec = gridIF->Layer (LayerID - 1)) != (DBObjRecord *) NULL) gridIF->RenameLayer (layerRec,LayerName);
				if (Next != (RenameCLS *) NULL) Next->RenameLayer (gridIF);
				}
		} *renameCLS = (RenameCLS *) NULL;
  
	for (argPos = 1;argPos < argNum; )
		{
		if (CMargTest (argv [argPos],"-r","--rename"))
			{
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing layerID!"); return (CMfailed); }
			if (sscanf (argv[argPos],"%d",&layerID) != 1)
				{
				CMmsgPrint (CMmsgUsrError,"Invalid layerID!");
				if (renameCLS != (RenameCLS *) NULL) { renameCLS->DeleteLink (); delete renameCLS; }
				return (CMfailed);
				}
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{
				CMmsgPrint (CMmsgUsrError,"Missing layername!");
				if (renameCLS != (RenameCLS *) NULL) { renameCLS->DeleteLink (); delete renameCLS; }
				return (CMfailed);
				}
			if (renameCLS == (RenameCLS *) NULL) renameCLS = new RenameCLS (layerID,argv [argPos]);
			else renameCLS->AddLink (new RenameCLS (layerID,argv [argPos]));
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-s","--shadeset"))
			{
			int shadeCodes [] = {	DBDataFlagDispModeContStandard,
			                        DBDataFlagDispModeContGreyScale,
			                        DBDataFlagDispModeContBlueScale,
			                        DBDataFlagDispModeContBlueRed,
			                        DBDataFlagDispModeContElevation };
			const char *shadeSets [] = { "standard","grey","blue","blue-to-red","elevation", (char *) NULL };

			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing shadeset!");     return (CMfailed); }
			if ((shadeSet = CMoptLookup (shadeSets,argv [argPos],true)) == CMfailed)
				{ CMmsgPrint (CMmsgUsrError,"Invalid shadeset!");     return (CMfailed); }
			shadeSet = shadeCodes [shadeSet];
			changeShadeSet = true;
			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 grid> <output grid>",CMprgName(argv[0]));
			CMmsgPrint (CMmsgInfo,"     -r,--rename    [layerID layerName]");
			CMmsgPrint (CMmsgInfo,"     -s,--shadeset  [standard|grey|blue|blue-to-red|elevation]");
			CMmsgPrint (CMmsgInfo,"     -V,--verbose");
			CMmsgPrint (CMmsgInfo,"     -h,--help");
			return (DBSuccess);
			}

		if ((argv [argPos][0] == '-') && (strlen (argv [argPos]) > 1))
			{
			CMmsgPrint (CMmsgUsrError,"Unknown option: %s!",argv [argPos]);
			if (renameCLS != (RenameCLS *) NULL) { renameCLS->DeleteLink (); delete renameCLS; }
			return (CMfailed);
			}
		argPos++;
		}
  
	if (argNum > 3)
		{
		CMmsgPrint (CMmsgUsrError,"Extra arguments!");
		if (renameCLS != (RenameCLS *) NULL) { renameCLS->DeleteLink (); delete renameCLS; }
		return (CMfailed);
		}
	if (verbose) RGlibPauseOpen (argv[0]);

	dbData = new DBObjData ();
	ret = (argNum > 1) && (strcmp (argv [1],"-") != 0) ? dbData->Read (argv [1]) : dbData->Read (stdin);
	if ((ret == DBFault) || ((dbData->Type () != DBTypeGridContinuous) && (dbData->Type () != DBTypeGridDiscrete)))
		{
		delete dbData;
		if (renameCLS != (RenameCLS *) NULL) { renameCLS->DeleteLink (); delete renameCLS; }
		return (CMfailed);
		}
	gridIF = new DBGridIF (dbData);

	if (renameCLS != (RenameCLS *) NULL) renameCLS->RenameLayer (gridIF);

	if (changeShadeSet && (dbData->Type () == DBTypeGridContinuous))
		{
		dbData->Flags (DBDataFlagDispModeContShadeSets,DBClear);
		dbData->Flags (shadeSet, DBSet);
		}
	ret = (argNum > 2) && (strcmp (argv [2],"-") != 0) ? dbData->Write (argv [2]) : dbData->Write (stdout);

	if (renameCLS != (RenameCLS *) NULL) { renameCLS->DeleteLink (); delete renameCLS; }

	delete gridIF;
	delete dbData;
	if (verbose) RGlibPauseClose ();
	return (ret);
	}
Exemplo n.º 19
0
void DBGridOperation(DBObjData *leftGrd, DBObjData *rightGrd, DBInt oper, DBInt mergeMissingVal) {
    DBInt leftID, rightID;
    DBFloat leftVal, rightVal;
    DBPosition pos;
    DBCoordinate coord;
    DBObjRecord *leftRec, *rightRec;
    DBGridIF *leftIF = new DBGridIF(leftGrd);
    DBGridIF *rightIF = new DBGridIF(rightGrd);

    for (leftID = 0; leftID < leftIF->LayerNum(); ++leftID) {
        leftRec = leftIF->Layer(leftID);
        if ((leftRec->Flags() & DBObjectFlagIdle) != DBObjectFlagIdle) break;
    }
    if (leftID == leftIF->LayerNum()) {
        CMmsgPrint(CMmsgAppError, "No Layer to Process in %s %d", __FILE__, __LINE__);
        return;
    }
    for (rightID = 0; rightID < rightIF->LayerNum(); ++rightID) {
        rightRec = rightIF->Layer(rightID);
        if ((rightRec->Flags() & DBObjectFlagIdle) != DBObjectFlagIdle) break;
    }
    if (rightID == rightIF->LayerNum()) {
        CMmsgPrint(CMmsgAppError, "No Layer to Process in %s %d", __FILE__, __LINE__);
        return;
    }

    rightID = (DBInt) 0;
    for (leftID = 0; leftID < leftIF->LayerNum(); ++leftID) {
        leftRec = leftIF->Layer(leftID);
        while ((leftRec->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle) {
            ++leftID;
            if (leftID == leftIF->LayerNum()) goto Stop;
            leftRec = leftIF->Layer(leftID);
        }
        if ((rightRec = rightIF->Layer(rightID)) == (DBObjRecord *) NULL) {
            rightID = 0;
            rightRec = rightIF->Layer(rightID);
        }
        while ((rightRec->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle) {
            ++rightID;
            if (rightID == rightIF->LayerNum()) rightID = 0;
            rightRec = rightIF->Layer(rightID);
        }

        for (pos.Row = 0; pos.Row < leftIF->RowNum(); pos.Row++) {
            if (DBPause((leftID * leftIF->RowNum() + pos.Row) * 100 / (leftIF->LayerNum() * leftIF->RowNum())))
                goto Stop;
            for (pos.Col = 0; pos.Col < leftIF->ColNum(); pos.Col++) {
                leftIF->Pos2Coord(pos, coord);
                if (leftIF->Value(leftRec, pos, &leftVal)) {
                    if (rightIF->Value(rightRec, coord, &rightVal))
                        switch (oper) {
                            case DBMathOperatorAdd:
                                leftIF->Value(leftRec, pos, leftVal + rightVal);
                                break;
                            case DBMathOperatorSub:
                                leftIF->Value(leftRec, pos, leftVal - rightVal);
                                break;
                            case DBMathOperatorMul:
                                leftIF->Value(leftRec, pos, leftVal * rightVal);
                                break;
                            case DBMathOperatorDiv:
                                if (fabs(rightVal) > 0.000001) leftIF->Value(leftRec, pos, leftVal / rightVal);
                                else leftIF->Value(leftRec, pos, leftIF->MissingValue());
                                break;
                        }
                    else if (mergeMissingVal) leftIF->Value(leftRec, pos, leftIF->MissingValue());
                }
            }
        }
        ++rightID;
        leftIF->RecalcStats(leftRec);
    }
    Stop:
    return;
}
Exemplo n.º 20
0
DBInt RGlibRGIS2DataStream(DBObjData *grdData, DBObjData *tmplData, char *fieldName, FILE *outFile) {
    DBInt layerID, ret = DBSuccess, itemSize, itemID;
    DBInt intValue;
    DBFloat floatValue;
    void *data;
    MFVarHeader_t varHeader;
    DBObjRecord *layerRec, *gridRec;
    DBObjTableField *fieldPTR = (DBObjTableField *) NULL;
    DBGridIF *gridIF;
    DBVPointIF *tmplPntIF = (DBVPointIF *) NULL;
    DBGridIF *tmplGrdIF = (DBGridIF *) NULL;
    DBNetworkIF *tmplNetIF = (DBNetworkIF *) NULL;

    gridIF = new DBGridIF(grdData);

    varHeader.Swap = 1;
    if (grdData->Type() == DBTypeGridDiscrete) {
        DBObjTable *itemTable = grdData->Table(DBrNItems);

        if (fieldName == (char *) NULL) fieldName = DBrNGridValue;
        if ((fieldPTR = itemTable->Field(fieldName)) == (DBObjTableField *) NULL) {
            CMmsgPrint(CMmsgAppError, "Error: Invalid field [%s] in: %s %d", fieldName, __FILE__, __LINE__);
            return (DBFault);
        }
        itemSize = fieldPTR->Length();
        switch (fieldPTR->Type()) {
            case DBTableFieldInt:
                switch (itemSize) {
                    default:
                    case sizeof(DBByte):
                        varHeader.DataType = MFByte;
                        break;
                    case sizeof(DBShort):
                        varHeader.DataType = MFShort;
                        break;
                    case sizeof(DBInt):
                        varHeader.DataType = MFInt;
                        break;
                }
                varHeader.Missing.Int = fieldPTR->IntNoData();
                break;
            case DBTableFieldFloat:
                switch (itemSize) {
                    default:
                    case sizeof(DBFloat4):
                        varHeader.DataType = MFFloat;
                        break;
                    case sizeof(DBFloat):
                        varHeader.DataType = MFDouble;
                        break;
                }
                varHeader.Missing.Float = fieldPTR->FloatNoData();
                break;
        }
    }
    else {
        if (fieldName != (char *) NULL) CMmsgPrint(CMmsgUsrError, "Warning: Fieldname ignored for continuous grid!");
        itemSize = gridIF->ValueSize();
        switch (gridIF->ValueType()) {
            case DBVariableInt:
                switch (itemSize) {
                    case 1:
                        varHeader.DataType = MFByte;
                        break;
                    case 2:
                        varHeader.DataType = MFShort;
                        break;
                    case 4:
                        varHeader.DataType = MFInt;
                        break;
                }
                varHeader.Missing.Int = (int) gridIF->MissingValue();
                break;
            case DBVariableFloat:
                switch (itemSize) {
                    case 4:
                        varHeader.DataType = MFFloat;
                        break;
                    case 8:
                        varHeader.DataType = MFDouble;
                        break;
                }
                varHeader.Missing.Float = gridIF->MissingValue();
                break;
        }
    }

    if (tmplData == (DBObjData *) NULL) {
        tmplGrdIF = gridIF;
        varHeader.ItemNum = gridIF->RowNum() * gridIF->ColNum();
    }
    else {
        switch (tmplData->Type()) {
            case DBTypeVectorPoint:
                tmplPntIF = new DBVPointIF(tmplData);
                varHeader.ItemNum = tmplPntIF->ItemNum();
                break;
            case DBTypeGridContinuous:
            case DBTypeGridDiscrete:
                tmplGrdIF = new DBGridIF(tmplData);
                varHeader.ItemNum = gridIF->RowNum() * gridIF->ColNum();
                break;
            case DBTypeNetwork:
                tmplNetIF = new DBNetworkIF(tmplData);
                varHeader.ItemNum = tmplNetIF->CellNum();
                break;
            default:
                delete gridIF;
                return (DBFault);
        }
    }
    if ((data = (void *) calloc(varHeader.ItemNum, itemSize)) == (void *) NULL) {
        CMmsgPrint(CMmsgSysError, "Error! Allocating %d items of %d size in: %s %d", varHeader.ItemNum, itemSize,
                   __FILE__, __LINE__);
        return (DBFault);
    }

/**************************************************************
*                                                             *
* Point template                                              *
*                                                             *
**************************************************************/

    if (tmplPntIF != (DBVPointIF *) NULL) {
        DBObjRecord *pntRec;

        if (fieldPTR == (DBObjTableField *) NULL) {
            for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) {
                layerRec = gridIF->Layer(layerID);
                strncpy(varHeader.Date, layerRec->Name(), MFDateStringLength - 1);
                for (itemID = 0; itemID < varHeader.ItemNum; ++itemID) {
                    pntRec = tmplPntIF->Item(itemID);
                    if ((varHeader.DataType == MFByte) || (varHeader.DataType == MFShort) ||
                        (varHeader.DataType == MFInt)) {
                        if (gridIF->Value(layerRec, tmplPntIF->Coordinate(pntRec), &intValue) == false)
                            intValue = varHeader.Missing.Int;
                        switch (varHeader.DataType) {
                            case MFByte:
                                ((char *) data)[itemID] = (char) intValue;
                                break;
                            case MFShort:
                                ((short *) data)[itemID] = (short) intValue;
                                break;
                            case MFInt:
                                ((int *) data)[itemID] = (short) intValue;
                                break;
                        }
                    }
                    else {
                        if (gridIF->Value(layerRec, tmplPntIF->Coordinate(pntRec), &floatValue) == false)
                            floatValue = varHeader.Missing.Float;
                        switch (varHeader.DataType) {
                            case MFFloat:
                                ((float *) data)[itemID] = (float) floatValue;
                                break;
                            case MFDouble:
                                ((double *) data)[itemID] = (double) floatValue;
                                break;
                        }
                    }
                }
                if ((DBInt) fwrite(&varHeader, sizeof(MFVarHeader_t), 1, outFile) != 1) {
                    CMmsgPrint(CMmsgSysError, "Error: Writing record header in: %s %d", __FILE__, __LINE__);
                    ret = DBFault;
                    break;
                }
                if ((DBInt) fwrite(data, itemSize, varHeader.ItemNum, outFile) != varHeader.ItemNum) {
                    CMmsgPrint(CMmsgSysError, "Error: Writing data in: %s %d", __FILE__, __LINE__);
                    ret = DBFault;
                    break;
                }
            }
        }
        else {
            for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) {
                layerRec = gridIF->Layer(layerID);
                strncpy(varHeader.Date, layerRec->Name(), MFDateStringLength - 1);
                for (itemID = 0; itemID < varHeader.ItemNum; ++itemID) {
                    pntRec = tmplPntIF->Item(itemID);
                    gridRec = gridIF->GridItem(layerRec, tmplPntIF->Coordinate(pntRec));
                    switch (varHeader.DataType) {
                        case MFByte:
                            ((char *) data)[itemID] =
                                    gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->IntNoData();
                            break;
                        case MFShort:
                            ((short *) data)[itemID] =
                                    gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->IntNoData();
                            break;
                        case MFInt:
                            ((int *) data)[itemID] =
                                    gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->IntNoData();
                            break;
                        case MFFloat:
                            ((float *) data)[itemID] =
                                    gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->FloatNoData();
                            break;
                        case MFDouble:
                            ((double *) data)[itemID] =
                                    gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->FloatNoData();
                            break;
                    }
                }
                if ((DBInt) fwrite(&varHeader, sizeof(MFVarHeader_t), 1, outFile) != 1) {
                    CMmsgPrint(CMmsgSysError, "Error: Writing record header in: %s %d", __FILE__, __LINE__);
                    ret = DBFault;
                    break;
                }
                if ((DBInt) fwrite(data, itemSize, varHeader.ItemNum, outFile) != varHeader.ItemNum) {
                    CMmsgPrint(CMmsgSysError, "Error: Writing data in: %s %d", __FILE__, __LINE__);
                    ret = DBFault;
                    break;
                }
            }
        }
        delete tmplPntIF;
    }

/**************************************************************
*                                                             *
* Grid Template (default when no template coverage is given.  *
*                                                             *
**************************************************************/
    else if (tmplGrdIF != (DBGridIF *) NULL) {
        DBPosition pos;
        DBCoordinate coord;

        if (fieldPTR == (DBObjTableField *) NULL) {
            for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) {
                layerRec = gridIF->Layer(layerID);
                strncpy(varHeader.Date, layerRec->Name(), MFDateStringLength - 1);
                for (pos.Row = 0; pos.Row < tmplGrdIF->RowNum(); ++pos.Row)
                    for (pos.Col = 0; pos.Col < tmplGrdIF->ColNum(); ++pos.Col) {
                        itemID = pos.Row * tmplGrdIF->ColNum() + pos.Col;
                        if ((varHeader.DataType == MFByte) || (varHeader.DataType == MFShort) ||
                            (varHeader.DataType == MFInt)) {
                            if (tmplGrdIF != gridIF) {
                                tmplGrdIF->Pos2Coord(pos, coord);
                                if (gridIF->Value(layerRec, coord, &intValue) == false)
                                    intValue = varHeader.Missing.Int;
                            }
                            else {
                                if (gridIF->Value(layerRec, pos, &intValue) == false) intValue = varHeader.Missing.Int;
                            }
                            switch (varHeader.DataType) {
                                case MFByte:
                                    ((char *) data)[itemID] = (char) intValue;
                                    break;
                                case MFShort:
                                    ((short *) data)[itemID] = (short) intValue;
                                    break;
                                case MFInt:
                                    ((int *) data)[itemID] = (short) intValue;
                                    break;
                            }
                        }
                        else {
                            if (tmplGrdIF != gridIF) {
                                tmplGrdIF->Pos2Coord(pos, coord);
                                if (gridIF->Value(layerRec, coord, &floatValue) == false)
                                    floatValue = varHeader.Missing.Float;
                            }
                            else {
                                if (gridIF->Value(layerRec, pos, &floatValue) == false)
                                    floatValue = varHeader.Missing.Float;
                            }
                            switch (varHeader.DataType) {
                                case MFFloat:
                                    ((float *) data)[itemID] = (float) floatValue;
                                    break;
                                case MFDouble:
                                    ((double *) data)[itemID] = (double) floatValue;
                                    break;
                            }
                        }
                    }
                if ((DBInt) fwrite(&varHeader, sizeof(MFVarHeader_t), 1, outFile) != 1) {
                    CMmsgPrint(CMmsgSysError, "Error: Writing record header in: %s %d", __FILE__, __LINE__);
                    ret = DBFault;
                    break;
                }
                if ((DBInt) fwrite(data, itemSize, varHeader.ItemNum, outFile) != varHeader.ItemNum) {
                    CMmsgPrint(CMmsgSysError, "Error: Writing data in: %s %d", __FILE__, __LINE__);
                    ret = DBFault;
                    break;
                }
            }
        }
        else {
            for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) {
                layerRec = gridIF->Layer(layerID);
                strncpy(varHeader.Date, layerRec->Name(), MFDateStringLength - 1);
                for (pos.Row = 0; pos.Row < tmplGrdIF->RowNum(); ++pos.Row)
                    for (pos.Col = 0; pos.Col < tmplGrdIF->ColNum(); ++pos.Col) {
                        itemID = pos.Row * tmplGrdIF->ColNum() + pos.Col;
                        if (tmplGrdIF != gridIF) {
                            tmplGrdIF->Pos2Coord(pos, coord);
                            gridRec = gridIF->GridItem(layerRec, coord);
                        }
                        else gridRec = gridIF->GridItem(layerRec, pos);
                        switch (varHeader.DataType) {
                            case MFByte:
                                ((char *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec)
                                                                                          : fieldPTR->IntNoData();
                                break;
                            case MFShort:
                                ((short *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec)
                                                                                           : fieldPTR->IntNoData();
                                break;
                            case MFInt:
                                ((int *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec)
                                                                                         : fieldPTR->IntNoData();
                                break;
                            case MFFloat:
                                ((float *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec)
                                                                                           : fieldPTR->FloatNoData();
                                break;
                            case MFDouble:
                                ((double *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec)
                                                                                            : fieldPTR->FloatNoData();
                                break;
                        }
                    }
                if ((DBInt) fwrite(&varHeader, sizeof(MFVarHeader_t), 1, outFile) != 1) {
                    CMmsgPrint(CMmsgSysError, "Error: Writing record header in: %s %d", __FILE__, __LINE__);
                    ret = DBFault;
                    break;
                }
                if ((DBInt) fwrite(data, itemSize, varHeader.ItemNum, outFile) != varHeader.ItemNum) {
                    CMmsgPrint(CMmsgSysError, "Error: Writing data in: %s %d", __FILE__, __LINE__);
                    ret = DBFault;
                    break;
                }
            }
        }
        if (tmplGrdIF != gridIF) delete tmplGrdIF;
    }

/**************************************************************
*                                                             *
* Network Template                                            *
*                                                             *
**************************************************************/
    else if (tmplNetIF != (DBNetworkIF *) NULL) {
        DBObjRecord *cellRec;

        if (fieldPTR == (DBObjTableField *) NULL) {
            for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) {
                layerRec = gridIF->Layer(layerID);
                strncpy(varHeader.Date, layerRec->Name(), MFDateStringLength - 1);
                for (itemID = 0; itemID < varHeader.ItemNum; ++itemID) {
                    cellRec = tmplNetIF->Cell(itemID);
                    if ((varHeader.DataType == MFByte) || (varHeader.DataType == MFShort) ||
                        (varHeader.DataType == MFInt)) {
                        if (gridIF->Value(layerRec, tmplNetIF->Center(cellRec), &intValue) == false)
                            intValue = varHeader.Missing.Int;
                        switch (varHeader.DataType) {
                            case MFByte:
                                ((char *) data)[itemID] = (char) intValue;
                                break;
                            case MFShort:
                                ((short *) data)[itemID] = (short) intValue;
                                break;
                            case MFInt:
                                ((int *) data)[itemID] = (short) intValue;
                                break;
                        }
                    }
                    else {
                        if (gridIF->Value(layerRec, tmplNetIF->Center(cellRec), &floatValue) == false)
                            floatValue = varHeader.Missing.Float;
                        switch (varHeader.DataType) {
                            case MFFloat:
                                ((float *) data)[itemID] = (float) floatValue;
                                break;
                            case MFDouble:
                                ((double *) data)[itemID] = (double) floatValue;
                                break;
                        }
                    }
                }
                if ((DBInt) fwrite(&varHeader, sizeof(MFVarHeader_t), 1, outFile) != 1) {
                    CMmsgPrint(CMmsgSysError, "Error: Writing record header in: %s %d", __FILE__, __LINE__);
                    ret = DBFault;
                    break;
                }
                if ((DBInt) fwrite(data, itemSize, varHeader.ItemNum, outFile) != varHeader.ItemNum) {
                    CMmsgPrint(CMmsgSysError, "Error: Writing data in: %s %d", __FILE__, __LINE__);
                    ret = DBFault;
                    break;
                }
            }
        }
        else {
            for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) {
                layerRec = gridIF->Layer(layerID);
                strncpy(varHeader.Date, layerRec->Name(), MFDateStringLength - 1);
                for (itemID = 0; itemID < varHeader.ItemNum; ++itemID) {
                    cellRec = tmplNetIF->Cell(itemID);
                    gridRec = gridIF->GridItem(layerRec, tmplNetIF->Center(cellRec));
                    switch (varHeader.DataType) {
                        case MFByte:
                            ((char *) data)[itemID] =
                                    gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->IntNoData();
                            break;
                        case MFShort:
                            ((short *) data)[itemID] =
                                    gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->IntNoData();
                            break;
                        case MFInt:
                            ((int *) data)[itemID] =
                                    gridRec != (DBObjRecord *) NULL ? fieldPTR->Int(gridRec) : fieldPTR->IntNoData();
                            break;
                        case MFFloat:
                            ((float *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Float(gridRec)
                                                                                       : fieldPTR->FloatNoData();
                            break;
                        case MFDouble:
                            ((double *) data)[itemID] = gridRec != (DBObjRecord *) NULL ? fieldPTR->Float(gridRec)
                                                                                        : fieldPTR->FloatNoData();
                            break;
                    }
                }
                if ((DBInt) fwrite(&varHeader, sizeof(MFVarHeader_t), 1, outFile) != 1) {
                    CMmsgPrint(CMmsgSysError, "Error: Writing record header in: %s %d", __FILE__, __LINE__);
                    ret = DBFault;
                    break;
                }
                if ((DBInt) fwrite(data, itemSize, varHeader.ItemNum, outFile) != varHeader.ItemNum) {
                    CMmsgPrint(CMmsgSysError, "Error: Writing data in: %s %d", __FILE__, __LINE__);
                    ret = DBFault;
                    break;
                }
            }
        }
        delete tmplNetIF;
    }

    free(data);
    delete gridIF;
    return (ret);
}
Exemplo n.º 21
0
DBInt RGlibDataStream2RGIS(DBObjData *outData, DBObjData *tmplData, FILE *inFile) {
    DBInt layerID = 0, itemSize;
    DBPosition pos;
    DBFloat val;
    void *data = (void *) NULL;
    MFVarHeader_t header;
    DBObjRecord *record;


    switch (tmplData->Type()) {
        case DBTypeVectorPoint: {
            DBInt itemID;
            DBDate date;
            DBObjTable *itemTable = outData->Table(DBrNItems);
            DBObjTableField *idField = new DBObjTableField("ItemID", DBTableFieldInt, "%6d", sizeof(DBInt), false);
            DBObjTableField *dateField = new DBObjTableField("Date", DBTableFieldDate, "%s", sizeof(DBDate), false);
            DBObjTableField *valField;
            DBVPointIF *pntIF = new DBVPointIF(tmplData);

            itemTable->AddField(idField);
            itemTable->AddField(dateField);

            while (MFVarReadHeader(&header, inFile)) {
                if (header.ItemNum != pntIF->ItemNum()) {
                    CMmsgPrint(CMmsgUsrError, "Error: Datastream inconsistency %d %d!", header.ItemNum,
                               pntIF->ItemNum());
                    return (DBFault);
                }
                if (data == (void *) NULL) {
                    itemSize = MFVarItemSize(header.DataType);
                    if ((data = (void *) realloc(data, header.ItemNum * itemSize)) == (void *) NULL) {
                        CMmsgPrint(CMmsgSysError, "Memory allocation error in: %s %d", __FILE__, __LINE__);
                        return (DBFault);
                    }
                    switch (header.DataType) {
                        case MFByte:
                            valField = new DBObjTableField("Value", DBTableFieldInt, "%2d", sizeof(char), false);
                        case MFShort:
                            valField = new DBObjTableField("Value", DBTableFieldInt, "%4d", sizeof(DBShort), false);
                        case MFInt:
                            valField = new DBObjTableField("Value", DBTableFieldInt, "%8d", sizeof(DBInt), false);
                        case MFFloat:
                            valField = new DBObjTableField("Value", DBTableFieldFloat, "%8.2f", sizeof(DBFloat4),
                                                           false);
                        case MFDouble:
                            valField = new DBObjTableField("Value", DBTableFieldFloat, "%8.2f", sizeof(DBFloat), false);
                    }
                    itemTable->AddField(valField);
                }
                if ((int) fread(data, itemSize, header.ItemNum, inFile) != header.ItemNum) {
                    CMmsgPrint(CMmsgSysError, "Error: Data stream read in: %s %d", __FILE__, __LINE__);
                    return (DBFault);
                }
                for (itemID = 0; itemID < header.ItemNum; ++itemID) {
                    record = itemTable->Add(header.Date);
                    date.Set(header.Date);
                    idField->Int(record, itemID);
                    dateField->Date(record, date);
/*					decDateField->Float (record,date);
*/                    switch (header.DataType) {
                        case MFByte:
                            valField->Int(record, ((char *) data)[itemID]);
                            break;
                        case MFShort:
                            valField->Int(record, ((short *) data)[itemID]);
                            break;
                        case MFInt:
                            valField->Int(record, ((int *) data)[itemID]);
                            break;
                        case MFFloat:
                            valField->Float(record, ((float *) data)[itemID]);
                            break;
                        case MFDouble:
                            valField->Float(record, ((double *) data)[itemID]);
                            break;
                    }
                }
            }
            delete pntIF;
        }
            break;
        case DBTypeGridContinuous:
        case DBTypeGridDiscrete: {
            DBGridIF *gridIF = new DBGridIF(outData);

            while (MFVarReadHeader(&header, inFile)) {
                if (header.ItemNum != gridIF->RowNum() * gridIF->ColNum()) {
                    CMmsgPrint(CMmsgUsrError, "Error: Datastream inconsistency!");
                    return (DBFault);
                }
                if (layerID == 0) {
                    itemSize = MFVarItemSize(header.DataType);
                    if ((data = (void *) realloc(data, header.ItemNum * itemSize)) == (void *) NULL) {
                        CMmsgPrint(CMmsgSysError, "Memory allocation error in: %s %d", __FILE__, __LINE__);
                        return (DBFault);
                    }
                    record = gridIF->Layer(layerID);
                    gridIF->RenameLayer(header.Date);
                }
                else record = gridIF->AddLayer(header.Date);

                switch (header.DataType) {
                    case MFByte:
                    case MFShort:
                    case MFInt:
                        gridIF->MissingValue(record, header.Missing.Int);
                        break;
                    case MFFloat:
                    case MFDouble:
                        gridIF->MissingValue(record, header.Missing.Float);
                        break;
                }
                if ((int) fread(data, itemSize, header.ItemNum, inFile) != header.ItemNum) {
                    CMmsgPrint(CMmsgSysError, "Error: Data stream read in: %s %d", __FILE__, __LINE__);
                    return (DBFault);
                }

                for (pos.Row = 0; pos.Row < gridIF->RowNum(); ++pos.Row)
                    for (pos.Col = 0; pos.Col < gridIF->ColNum(); ++pos.Col) {
                        switch (header.DataType) {
                            case MFByte:
                                val = (DBFloat) (((char *) data)[pos.Row * gridIF->ColNum() + pos.Col]);
                                break;
                            case MFShort:
                                val = (DBFloat) (((short *) data)[pos.Row * gridIF->ColNum() + pos.Col]);
                                break;
                            case MFInt:
                                val = (DBFloat) (((int *) data)[pos.Row * gridIF->ColNum() + pos.Col]);
                                break;
                            case MFFloat:
                                val = (DBFloat) (((float *) data)[pos.Row * gridIF->ColNum() + pos.Col]);
                                break;
                            case MFDouble:
                                val = (DBFloat) (((double *) data)[pos.Row * gridIF->ColNum() + pos.Col]);
                                break;
                        }
                        gridIF->Value(record, pos, val);
                    }
                layerID++;
            }
            gridIF->RecalcStats();
        }
            break;
        case DBTypeNetwork: {
            DBInt cellID;
            DBGridIF *gridIF = new DBGridIF(outData);
            DBNetworkIF *netIF = new DBNetworkIF(tmplData);

            while (MFVarReadHeader(&header, inFile)) {
                if (header.ItemNum != netIF->CellNum()) {
                    CMmsgPrint(CMmsgUsrError, "Error: Datastream inconsistency!");
                    return (DBFault);
                }
                if (layerID == 0) {
                    itemSize = MFVarItemSize(header.DataType);
                    if ((data = (void *) realloc(data, header.ItemNum * itemSize)) == (void *) NULL) {
                        CMmsgPrint(CMmsgSysError, "Memory allocation error in: %s %d", __FILE__, __LINE__);
                        return (DBFault);
                    }
                    record = gridIF->Layer(layerID);
                    gridIF->RenameLayer(header.Date);
                }
                else record = gridIF->AddLayer(header.Date);
                if ((int) fread(data, itemSize, header.ItemNum, inFile) != header.ItemNum) {
                    CMmsgPrint(CMmsgSysError, "Error: Data stream read in: %s %d", __FILE__, __LINE__);
                    delete netIF;
                    return (DBFault);
                }

                for (pos.Row = 0; pos.Row < gridIF->RowNum(); ++pos.Row)
                    for (pos.Col = 0; pos.Col < gridIF->ColNum(); ++pos.Col)
                        gridIF->Value(record, pos, gridIF->MissingValue());

                for (cellID = 0; cellID < netIF->CellNum(); ++cellID) {
                    pos = netIF->CellPosition(netIF->Cell(cellID));

                    switch (header.DataType) {
                        case MFByte:
                            val = (DBFloat) (((char *) data)[cellID]);
                            break;
                        case MFShort:
                            val = (DBFloat) (((short *) data)[cellID]);
                            break;
                        case MFInt:
                            val = (DBFloat) (((int *) data)[cellID]);
                            break;
                        case MFFloat:
                            val = (DBFloat) (((float *) data)[cellID]);
                            break;
                        case MFDouble:
                            val = (DBFloat) (((double *) data)[cellID]);
                            break;
                    }
                    gridIF->Value(record, pos, val);
                }
                layerID++;
            }
            gridIF->RecalcStats();
        }
            break;
    }
    return (DBSuccess);
}
Exemplo n.º 22
0
			void RenameLayer (DBGridIF *gridIF)
				{
				DBObjRecord *layerRec;
				if ((layerRec = gridIF->Layer (LayerID - 1)) != (DBObjRecord *) NULL) gridIF->RenameLayer (layerRec,LayerName);
				if (Next != (RenameCLS *) NULL) Next->RenameLayer (gridIF);
				}
Exemplo n.º 23
0
void RGISAnalyseLineMSampleGridCBK (Widget widget, RGISWorkspace *workspace,XmAnyCallbackStruct *callData)

	{
	DBInt layerID, layerNum;
	DBCoordinate coord;
	DBFloat realValue;
	DBDataset *dataset  = UIDataset ();
	DBObjData *dbData  = dataset->Data ();
	DBObjData *grdData  = dbData->LinkedData ();
	DBObjData *tblData;
	DBObjTable *table, *itemTable = dbData->Table (DBrNItems);
	DBObjTableField *lineIDFLD;
	DBObjTableField *layerIDFLD;
	DBObjTableField *layerNameFLD;
	DBObjTableField *fromValueFLD = (DBObjTableField *) NULL;
	DBObjTableField *toValueFLD = (DBObjTableField *) NULL;
	DBVLineIF	*lineIF = (DBVLineIF *)	 NULL;
	DBGridIF *gridIF;
	DBObjRecord *record, *layerRec, *tblRec;
	DBObjectLIST<DBObjTableField> *fields;

	widget = widget; callData = callData;

	gridIF = new DBGridIF (grdData);
	for (layerID = 0;layerID < gridIF->LayerNum ();++layerID)
		{
		layerRec = gridIF->Layer (layerID);
		if ((layerRec->Flags () & DBObjectFlagIdle) != DBObjectFlagIdle) ++layerNum;
		}
	if (layerNum < 1)
		{ CMmsgPrint (CMmsgAppError, "No Layer to Process in: %s %d",__FILE__,__LINE__); delete gridIF; return; }


	tblData  = new DBObjData ("",DBTypeTable);
	tblData->Document (DBDocGeoDomain,dbData->Document (DBDocGeoDomain));
	tblData->Document (DBDocSubject,grdData->Document (DBDocSubject));

	if (UIDataHeaderForm (tblData) == false) { delete gridIF; delete tblData; return; }
	table = tblData->Table (DBrNItems);

	lineIF = new DBVLineIF (dbData);

	table->AddField (lineIDFLD =		new DBObjTableField ("GHAASPointID",DBTableFieldInt,	"%8d",sizeof (DBInt)));
	table->AddField (layerIDFLD =		new DBObjTableField ("LayerID",		DBTableFieldInt,	"%4d",sizeof (DBShort)));
	table->AddField (layerNameFLD =	new DBObjTableField ("LayerName",	DBTableFieldString,"%s",DBStringLength));
	table->AddField (fromValueFLD =	new DBObjTableField (RGISLineFromNodeValue,DBTableFieldFloat,gridIF->ValueFormat (),sizeof (DBFloat4)));
	table->AddField (toValueFLD =		new DBObjTableField (RGISLineToNodeValue,DBTableFieldFloat,gridIF->ValueFormat (),sizeof (DBFloat4)));

	grdData->Flags (DBObjectFlagProcessed,DBSet);
	UIPauseDialogOpen ((char *) "Sampling Grid(s)");
	for (layerID = 0;layerID < gridIF->LayerNum ();++layerID)
		{
		layerRec = gridIF->Layer (layerID);
		if ((layerRec->Flags () & DBObjectFlagIdle) == DBObjectFlagIdle) continue;
		for (record = itemTable->First ();record != (DBObjRecord *) NULL;record = itemTable->Next ())
			{
			if (UIPause ((layerRec->RowID () * itemTable->ItemNum () + record->RowID ()) * 100 / (itemTable->ItemNum () * gridIF->LayerNum ()))) goto Stop;
			if ((record->Flags () & DBObjectFlagIdle) == DBObjectFlagIdle) continue;
			tblRec = table->Add (record->Name ());
			lineIDFLD->Int (tblRec,record->RowID () + 1);
			layerIDFLD->Int (tblRec,layerRec->RowID ());
			layerNameFLD->String (tblRec,layerRec->Name ());
			coord = lineIF->FromCoord (record);
			if (gridIF->Value (layerRec,coord,&realValue))
				fromValueFLD->Float (tblRec,realValue);
			coord = lineIF->ToCoord (record);
			if (gridIF->Value (layerRec,coord,&realValue))
				toValueFLD->Float (tblRec,realValue);
			}
		}
Stop:
	UIPauseDialogClose ();
	delete gridIF;
	delete lineIF;

	fields = new DBObjectLIST<DBObjTableField> ("Field List");
	fields->Add (new DBObjTableField (*lineIDFLD));
	fields->Add (new DBObjTableField (*layerIDFLD));
	table->ListSort (fields);
	workspace->CurrentData  (tblData);
	delete fields;
	}
Exemplo n.º 24
0
int _CMDnetErosion(DBObjData *netData, DBObjData *inData, DBObjData *weightData,
                   DBObjData *outData, DBFloat coeff, DBInt areaMult) {
    DBInt ret = DBSuccess, layerID, cellID, progress, maxProgress;
    DBFloat inValue, weight, outValue, *sumWeights;
    DBPosition pos;
    DBNetworkIF *netIF = new DBNetworkIF(netData);
    DBGridIF *inIF = new DBGridIF(inData);
    DBGridIF *outIF = new DBGridIF(outData);
    DBGridIF *weightIF = weightData != (DBObjData *) NULL ? new DBGridIF(weightData) : (DBGridIF *) NULL;
    DBObjRecord *inLayerRec, *outLayerRec, *weightLayerRec, *cellRec, *toCell;

    if ((sumWeights = (DBFloat *) calloc(netIF->CellNum(), sizeof(DBFloat))) == (DBFloat *) NULL) {
        CMmsgPrint(CMmsgSysError, "Memory allocation error in: %s %d", __FILE__, __LINE__);
        ret = DBFault;
        goto Stop;
    }

    layerID = 0;
    inLayerRec = inIF->Layer(layerID);

    outLayerRec = outIF->Layer(layerID);
    outIF->RenameLayer(outLayerRec, inLayerRec->Name());
    outValue = outIF->MissingValue(outLayerRec);
    for (pos.Row = 0; pos.Row < outIF->RowNum(); pos.Row++)
        for (pos.Col = 0; pos.Col < outIF->ColNum(); pos.Col++) outIF->Value(outLayerRec, pos, outValue);

    for (layerID = 1; layerID < inIF->LayerNum(); ++layerID) {
        inLayerRec = inIF->Layer(layerID);
        if ((outLayerRec = outIF->AddLayer(inLayerRec->Name())) == (DBObjRecord *) NULL) {
            ret = DBFault;
            goto Stop;
        }
        for (pos.Row = 0; pos.Row < outIF->RowNum(); pos.Row++)
            for (pos.Col = 0; pos.Col < outIF->ColNum(); pos.Col++) outIF->Value(outLayerRec, pos, outValue);
    }
    maxProgress = inIF->LayerNum() * netIF->CellNum();
    for (layerID = 0; layerID < inIF->LayerNum(); ++layerID) {
        inLayerRec = inIF->Layer(layerID);
        outLayerRec = outIF->Layer(layerID);
        if (weightIF != (DBGridIF *) NULL)
            weightLayerRec = weightIF->Layer(layerID % weightIF->LayerNum());
        for (cellID = 0; cellID < netIF->CellNum(); cellID++) {
            sumWeights[cellID] = 0.0;
            cellRec = netIF->Cell(cellID);
            if (inIF->Value(inLayerRec, netIF->Center(cellRec), &inValue) == false)
                outIF->Value(outLayerRec, netIF->CellPosition(cellRec), 0.0);
            else {
                if (weightIF != (DBGridIF *) NULL)
                    weight = weightIF->Value(weightLayerRec, netIF->Center(cellRec), &weight) == false ?
                             0.0 : weight * coeff;
                else weight = coeff;
                if (areaMult) weight = weight * netIF->CellArea(cellRec);
                sumWeights[cellID] = weight;
                outIF->Value(outLayerRec, netIF->CellPosition(cellRec), inValue * weight);
            }
        }

        for (cellID = netIF->CellNum() - 1; cellID >= 0; --cellID) {
            progress = layerID * netIF->CellNum() + (netIF->CellNum() - cellID);
            if (DBPause(progress * 100 / maxProgress)) goto Stop;
            cellRec = netIF->Cell(cellID);
            if ((toCell = netIF->ToCell(cellRec)) == (DBObjRecord *) NULL) continue;
            if (outIF->Value(outLayerRec, netIF->CellPosition(cellRec), &inValue) == false) continue;
            if (outIF->Value(outLayerRec, netIF->CellPosition(toCell), &outValue) == false) continue;

            sumWeights[toCell->RowID()] = sumWeights[toCell->RowID()] + weight;
            outIF->Value(outLayerRec, netIF->CellPosition(toCell), outValue + inValue);
        }
        outIF->RecalcStats(outLayerRec);
    }

    free(sumWeights);
    Stop:
    delete netIF;
    delete inIF;
    delete outIF;
    if (weightIF != (DBGridIF *) NULL) delete weightIF;
    return (ret);
}
Exemplo n.º 25
0
		DBInt Write (FILE *file,DBObjData *data)
			{
			char *dmRecord;
			DBInt layerID, docLen, dbType, intVal;
			DBFloat floatVal;
			DBPosition pos;
			DBObjRecord *layerRec;
			DBGridIF *gridIF = new DBGridIF (data);
			DMLayerHeader dmLayerHeader;

			dbType = gridIF->ValueType ();
			switch (dbType)
				{
				case DBTableFieldFloat: DataType (DMFloat);	break;
				case DBTableFieldInt:
					DataType (gridIF->ValueSize () > 1 ? DMInt : DMByte); 	break;
				}
			CellWidth (gridIF->CellWidth ());
			CellHeight (gridIF->CellHeight ());
			Extent (data->Extent ());
			LayerNum (gridIF->LayerNum ());
			RowNum (gridIF->RowNum ());
			ColNum (gridIF->ColNum ());
			dmRecord = (char *) calloc (RowNum () * ColNum (),DataType () != DMByte ? sizeof (int) : sizeof (char));
			if (dmRecord == (char *) NULL)
				{ CMmsgPrint (CMmsgSysError, "Memory Allocation Error in: %s %d",__FILE__,__LINE__); return (DBFault); }

			DMFileHeader::Write (file);
			for (layerID = 0;layerID < gridIF->LayerNum ();++layerID)
				{
				layerRec = gridIF->Layer (layerID);
				dmLayerHeader.Description (layerRec->Name ());
				dmLayerHeader.Write (file);
				}
			docLen = strlen (data->Document (DBDocComment));
			if (fwrite (&docLen,sizeof (int),1,file) != 1)
				{ CMmsgPrint (CMmsgSysError, "File Writing Error in: %s %d",__FILE__,__LINE__); return (DBFault); }
			if (docLen > 0)
				{
				if (fwrite (data->Document (DBDocComment),docLen,1,file) != 1)
					{ CMmsgPrint (CMmsgSysError, "File Writing Error in: %s %d",__FILE__,__LINE__); return (DBFault); }
				}
			for (layerID = 0;layerID < gridIF->LayerNum ();++layerID)
				{
				layerRec = gridIF->Layer (layerID);
				switch (data->Type ())
					{
					case DBTypeGridContinuous:
						layerRec = gridIF->Layer (layerID);
						if (dbType == DBTableFieldFloat)
							{
							for (pos.Row = 0;pos.Row < RowNum ();pos.Row++)
								for (pos.Col = 0;pos.Col < ColNum ();pos.Col++)
									if (gridIF->Value (layerRec,pos,&floatVal))
										((float *) dmRecord) [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = (float) floatVal;
									else
										((float *) dmRecord) [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = MissingValue ();
							}
						else
							{
							for (pos.Row = 0;pos.Row < RowNum ();pos.Row++)
								for (pos.Col = 0;pos.Col < ColNum ();pos.Col++)
									if (gridIF->Value (layerRec,pos,&intVal))
										{
										if (DataType () == DMInt)
											((int *) dmRecord) [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = (int) intVal;
										else
											dmRecord [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = intVal;
										}
									else
										{
										if (DataType () == DMInt)
											((int *) dmRecord) [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = (int) MissingValue ();
										else
											dmRecord [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = -99;
										}

							}
						break;
					case DBTypeGridDiscrete:
						for (pos.Row = 0;pos.Row < RowNum ();pos.Row++)
							for (pos.Col = 0;pos.Col < ColNum ();pos.Col++)
								{
								intVal = gridIF->GridValue (layerRec,pos);
								if (DataType () == DMInt)
									((int *) dmRecord) [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = intVal;
								else
									dmRecord [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = -99;

								}
						break;
					default:
						CMmsgPrint (CMmsgAppError, "Invalid Data Type in: %s %d",__FILE__,__LINE__);
						free (dmRecord);
						delete gridIF;
						return (DBFault);
					}
				if ((DBInt) fwrite (dmRecord,DataType () == DMByte ? sizeof (char) : sizeof (int),DataPointNum (),file) != DataPointNum ())
					{ CMmsgPrint (CMmsgSysError, "File Writing Error in: %s %d",__FILE__,__LINE__); return (DBFault); }
				}
			free (dmRecord);
			delete gridIF;
			return (DBSuccess);
			}
Exemplo n.º 26
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);
			}
Exemplo n.º 27
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);
	}
Exemplo n.º 28
0
UIAttribView::UIAttribView (DBObjData *data) : DBObject (data->Name (),sizeof (UIAttribView))

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

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

	switch (DataPTR->Type ())
		{
		case DBTypeVectorPoint:
		case DBTypeVectorLine:
		case DBTypeVectorPolygon:
		case DBTypeGridDiscrete:
			fields = ItemTable->Fields ();
			for (field = fields->First ();field != (DBObjTableField *) NULL;field = fields->Next ())
				if (DBTableFieldIsVisible (field) == true)	NewField (field->Name (),field->Format ());
			break;
		case DBTypeGridContinuous:
			{
			DBObjRecord *record;
			DBGridIF *gridIF = new DBGridIF (DataPTR);
			ItemTable = DataPTR->Table (DBrNLayers);
			for (record = ItemTable->First ();record != (DBObjRecord *) NULL;record = ItemTable->Next ())
				NewField (record->Name (),gridIF->ValueFormat ());
			delete gridIF;
			} break;
		case DBTypeNetwork:
			{
			DBObjTable *cellTable = DataPTR->Table (DBrNCells);

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

			fields =  cellTable->Fields ();
			for (field = fields->First ();field != (DBObjTableField *) NULL;field = fields->Next ())
				if (DBTableFieldIsVisible (field) == true)	NewField (field->Name (),field->Format ());
			} break;
		default:	break;
		}
	XtManageChild (mainForm);
	UILoop ();
	}
Exemplo n.º 29
0
void RGISAnalyseLineSSampleGridCBK (Widget widget, RGISWorkspace *workspace,XmAnyCallbackStruct *callData)

	{
	char *fText;
	int allowOk;
	static int sample;
	DBDataset *dataset = UIDataset ();
	DBObjData *dbData  = dataset->Data (), *grdData = dbData->LinkedData ();
	DBObjTable *itemTable = dbData->Table (DBrNItems);
	static Widget dShell = (Widget) NULL, mainForm;
	static Widget fromNameTextF, toNameTextF;
	XmString string;

	widget = widget;	workspace = workspace; callData = callData;
	_RGISAnLineSampleGridFields = itemTable->Fields ();
	if (dShell == (Widget) NULL)
		{
		Widget button;

		dShell = UIDialogForm ((char *) "Single Layer Grid Sampling",false);
		mainForm = UIDialogFormGetMainForm (dShell);

		string = XmStringCreate ((char *) "Select",UICharSetBold);
		button = XtVaCreateManagedWidget ("RGISAnalyseLineSSampleNameButton",xmPushButtonWidgetClass,mainForm,
								XmNtopAttachment,			XmATTACH_FORM,
								XmNtopOffset,				10,
								XmNrightAttachment,		XmATTACH_FORM,
								XmNrightOffset,			10,
								XmNmarginHeight,			5,
								XmNtraversalOn,			False,
								XmNlabelString,			string,
								XmNuserData,				grdData->Type () == DBTypeGridContinuous ? DBTableFieldIsNumeric : DBTableFieldIsCategory,
								NULL);
		XmStringFree (string);
		fromNameTextF = XtVaCreateManagedWidget ("RGISAnalyseLineSSampleNameTextF",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) _RGIAnalyseLineSSampleGridSSelectCBK,fromNameTextF);
		string = XmStringCreate ((char *) "From Field:",UICharSetBold);
		XtVaCreateManagedWidget ("RGISAnalyseLineSSampleNameLabel",xmLabelWidgetClass,mainForm,
								XmNtopAttachment,			XmATTACH_OPPOSITE_WIDGET,
								XmNtopWidget,				button,
								XmNleftAttachment,		XmATTACH_FORM,
								XmNleftOffset,				10,
								XmNrightAttachment,		XmATTACH_WIDGET,
								XmNrightWidget,			fromNameTextF,
								XmNrightOffset,			10,
								XmNbottomAttachment,		XmATTACH_OPPOSITE_WIDGET,
								XmNbottomWidget,			button,
								XmNlabelString,			string,
								NULL);
		XmStringFree (string);

		string = XmStringCreate ((char *) "Select",UICharSetBold);
		button = XtVaCreateManagedWidget ("RGISAnalyseLineSSampleNameButton",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,				grdData->Type () == DBTypeGridContinuous ? DBTableFieldIsNumeric : DBTableFieldIsCategory,
								NULL);
		XmStringFree (string);
		toNameTextF = XtVaCreateManagedWidget ("RGISAnalyseLineSSampleNameTextF",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) _RGIAnalyseLineSSampleGridSSelectCBK,toNameTextF);
		string = XmStringCreate ((char *) "To Field:",UICharSetBold);
		XtVaCreateManagedWidget ("RGISAnalyseLineSSampleNameLabel",xmLabelWidgetClass,mainForm,
								XmNtopAttachment,			XmATTACH_OPPOSITE_WIDGET,
								XmNtopWidget,				button,
								XmNleftAttachment,		XmATTACH_FORM,
								XmNleftOffset,				10,
								XmNrightAttachment,		XmATTACH_WIDGET,
								XmNrightWidget,			toNameTextF,
								XmNrightOffset,			10,
								XmNbottomAttachment,		XmATTACH_OPPOSITE_WIDGET,
								XmNbottomWidget,			button,
								XmNlabelString,			string,
								NULL);
		XmStringFree (string);
		XtAddCallback (UIDialogFormGetOkButton (dShell),XmNactivateCallback,(XtCallbackProc) UIAuxSetBooleanTrueCBK,&sample);
		}

	sample = false;
	UIDialogFormPopup (dShell);
	while (UILoop ())
		{
		allowOk = false;
		fText = XmTextFieldGetString (fromNameTextF);
		if (strlen (fText) > 0) allowOk = true;
		XtFree (fText);
		fText = XmTextFieldGetString (toNameTextF);
		if (strlen (fText) > 0) allowOk = true;
		XtFree (fText);
		XtSetSensitive (UIDialogFormGetOkButton (dShell),allowOk);
		}
	UIDialogFormPopdown (dShell);

	if (sample)
		{
		DBInt ret;
		DBFloat value;
		DBCoordinate coord;
		DBGridIF *gridIF = new DBGridIF (grdData);
		DBVLineIF *lineIF = new DBVLineIF (dbData);
		DBObjTableField *fromField;
		DBObjTableField *toField;
		DBObjRecord *record;

		fText = XmTextFieldGetString (fromNameTextF);
		if (strlen (fText) > 0)
			{
			if ((fromField = itemTable->Field (fText)) == (DBObjTableField *) NULL)
				itemTable->AddField (fromField = new DBObjTableField (fText,DBTableFieldFloat,"%10.3f",sizeof (DBFloat4)));
			}
		else	fromField = (DBObjTableField *) NULL;
		XtFree (fText);
		fText = XmTextFieldGetString (toNameTextF);
		if (strlen (fText) > 0)
			{
			if ((toField = itemTable->Field (fText)) == (DBObjTableField *) NULL)
				itemTable->AddField (toField = new DBObjTableField (fText,DBTableFieldFloat,"%10.3f",sizeof (DBFloat4)));
			}
		else	toField = (DBObjTableField *) NULL;
		XtFree (fText);

		UIPauseDialogOpen ((char *) "Sampling Grid");
		for (record = itemTable->First ();record != (DBObjRecord *) NULL;record = itemTable->Next ())
			{
			if (UIPause (record->RowID () * 100 / itemTable->ItemNum ())) goto Stop;
			if (fromField != (DBObjTableField *) NULL)
				{
				coord = lineIF->FromCoord (record);
				ret = gridIF->Value (coord,&value);
				if (fromField->Type () == DBTableFieldFloat)
					{
					if (ret)	fromField->Float (record,value);
					else		fromField->Float (record,fromField->FloatNoData ());
					}
				else
					{
					if (ret)	fromField->Int (record,(DBInt) value);
					else		fromField->Int (record,fromField->IntNoData ());
					}
				}
			if (toField != (DBObjTableField *) NULL)
				{
				coord = lineIF->ToCoord (record);
				ret = gridIF->Value (coord,&value);
				if (toField->Type () == DBTableFieldFloat)
					{
					if (ret)	toField->Float (record,value);
					else		toField->Float (record,toField->FloatNoData ());
					}
				else
					{
					if (ret)	toField->Int (record,(DBInt) value);
					else		toField->Int (record,toField->IntNoData ());
					}
				}
			}
Stop:
		UIPauseDialogClose ();
		delete lineIF;
		delete gridIF;
		}
	}
Exemplo n.º 30
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);
}