Beispiel #1
0
        public float GridQuery(gView.Framework.Carto.IDisplay display, IPoint point, ISpatialReference sRef)
        {
            float floatNodata = (float)_nodata;

            TFWFile tfw = this.WorldFile as TFWFile;

            if (tfw == null)
            {
                return(floatNodata);
            }

            if (this.SpatialReference != null && sRef != null &&
                !sRef.Equals(this.SpatialReference))
            {
                point = GeometricTransformerFactory.Transform2D(point, sRef, this.SpatialReference) as IPoint;
            }
            if (point == null)
            {
                return(floatNodata);
            }

            // Punkt transformieren -> Bild
            vector2[] vecs = new vector2[1];
            vecs[0] = new vector2(point.X, point.Y);

            if (!tfw.ProjectInv(vecs))
            {
                return(floatNodata);
            }

            if (vecs[0].x < 0 || vecs[0].x >= _iWidth ||
                vecs[0].y < 0 || vecs[0].y >= _iHeight)
            {
                return(floatNodata);
            }

            unsafe
            {
                fixed(float *buf = new float[2])
                {
                    _gridQueryBand.ReadRaster((int)vecs[0].x, (int)vecs[0].y, 1, 1,
                                              (IntPtr)buf,
                                              1, 1, OSGeo_v1.GDAL.DataType.GDT_CFloat32, 4, 0);

                    if ((_hasNoDataVal != 0 && buf[0] == floatNodata) ||
                        (_useIgnoreValue && buf[0] == _ignoreValue))
                    {
                        return(floatNodata);
                    }

                    return(buf[0]);
                }
            }
        }
Beispiel #2
0
        public Task <ICursor> PointQuery(gView.Framework.Carto.IDisplay display, IPoint point, ISpatialReference sRef, IUserData userdata)
        {
            TFWFile tfw = this.WorldFile as TFWFile;

            if (tfw == null)
            {
                return(Task.FromResult <ICursor>(null));
            }

            if (this.SpatialReference != null && sRef != null &&
                !sRef.Equals(this.SpatialReference))
            {
                point = GeometricTransformerFactory.Transform2D(point, sRef, this.SpatialReference) as IPoint;
            }
            if (point == null)
            {
                return(Task.FromResult <ICursor>(null));;
            }

            // Punkt transformieren -> Bild
            vector2[] vecs = new vector2[1];
            vecs[0] = new vector2(point.X, point.Y);

            if (!tfw.ProjectInv(vecs))
            {
                return(Task.FromResult <ICursor>(null));;
            }

            if (vecs[0].x < 0 || vecs[0].x >= _iWidth ||
                vecs[0].y < 0 || vecs[0].y >= _iHeight)
            {
                return(Task.FromResult <ICursor>(null));
            }

            switch (_type)
            {
            case RasterType.image:
                return(Task.FromResult <ICursor>(QueryImage((int)Math.Floor(vecs[0].x), (int)Math.Floor(vecs[0].y))));

            case RasterType.grid:
                return(Task.FromResult <ICursor>(QueryGrid((int)Math.Floor(vecs[0].x), (int)Math.Floor(vecs[0].y))));
            }

            return(Task.FromResult <ICursor>(null));;
        }
