Пример #1
0
 public void Dispose()
 {
     if (Image != null)
     {
         Image.Dispose();
         Image = null;
     }
 }
Пример #2
0
 public void Dispose()
 {
     if (Bitmap != null)
     {
         Bitmap.Dispose();
         Bitmap = null;
     }
     Envelope         = null;
     SpatialReference = null;
 }
Пример #3
0
 public void Dispose()
 {
     if (_canvas != null)
     {
         _canvas.Dispose();
         _canvas = null;
     }
     if (_bitmap != null)
     {
         _bitmap.Dispose();
         _bitmap = null;
     }
     _gridArrayPolygons = null;
 }
Пример #4
0
        public void DrawOverlay(IGraphicsContainer container, bool clearOld)
        {
            if (RenderOverlayImage == null || _canvas != null)
            {
                return;
            }

            if (container == null)
            {
                ClearOverlay();
            }

            GraphicsEngine.Abstraction.IBitmap bm = null;
            try
            {
                bm = GraphicsEngine.Current.Engine.CreateBitmap(iWidth, iHeight);
                bm.MakeTransparent();

                _canvas = bm.CreateCanvas();
                foreach (IGraphicElement element in container.Elements)
                {
                    element.Draw(this);
                }

                RenderOverlayImage(bm, clearOld);
            }
            catch
            {
            }
            finally
            {
                if (_canvas != null)
                {
                    _canvas.Dispose();
                }

                _canvas = null;
                if (bm != null)
                {
                    bm.Dispose();
                }
            }
        }
Пример #5
0
        public GraphicsEngine.Abstraction.IBitmap Merge()
        {
            GraphicsEngine.Abstraction.ICanvas gr  = null;
            GraphicsEngine.Abstraction.IBitmap ret = null;
            try
            {
                foreach (GeorefBitmap geoBmp in _picList)
                {
                    if (geoBmp == null || geoBmp.Bitmap == null)
                    {
                        continue;
                    }

                    if (gr == null)
                    {
                        ret = geoBmp.Bitmap;
                        gr  = geoBmp.Bitmap.CreateCanvas();
                    }
                    else
                    {
                        gr.DrawBitmap(geoBmp.Bitmap,
                                      new GraphicsEngine.CanvasRectangle(0, 0, ret.Width, ret.Height),
                                      new GraphicsEngine.CanvasRectangle(0, 0, geoBmp.Bitmap.Width, geoBmp.Bitmap.Height));
                        geoBmp.Dispose();
                    }
                }

                this.Clear();
                return(ret);
            }
            catch
            {
                return(ret);
            }
            finally
            {
                if (gr != null)
                {
                    gr.Dispose();
                }
            }
        }
Пример #6
0
        private void SetBounds(GraphicsEngine.Abstraction.IBitmap bitmap)
        {
            if (bitmap != null)
            {
                _iWidth  = bitmap.Width;
                _iHeight = bitmap.Height;
            }
            _polygon = new Polygon();
            Ring ring = new Ring();

            gView.Framework.Geometry.Point p1 = new gView.Framework.Geometry.Point(
                _tfw.X - _tfw.dx_X / 2.0 - _tfw.dy_X / 2.0,
                _tfw.Y - _tfw.dx_Y / 2.0 - _tfw.dy_Y / 2.0);

            ring.AddPoint(p1);
            ring.AddPoint(new gView.Framework.Geometry.Point(p1.X + _tfw.dx_X * _iWidth, p1.Y + _tfw.dx_Y * _iWidth));
            ring.AddPoint(new gView.Framework.Geometry.Point(p1.X + _tfw.dx_X * _iWidth + _tfw.dy_X * _iHeight, p1.Y + _tfw.dx_Y * _iWidth + _tfw.dy_Y * _iHeight));
            ring.AddPoint(new gView.Framework.Geometry.Point(p1.X + _tfw.dy_X * _iHeight, p1.Y + _tfw.dy_Y * _iHeight));
            _polygon.AddRing(ring);
        }
Пример #7
0
        public void MakeTransparent(GraphicsEngine.ArgbColor transColor)
        {
            if (Bitmap == null)
            {
                return;
            }

            try
            {
                var b = GraphicsEngine.Current.Engine.CreateBitmap(Bitmap.Width, Bitmap.Height, GraphicsEngine.PixelFormat.Rgba32);
                using (var g = b.CreateCanvas())
                {
                    g.DrawBitmap(Bitmap, new GraphicsEngine.CanvasPoint(0, 0));
                }
                b.MakeTransparent(transColor);
                Bitmap.Dispose();
                Bitmap = b;
            }
            catch { }
        }
Пример #8
0
        public void Init(IDisplay display, bool directDraw)
        {
            try
            {
                if (display == null)
                {
                    return;
                }
                //if (_bm != null && (_bm.Width != display.iWidth || _bm.Height != display.iHeight))
                {
                    Dispose();
                }

                if (_bitmap == null)
                {
                    _bitmap = GraphicsEngine.Current.Engine.CreateBitmap(display.iWidth, display.iHeight, GraphicsEngine.PixelFormat.Rgba32);
                }

                _canvas = _bitmap.CreateCanvas();

                //using (var brush = GraphicsEngine.Current.Engine.CreateSolidBrush(GraphicsEngine.ArgbColor.Transparent))
                //{
                //    _canvas.FillRectangle(brush, new GraphicsEngine.CanvasRectangle(0, 0, _bitmap.Width, _bitmap.Height));
                //}
                _bitmap.MakeTransparent();

                _back       = _bitmap.GetPixel(0, 0);
                _first      = true;
                _directDraw = directDraw;
                //_bm.MakeTransparent(Color.White);

                _gridArrayPolygons = new GridArray <List <IAnnotationPolygonCollision> >(
                    new Envelope(0.0, 0.0, display.iWidth, display.iHeight),
                    new int[] { 50, 25, 18, 10, 5, 2 },
                    new int[] { 50, 25, 18, 10, 5, 2 });
            }
            catch
            {
                Dispose();
            }
        }
