예제 #1
0
        /// <summary>
        /// Reprojects a <see cref="Extent"/>.
        /// </summary>
        /// <param name="extent">The object to be reprojected.</param>
        /// <param name="source">The coordinate system corresponding to <paramref name="extent"/>.</param>
        /// <param name="target">The target coordinate system.</param>
        /// <returns>The reprojected <see cref="Extent"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when any input argument is <c>null</c>.</exception>
        public static Extent Reproject(this Extent extent, ProjectionInfo source, ProjectionInfo target)
        {
            if (extent == null)
            {
                throw new ArgumentNullException(nameof(extent));
            }

            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            if (target.Transform == null)
            {
                return(extent);
            }

            double[] xy = ToSequence(extent);
            DotSpatialReproject.ReprojectPoints(xy, null, source, target, 0, xy.Length / 2);
            return(ToExtent(xy));
        }
예제 #2
0
        private IEnumerable <Tuple <Point, Point> > GetValidPoints(int y, int offsetY, int x1, int x2,
                                                                   WorldFile sourceReference, Size sourceTileSize)
        {
            int len = x2 - x1;
            var xy  = new double[len * 2];
            var i   = 0;

            for (int x = x1; x < x2; x++)
            {
                Coordinate c = mapArgs.PixelToProj(new Point(x, y));
                xy[i]     = c.X;
                xy[i + 1] = c.Y;
                i         = i + 2;
            }

            DotSpatialReproject.ReprojectPoints(xy, null, target, source, 0, len);

            i  = 0;
            y -= offsetY;
            for (var x = 0; x < len; x++)
            {
                var   coord = new Coordinate(xy[i++], xy[i++]);
                Point sourcePixelLocation = sourceReference.ToScreenCoordinates(coord);

                if (IsSourcePointInsideArea(sourceTileSize, sourcePixelLocation))
                {
                    yield return(Tuple.Create(sourcePixelLocation, new Point(x, y)));
                }
            }
        }
예제 #3
0
        private static Coordinate[] Reproject(this Coordinate[] coordinates, ProjectionInfo source, ProjectionInfo target)
        {
            if (target.Transform == null)
            {
                return(coordinates);
            }

            var xy = new double[coordinates.Length * 2];
            var z  = new double[coordinates.Length];
            var j  = 0;

            for (var i = 0; i < coordinates.Length; i++)
            {
                Coordinate c = coordinates[i];
                xy[j]     = c.X;
                xy[j + 1] = c.Y;
                j         = j + 2;
                z[i]      = double.IsNaN(c.Z) ? 0 : c.Z;
            }

            DotSpatialReproject.ReprojectPoints(xy, z, source, target, 0, coordinates.Length);

            var result = new List <Coordinate>(coordinates.Length);

            j = 0;
            for (var i = 0; i < coordinates.Length; i++)
            {
                result.Add(new Coordinate(xy[j++], xy[j++]));
            }

            return(result.ToArray());
        }
예제 #4
0
        private static ICoordinateSequence TransformSequence(ICoordinateSequence sequence, ProjectionInfo from, ProjectionInfo to, ICoordinateSequenceFactory factory)
        {
            var res = factory.Create(sequence.Count, sequence.Ordinates);

            double[] z;
            double[] ordinates;
            if (sequence is NetTopologySuite.Geometries.Implementation.DotSpatialAffineCoordinateSequence)
            {
                var dss = (NetTopologySuite.Geometries.Implementation.DotSpatialAffineCoordinateSequence)sequence;
                z         = (double[])dss.Z.Clone();
                ordinates = (double[])dss.XY.Clone();
            }
            else
            {
                ordinates = ToDoubleArray(sequence, out z);
            }

            Reproject.ReprojectPoints(ordinates, z, from, to, 0, sequence.Count);

            if (res is NetTopologySuite.Geometries.Implementation.DotSpatialAffineCoordinateSequence)
            {
                var dss = (NetTopologySuite.Geometries.Implementation.DotSpatialAffineCoordinateSequence)res;
                Array.Copy(ordinates, dss.XY, ordinates.Length);
                if (z != null)
                {
                    Array.Copy(z, dss.Z, z.Length);
                }
            }
            else
            {
                var j = 0;
                for (var i = 0; i < sequence.Count; i++)
                {
                    res.SetOrdinate(i, Ordinate.X, ordinates[j++]);
                    res.SetOrdinate(i, Ordinate.Y, ordinates[j++]);
                    if (z != null)
                    {
                        res.SetOrdinate(i, Ordinate.Z, z[i]);
                    }
                }
            }
            return(res);
        }