示例#1
0
        private ICoordinate PrepareForSelect(Point position)
        {
            //BoundingRectangle mapCoordsViewBox = _map.MapViewBoxFromPresentationViewBox(_viewBox);

            double x = _viewBox.Width / ActualWidth * position.X + _viewBox.MinX;
            double y = _viewBox.MaxY - _viewBox.Height / ActualHeight * position.Y;

            // Caculate the error of selecting the point and line objects
            _map.SelectionPointRadius = _selectionMargin * _viewBox.Width / ActualWidth;

            ICoordinate result = PlanimetryEnvironment.NewCoordinate(x, y);

            if (_map.OnTheFlyTransform != null)
            {
                ICoordinate    delta            = PlanimetryEnvironment.NewCoordinate(result.X + _map.SelectionPointRadius, result.Y);
                IMathTransform inverseTransform = _map.OnTheFlyTransform.Inverse();

                delta = PlanimetryEnvironment.NewCoordinate(inverseTransform.Transform(delta.Values()));

                _map.SelectionPointRadius =
                    PlanimetryAlgorithms.Distance(PlanimetryEnvironment.NewCoordinate(inverseTransform.Transform(result.Values())), delta);
            }

            return(result);
        }
示例#2
0
        private static ICoordinate[] getArcIntersections(ICoordinate p1, ICoordinate p2, double ly)
        {
            if (p1.X > p2.X)
            {
                ICoordinate p = p1;
                p1 = p2;
                p2 = p;
            }

            if (ly == p2.Y)
            {
                return new ICoordinate[] { PlanimetryEnvironment.NewCoordinate((p1.X + p2.X) / 2, double.PositiveInfinity) }
            }
            ;

            double f     = (ly - p1.Y) / (ly - p2.Y);
            double a     = 1 - f;
            double lpow2 = ly * ly;
            double yn    = lpow2 - p2.X * p2.X - p2.Y * p2.Y;

            if (a == 0)
            {
                double x = 0.5 * (p1.X + p2.X);

                double y = (yn - x * x + 2 * p2.X * x) / (ly - p2.Y);
                return(new ICoordinate[] { PlanimetryEnvironment.NewCoordinate(x, y) });
            }
            double b = 2 * (p2.X * f - p1.X);
            double c = f * yn + p1.X * p1.X + p1.Y * p1.Y - lpow2;

            double d = b * b - 4 * a * c;

            if (d < 0)
            {
                // no real roots
                return new ICoordinate[] { }
            }
            ;
            else
            {
                double sb = b == 0 ? 1 : Math.Sign(b);

                // This "trick" to avoid loss of accuracy in the calculation
                // of one of the roots due to the subtraction of large numbers
                double x1 = 0.5 * (-b + sb * Math.Sqrt(d)) / a;
                double x2 = (x1 != 0 ? c / a / x1 : 0);

                double p1ypow2 = p1.Y * p1.Y;
                double den     = 2 * (p1.Y - ly);

                double y1 = (p1ypow2 + (p1.X - x1) * (p1.X - x1) - lpow2) / den;
                double y2 = (p1ypow2 + (p1.X - x2) * (p1.X - x2) - lpow2) / den;

                return(new ICoordinate[]
                {
                    PlanimetryEnvironment.NewCoordinate(x1, y1),
                    PlanimetryEnvironment.NewCoordinate(x2, y2)
                });
            }
        }