Пример #9
0
        private void StreamImage(ref MemoryStream stream, GraphicsEngine.Abstraction.IBitmap bitmap)
        {
            try
            {
                if (bitmap == null)
                {
                    return;
                }

                if (stream != null)
                {
                    stream.Dispose();
                }

                stream = new MemoryStream();
                bitmap.Save(stream, GraphicsEngine.ImageFormat.Png);
            }
            catch (Exception)
            {
            }
        }
Пример #10
0
 public GeorefBitmap(GraphicsEngine.Abstraction.IBitmap bitmap)
 {
     Bitmap = bitmap;
 }
Пример #11
0
        async private Task Render(IFeatureLayer layer)
        {
            IFeatureRenderer clonedFeatureRenderer = null;
            ILabelRenderer   clonedLabelRenderer   = null;

            GraphicsEngine.Abstraction.IBitmap compositionModeCopyBitmap = null;
            GraphicsEngine.Abstraction.ICanvas compositionModeCopyCanvas = null, originalCanvas = null;

            try
            {
                _map.FireOnUserInterface(true);
                if ((
                        layer.FeatureRenderer == null ||
                        layer.FeatureRenderer.HasEffect(layer, _map) == false)
                    &&
                    (
                        layer.LabelRenderer == null ||
                        _useLabelRenderer == false
                    ))
                {
                    return;
                }

                IFeatureClass fClass = layer.FeatureClass;
                if (fClass == null)
                {
                    return;
                }

                //IDataset dataset = (IDataset)_map[layer];
                //if (dataset == null) return;

                //if (!(dataset is IFeatureDataset)) return;

                IGeometry filterGeom = _map.Display.DisplayTransformation.TransformedBounds(_map.Display); //_map.Display.Envelope;

                if (_map.Display.GeometricTransformer != null)
                {
                    filterGeom = MapHelper.Project(fClass, _map.Display);
                }

                gView.Framework.Data.SpatialFilter filter = new gView.Framework.Data.SpatialFilter();
                filter.DatasetCachingContext = _datasetCachingContext;
                filter.Geometry = filterGeom;
                filter.AddField(fClass.ShapeFieldName);
                //filter.FuzzyQuery = true;
                filter.SpatialRelation = spatialRelation.SpatialRelationMapEnvelopeIntersects;
                filter.MapScale        = _map.Display.mapScale;
                filter.CancelTracker   = _cancelTracker;

                if (layer.FilterQuery != null)
                {
                    filter.WhereClause = layer.FilterQuery.WhereClause;
                    if (layer.FilterQuery is IBufferQueryFilter)
                    {
                        ISpatialFilter sFilter = await BufferQueryFilter.ConvertToSpatialFilter(layer.FilterQuery as IBufferQueryFilter);

                        if (sFilter == null)
                        {
                            return;
                        }
                        filter.SpatialRelation = spatialRelation.SpatialRelationIntersects;
                        filter.Geometry        = sFilter.Geometry;
                    }
                    if (layer.FilterQuery is ISpatialFilter)
                    {
                        //filter.FuzzyQuery = ((ISpatialFilter)layer.FilterQuery).FuzzyQuery;
                        filter.SpatialRelation = ((ISpatialFilter)layer.FilterQuery).SpatialRelation;
                        filter.Geometry        = ((ISpatialFilter)layer.FilterQuery).Geometry;
                    }
                }

                // Erst nach dem Clonen anwenden!!!
                //if (layer.FeatureRenderer != null && layer.FeatureRenderer.HasEffect(layer, _map))
                //{
                //    layer.FeatureRenderer.PrepareQueryFilter(layer, filter);
                //}
                //if (layer.LabelRenderer != null && _useLabelRenderer)
                //{
                //    layer.LabelRenderer.PrepareQueryFilter(_map.Display, layer, filter);
                //}

                IDisplay display  = _map;
                double   refScale = display.refScale;

                #region Layer Clonen

                IFeatureRenderer renderer      = null;
                ILabelRenderer   labelRenderer = null;

                lock (lockThis)
                {
                    // Beim Clonen sprerren...
                    // Da sonst bei der Servicemap bei gleichzeitigen Requests
                    // Exception "Objekt wird bereits an anderer Stelle verwendet" auftreten kann!
                    if (layer.FeatureRenderer != null && layer.FeatureRenderer.HasEffect(layer, _map))
                    {
                        if (layer.RequiresFeatureRendererClone(display))
                        {
                            renderer = clonedFeatureRenderer = (IFeatureRenderer)layer.FeatureRenderer.Clone(
                                new CloneOptions(display,
                                                 layer.UseWithRefScale(display),
                                                 maxRefScaleFactor: layer.MaxRefScaleFactor));
                        }
                        else
                        {
                            renderer = layer.FeatureRenderer;
                        }
                    }
                    if (layer.LabelRenderer != null && _useLabelRenderer)
                    {
                        if (layer.RequiresLabelRendererClone(display))
                        {
                            labelRenderer = clonedLabelRenderer =
                                (ILabelRenderer)layer.LabelRenderer.Clone(new CloneOptions(display,
                                                                                           layer.UseLabelsWithRefScale(display),
                                                                                           maxLabelRefscaleFactor: layer.MaxLabelRefScaleFactor));
                        }
                        else  // Clone with null => simple clone
                        {
                            //display.refScale = 0;
                            labelRenderer = clonedLabelRenderer = (ILabelRenderer)layer.LabelRenderer.Clone(null);
                            //display.refScale = refScale;
                        }
                    }
                }

                #endregion

                #region Prepare filter

                // Prepare erst auf geclonte renderer anwenden!! (Threadsafe)
                if (renderer != null && renderer.HasEffect(layer, _map))
                {
                    renderer.PrepareQueryFilter(layer, filter);
                }
                if (labelRenderer != null && _useLabelRenderer)
                {
                    labelRenderer.PrepareQueryFilter(_map.Display, layer, filter);
                }

                #endregion

                using (IFeatureCursor fCursor = await fClass.GetFeatures(MapHelper.MapQueryFilter(filter)))
                {
                    _map.FireOnUserInterface(false);

                    if (fCursor != null)
                    {
                        IFeature feature;

                        if (renderer != null)
                        {
                            renderer.StartDrawing(_map);

                            bool useCompostionModeCopy = layer is IFeatureLayerComposition &&
                                                         ((IFeatureLayerComposition)layer).CompositionMode == FeatureLayerCompositionMode.Copy;

                            if (useCompostionModeCopy)
                            {
                                originalCanvas            = _map.Display.Canvas;
                                compositionModeCopyBitmap = GraphicsEngine.Current.Engine.CreateBitmap(_map.Display.Bitmap.Width, _map.Display.Bitmap.Height, GraphicsEngine.PixelFormat.Rgba32);
                                compositionModeCopyCanvas = compositionModeCopyBitmap.CreateCanvas();

                                compositionModeCopyBitmap.MakeTransparent();
                                compositionModeCopyBitmap.SetResolution(_map.Display.Bitmap.DpiX,
                                                                        _map.Display.Bitmap.DpiY);

                                ((Display)_map.Display).Canvas = compositionModeCopyCanvas;
                            }

                            while ((feature = await fCursor.NextFeature()) != null)
                            {
                                if (_cancelTracker != null)
                                {
                                    if (!_cancelTracker.Continue)
                                    {
                                        break;
                                    }
                                }

                                renderer.Draw(_map, feature);

                                if (labelRenderer != null)
                                {
                                    labelRenderer.Draw(_map, feature);
                                }

                                _counter.Counter++;

                                if (_isServiceMap == false)
                                {
                                    if (_counter.Counter % 100 == 0)
                                    {
                                        _map.FireRefreshMapView();
                                    }
                                }
                            }
                        }
                        else if (labelRenderer != null && _cancelTracker.Continue)
                        {
                            while ((feature = await fCursor.NextFeature()) != null)
                            {
                                if (_cancelTracker != null)
                                {
                                    if (!_cancelTracker.Continue)
                                    {
                                        break;
                                    }
                                }

                                labelRenderer.Draw(_map, feature);
                                _counter.Counter++;
                            }
                        }

                        if (labelRenderer != null)
                        {
                            labelRenderer.Release();
                        }

                        if (renderer != null)
                        {
                            renderer.FinishDrawing(_map, _cancelTracker);
                        }

                        if (compositionModeCopyCanvas != null && compositionModeCopyBitmap != null)
                        {
                            originalCanvas.DrawBitmap(compositionModeCopyBitmap,
                                                      new GraphicsEngine.CanvasRectangle(0, 0, compositionModeCopyBitmap.Width, compositionModeCopyBitmap.Height),
                                                      new GraphicsEngine.CanvasRectangle(0, 0, compositionModeCopyBitmap.Width, compositionModeCopyBitmap.Height),
                                                      opacity: (float)Math.Min(1, (100f - ((IFeatureLayerComposition)layer).CompositionModeCopyTransparency) / 100));
                        }
                    }
                    else
                    {
                        if (fClass is IDebugging && ((IDebugging)fClass).LastException != null)
                        {
                            throw ((IDebugging)fClass).LastException;
                        }

                        throw new Exception("Can't query feature class. Unknown error");
                    }
                }
            }
            catch (Exception ex)
            {
                if (_map is IServiceMap && ((IServiceMap)_map).MapServer != null)
                {
                    await((IServiceMap)_map).MapServer.LogAsync(
                        ((IServiceMap)_map).Name,
                        "RenderFeatureLayer: " + ((layer != null) ? layer.Title : String.Empty),
                        loggingMethod.error,
                        ex.Message + "\n" + ex.Source + "\n" + ex.StackTrace);
                }
                if (_map != null)
                {
                    _map.AddRequestException(new Exception("RenderFeatureLayerThread: " + ((layer != null) ? layer.Title : String.Empty) + "\n" + ex.Message, ex));
                }
            }
            finally
            {
                if (clonedFeatureRenderer != null)
                {
                    clonedFeatureRenderer.Release();
                }

                if (clonedLabelRenderer != null)
                {
                    clonedLabelRenderer.Release();
                }

                if (originalCanvas != null)
                {
                    ((Display)_map.Display).Canvas = originalCanvas;
                }

                if (compositionModeCopyCanvas != null)
                {
                    compositionModeCopyCanvas.Dispose();
                    compositionModeCopyCanvas = null;
                }

                if (compositionModeCopyBitmap != null)
                {
                    compositionModeCopyBitmap.Dispose();
                    compositionModeCopyBitmap = null;
                }

                _map.FireOnUserInterface(false);
            }
        }
