Exemplo n.º 1
0
        private bool calcPolygon()
        {
            if (!InitReader())
            {
                return(false);
            }

            TFWFile tfw = this.GeoCoord as TFWFile;

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

            int iWidth  = _geoCoord.iWidth;
            int iHeight = _geoCoord.iHeight;

            _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);

            return(true);
        }
Exemplo n.º 2
0
        private void calcPolygon()
        {
            _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);
        }
Exemplo n.º 3
0
        public Polygon CreatePolygon(int width, int height)
        {
            Polygon polygon = new Polygon();
            Ring    ring    = new Ring();

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

            ring.AddPoint(p1);
            ring.AddPoint(new gView.Framework.Geometry.Point(p1.X + dx_X * width, p1.Y + dx_Y * width));
            ring.AddPoint(new gView.Framework.Geometry.Point(p1.X + dx_X * width + dy_X * height, p1.Y + dx_Y * width + dy_Y * height));
            ring.AddPoint(new gView.Framework.Geometry.Point(p1.X + dy_X * height, p1.Y + dy_Y * height));
            polygon.AddRing(ring);

            return(polygon);
        }
Exemplo n.º 4
0
        public Polygon CreatePolygon()
        {
            Polygon polygon = new Polygon();
            Ring    ring    = new Ring();

            gView.Framework.Geometry.Point p1 = new gView.Framework.Geometry.Point(
                X - dx1 / 2.0 - dy1 / 2.0,
                Y - dx2 / 2.0 - dy2 / 2.0);

            ring.AddPoint(p1);
            ring.AddPoint(new gView.Framework.Geometry.Point(p1.X + dx1 * iWidth, p1.Y + dx2 * iWidth));
            ring.AddPoint(new gView.Framework.Geometry.Point(p1.X + dx1 * iWidth + dy1 * iHeight, p1.Y + dx2 * iWidth + dy2 * iHeight));
            ring.AddPoint(new gView.Framework.Geometry.Point(p1.X + dy1 * iHeight, p1.Y + dy2 * iHeight));
            polygon.AddRing(ring);

            return(polygon);
        }
Exemplo n.º 5
0
        private static IGeometry GeometryFromSymbol(ISymbol symbol, IEnvelope env)
        {
            IGeometry geometry = null;

            if (symbol is ISymbolCollection)
            {
                if (((ISymbolCollection)symbol).Symbols.Count > 0)
                {
                    geometry = GeometryFromSymbol(((ISymbolCollection)symbol).Symbols[0].Symbol, env);
                }
            }
            else if (symbol is IPointSymbol || symbol is ITextSymbol)
            {
                geometry = new gView.Framework.Geometry.Point((env.minx + env.maxx) / 2, Math.Abs(env.miny - env.maxy) / 2);
            }
            else if (symbol is ILineSymbol)
            {
                IPoint p1   = new gView.Framework.Geometry.Point(env.minx + 5, Math.Abs(env.miny - env.maxy) / 2);
                IPoint p2   = new gView.Framework.Geometry.Point(env.maxx - 5, Math.Abs(env.miny - env.maxy) / 2);
                IPath  path = new Path();
                path.AddPoint(p1);
                path.AddPoint(p2);
                IPolyline line = new Polyline();
                line.AddPath(path);
                geometry = line;
            }
            else if (symbol is IFillSymbol)
            {
                IPoint p1   = new gView.Framework.Geometry.Point(env.minx + 5, 5);
                IPoint p2   = new gView.Framework.Geometry.Point(env.maxx - 5, 5);
                IPoint p3   = new gView.Framework.Geometry.Point(env.maxx - 5, Math.Abs(env.miny - env.maxy) - 5);
                IPoint p4   = new gView.Framework.Geometry.Point(env.minx + 5, Math.Abs(env.miny - env.maxy) - 5);
                IRing  ring = new Ring();
                ring.AddPoint(p1);
                ring.AddPoint(p2);
                ring.AddPoint(p3);
                ring.AddPoint(p4);
                IPolygon polygon = new Polygon();
                polygon.AddRing(ring);
                geometry = polygon;
            }

            return(geometry);
        }