示例#3
0
        private ICoordinate GetAvgMouseSpeed()
        {
            ICoordinate v1 = GetMouseSpeed(_mouseTime[3],
                                           _mouseTime[2],
                                           new Point(_mouseX[3], _mouseY[3]),
                                           new Point(_mouseX[2], _mouseY[2]));

            ICoordinate v2 = GetMouseSpeed(_mouseTime[2],
                                           _mouseTime[1],
                                           new Point(_mouseX[2], _mouseY[2]),
                                           new Point(_mouseX[1], _mouseY[1]));

            ICoordinate v3 = GetMouseSpeed(_mouseTime[1],
                                           _mouseTime[0],
                                           new Point(_mouseX[1], _mouseY[1]),
                                           new Point(_mouseX[0], _mouseY[0]));

            double vxAvg = 0.35 *
                           -(v1.X * (_mouseTime[2] - _mouseTime[3]).TotalMilliseconds +
                             v2.X * (_mouseTime[1] - _mouseTime[2]).TotalMilliseconds +
                             v3.X * (_mouseTime[0] - _mouseTime[1]).TotalMilliseconds) /
                           (_mouseTime[0] - _mouseTime[3]).TotalMilliseconds;

            double vyAvg = 0.35 *
                           -(v1.Y * (_mouseTime[2] - _mouseTime[3]).TotalMilliseconds +
                             v2.Y * (_mouseTime[1] - _mouseTime[2]).TotalMilliseconds +
                             v3.Y * (_mouseTime[0] - _mouseTime[1]).TotalMilliseconds) /
                           (_mouseTime[0] - _mouseTime[3]).TotalMilliseconds;

            return(PlanimetryEnvironment.NewCoordinate(vxAvg, vyAvg));
        }
示例#4
0
        private IGeometry geometryFromShapeRecord(ShapeFileRecord record)
        {
            switch (record.ShapeType)
            {
            // point
            case 1:
                return(new PointD(record.Points[0].X, record.Points[0].Y));

            // polyline
            case 3:
                Polyline polyline = new Polyline();
                for (int i = 0; i < record.Parts.Count; i++)
                {
                    LinePath path = new LinePath();
                    int      j;
                    for (j = record.Parts[i]; j < (i == record.Parts.Count - 1 ? record.Points.Count : record.Parts[i + 1]); j++)
                    {
                        path.Vertices.Add(PlanimetryEnvironment.NewCoordinate(record.Points[j].X, record.Points[j].Y));
                    }

                    polyline.Paths.Add(path);
                }
                return(polyline);

            // ground
            case 5:
                Polygon p = new Polygon();
                for (int i = 0; i < record.Parts.Count; i++)
                {
                    Contour contour = new Contour();
                    int     j;
                    for (j = record.Parts[i]; j < (i == record.Parts.Count - 1 ? record.Points.Count : record.Parts[i + 1]); j++)
                    {
                        contour.Vertices.Add(PlanimetryEnvironment.NewCoordinate(record.Points[j].X, record.Points[j].Y));
                    }

                    contour.Vertices.RemoveAt(contour.Vertices.Count - 1);
                    p.Contours.Add(contour);
                }
                if (p.CoordinateCount > 0)
                {
                    return(p);
                }
                else
                {
                    return(null);
                }

            // set of points
            case 8:
                MultiPoint mp = new MultiPoint();
                for (int i = 0; i < record.Points.Count; i++)
                {
                    mp.Points.Add(PlanimetryEnvironment.NewCoordinate(record.Points[i].X, record.Points[i].Y));
                }
                return(mp);
            }

            return(null);
        }
示例#5
0
        /// <summary>
        /// Читает запись представляющую полигон.
        /// </summary>
        /// <param name="file">Входной поток</param>
        /// <param name="record">Запись Shape-файла в которую будет помещена прочитанная информация</param>
        /// <param name="bounds">Ограничивающий прямоугольник, с которым должен пересекаться ограничивающий прямоугольник записи</param>
        public override bool Read(/*BigEndianBinaryReader*/ Stream file, BoundingRectangle bounds, ShapeFileRecord record)
        {
            record.MinX = file.ReadDouble();  // ShapeFile.ReadDouble64_LE(stream);
            record.MinY = file.ReadDouble();  //ShapeFile.ReadDouble64_LE(stream);
            record.MaxX = file.ReadDouble();; // ShapeFile.ReadDouble64_LE(stream);
            record.MaxY = file.ReadDouble();; // ShapeFile.ReadDouble64_LE(stream);

            int numParts  = file.ReadInt32(); // ShapeFile.ReadInt32_LE(stream);
            int numPoints = file.ReadInt32(); //ShapeFile.ReadInt32_LE(stream);

            if (!ShapeHandler.IsRecordInView(bounds, record))
            {
                file.Seek((long)numPoints * 16 + numParts * 4, SeekOrigin.Current);
                return(false);
            }

            for (int i = 0; i < numParts; i++)
            {
                record.Parts.Add(file.ReadInt32());//ShapeFile.ReadInt32_LE(stream));
            }
            for (int i = 0; i < numPoints; i++)
            {
                ICoordinate p =
                    PlanimetryEnvironment.NewCoordinate(
                        file.ReadDouble(),  //ShapeFile.ReadDouble64_LE(stream),
                        file.ReadDouble()); //ShapeFile.ReadDouble64_LE(stream));

                record.Points.Add(p);
            }

            return(true);
        }