Пример #12
0
        // Thread
        async public Task Render()
        {
            GraphicsEngine.Abstraction.IBitmap _filteredBitmap = null;

            try
            {
                if (_layer == null || _map == null || _cancelTracker == null)
                {
                    return;
                }

                if (_layer.RasterClass.Polygon == null)
                {
                    return;
                }

                IEnvelope env = _layer.RasterClass.Polygon.Envelope;
                double    minx = env.minx, miny = env.miny, maxx = env.maxx, maxy = env.maxy;

                _map.World2Image(ref minx, ref miny);
                _map.World2Image(ref maxx, ref maxy);

                int iWidth = 0, iHeight = 0;
                int min_x = Math.Max(0, (int)Math.Min(minx, maxx) - 1);
                int min_y = Math.Max(0, (int)Math.Min(miny, maxy) - 1);
                int max_x = Math.Min(iWidth = _map.iWidth, (int)Math.Max(minx, maxx) + 1);
                int max_y = Math.Min(iHeight = _map.iHeight, (int)Math.Max(miny, maxy) + 1);


                using (var paintContext = await _layer.RasterClass.BeginPaint(_map.Display, _cancelTracker))
                {
                    if (_filter != FilterImplementations.Default)
                    {
                        _filteredBitmap = BaseFilter.ApplyFilter(paintContext.Bitmap, _filter);
                    }

                    if (paintContext.Bitmap == null && _filteredBitmap == null)
                    {
                        return;
                    }

                    //System.Windows.Forms.MessageBox.Show("begin");

                    double W    = (_map.Envelope.maxx - _map.Envelope.minx);
                    double H    = (_map.Envelope.maxy - _map.Envelope.miny);
                    double MinX = _map.Envelope.minx;
                    double MinY = _map.Envelope.miny;

                    //_lastRasterLayer = _layer;

                    var canvas = _map.Display.Canvas;
                    if (canvas == null)
                    {
                        return;
                    }

                    canvas.InterpolationMode = (GraphicsEngine.InterpolationMode)_interpolMethod;

                    // Transformation berechnen
                    GraphicsEngine.CanvasRectangleF rect;
                    switch (canvas.InterpolationMode)
                    {
                    case GraphicsEngine.InterpolationMode.Bilinear:
                    case GraphicsEngine.InterpolationMode.Bicubic:
                        rect = new GraphicsEngine.CanvasRectangleF(0, 0, paintContext.Bitmap.Width - 1f, paintContext.Bitmap.Height - 1f);
                        break;

                    case GraphicsEngine.InterpolationMode.NearestNeighbor:
                        rect = new GraphicsEngine.CanvasRectangleF(-0.5f, -0.5f, paintContext.Bitmap.Width, paintContext.Bitmap.Height);
                        //rect = new GraphicsEngine.CanvasRectangleF(0f, 0f, _layer.RasterClass.Bitmap.Width, _layer.RasterClass.Bitmap.Height);
                        break;

                    default:
                        rect = new GraphicsEngine.CanvasRectangleF(0, 0, paintContext.Bitmap.Width, paintContext.Bitmap.Height);
                        break;
                    }

                    var points = new GraphicsEngine.CanvasPointF[3];

                    if (_layer.RasterClass is IRasterClass2)
                    {
                        IPoint p1 = ((IRasterClass2)_layer.RasterClass).PicPoint1;
                        IPoint p2 = ((IRasterClass2)_layer.RasterClass).PicPoint2;
                        IPoint p3 = ((IRasterClass2)_layer.RasterClass).PicPoint3;
                        if (_map.Display.GeometricTransformer != null)
                        {
                            p1 = (IPoint)_map.Display.GeometricTransformer.Transform2D(p1);
                            p2 = (IPoint)_map.Display.GeometricTransformer.Transform2D(p2);
                            p3 = (IPoint)_map.Display.GeometricTransformer.Transform2D(p3);
                        }

                        double X = p1.X, Y = p1.Y;
                        _map.Display.World2Image(ref X, ref Y);
                        points[0] = new GraphicsEngine.CanvasPointF(ToPixelFloat(X), ToPixelFloat(Y));

                        X = p2.X; Y = p2.Y;
                        _map.Display.World2Image(ref X, ref Y);
                        points[1] = new GraphicsEngine.CanvasPointF(ToPixelFloat(X), ToPixelFloat(Y));

                        X = p3.X; Y = p3.Y;
                        _map.Display.World2Image(ref X, ref Y);
                        points[2] = new GraphicsEngine.CanvasPointF(ToPixelFloat(X), ToPixelFloat(Y));

                        RoundGraphicPixelPoints(points);
                    }
                    else
                    {
                        double X1 = _layer.RasterClass.oX - _layer.RasterClass.dx1 / 2.0 - _layer.RasterClass.dy1 / 2.0;
                        double Y1 = _layer.RasterClass.oY - _layer.RasterClass.dx2 / 2.0 - _layer.RasterClass.dy2 / 2.0;
                        double X  = X1;
                        double Y  = Y1;
                        if (_map.Display.GeometricTransformer != null)
                        {
                            IPoint p = (IPoint)_map.Display.GeometricTransformer.Transform2D(new Point(X, Y));
                            X = p.X; Y = p.Y;
                        }

                        _map.Display.World2Image(ref X, ref Y);
                        points[0] = new GraphicsEngine.CanvasPointF(ToPixelFloat(X), ToPixelFloat(Y));
                        X         = X1 + (paintContext.Bitmap.Width) * _layer.RasterClass.dx1;
                        Y         = Y1 + (paintContext.Bitmap.Width) * _layer.RasterClass.dx2;
                        if (_map.Display.GeometricTransformer != null)
                        {
                            IPoint p = (IPoint)_map.Display.GeometricTransformer.Transform2D(new Point(X, Y));
                            X = p.X; Y = p.Y;
                        }

                        _map.Display.World2Image(ref X, ref Y);
                        points[1] = new GraphicsEngine.CanvasPointF(ToPixelFloat(X), ToPixelFloat(Y));
                        X         = X1 + (paintContext.Bitmap.Height) * _layer.RasterClass.dy1;
                        Y         = Y1 + (paintContext.Bitmap.Height) * _layer.RasterClass.dy2;
                        if (_map.Display.GeometricTransformer != null)
                        {
                            IPoint p = (IPoint)_map.Display.GeometricTransformer.Transform2D(new Point(X, Y));
                            X = p.X; Y = p.Y;
                        }

                        _map.Display.World2Image(ref X, ref Y);
                        points[2] = new GraphicsEngine.CanvasPointF(ToPixelFloat(X), ToPixelFloat(Y));
                    }

                    if (_transColor.ToArgb() != System.Drawing.Color.Transparent.ToArgb())
                    {
                        try
                        {
                            // kann OutOfMemoryException auslösen...
                            paintContext.Bitmap.MakeTransparent(_transColor);
                        }
                        catch (Exception ex)
                        {
                            if (_map is IServiceMap && ((IServiceMap)_map).MapServer != null)
                            {
                                await((IServiceMap)_map).MapServer.LogAsync(
                                    ((IServiceMap)_map).Name,
                                    "RenderRasterLayerThread: " + ((_layer != null) ? _layer.Title : String.Empty),
                                    loggingMethod.error,
                                    ex.Message + "\n" + ex.Source + "\n" + ex.StackTrace);
                            }
                            if (_map != null)
                            {
                                if (_map != null)
                                {
                                    _map.AddRequestException(new Exception("RenderRasterLayerThread: " + ((_layer != null) ? _layer.Title : String.Empty) + "\n" + ex.Message, ex));
                                }
                            }
                        }
                    }

                    //var comQual = gr.CompositingQuality;
                    //gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                    float opaque = 1.0f - _transparency;

                    canvas.DrawBitmap(_filteredBitmap ?? paintContext.Bitmap,
                                      points,
                                      rect,
                                      opacity: opaque);

                    _map.FireRefreshMapView();
                }
            }
            catch (Exception ex)
            {
                if (_map is IServiceMap && ((IServiceMap)_map).MapServer != null)
                {
                    await((IServiceMap)_map).MapServer.LogAsync(
                        ((IServiceMap)_map).Name,
                        "RenderRasterLayerThread:" + ((_layer != null) ? _layer.Title : String.Empty), loggingMethod.error,
                        ex.Message + "\n" + ex.Source + "\n" + ex.StackTrace);
                }
                if (_map != null)
                {
                    if (_map != null)
                    {
                        _map.AddRequestException(new Exception("RenderRasterLayerThread: " + ((_layer != null) ? _layer.Title : String.Empty) + "\n" + ex.Message, ex));
                    }
                }
            }
            finally
            {
                if (_filteredBitmap != null)
                {
                    _filteredBitmap.Dispose();
                }
            }
        }