Exemplo n.º 6
0
 public void Draw(IDisplay display, IGeometry geometry)
 {
     if (display != null && geometry is IPoint)
     {
         double x = ((IPoint)geometry).X;
         double y = ((IPoint)geometry).Y;
         display.World2Image(ref x, ref y);
         IPoint p = new gView.Framework.Geometry.Point(x, y);
         DrawPoint(display, p);
     }
     else if (geometry is IMultiPoint)
     {
         for (int i = 0, to = ((IMultiPoint)geometry).PointCount; i < to; i++)
         {
             IPoint p = ((IMultiPoint)geometry)[i];
             Draw(display, p);
         }
     }
 }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        private void setBounds(Image image)
        {
            if (image != null)
            {
                _iWidth  = image.Width;
                _iHeight = image.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);
        }
Exemplo n.º 9
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
            {
            }
        }
Exemplo n.º 10
0
        async public override Task <IFeature> NextFeature()
        {
            try
            {
                while (true)
                {
                    if (_reader == null)
                    {
                        return(null);
                    }

                    if (!await _reader.ReadAsync())
                    {
                        await ExecuteReaderAsync();

                        //return NextFeature;
                        continue;
                    }

                    bool    nextFeature = false;
                    Feature feature     = new Feature();
                    for (int i = 0; i < _reader.FieldCount; i++)
                    {
                        string name = _reader.GetName(i);
                        object obj  = null;
                        try
                        {
                            obj = _reader.GetValue(i);
                        }
                        catch { }

                        if (/*_schemaTable.Rows[i][0].ToString()*/ name == "FDB_SHAPE" && obj != DBNull.Value)
                        {
                            BinaryReader r = new BinaryReader(new MemoryStream());
                            r.BaseStream.Write((byte[])obj, 0, ((byte[])obj).Length);
                            r.BaseStream.Position = 0;

                            IGeometry p = null;
                            switch (_geomDef.GeometryType)
                            {
                            case geometryType.Point:
                                p = new gView.Framework.Geometry.Point();
                                break;

                            case geometryType.Polyline:
                                p = new gView.Framework.Geometry.Polyline();
                                break;

                            case geometryType.Polygon:
                                p = new gView.Framework.Geometry.Polygon();
                                break;
                            }
                            if (p != null)
                            {
                                p.Deserialize(r, _geomDef);
                                r.Close();

                                /*
                                 * if(_queryEnvelope!=null)
                                 * {
                                 *  if(!_queryEnvelope.Intersects(p.Envelope))
                                 *      return NextFeature;
                                 *  if (_queryGeometry is IEnvelope)
                                 *  {
                                 *      if (!Algorithm.InBox(p, (IEnvelope)_queryGeometry))
                                 *          return NextFeature;
                                 *  }
                                 * }
                                 */
                                if (_spatialFilter != null)
                                {
                                    if (!gView.Framework.Geometry.SpatialRelation.Check(_spatialFilter, p))
                                    {
                                        nextFeature = true;
                                        break;
                                    }
                                }
                                feature.Shape = p;
                            }
                        }
                        else
                        {
                            FieldValue fv = new FieldValue(/*_schemaTable.Rows[i][0].ToString()*/ name, obj);
                            feature.Fields.Add(fv);
                            if (fv.Name == "FDB_OID")
                            {
                                feature.OID = Convert.ToInt32(obj);
                            }
                        }
                    }

                    if (nextFeature == true)
                    {
                        continue;
                    }

                    Transform(feature);
                    return(feature);
                }
            }
            catch (Exception ex)
            {
                Dispose();
                throw (ex);
                //return null;
            }
        }