示例#6
0
        /// <summary>
        /// Initializes a new instance of MapAround.Geometry.Tesselations.VoronoiNode
        /// </summary>
        public VoronoiNode(double x, double y)
        {
            _point = PlanimetryEnvironment.NewCoordinate(x, y);

            _point.X = x;
            _point.Y = y;
        }
示例#7
0
        /// <summary>
        /// Записывает данные геометрического  объекта в указанный поток.
        /// </summary>
        /// <param name="geometry">Геометрический объект для записи</param>
        /// <param name="file">Поток записи</param>
        public override void Write(IGeometry geometry, BinaryWriter file)
        {
            file.Write(int.Parse(Enum.Format(typeof(ShapeType), ShapeType, "d")));

            BoundingRectangle bounds = geometry.GetBoundingRectangle(); // GetEnvelopeExternal(/*geometryFactory.PrecisionModel,*/  box);

            file.Write(bounds.MinX);
            file.Write(bounds.MinY);
            file.Write(bounds.MaxX);
            file.Write(bounds.MaxY);

            int numParts  = GetNumParts(geometry);
            int numPoints = geometry.CoordinateCount + numParts;

            file.Write(numParts);
            file.Write(numPoints);

            //parts
            int offset = 0;

            foreach (Contour contour in ((Polygon)geometry).Contours)
            {
                file.Write(offset);
                offset += contour.Vertices.Count + 1;
            }

            foreach (Contour contour in ((Polygon)geometry).Contours)
            {
                System.Collections.Generic.List <ICoordinate> points = contour.Vertices.ToList();
                points.Add(PlanimetryEnvironment.NewCoordinate(contour.Vertices[0].X, contour.Vertices[0].Y));
                WriteCoords(points, file);
            }
        }
示例#8
0
        private static Polyline readMultiLineString(Stream stream, WKBByteOrder byteOrder)
        {
            int numLineStrings = (int)readUInt32(stream, byteOrder);

            Polyline result = new Polyline();

            result.Paths = new List <LinePath>((int)numLineStrings);

            for (int i = 0; i < numLineStrings; i++)
            {
                // порядок байтов
                stream.ReadByte();
                // тип фигуры
                readUInt32(stream, byteOrder);
                // количество вершин
                int numPoints = (int)readUInt32(stream, byteOrder);

                result.Paths.Add(new LinePath());
                // вершины
                for (int j = 0; j < numPoints; j++)
                {
                    result.Paths[i].Vertices.Add(PlanimetryEnvironment.NewCoordinate(readDouble(stream, byteOrder), readDouble(stream, byteOrder)));
                }
            }

            return(result);
        }
