Exemple #1
0
        /// <summary>
        /// Gets a boolean that is true if the Esri WKT string created by the projections matches.
        ///   There are multiple ways to write the same projection, but the output Esri WKT string
        ///   should be a good indicator of whether or not they are the same.
        /// </summary>
        /// <param name="other">
        /// The other projection to compare with.
        /// </param>
        /// <returns>
        /// Boolean, true if the projections are the same.
        /// </returns>
        public bool Equals(ProjectionInfo other)
        {
            if (other == null)
            {
                return(false);
            }

            return(ToEsriString().Equals(other.ToEsriString()) || ToProj4String().Equals(other.ToProj4String()));
        }
        public override void Reproject(ProjectionInfo targetProjection)
        {
            var ctFac = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
            var csFac = new ProjNet.CoordinateSystems.CoordinateSystemFactory();

            var csTarget = csFac.CreateFromWkt(targetProjection.ToEsriString());

            foreach (var layer in EnumerateLayers(_map))
            {
                var lLayer = layer as SharpMap.Layers.Layer;
                if (lLayer == null) continue;

                GeoAPI.CoordinateSystems.ICoordinateSystem csSource = null;
                if (lLayer.CoordinateTransformation != null)
                {
                    csSource = lLayer.CoordinateTransformation.SourceCS;
                }
                if (!string.IsNullOrEmpty(layer.Proj4Projection))
                {
                    csSource = csFac.CreateFromWkt(ProjectionInfo.FromProj4String(layer.Proj4Projection).ToEsriString());
                }
                else if (layer.SRID != 0)
                {
                    csSource = csFac.CreateFromWkt(ProjectionInfo.FromEpsgCode(layer.SRID).ToEsriString());
                }
                var ctF = ctFac.CreateFromCoordinateSystems(csSource, csTarget);
                var ctR = ctFac.CreateFromCoordinateSystems(csTarget, csSource);

                lLayer.CoordinateTransformation = ctF;
                lLayer.ReverseCoordinateTransformation = ctR;

            }
            
            throw new InvalidOperationException("Cannot Setup CoordinateTransformation as long as ProjectionInfo does not maintain SRID values.");
        }
        /// <summary>
        /// Gets a boolean that is true if the Esri WKT string created by the projections matches.
        ///   There are multiple ways to write the same projection, but the output Esri WKT string
        ///   should be a good indicator of whether or not they are the same.
        /// </summary>
        /// <param name="other">
        /// The other projection to compare with.
        /// </param>
        /// <returns>
        /// Boolean, true if the projections are the same.
        /// </returns>
        public bool Equals(ProjectionInfo other)
        {
            if (other == null)
            {
                return false;
            }

            return ToEsriString().Equals(other.ToEsriString()) || ToProj4String().Equals(other.ToProj4String());
        }