Пример #13
0
        public bool Create(GraphicsEngine.Abstraction.IBitmap bitmap, int a, int y)
        {
            double dpm = _dpi / 0.0256;
            double pix = _scale / dpm;
            double bl  = pix * (200 * (_dpi / 96)) / 5.0;
            float  fac = (float)_dpi / 96;

            if (bl > 1000000)
            {
                bl = Math.Round((int)(bl / 100000) * 100000.0, 0);
            }
            else if (bl > 100000)
            {
                bl = Math.Round((int)(bl / 10000) * 10000.0, 0);
            }
            else if (bl > 10000)
            {
                bl = Math.Round((int)(bl / 5000) * 5000.0, 0);
            }
            else if (bl > 1000)
            {
                bl = Math.Round((int)(bl / 500) * 500.0, 0);
            }
            else if (bl > 100)
            {
                bl = Math.Round((int)(bl / 100) * 100.0, 0);
            }
            else if (bl > 10)
            {
                bl = Math.Round((int)(bl / 10) * 10.0, 0);
            }

            int bm_bl = (int)(bl / pix);

            using (var canvas = bitmap.CreateCanvas())
                using (var brush = GraphicsEngine.Current.Engine.CreateSolidBrush(GraphicsEngine.ArgbColor.FromArgb(155, 149, 149)))
                    using (var brush2 = GraphicsEngine.Current.Engine.CreateSolidBrush(GraphicsEngine.ArgbColor.White))
                        using (var brush3 = GraphicsEngine.Current.Engine.CreateSolidBrush(GraphicsEngine.ArgbColor.White))
                            using (var pen = GraphicsEngine.Current.Engine.CreatePen(GraphicsEngine.ArgbColor.Black, 1f))
                                using (var font = GraphicsEngine.Current.Engine.CreateFont("Verdana", 7 * fac, GraphicsEngine.FontStyle.Bold))
                                {
                                    int dist = (int)Math.Round(bl * 5, 0);

                                    // Hintergrund und Rahmen zeichnen
                                    canvas.FillRectangle(brush, new GraphicsEngine.CanvasRectangleF(a + 0, 15 * fac + y, bm_bl, 5 * fac));
                                    canvas.FillRectangle(brush, new GraphicsEngine.CanvasRectangleF(a + 2 * bm_bl, 15 * fac + y, bm_bl, 5 * fac));
                                    canvas.FillRectangle(brush, new GraphicsEngine.CanvasRectangleF(a + 4 * bm_bl, 15 * fac + y, bm_bl, 5 * fac));

                                    canvas.FillRectangle(brush2, new GraphicsEngine.CanvasRectangleF(a + 1 * bm_bl, 15 * fac + y, bm_bl, 5 * fac));
                                    canvas.FillRectangle(brush2, new GraphicsEngine.CanvasRectangleF(a + 3 * bm_bl, 15 * fac + y, bm_bl, 5 * fac));

                                    canvas.DrawRectangle(pen, new GraphicsEngine.CanvasRectangleF(a + 0, 14 * fac + y, bm_bl * 5 - 1, 5 * fac));
                                    canvas.DrawLine(pen, a, 12 * fac + y, a, 19 * fac + y);
                                    canvas.DrawLine(pen, a + bm_bl * 5 - 1, 12 * fac + y, a + bm_bl * 5 - 1, 19 * fac + y);
                                    canvas.DrawLine(pen, a + bm_bl, 14 * fac + y, a + bm_bl, 19 * fac + y);
                                    canvas.DrawLine(pen, a + bm_bl * 2, 14 * fac + y, a + bm_bl * 2, 19 * fac + y);
                                    canvas.DrawLine(pen, a + bm_bl * 3, 14 * fac + y, a + bm_bl * 3, 19 * fac + y);
                                    canvas.DrawLine(pen, a + bm_bl * 4, 14 * fac + y, a + bm_bl * 4, 19 * fac + y);

                                    string text = Math.Round(_scale, 0).ToString(), t = "";
                                    int    counter = 1;
                                    // Tausenderpunkte
                                    for (int i = text.Length - 1; i > 0; i--)
                                    {
                                        t = text[i] + t;
                                        if ((counter++ % 3) == 0)
                                        {
                                            t = "." + t;
                                        }
                                    }
                                    t    = text[0] + t;
                                    text = "M 1:" + t;
                                    drawString(canvas, font, text, (float)(a + (bm_bl * 5 - canvas.MeasureText(text, font).Width) / 2), y);
                                    drawString(canvas, font, "0", a - 4, y);

                                    if (dist > 1000)
                                    {
                                        float x = dist / (float)1000;
                                        text = x.ToString() + " km";
                                    }
                                    else
                                    {
                                        text = dist.ToString() + " m";
                                    }
                                    drawString(canvas, font, text, (float)(a + bm_bl * 5 - 5 * fac), y);
                                }
            return(true);
        }