示例#9
0
        /// <summary>
        /// Transforms coordinates of the segment.
        /// </summary>
        /// <param name="s">Segment to transform</param>
        /// <param name="transform">The transformation to apply</param>
        /// <returns>The transformed segment</returns>
        public static Segment TransformSegment(Segment s, IMathTransform transform)
        {
            Segment result = new Segment();

            result.V1 = PlanimetryEnvironment.NewCoordinate(transform.Transform(s.V1.Values()));
            result.V2 = PlanimetryEnvironment.NewCoordinate(transform.Transform(s.V2.Values()));
            return(result);
        }
        private int[] calculateOptimalAffineTransformPoints()
        {
            int[]  result  = new int[3];
            double minNorm = double.MaxValue;

            for (int i1 = 0; i1 < _sourceControlPoints.Length - 2; i1++)
            {
                for (int i2 = i1 + 1; i2 < _sourceControlPoints.Length - 1; i2++)
                {
                    for (int i3 = i2 + 1; i3 < _sourceControlPoints.Length; i3++)
                    {
                        ICoordinate p01 = _sourceControlPoints[i1];
                        ICoordinate p02 = _sourceControlPoints[i2];
                        ICoordinate p03 = _sourceControlPoints[i3];

                        ICoordinate p11 = _destinationControlPoints[i1];
                        ICoordinate p12 = _destinationControlPoints[i2];
                        ICoordinate p13 = _destinationControlPoints[i3];

                        Matrix m = getAffineTransformMatrix(p01, p02, p03, p11, p12, p13);

                        if (m != null)
                        {
                            ICoordinate[] tempPoints = new ICoordinate[_sourceControlPoints.Length];
                            for (int i = 0; i < _sourceControlPoints.Length; i++)
                            {
                                tempPoints[i] = (ICoordinate)_sourceControlPoints[i].Clone();
                            }

                            Affine affineTransform = new Affine(m);

                            for (int i = 0; i < tempPoints.Length; i++)
                            {
                                tempPoints[i] =
                                    PlanimetryEnvironment.NewCoordinate(
                                        affineTransform.Transform(tempPoints[i].Values()));
                            }

                            double currentNorm = 0;
                            for (int i = 0; i < tempPoints.Length; i++)
                            {
                                currentNorm += PlanimetryAlgorithms.Distance(_destinationControlPoints[i], PlanimetryEnvironment.NewCoordinate(tempPoints[i].X, tempPoints[i].Y));
                            }

                            if (currentNorm < minNorm)
                            {
                                minNorm   = currentNorm;
                                result[0] = i1;
                                result[1] = i2;
                                result[2] = i3;
                            }
                        }
                    }
                }
            }

            return(result);
        }
示例#11
0
        private List <ICoordinate> getStrokePoints(IList <ICoordinate> points,
                                                   double startLength,
                                                   double strokeLength,
                                                   ref int segmentIndex,
                                                   ref double traversedLength)
        {
            List <ICoordinate> result = new List <ICoordinate>();

            double endLength     = startLength + strokeLength;
            bool   strokeStarted = false;

            for (int i = segmentIndex; i < points.Count - 1; i++)
            {
                double currentSegmentLength = PlanimetryAlgorithms.Distance(points[i], points[i + 1]);

                if (!strokeStarted)
                {
                    if (traversedLength + currentSegmentLength < startLength)
                    {
                        traversedLength += currentSegmentLength;
                        continue;
                    }
                    else
                    {
                        double      remaindeLength = startLength - traversedLength;
                        double      f = remaindeLength / (currentSegmentLength - remaindeLength);
                        ICoordinate p = PlanimetryEnvironment.NewCoordinate(
                            (points[i].X + f * points[i + 1].X) / (1 + f),
                            (points[i].Y + f * points[i + 1].Y) / (1 + f));
                        result.Add(p);
                        strokeStarted = true;
                    }
                }
                if (strokeStarted)
                {
                    if (traversedLength + currentSegmentLength <= endLength)
                    {
                        traversedLength += currentSegmentLength;
                        result.Add(points[i + 1]);
                        continue;
                    }
                    else
                    {
                        double      remainderLength = endLength - traversedLength;
                        double      f = remainderLength / (currentSegmentLength - remainderLength);
                        ICoordinate p = PlanimetryEnvironment.NewCoordinate(
                            (points[i].X + f * points[i + 1].X) / (1 + f),
                            (points[i].Y + f * points[i + 1].Y) / (1 + f));
                        result.Add(p);
                        segmentIndex = i;
                        return(result);
                    }
                }
            }

            segmentIndex = points.Count - 1;
            return(result);
        }
        /// <summary>
        /// Performs a rubbersheeting transformation of raster.
        /// </summary>
        /// <param name="source">A System.Drawing.Bitmap instance containing the source image</param>
        /// <param name="sourceControlPoints">Control points of source</param>
        /// <param name="destinationControlPoints">Control points on the map</param>
        /// <param name="rectangle">A bounding rectangle defining a bouns of transformed raster</param>
        /// <param name="progress">Defines a method which is called to notify a subscriber about completion state.</param>
        /// <returns>A System.Drawing.Bitmap instance containing the transformed image</returns>
        public static Bitmap BindRaster(Bitmap source, Point[] sourceControlPoints, ICoordinate[] destinationControlPoints, out BoundingRectangle rectangle, RasterBindingProgress progress)
        {
#if DEMO
            throw new NotImplementedException("This method is not implemented in demo version.");
#else
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            if (sourceControlPoints.Length != destinationControlPoints.Length)
            {
                throw new ArgumentException("Number of control points of raster and map should be the same.");
            }

            if (sourceControlPoints.Length < 3)
            {
                throw new ArgumentException("Number of control points should not be less than 3");
            }

            if (!checkControlPoints(source.Width, source.Height, sourceControlPoints))
            {
                throw new ArgumentException("At least one source control point is outside raster", "sourceControlPoints");
            }

            ICoordinate[,] warpTransformResult = new ICoordinate[source.Width, source.Height];
            PointF[,] affinneTransformResult   = new PointF[source.Width, source.Height];

            // вычисляем результат аффинного преобразования примененного к координатам точек исходного растра
            calculateAffinneTransform(source.Width, source.Height, affinneTransformResult, sourceControlPoints, destinationControlPoints, progress);

            ICoordinate[] shifts = new ICoordinate[destinationControlPoints.Length];
            for (int i = 0; i < shifts.Length; i++)
            {
                PointF p = affinneTransformResult[sourceControlPoints[i].X, sourceControlPoints[i].Y];
                shifts[i] = PlanimetryEnvironment.NewCoordinate(destinationControlPoints[i].X - p.X, destinationControlPoints[i].Y - p.Y);
            }

            // вычисляем новые координаты точек исходного растра, полученные в результате "коробления"
            calculateRubberSheetTransform(source.Width, source.Height, affinneTransformResult, warpTransformResult, destinationControlPoints, shifts, progress);

            // вычисляем ограничивающий прямоугольник преобразованного растра
            rectangle = new BoundingRectangle();
            for (int i = 0; i < source.Width; i++)
            {
                for (int j = 0; j < source.Height; j++)
                {
                    if (!double.IsNaN(warpTransformResult[i, j].X) && !double.IsNaN(warpTransformResult[i, j].Y))
                    {
                        rectangle.Join(warpTransformResult[i, j]);
                    }
                }
            }

            return(calcDestRaster(source, rectangle, warpTransformResult, progress));
#endif
        }