Exemplo n.º 11
0
        public void Draw(IDisplay display, IGeometry geometry, TextSymbolAlignment symbolAlignment)
        {
            if (_font == null)
            {
                return;
            }

            if (geometry is IPoint)
            {
                #region IPoint

                double x = ((IPoint)geometry).X;
                double y = ((IPoint)geometry).Y;
                display.World2Image(ref x, ref y);
                IPoint p = new gView.Framework.Geometry.Point(x, y);

                DrawAtPoint(display, p, _text, 0, StringFormatFromAlignment(symbolAlignment));

                #endregion
            }
            if (geometry is IMultiPoint)
            {
                #region IMultiPoint

                IMultiPoint pColl = (IMultiPoint)geometry;
                for (int i = 0; i < pColl.PointCount; i++)
                {
                    double x = pColl[i].X;
                    double y = pColl[i].Y;

                    display.World2Image(ref x, ref y);
                    IPoint p = new gView.Framework.Geometry.Point(x, y);

                    DrawAtPoint(display, p, _text, 0, StringFormatFromAlignment(symbolAlignment));
                }

                #endregion
            }
            else if (geometry is IDisplayPath && ((IDisplayPath)geometry).AnnotationPolygonCollision is AnnotationPolygonCollection)
            {
                if (String.IsNullOrEmpty(_text))
                {
                    return;
                }

                IDisplayPath path = (IDisplayPath)geometry;
                AnnotationPolygonCollection apc = path.AnnotationPolygonCollision as AnnotationPolygonCollection;
                var format = StringFormatFromAlignment(symbolAlignment);
                format.LineAlignment = StringAlignment.Center;
                format.Alignment     = StringAlignment.Center;

                if (_text.Length == apc.Count)
                {
                    int drawingLevels = this.DrawingLevels; // Für Blockout und Glowing Text -> Zuerst den Blockout für alle Zeichen...
                    for (int level = 0; level < drawingLevels; level++)
                    {
                        for (int i = 0; i < _text.Length; i++)
                        {
                            AnnotationPolygon ap = apc[i] as AnnotationPolygon;
                            if (ap != null)
                            {
                                var centerPoint = ap.CenterPoint;
                                DrawAtPoint(display, new Geometry.Point(centerPoint.X, centerPoint.Y), _text[i].ToString(), (float)ap.Angle, format, level);
                            }
                        }
                    }
                }

                #region Old Method

                /*
                 #region Text On Path
                 * StringFormat format = stringFormatFromAlignment;
                 * DisplayCharacterRanges ranges = new DisplayCharacterRanges(display.GraphicsContext, _font, format, _text);
                 *
                 * double sizeW = ranges.Width;
                 * double len = path.Length;
                 * double stat0 = len / 2 - sizeW / 2, stat1 = stat0 + sizeW;
                 * if (stat0 < 0) return;
                 *
                 #region Richtung des Textes
                 * Geometry.Point p1_ = SpatialAlgorithms.Algorithm.DisplayPathPoint(path, stat0);
                 * Geometry.Point p2_ = SpatialAlgorithms.Algorithm.DisplayPathPoint(path, stat1);
                 * if (p1_ == null || p2_ == null)
                 *  return;
                 * if (p1_.X > p2_.X)
                 * {
                 #region Swap Path Direction
                 *  path.ChangeDirection();
                 #endregion
                 * }
                 #endregion
                 *
                 * AnnotationPolygonCollection charPolygons = new AnnotationPolygonCollection();
                 * double x, y, angle;
                 *
                 * for (int i = 0; i < _text.Length; i++)
                 * {
                 *  RectangleF cSize = ranges[i];
                 *  Geometry.Point p1, p2;
                 *  while (true)
                 *  {
                 *      p1 = SpatialAlgorithms.Algorithm.DisplayPathPoint(path, stat0);
                 *      p2 = SpatialAlgorithms.Algorithm.DisplayPathPoint(path, stat0 + cSize.Width);
                 *      if (p1 == null || p2 == null)
                 *          return;
                 *
                 *      angle = Math.Atan2(p2.Y - p1.Y, p2.X - p1.X) * 180.0 / Math.PI;
                 *
                 *      x = p1.X; y = p1.Y;
                 *      AnnotationPolygon polygon = null;
                 *      switch (format.LineAlignment)
                 *      {
                 *          case StringAlignment.Near:
                 *              polygon = new Symbology.AnnotationPolygon((float)x + .1f * cSize.Width, (float)y + .2f * cSize.Height,
                 *                                                         .8f * cSize.Width, .6f * cSize.Height);
                 *              break;
                 *          case StringAlignment.Far:
                 *              polygon = new Symbology.AnnotationPolygon((float)x + .1f * cSize.Width, (float)y - .8f * cSize.Height,
                 *                                                         .8f * cSize.Width, .6f * cSize.Height);
                 *              break;
                 *          default:
                 *              polygon = new Symbology.AnnotationPolygon((float)x + .1f * cSize.Width, (float)y - .6f * cSize.Height / 2f,
                 *                                                         .8f * cSize.Width, .6f * cSize.Height);
                 *              break;
                 *      }
                 *      polygon.Rotate((float)x, (float)y, Angle + angle);
                 *      if (charPolygons.CheckCollision(polygon))
                 *      {
                 *          stat0 += cSize.Width / 10.0;
                 *          continue;
                 *      }
                 *      charPolygons.Add(polygon);
                 *
                 *      //using (System.Drawing.Drawing2D.GraphicsPath grpath = new System.Drawing.Drawing2D.GraphicsPath())
                 *      //{
                 *      //    grpath.StartFigure();
                 *      //    grpath.AddLine(polygon[0], polygon[1]);
                 *      //    grpath.AddLine(polygon[1], polygon[2]);
                 *      //    grpath.AddLine(polygon[2], polygon[3]);
                 *      //    grpath.CloseFigure();
                 *
                 *      //    display.GraphicsContext.FillPath(Brushes.Aqua, grpath);
                 *      //}
                 *
                 *      break;
                 *  }
                 *
                 *  if (format.Alignment == StringAlignment.Center)
                 *  {
                 *      x = p1.X * 0.5 + p2.X * 0.5;
                 *      y = p1.Y * 0.5 + p2.Y * 0.5;
                 *  }
                 *  else if (format.Alignment == StringAlignment.Far)
                 *  {
                 *      x = p2.X;
                 *      y = p2.Y;
                 *  }
                 *  else
                 *  {
                 *      x = p1.X;
                 *      y = p1.Y;
                 *  }
                 *  DrawAtPoint(display, new Geometry.Point(x, y), _text[i].ToString(), (float)angle, format);
                 *
                 *  stat0 += (double)cSize.Width;
                 * }
                 * //display.GraphicsContext.FillEllipse(Brushes.Green, (float)p1_.X - 3, (float)p1_.Y - 3, 6f, 6f);
                 * //display.GraphicsContext.FillEllipse(Brushes.Blue, (float)p2_.X - 3, (float)p2_.Y - 3, 6f, 6f);
                 #endregion
                 * */
                #endregion
            }
            else if (geometry is IPolyline)
            {
                IPolyline pLine = (IPolyline)geometry;
                for (int iPath = 0; iPath < pLine.PathCount; iPath++)
                {
                    IPath path = pLine[iPath];
                    if (path.PointCount == 0)
                    {
                        continue;
                    }

                    #region Parallel Text

                    IPoint p1 = path[0], p2;
                    for (int iPoint = 1; iPoint < path.PointCount; iPoint++)
                    {
                        p2 = path[iPoint];
                        double angle = -Math.Atan2(p2.Y - p1.Y, p2.X - p1.X) * 180.0 / Math.PI;
                        if (display.DisplayTransformation.UseTransformation)
                        {
                            angle -= display.DisplayTransformation.DisplayRotation;
                        }

                        var format = StringFormatFromAlignment(symbolAlignment);

                        if (angle < 0)
                        {
                            angle += 360;
                        }

                        if (angle > 90 && angle < 270)
                        {
                            if (format.Alignment != StringAlignment.Center)
                            {
                                // swap points & alignment
                                var p_ = p1;
                                p1 = p2;
                                p2 = p_;
                                if (format.Alignment == StringAlignment.Far)
                                {
                                    format.Alignment = StringAlignment.Near;
                                }
                                else if (format.Alignment == StringAlignment.Near)
                                {
                                    format.Alignment = StringAlignment.Far;
                                }
                            }
                            angle -= 180;
                        }


                        double x, y;
                        if (format.Alignment == StringAlignment.Center)
                        {
                            x = p1.X * 0.5 + p2.X * 0.5;
                            y = p1.Y * 0.5 + p2.Y * 0.5;
                        }
                        else if (format.Alignment == StringAlignment.Far)
                        {
                            x = p2.X;
                            y = p2.Y;
                        }
                        else
                        {
                            x = p1.X;
                            y = p1.Y;
                        }
                        display.World2Image(ref x, ref y);
                        IPoint p = new gView.Framework.Geometry.Point(x, y);

                        //_text += "  " + angle.ToString();
                        DrawAtPoint(display, p, _text, (float)angle, format);
                        p1 = p2;
                    }

                    #endregion
                }
            }
            else if (geometry is IPolygon)
            {
                /*
                 * GraphicsPath path = DisplayOperations.Geometry2GraphicsPath(display, geometry);
                 *
                 * foreach (PointF point in gView.SpatialAlgorithms.Algorithm.LabelPoints(path))
                 * {
                 *  DrawAtPoint(display, new gView.Framework.Geometry.Point(point.X, point.Y), 0, stringFormatFromAlignment);
                 * }
                 * */
            }
            else if (geometry is IAggregateGeometry)
            {
                for (int i = 0; i < ((IAggregateGeometry)geometry).GeometryCount; i++)
                {
                    Draw(display, ((IAggregateGeometry)geometry)[i]);
                }
            }
        }
