示例#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]);
                }
            }
        }
示例#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));;
        }
示例#3
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
            {
            }
        }