Пример #14
0
        async public Task <bool> LegendRequest(gView.Framework.Carto.IDisplay display)
        {
            if (_dataset == null)
            {
                return(false);
            }

            List <IWebServiceTheme> themes = Themes;

            if (themes == null)
            {
                return(false);
            }

            #region Check for visible Layers
            bool visFound = false;
            foreach (IWebServiceTheme theme in themes)
            {
                if (!theme.Visible)
                {
                    continue;
                }

                if (theme.MinimumScale > 1 && theme.MinimumScale > display.mapScale)
                {
                    continue;
                }

                if (theme.MaximumScale > 1 && theme.MaximumScale < display.mapScale)
                {
                    continue;
                }

                visFound = true;
                break;
            }
            if (!visFound)
            {
                if (_legend != null)
                {
                    _legend.Dispose();
                    _legend = null;
                }
                return(true);
            }
            #endregion

            string server  = ConfigTextStream.ExtractValue(_dataset.ConnectionString, "server");
            string service = ConfigTextStream.ExtractValue(_dataset.ConnectionString, "service");
            string user    = ConfigTextStream.ExtractValue(_dataset.ConnectionString, "user");
            string pwd     = ConfigTextStream.ExtractValue(_dataset.ConnectionString, "pwd");
            IServiceRequestContext context = display.Map as IServiceRequestContext;

            //if ((user == "#" || user == "$") &&
            //    context != null && context.ServiceRequest != null && context.ServiceRequest.Identity != null)
            //{
            //    string roles = String.Empty;
            //    if (user == "#" && context.ServiceRequest.Identity.UserRoles != null)
            //    {
            //        foreach (string role in context.ServiceRequest.Identity.UserRoles)
            //        {
            //            if (String.IsNullOrEmpty(role)) continue;
            //            roles += "|" + role;
            //        }
            //    }
            //    user = context.ServiceRequest.Identity.UserName + roles;
            //    pwd = context.ServiceRequest.Identity.HashedPassword;
            //}

            dotNETConnector connector = new dotNETConnector();
            if (!String.IsNullOrEmpty(user) || !String.IsNullOrEmpty(pwd))
            {
                connector.setAuthentification(user, pwd);
            }

            if (_dataset.State != DatasetState.opened)
            {
                if (!await _dataset.Open(context))
                {
                    return(false);
                }
            }

            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("<?xml version='1.0' encoding='utf-8'?>");
                sb.Append("<ARCXML version='1.1'>");
                sb.Append("<REQUEST>");
                sb.Append("<GET_IMAGE>");
                sb.Append("<PROPERTIES>");
                sb.Append("<ENVELOPE minx='" + display.Envelope.minx.ToString() + "' miny='" + display.Envelope.miny.ToString() + "' maxx='" + display.Envelope.maxx.ToString() + "' maxy='" + display.Envelope.maxy.ToString() + "' />");
                sb.Append("<IMAGESIZE width='" + display.iWidth + "' height='" + display.iHeight + "' />");
                sb.Append("<BACKGROUND color='255,255,255' transcolor='255,255,255' />");

                sb.Append(_dataset._properties.PropertyString);

                sb.Append("<LAYERLIST>");
                foreach (IWebServiceTheme theme in themes)
                {
                    sb.Append("<LAYERDEF id='" + theme.LayerID + "' visible='" + (theme.Visible && !theme.Locked).ToString() + "'");
                    XmlNode xmlnode;
                    if (LayerRenderer.TryGetValue(theme.LayerID, out xmlnode))
                    {
                        sb.Append(">\n" + xmlnode.OuterXml + "\n</LAYERDEF>");
                    }
                    else if (theme.FeatureRenderer != null)
                    {
                        string renderer = ObjectFromAXLFactory.ConvertToAXL(theme.FeatureRenderer);
                        sb.Append(">\n" + renderer + "\n</LAYERDEF>");
                    }
                    else
                    {
                        sb.Append("/>");
                    }
                }
                sb.Append("</LAYERLIST>");
                sb.Append("<DRAW map=\"false\" />");
                sb.Append("<LEGEND font=\"Arial\" autoextend=\"true\" columns=\"1\" width=\"165\" height=\"170\" backgroundcolor=\"255,255,255\" layerfontsize=\"11\" valuefontsize=\"10\">");
                sb.Append("<LAYERS />");
                sb.Append("</LEGEND>");
                sb.Append("</PROPERTIES>");
                foreach (XmlNode additional in this.AppendedLayers)
                {
                    sb.Append(additional.OuterXml);
                }
                sb.Append("</GET_IMAGE>");
                sb.Append("</REQUEST>");
                sb.Append("</ARCXML>");

                await ArcIMSClass.LogAsync(display as IServiceRequestContext, "GetLegend Request", server, service, sb);

                string resp = connector.SendRequest(sb, server, service);
                await ArcIMSClass.LogAsync(display as IServiceRequestContext, "GetLegend Response", server, service, resp);

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(resp);

                XmlNode output = doc.SelectSingleNode("//LEGEND");

                if (ModifyResponseOuput != null)
                {
                    ModifyResponseOuput(this, new ModifyOutputEventArgs(output));
                }

                if (_legend != null)
                {
                    _legend.Dispose();
                }

                _legend = WebFunctions.DownloadImage(output);
                return(true);
            }
            catch (Exception ex)
            {
                await ArcIMSClass.ErrorLog(context, "LegendRequest", server, service, ex);

                return(false);
            }
        }
