예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="TGeometry"></typeparam>
        /// <param name="geometry"></param>
        /// <param name="toSrid"></param>
        /// <returns></returns>
        public static TGeometry Reproject <TGeometry>(this TGeometry geometry, SridItem toSrid)
            where TGeometry : Geometry
        {
            if (geometry == null)
            {
                return(null);
            }

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

            int srcSRID = geometry.SRID;

            if (srcSRID == 0)
            {
                throw new ArgumentOutOfRangeException(nameof(geometry), "Geometry doesn't have valid srid");
            }

            SridItem srcItem = SridRegister.GetByValue(srcSRID);

            using (ProjContext pc = toSrid.CRS.Context.Clone()) // Make thread-safe. Use settings from crs
                using (CoordinateTransform ct = CoordinateTransform.Create(srcItem, toSrid, pc))
                {
                    return(Reproject(geometry, ct, toSrid.Factory));
                }
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="TGeometry"></typeparam>
        /// <param name="geometry"></param>
        /// <param name="toSRID"></param>
        /// <returns></returns>
        public static TGeometry Reproject <TGeometry>(this TGeometry geometry, int toSRID)
            where TGeometry : Geometry
        {
            if (geometry == null)
            {
                return(null);
            }

            SridItem toSridItem = SridRegister.GetByValue(toSRID);

            return(Reproject(geometry, toSridItem));
        }