Beispiel #3
0
        public RasterClass(IRasterDataset dataset, string filename, IPolygon polygon)
        {
            try
            {
                FileInfo fi = new FileInfo(filename);
                _title    = fi.Name;
                _filename = filename;
                _dataset  = dataset;

                OSGeo.GDAL.Gdal.AllRegister();
                _gDS = OSGeo.GDAL.Gdal.Open(fi.FullName, 0);
                if (_gDS == null && _gDS.RasterCount == 0)
                {
                    _valid = false;
                    return;
                }

                _iWidth  = _gDS.RasterXSize;
                _iHeight = _gDS.RasterYSize;

                switch (fi.Extension.ToLower())
                {
                case ".adf":
                case ".gsd":
                    _type = RasterType.grid;
                    break;
                    //case ".jp2":
                    //    _type = RasterType.wavelet;
                    //    break;
                }

                using (OSGeo.GDAL.Band band = _gDS.GetRasterBand(1))
                {
                    if (_gDS.RasterCount == 1)
                    {
                        if (band.DataType != OSGeo.GDAL.DataType.GDT_Byte)
                        {
                            _type = RasterType.grid;
                        }
                    }
                    band.GetMinimum(out _min, out _hasNoDataVal);
                    band.GetMaximum(out _max, out _hasNoDataVal);
                    band.GetNoDataValue(out _nodata, out _hasNoDataVal);
                }
                OSGeo.GDAL.Driver driver = _gDS.GetDriver();

                double[] tfw = new double[6];
                _gDS.GetGeoTransform(tfw);

                string tfwFilename = fi.FullName.Substring(0, fi.FullName.Length - fi.Extension.Length);
                switch (fi.Extension.ToLower())
                {
                case ".jpg":
                case ".jpeg":
                    tfwFilename += ".jgw";
                    break;

                case ".jp2":
                    tfwFilename += ".j2w";
                    break;

                case ".tif":
                case ".tiff":
                    tfwFilename += ".tfw";
                    break;

                case ".ecw":
                    tfwFilename += ".eww";
                    break;

                default:
                    break;
                }

                FileInfo tfwInfo = new FileInfo(tfwFilename);

                _tfw = new TFWFile(tfw[0], tfw[3], tfw[1], tfw[2], tfw[4], tfw[5]);
                if (tfwInfo.Exists)
                {
                    _tfw.Filename = tfwFilename;
                }

                if (_tfw.X == 0.0 && _tfw.Y == 0.0 &&
                    Math.Abs(_tfw.dx_X) == 1.0 && _tfw.dx_Y == 0.0 &&
                    Math.Abs(_tfw.dy_Y) == 1.0 && _tfw.dy_X == 0.0 && driver != null)
                {
                    if (tfwInfo.Exists)
                    {
                        _tfw = new TFWFile(tfwFilename);
                    }
                    else
                    {
                        _tfw.isValid = false;
                    }
                }
                else
                {
                    // Bei dem Driver schein es nicht Pixelmitte sein, oder ist das bei GDAL generell
                    //if (driver.ShortName.ToLower() == "jp2openjpeg")
                    {
                        _tfw.X += (_tfw.dx_X / 2.0D + _tfw.dx_Y / 2.0D);
                        _tfw.Y += (_tfw.dy_X / 2.0D + _tfw.dy_Y / 2.0D);
                    }
                }


                FileInfo fiPrj = new FileInfo(fi.FullName.Substring(0, fi.FullName.Length - fi.Extension.Length) + ".prj");
                if (fiPrj.Exists)
                {
                    StreamReader sr  = new StreamReader(fiPrj.FullName);
                    string       wkt = sr.ReadToEnd();
                    sr.Close();

                    _sRef = gView.Framework.Geometry.SpatialReference.FromWKT(wkt);
                }
                else
                {
                    fiPrj = new FileInfo(fi.FullName.Substring(0, fi.FullName.Length - fi.Extension.Length) + ".wkt");
                    if (fiPrj.Exists)
                    {
                        StreamReader sr  = new StreamReader(fiPrj.FullName);
                        string       wkt = sr.ReadToEnd();
                        sr.Close();

                        _sRef = gView.Framework.Geometry.SpatialReference.FromWKT(wkt);
                    }
                }
                if (polygon != null)
                {
                    _polygon = polygon;
                }
                else
                {
                    calcPolygon();
                }
            }
            catch (Exception ex)
            {
                string errMsg = ex.Message;
                _valid = false;
            }
        }