Пример #15
0
        public bool Merge(GraphicsEngine.Abstraction.IBitmap bitmap, IDisplay display)
        {
            try
            {
                int iWidth  = bitmap.Width;
                int iHeight = bitmap.Height;

                using (var canvas = bitmap.CreateCanvas())
                {
                    canvas.CompositingMode = GraphicsEngine.CompositingMode.SourceOver;

                    foreach (GeorefBitmap geoBmp in _picList)
                    {
                        if (geoBmp == null || geoBmp.Bitmap == null)
                        {
                            continue;
                        }

                        if (bitmap != geoBmp.Bitmap)
                        {
                            if (geoBmp.Envelope != null)
                            {
                                double x0, y0, x1, y1, x2, y2;
                                gView.Framework.Geometry.IGeometry geom = gView.Framework.Geometry.GeometricTransformerFactory.Transform2D(geoBmp.Envelope, geoBmp.SpatialReference, display.SpatialReference);
                                if (geom is gView.Framework.Geometry.IPolygon)
                                {
                                    gView.Framework.Geometry.IRing ring = ((gView.Framework.Geometry.IPolygon)geom)[0];

                                    x0 = ring[1].X; y0 = ring[1].Y;
                                    x1 = ring[2].X; y1 = ring[2].Y;
                                    x2 = ring[0].X; y2 = ring[0].Y;

                                    /////////////////////////////////////////////////////////
                                    Display d = new Display(display.Map, false);
                                    d.Limit            = d.Envelope = geoBmp.Envelope;
                                    d.iWidth           = geoBmp.Bitmap.Width;
                                    d.iHeight          = geoBmp.Bitmap.Height;
                                    d.SpatialReference = geoBmp.SpatialReference;
                                    Resample(bitmap, display, geoBmp.Bitmap, d);
                                    continue;
                                }
                                else
                                {
                                    x0 = geoBmp.Envelope.minx; y0 = geoBmp.Envelope.maxy;
                                    x1 = geoBmp.Envelope.maxx; y1 = geoBmp.Envelope.maxy;
                                    x2 = geoBmp.Envelope.minx; y2 = geoBmp.Envelope.miny;
                                }

                                display.World2Image(ref x0, ref y0);
                                display.World2Image(ref x1, ref y1);
                                display.World2Image(ref x2, ref y2);

                                GraphicsEngine.CanvasPointF[] points =
                                {
                                    new GraphicsEngine.CanvasPointF((float)x0, (float)y0),
                                    new GraphicsEngine.CanvasPointF((float)x1, (float)y1),
                                    new GraphicsEngine.CanvasPointF((float)x2, (float)y2)
                                };

                                canvas.DrawBitmap(geoBmp.Bitmap,
                                                  points,
                                                  new GraphicsEngine.CanvasRectangleF(0, 0, geoBmp.Bitmap.Width, geoBmp.Bitmap.Height),
                                                  opacity: geoBmp.Opacity);
                            }
                            else
                            {
                                canvas.DrawBitmap(geoBmp.Bitmap,
                                                  new GraphicsEngine.CanvasRectangle(0, 0, iWidth, iHeight),
                                                  new GraphicsEngine.CanvasRectangle(0, 0, geoBmp.Bitmap.Width, geoBmp.Bitmap.Height),
                                                  opacity: geoBmp.Opacity);
                            }
                        }
                    }
                }

                if (_scale > 0)
                {
                    Scalebar bar = new Scalebar(_scale, m_dpi);
                    bar.Create(bitmap, bitmap.Width - (int)(50 * m_dpi / 96.0) - bar.ScaleBarWidth, bitmap.Height - (int)(32 * m_dpi / 96.0));
                }
                return(true);
            }
            catch (Exception ex)
            {
                _errMsg = ex.Message + "\n" + ex.Source + "\n" + ex.StackTrace;
                return(false);
            }
        }