示例#13
0
 /// <summary>
 /// Создает экземпляр SimpleCircle.
 /// </summary>
 /// <param name="center">Центр</param>
 /// <param name="radius">Радиус</param>
 public SimpleCircle(ICoordinate center, float radius)
 {
     _center = center;
     _radius = radius;
     _rPow2  = _radius * _radius;
     _br     = new BoundingRectangle(
         PlanimetryEnvironment.NewCoordinate(_center.X - _radius, _center.Y - _radius),
         PlanimetryEnvironment.NewCoordinate(_center.X + _radius, _center.Y + _radius));
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="point"></param>
        /// <returns></returns>
        public override double[] Transform(double[] point)
        {
            // check whether we were in a knot interpolation
            for (int k = 0; k < _sourceControlPoints.Length; k++)
            {
                if (_sourceControlPoints[k].X == point[0] &&
                    _sourceControlPoints[k].Y == point[1])
                {
                    // hit
                    return(_destinationControlPoints[k].Values());
                }
            }

            ICoordinate source = PlanimetryEnvironment.NewCoordinate(point);
            ICoordinate result =
                PlanimetryEnvironment.NewCoordinate(_optimalAffineTransform.Transform(point));

            double[] distances = new double[_sourceControlPoints.Length];
            double[] w         = new double[_sourceControlPoints.Length];

            // calculation of distances to nodes
            double maxDistance = 0;

            for (int t = 0; t < _sourceControlPoints.Length; t++)
            {
                distances[t] = PlanimetryAlgorithms.Distance(_sourceControlPoints[t], source);
                if (maxDistance < distances[t])
                {
                    maxDistance = distances[t];
                }
            }

            // calculation of the weights of the denominators of nodes
            double sum = 0;

            for (int k = 0; k < _sourceControlPoints.Length; k++)
            {
                double temp = (maxDistance - distances[k]) / (maxDistance * distances[k]);
                sum += Math.Pow(temp, 2);
            }

            // calculation of the weights of nodes
            for (int k = 0; k < _sourceControlPoints.Length; k++)
            {
                double temp = (maxDistance - distances[k]) / (maxDistance * distances[k]);
                w[k] = Math.Pow(temp, 2) / sum;
            }

            for (int k = 0; k < _sourceControlPoints.Length; k++)
            {
                result.X += w[k] * _controlPointsShifts[k].X;
                result.Y += w[k] * _controlPointsShifts[k].Y;
            }

            return(result.Values());
        }
示例#15
0
        /// <summary>
        /// Transforms screen coordinates to map coordinates.
        /// </summary>
        /// <param name="point">A point on the screen</param>
        /// <returns>A point on the map</returns>
        public ICoordinate ClientToMap(Point point)
        {
            if (_viewBox == null)
            {
                throw new InvalidOperationException("Undefined view box");
            }

            return(PlanimetryEnvironment.NewCoordinate(_viewBox.Width / ActualWidth * point.X + _viewBox.MinX,
                                                       _viewBox.MaxY - _viewBox.Height / ActualHeight * point.Y));
        }
示例#16
0
        private static ICoordinate readPointCoords(WktStreamTokenizer tokenizer)
        {
            ICoordinate point = PlanimetryEnvironment.NewCoordinate(0, 0);

            tokenizer.NextToken();
            point.X = tokenizer.GetNumericValue();
            tokenizer.NextToken();
            point.Y = tokenizer.GetNumericValue();
            return(point);
        }
示例#17
0
        /// <summary>
        /// Sets the directions of dangles for infinite edges.
        /// </summary>
        /// <param name="rectangle">Bounding rectangle of the tessellation nodes</param>
        /// <param name="startVerticalNodes">The initial nodes of the infinit vertical edges,
        /// formed by points with the maximum Y coordinate</param>
        internal void Finish(BoundingRectangle rectangle, List <VoronoiNode> startVerticalNodes)
        {
            double l = rectangle.MinY - rectangle.Width - rectangle.Height;

            FortuneArc arc = Root;

            while (arc.Left != null)
            {
                arc = arc.Left;
            }
            while (arc != null)
            {
                FortuneArc rn = arc.RightNeighbor;

                if (rn != null)
                {
                    ICoordinate[] points =
                        getArcIntersections(arc.Site.Cell.DataPoint, rn.Site.Cell.DataPoint, 2 * l);

                    if (points.Length == 2)
                    {
                        ICoordinate p1 = points[0].X < points[1].X ? points[0] : points[1];
                        ICoordinate p2 = points[0].X < points[1].X ? points[1] : points[0];

                        if (arc.RightNode != null && arc.RightNode.IsInfinit)
                        {
                            if (arc.Site.Cell.DataPoint.Y > rn.Site.Cell.DataPoint.Y)
                            {
                                arc.RightNode.Point = p1;
                            }
                            else
                            {
                                arc.RightNode.Point = p2;
                            }
                        }
                    }

                    if (points.Length == 1)
                    {
                        if (arc.RightNode != null && arc.RightNode.IsInfinit)
                        {
                            arc.RightNode.Point = points[0];
                        }
                    }
                }

                arc = rn;
            }

            foreach (VoronoiNode node in startVerticalNodes)
            {
                node.Point = PlanimetryEnvironment.NewCoordinate(node.Point.X, rectangle.MaxY + rectangle.Height);
            }
        }
示例#18
0
        private ICoordinate GetMouseSpeed(DateTime satrtTime, DateTime endtime, Point startPoint, Point endPoint)
        {
            double milliseconds = (endtime - satrtTime).TotalMilliseconds;

            if (milliseconds == 0)
            {
                return(PlanimetryEnvironment.NewCoordinate(0, 0));
            }

            return(PlanimetryEnvironment.NewCoordinate((startPoint.X - endPoint.X) / milliseconds,
                                                       (startPoint.Y - endPoint.Y) / milliseconds));
        }
示例#19
0
        private static List <ICoordinate> readCoordsList(Stream stream, WKBByteOrder byteOrder)
        {
            int numPoints = (int)readUInt32(stream, byteOrder);

            List <ICoordinate> result = new List <ICoordinate>(numPoints);

            for (int i = 0; i < numPoints; i++)
            {
                result.Add(PlanimetryEnvironment.NewCoordinate(readDouble(stream, byteOrder), readDouble(stream, byteOrder)));
            }

            return(result);
        }
示例#20
0
 private static bool isRecordInView(BoundingRectangle bounds, ShapeFileRecord record)
 {
     if (bounds != null && !bounds.IsEmpty())
     {
         if (!bounds.Intersects(
                 new BoundingRectangle(PlanimetryEnvironment.NewCoordinate(record.MinX, record.MinY),
                                       PlanimetryEnvironment.NewCoordinate(record.MaxX, record.MaxY))))
         {
             return(false);
         }
     }
     return(true);
 }
示例#21
0
        private static MultiPoint projectMultiPoint(GeoMultiPoint multiPoint, GnomonicProjection projection)
        {
            MultiPoint mp = multiPoint.ToPlanarMultiPoint(false);

            for (int i = 0; i < mp.Points.Count; i++)
            {
                double x, y;
                projection.Project(mp.Points[i].Y, mp.Points[i].X, out x, out y);
                mp.Points[i] = PlanimetryEnvironment.NewCoordinate(x, y);
            }

            return(mp);
        }
        private void calcControlPointsShifts()
        {
            _controlPointsShifts = new ICoordinate[_sourceControlPoints.Length];

            for (int i = 0; i < _sourceControlPoints.Length; i++)
            {
                ICoordinate transformed =
                    PlanimetryEnvironment.NewCoordinate(_optimalAffineTransform.Transform(_sourceControlPoints[i].Values()));

                _controlPointsShifts[i] =
                    PlanimetryEnvironment.NewCoordinate(_destinationControlPoints[i].X - transformed.X,
                                                        _destinationControlPoints[i].Y - transformed.Y);
            }
        }
示例#23
0
        /// <summary>
        /// Deserializes an instance of MapAround.Geometry.MultiPoint from the specified stream.
        /// </summary>
        /// <param name="stream">A stream containing the multipoint geometry</param>
        /// <returns>Deserialized instance of MapAround.Geometry.MultiPoint</returns>
        public static MultiPoint DeserializeMultiPoint(Stream stream)
        {
            int        partLength = readInt(stream);
            MultiPoint multiPoint = new MultiPoint();

            for (int j = 0; j < partLength; j++)
            {
                double x = readDouble(stream);
                double y = readDouble(stream);
                multiPoint.Points.Add(PlanimetryEnvironment.NewCoordinate(x, y));
            }

            return(multiPoint);
        }
示例#24
0
        private static Polygon projectPolygon(GeoPolygon polygon, GnomonicProjection projection)
        {
            Polygon p = polygon.ToPlanarPolygon(false);

            foreach (Contour contour in p.Contours)
            {
                for (int i = 0; i < contour.Vertices.Count; i++)
                {
                    double x, y;
                    projection.Project(contour.Vertices[i].Y, contour.Vertices[i].X, out x, out y);
                    contour.Vertices[i] = PlanimetryEnvironment.NewCoordinate(x, y);
                }
            }

            return(p);
        }
示例#25
0
        private static Polyline projectPolyline(GeoPolyline polyline, GnomonicProjection projection)
        {
            Polyline p = polyline.ToPlanarPolyline(false);

            foreach (LinePath path in p.Paths)
            {
                for (int i = 0; i < path.Vertices.Count; i++)
                {
                    double x, y;
                    projection.Project(path.Vertices[i].Y, path.Vertices[i].X, out x, out y);
                    path.Vertices[i] = PlanimetryEnvironment.NewCoordinate(x, y);
                }
            }

            return(p);
        }
示例#26
0
        private ICoordinate getCircleCenter(ICoordinate p1, ICoordinate p2, ICoordinate p3)
        {
            if (p1.ExactEquals(p2) || p1.ExactEquals(p3) || p2.ExactEquals(p3))
            {
                return(null);
            }

            // get rid of the vertical lines
            if (p1.X == p2.X)
            {
                ICoordinate temp = p1;
                p1 = p3;
                p3 = temp;
            }

            if (p2.X == p3.X)
            {
                ICoordinate temp = p2;
                p2 = p1;
                p1 = temp;
            }

            double ma = (p2.Y - p1.Y) / (p2.X - p1.X);
            double mb = (p3.Y - p2.Y) / (p3.X - p2.X);

            // collinear lines, circles do not
            if (mb == ma || (double.IsInfinity(ma) && double.IsInfinity(mb)))
            {
                return(null);
            }

            //coordinates of the center of the circle
            double x = 0.5 * (ma * mb * (p1.Y - p3.Y) + mb * (p1.X + p2.X) - ma * (p2.X + p3.X)) / (mb - ma);

            double y = double.NaN;

            if (ma != 0 && !double.IsInfinity(ma))
            {
                y = -1 / ma * (x - 0.5 * (p1.X + p2.X)) + 0.5 * (p1.Y + p2.Y);
            }
            else
            {
                y = -1 / mb * (x - 0.5 * (p2.X + p3.X)) + 0.5 * (p2.Y + p3.Y);
            }

            return(PlanimetryEnvironment.NewCoordinate(x, y));
        }
示例#27
0
        private static ICoordinate[] getCirclePoints(ICoordinate point, double startAngle, double endAngle, double distance, int pointsPerCircle)
        {
            int n = (int)Math.Round(pointsPerCircle * (endAngle - startAngle) / _twoPi);

            ICoordinate[] result = new ICoordinate[n + 1];
            double        angle  = startAngle;
            double        da     = _twoPi / pointsPerCircle;

            for (int i = 0; i < n; i++)
            {
                result[i] = PlanimetryEnvironment.NewCoordinate(point.X + distance * Math.Cos(angle), point.Y + distance * Math.Sin(angle));
                angle    += da;
            }
            result[n] = PlanimetryEnvironment.NewCoordinate(point.X + distance * Math.Cos(endAngle), point.Y + distance * Math.Sin(endAngle));

            return(result);
        }
示例#28
0
        private static MultiPoint readMultiPoint(Stream stream, WKBByteOrder byteOrder)
        {
            MultiPoint multiPoint = new MultiPoint();

            int numPoints = (int)readUInt32(stream, byteOrder);

            for (int i = 0; i < numPoints; i++)
            {
                // порядок байтов
                stream.ReadByte();
                // тип фигуры
                readUInt32(stream, byteOrder);

                multiPoint.Points.Add(PlanimetryEnvironment.NewCoordinate(readDouble(stream, byteOrder), readDouble(stream, byteOrder)));
            }
            return(multiPoint);
        }
示例#29
0
        /// <summary>
        /// Transforms coordinates of the bounding rectangle.
        /// </summary>
        /// <param name="box">Rectangle to transform</param>
        /// <param name="transform">The transformation to apply</param>
        /// <returns>The transformed rectangle</returns>
        public static BoundingRectangle TransformBoundingRectangle(BoundingRectangle box, IMathTransform transform)
        {
            if (box == null)
            {
                return(null);
            }
            ICoordinate[] corners = new ICoordinate[4];
            corners[0] = PlanimetryEnvironment.NewCoordinate(transform.Transform(box.Min.Values()));
            corners[1] = PlanimetryEnvironment.NewCoordinate(transform.Transform(box.Max.Values()));
            corners[2] = PlanimetryEnvironment.NewCoordinate(transform.Transform(PlanimetryEnvironment.NewCoordinate(box.MinX, box.MaxY).Values()));
            corners[3] = PlanimetryEnvironment.NewCoordinate(transform.Transform(PlanimetryEnvironment.NewCoordinate(box.MaxX, box.MinY).Values()));

            BoundingRectangle result = new BoundingRectangle();

            for (int i = 0; i < 4; i++)
            {
                result.Join(corners[i]);
            }
            return(result);
        }
示例#30
0
        /// <summary>
        /// Deserializes an instance of MapAround.Geometry.Polygon from the specified stream.
        /// </summary>
        /// <param name="stream">A stream containing the polygon geometry</param>
        /// <returns>Deserialized instance of MapAround.Geometry.Polygon</returns>
        public static Polygon DeserializePolygon(Stream stream)
        {
            int     contourCount = readInt(stream);
            Polygon pg           = new Polygon();

            for (int i = 0; i < contourCount; i++)
            {
                int     contourLength = readInt(stream);
                Contour c             = new Contour();
                for (int j = 0; j < contourLength; j++)
                {
                    double x = readDouble(stream);
                    double y = readDouble(stream);
                    c.Vertices.Add(PlanimetryEnvironment.NewCoordinate(x, y));
                }
                pg.Contours.Add(c);
            }

            return(pg);
        }