Exemplo n.º 12
0
        public void BeginPaint(gView.Framework.Carto.IDisplay display, ICancelTracker cancelTracker)
        {
            IntPtr     bufferData = (IntPtr)0;
            BitmapData bitmapData = null;
            double     mag        = 1f; // mag immer als float, läuft stabiler!!!

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

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

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

                TFWFile tfw = this.GeoCoord 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, _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, (double)mag);
                if (bufferData == (IntPtr)0)
                {
                    return;
                }

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

                if (_bm != null)
                {
                    _bm.Dispose();
                }
                _bm        = new Bitmap(totalWidth, totalHeight, PixelFormat.Format24bppRgb);
                bitmapData = _bm.LockBits(new Rectangle(0, 0, totalWidth, totalHeight), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

                Console.Write(bitmapData.Scan0);

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

                //_bm.Save(@"C:\temp\pic\" + Guid.NewGuid() + ".jpg", ImageFormat.Jpeg);
            }
            catch (Exception ex)
            {
                //string errMsg = ex.Message;
                EndPaint(cancelTracker);

                if (display is IServiceMap && ((IServiceMap)display).MapServer != null)
                {
                    IMapServer mapServer = ((IServiceMap)display).MapServer;
                    mapServer.Log(
                        "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;
                }
            }
            finally
            {
                if (bitmapData != null)
                {
                    _bm.UnlockBits(bitmapData);
                }
                MrSidWrapper.ReleaseBandData(bufferData);
                ReleaseReader();
            }
        }
Exemplo n.º 13
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();
            }
        }