Пример #16
0
        async public Task <IRasterPaintContext> BeginPaint(gView.Framework.Carto.IDisplay display, ICancelTracker cancelTracker)
        {
            IntPtr bufferData = (IntPtr)0;

            GraphicsEngine.BitmapPixelData bitmapData = null;
            double mag = 1f; // mag immer als float, läuft stabiler!!!

            int x       = 0;
            int y       = 0;
            int iWidth  = 0;
            int iHeight = 0;

            GraphicsEngine.Abstraction.IBitmap bitmap = null;

            try
            {
                if (_reader == (IntPtr)0)
                {
                    if (!InitReader())
                    {
                        return(null);
                    }
                }

                if (!(_polygon is ITopologicalOperation) || _reader == (IntPtr)0)
                {
                    return(null);
                }

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

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

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

                IPolygon cPolygon = (IPolygon)clipped;

                if (cPolygon.RingCount == 0 || cPolygon[0].Area == 0D)
                {
                    return(null);
                }

                // 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(null);
                }

                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, _geoCoord.iWidth);
                picEnv.maxy = Math.Min(picEnv.maxy, _geoCoord.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(_geoCoord.xRes * _geoCoord.xRes + _geoCoord.xRot * _geoCoord.xRot);
                double c2  = Math.Sqrt(_geoCoord.yRes * _geoCoord.yRes + _geoCoord.yRot * _geoCoord.yRot);
                mag = Math.Round((Math.Min(c1, c2) / pix), 8);

                // Immer in auf float runden! Läuft stabiler!!!
                //mag = (float)mag; //1.03;
                if (mag > 1f)
                {
                    mag = 1f;
                }

                if (mag < _geoCoord.MinMagnification)
                {
                    mag = (float)_geoCoord.MinMagnification;
                }

                x       = (int)(picEnv.minx * mag);
                y       = (int)(picEnv.miny * mag);
                iWidth  = (int)((picEnv.Width - 1) * mag);
                iHeight = (int)((picEnv.Height - 1) * mag);

                bufferData = MrSidWrapper.Read(_reader, x, y, iWidth, iHeight, mag);
                if (bufferData == (IntPtr)0)
                {
                    return(null);
                }

                int totalWidth  = MrSidWrapper.GetTotalCols(bufferData);
                int totalHeight = MrSidWrapper.GetTotalRows(bufferData);

                bitmap     = GraphicsEngine.Current.Engine.CreateBitmap(totalWidth, totalHeight, GraphicsEngine.PixelFormat.Rgb24);
                bitmapData = bitmap.LockBitmapPixelData(GraphicsEngine.BitmapLockMode.WriteOnly, GraphicsEngine.PixelFormat.Rgb24);

                MrSidWrapper.ReadBandData(bufferData, bitmapData.Scan0, 3, (uint)bitmapData.Stride);

                return(new RasterPaintContext(bitmap));
            }
            catch (Exception ex)
            {
                //string errMsg = ex.Message;

                if (display is IServiceMap && ((IServiceMap)display).MapServer != null)
                {
                    IMapServer mapServer = ((IServiceMap)display).MapServer;
                    await mapServer.LogAsync(
                        ((IServiceMap)display).Name,
                        "RenderRasterLayerThread", loggingMethod.error,
                        ex.Message + "\n" + ex.Source + "\n" + ex.StackTrace + "\n" +
                        "filename=" + _filename + "\n" +
                        "x=" + x.ToString() + "\n" +
                        "y=" + y.ToString() + "\n" +
                        "iWidth=" + iWidth.ToString() + "\n" +
                        "iHeight=" + iHeight.ToString() + "\n" +
                        "mag=" + mag.ToString() + "\n");
                }
                else
                {
                    throw ex;
                }

                return(null);
            }
            finally
            {
                if (bitmapData != null)
                {
                    bitmap.UnlockBitmapPixelData(bitmapData);
                }

                MrSidWrapper.ReleaseBandData(bufferData);
                ReleaseReader();
            }
        }