Beispiel #4
0
        public void BeginPaint(gView.Framework.Carto.IDisplay display, ICancelTracker cancelTracker)
        {
            EndPaint(cancelTracker);
            try
            {
                if (!(_polygon is ITopologicalOperation))
                {
                    return;
                }

                TFWFile tfw = this.WorldFile as TFWFile;
                if (tfw == null)
                {
                    return;
                }

                IEnvelope dispEnvelope = display.DisplayTransformation.TransformedBounds(display); //display.Envelope;
                if (display.GeometricTransformer != null)
                {
                    dispEnvelope = (IEnvelope)((IGeometry)display.GeometricTransformer.InvTransform2D(dispEnvelope)).Envelope;
                }

                IGeometry clipped;
                ((ITopologicalOperation)_polygon).Clip(dispEnvelope, out clipped);
                if (!(clipped is IPolygon))
                {
                    return;
                }

                IPolygon cPolygon = (IPolygon)clipped;

                // geclipptes Polygon transformieren -> Bild
                vector2[] vecs = new vector2[cPolygon[0].PointCount];
                for (int i = 0; i < cPolygon[0].PointCount; i++)
                {
                    vecs[i] = new vector2(cPolygon[0][i].X, cPolygon[0][i].Y);
                }
                if (!tfw.ProjectInv(vecs))
                {
                    return;
                }
                IEnvelope picEnv = vector2.IntegerEnvelope(vecs);
                picEnv.minx = Math.Max(0, picEnv.minx);
                picEnv.miny = Math.Max(0, picEnv.miny);
                picEnv.maxx = Math.Min(picEnv.maxx, _iWidth);
                picEnv.maxy = Math.Min(picEnv.maxy, _iHeight);

                // Ecken zurücktransformieren -> Welt
                vecs    = new vector2[3];
                vecs[0] = new vector2(picEnv.minx, picEnv.miny);
                vecs[1] = new vector2(picEnv.maxx, picEnv.miny);
                vecs[2] = new vector2(picEnv.minx, picEnv.maxy);
                tfw.Project(vecs);
                _p1 = new gView.Framework.Geometry.Point(vecs[0].x, vecs[0].y);
                _p2 = new gView.Framework.Geometry.Point(vecs[1].x, vecs[1].y);
                _p3 = new gView.Framework.Geometry.Point(vecs[2].x, vecs[2].y);

                double pix = display.mapScale / (display.dpi / 0.0254);  // [m]
                double c1  = Math.Sqrt(_tfw.dx_X * _tfw.dx_X + _tfw.dx_Y * _tfw.dx_Y);
                double c2  = Math.Sqrt(_tfw.dy_Y * _tfw.dy_Y + _tfw.dy_X * _tfw.dy_X);
                double mag = Math.Min(c1, c2) / pix;

                if (mag > 1.0)
                {
                    mag = 1.0;
                }

                int x       = (int)(picEnv.minx);
                int y       = (int)(picEnv.miny);
                int wWidth  = (int)(picEnv.Width);
                int wHeight = (int)(picEnv.Height);

                //if (wWidth + x > _iWidth) wWidth = _iWidth - x;
                //if (wHeight + y > _iHeight) wHeight = _iHeight - y;

                int iWidth  = (int)(wWidth * mag);
                int iHeight = (int)(wHeight * mag);

                switch (_type)
                {
                case RasterType.image:
                    PaintImage(x, y, wWidth, wHeight, iWidth, iHeight, cancelTracker);
                    break;

                case RasterType.wavelet:
                    PaintWavelet(x, y, wWidth, wHeight, iWidth, iHeight, cancelTracker);
                    break;

                case RasterType.grid:
                    if (_renderRawGridValues)
                    {
                        PaintGrid(x, y, wWidth, wHeight, iWidth, iHeight);
                    }
                    else
                    {
                        PaintHillShade(x, y, wWidth, wHeight, iWidth, iHeight, mag, cancelTracker);
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                string errMsg = ex.Message;
                EndPaint(cancelTracker);
            }
            finally
            {
            }
        }