Exemple #1
0
        private void Functions_CollectionChanging(object sender, NotifyCollectionChangingEventArgs e)
        {
            if (!AutoOpen())
            {
                return;
            }

            if ((e.Action == NotifyCollectionChangeAction.Add || e.Action == NotifyCollectionChangeAction.Replace) &&
                e.Item is IRegularGridCoverage)
            {
                var grid = (IRegularGridCoverage)e.Item;

                var driverName = GdalHelper.GetDriverName(path);

                RegisterGdal();

                using (var gdalDriver = Gdal.GetDriverByName(driverName))
                {
                    var gdalType          = GdalHelper.GetGdalDataType(gdalDriver, grid.Components[0].ValueType);
                    var gdalvariableValue = GdalHelper.GetVariableForDataType(gdalType);// TODO: strange logic, use supported GDAL types here (as .NET types) instead
                    var type = gdalvariableValue.ValueType;

                    if (type != grid.Components[0].ValueType)
                    {
                        throw new InvalidOperationException(string.Format("Value type {0} is not supported by GDAL driver", grid.Components[0].ValueType));
                    }
                }
            }
        }
Exemple #2
0
        private static IEnumerable <IVariable> GetDataSetComponentVariables(Dataset gdalDataset)
        {
            IList <IVariable> components = new List <IVariable>();

            for (var i = 1; i <= gdalDataset.RasterCount; i++)
            {
                using (var band = gdalDataset.GetRasterBand(i))
                {
                    var dataType = band.DataType;
                    var componentVariableName = "Raster" + i;
                    var componentVariable     = GdalHelper.GetVariableForDataType(dataType);
                    componentVariable.Name = componentVariableName;
                    int    hasNoDataValue;
                    double noDataValue;
                    band.GetNoDataValue(out noDataValue, out hasNoDataValue);

                    //ToDo check this logic versus specs of hdr definition for bil files.
                    if (noDataValue < 0 && (dataType == DataType.GDT_UInt32 || dataType == DataType.GDT_UInt16))
                    {
                        noDataValue = Math.Abs(noDataValue);
                        log.DebugFormat("Nodata value changed from a negative to a positive value");
                    }

                    if (hasNoDataValue > 0)
                    {
                        componentVariable.NoDataValues = new[] { noDataValue };
                    }

                    componentVariable.FixedSize = gdalDataset.RasterXSize * gdalDataset.RasterYSize;

                    components.Add(componentVariable);
                }
            }

            return(components);
        }