Пример #17
0
        public static void Resample(GraphicsEngine.Abstraction.IBitmap dest,
                                    IDisplay destDisplay,
                                    GraphicsEngine.Abstraction.IBitmap source,
                                    IDisplay sourceDisplay)
        {
            GraphicsEngine.BitmapPixelData destData = null, sourceData = null;
            using (var transformer = gView.Framework.Geometry.GeometricTransformerFactory.Create())
            {
                try
                {
                    transformer.SetSpatialReferences(sourceDisplay.SpatialReference, destDisplay.SpatialReference);

                    destData   = dest.LockBitmapPixelData(GraphicsEngine.BitmapLockMode.WriteOnly, GraphicsEngine.PixelFormat.Rgba32);
                    sourceData = source.LockBitmapPixelData(GraphicsEngine.BitmapLockMode.ReadOnly, GraphicsEngine.PixelFormat.Rgba32);

                    int sWidth = source.Width, sHeight = source.Height;
                    int dWidth = dest.Width, dHeight = dest.Height;

                    unsafe
                    {
                        byte *ptr = (byte *)destData.Scan0;

                        for (int y = 0; y < dHeight; y++)
                        {
                            for (int x = 0; x < dWidth; x++)
                            {
                                double xx = x, yy = y;
                                destDisplay.Image2World(ref xx, ref yy);
                                gView.Framework.Geometry.IPoint point = (gView.Framework.Geometry.IPoint)transformer.InvTransform2D(new gView.Framework.Geometry.Point(xx, yy));
                                xx = point.X; yy = point.Y;
                                sourceDisplay.World2Image(ref xx, ref yy);

                                int x_ = (int)xx, y_ = (int)yy;
                                if (x_ >= 0 && x_ < sWidth &&
                                    y_ >= 0 && y_ < sHeight)
                                {
                                    byte *p = (byte *)sourceData.Scan0;
                                    p += (y_ * destData.Stride + x_ * 4);

                                    if (p[3] != 0) // Transparenz!!!
                                    {
                                        ptr[0] = p[0];
                                        ptr[1] = p[1];
                                        ptr[2] = p[2];
                                        ptr[3] = p[3];
                                    }
                                }

                                ptr += 4;
                            }
                            ptr += destData.Stride - destData.Width * 4;
                        }
                    }
                }
                catch { }
                finally
                {
                    if (destData != null)
                    {
                        dest.UnlockBitmapPixelData(destData);
                    }

                    if (sourceData != null)
                    {
                        source.UnlockBitmapPixelData(sourceData);
                    }
                }
            }
        }