예제 #1
0
 /// <summary>Creates the coordinate system from the specified WKT representation.</summary>
 /// <param name="text">The WKT representation of the coordinate system to create.</param>
 /// <param name="id">The identifier of the coordinate system to get.</param>
 /// <returns>The coordinate system.</returns>
 public ICoordinateSystem CreateFromWkt(string text, Srid id)
 {
     var ret=new CoordinateSystem(DsProjections.ProjectionInfo.FromEsriString(text));
     // DotSpatial does not fill this field automatically
     ret.Projection.AuthorityCode=id.Value;
     return ret;
 }
예제 #2
0
        /// <summary>Gets the coordinate system with the specified <paramref name="id" />.</summary>
        /// <param name="id">The identifier of the coordinate system to get.</param>
        /// <returns>The coordinate system with the specified <paramref name="id" />.</returns>
        public CoordinateSystem GetById(Srid id)
        {
            // WGS84 by default
            if (id.Value==0)
                return Wgs84;

            CoordinateSystem ret=null;

            var args=new CreatingCoordinateSystemEventArgs(id);
            OnCreatingCoordinateSystem(args);

            if (args.CoordinateSystem!=null)
                ret=(CoordinateSystem)args.CoordinateSystem;
            else if (!string.IsNullOrEmpty(args.WellKnownText))
                ret=new CoordinateSystem(DsProjections.ProjectionInfo.FromEsriString(args.WellKnownText));

            if (ret!=null)
            {
                // DotSpatial does not fill this field automatically
                if (ret.Projection.AuthorityCode==0)
                    ret.Projection.AuthorityCode=id.Value;
                OnCreatedCoordinateSystem(new CreatedCoordinateSystemEventArgs(id, ret));
                return ret;
            }

            throw new InvalidOperationException(
                string.Format(
                    CultureInfo.CurrentCulture,
                    SR.CouldNotFindCoordinateSystemDefinitionException,
                    id.Value
                )
            );
        }
예제 #3
0
        /// <summary>Creates the coordinate system from the specified WKT representation.</summary>
        /// <param name="text">The WKT representation of the coordinate system to create.</param>
        /// <param name="id">The identifier of the coordinate system to get.</param>
        /// <returns>The coordinate system.</returns>
        public ICoordinateSystem CreateFromWkt(string text, Srid id)
        {
            var ret = new CoordinateSystem(DsProjections.ProjectionInfo.FromEsriString(text));

            // DotSpatial does not fill this field automatically
            ret.Projection.AuthorityCode = id.Value;
            return(ret);
        }
예제 #4
0
        /// <summary>Gets the coordinate system with the specified <paramref name="id" />.</summary>
        /// <param name="id">The identifier of the coordinate system to get.</param>
        /// <returns>The coordinate system with the specified <paramref name="id" />.</returns>
        public CoordinateSystem GetById(Srid id)
        {
            // WGS84 by default
            if (id.Value == 0)
            {
                return(Wgs84);
            }

            CoordinateSystem ret = null;

            var args = new CreatingCoordinateSystemEventArgs(id);

            OnCreatingCoordinateSystem(args);

            if (args.CoordinateSystem != null)
            {
                ret = (CoordinateSystem)args.CoordinateSystem;
            }
            else if (!string.IsNullOrEmpty(args.WellKnownText))
            {
                ret = new CoordinateSystem(DsProjections.ProjectionInfo.FromEsriString(args.WellKnownText));
            }

            if (ret != null)
            {
                // DotSpatial does not fill this field automatically
                if (ret.Projection.AuthorityCode == 0)
                {
                    ret.Projection.AuthorityCode = id.Value;
                }
                OnCreatedCoordinateSystem(new CreatedCoordinateSystemEventArgs(id, ret));
                return(ret);
            }

            throw new InvalidOperationException(
                      string.Format(
                          CultureInfo.CurrentCulture,
                          SR.CouldNotFindCoordinateSystemDefinitionException,
                          id.Value
                          )
                      );
        }
예제 #5
0
 ICoordinateSystem ICoordinateSystemProvider.GetById(Srid id)
 {
     return(GetById(id));
 }
예제 #6
0
 ICoordinateSystem ICoordinateSystemProvider.GetById(Srid id)
 {
     return GetById(id);
 }
예제 #7
0
        /// <summary>Gets the coordinate system with the specified <paramref name="id" />.</summary>
        /// <param name="id">The identifier of the coordinate system to get.</param>
        /// <returns>The coordinate system with the specified <paramref name="id" />.</returns>
        public CoordinateSystem GetById(Srid id)
        {
            // WGS84 by default
            if (id.Value == 0)
            {
                return(Wgs84);
            }

            CoordinateSystem ret = null;

            // Try custom implementation
            var args = new CreatingCoordinateSystemEventArgs(id);

            OnCreatingCoordinateSystem(args);

            if (args.CoordinateSystem != null)
            {
                ret = (CoordinateSystem)args.CoordinateSystem;
            }
            else if (!string.IsNullOrEmpty(args.WellKnownText))
            {
                ret = new CoordinateSystem(_CoordinateSystemFactory.CreateFromWkt(args.WellKnownText));
            }

            if (ret == null)
            {
                // Has the id already been used ?
                if (_WktDictionary.ContainsKey(id))
                {
                    ret = new CoordinateSystem(_CoordinateSystemFactory.CreateFromWkt(_WktDictionary[id]));
                }
            }

            if (ret == null)
            {
                // Load resources in memory
                if (!_InternalRead)
                {
                    using (StreamReader sr = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("GeoSik.ProjNet.Srid.csv")))
                        while (!sr.EndOfStream)
                        {
                            string[] def = sr.ReadLine().Split(new char[] { ';' }, 2);
                            if (def.Length > 1)
                            {
                                Srid srid = new Srid(int.Parse(def[0], CultureInfo.InvariantCulture));
                                if (!_WktDictionary.ContainsKey(srid))
                                {
                                    _WktDictionary.Add(srid, def[1]);
                                }
                            }
                        }
                    _InternalRead = true;

                    if (_WktDictionary.ContainsKey(id))
                    {
                        ret = new CoordinateSystem(_CoordinateSystemFactory.CreateFromWkt(_WktDictionary[id]));
                    }
                }
            }

            if (ret != null)
            {
                OnCreatedCoordinateSystem(new CreatedCoordinateSystemEventArgs(id, ret));
                return(ret);
            }

            throw new InvalidOperationException(
                      string.Format(
                          CultureInfo.CurrentCulture,
                          SR.CouldNotFindCoordinateSystemDefinitionException,
                          id.Value
                          )
                      );
        }
예제 #8
0
        /// <summary>Gets the coordinate system with the specified <paramref name="id" />.</summary>
        /// <param name="id">The identifier of the coordinate system to get.</param>
        /// <returns>The coordinate system with the specified <paramref name="id" />.</returns>
        public CoordinateSystem GetById(Srid id)
        {
            // WGS84 by default
            if (id.Value==0)
                return Wgs84;

            CoordinateSystem ret=null;

            // Try custom implementation
            var args=new CreatingCoordinateSystemEventArgs(id);
            OnCreatingCoordinateSystem(args);

            if (args.CoordinateSystem!=null)
                ret=(CoordinateSystem)args.CoordinateSystem;
            else if (!string.IsNullOrEmpty(args.WellKnownText))
                ret=new CoordinateSystem(_CoordinateSystemFactory.CreateFromWkt(args.WellKnownText));

            if (ret==null)
            {
                // Has the id already been used ?
                if (_WktDictionary.ContainsKey(id))
                    ret=new CoordinateSystem(_CoordinateSystemFactory.CreateFromWkt(_WktDictionary[id]));
            }

            if (ret==null)
            {
                // Load resources in memory
                if (!_InternalRead)
                {
                    using (StreamReader sr=new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("GeoSik.ProjNet.Srid.csv")))
                        while (!sr.EndOfStream)
                        {
                            string[] def=sr.ReadLine().Split(new char[] { ';' }, 2);
                            if (def.Length>1)
                            {
                                Srid srid=new Srid(int.Parse(def[0], CultureInfo.InvariantCulture));
                                if (!_WktDictionary.ContainsKey(srid))
                                    _WktDictionary.Add(srid, def[1]);
                            }
                        }
                    _InternalRead=true;

                    if (_WktDictionary.ContainsKey(id))
                        ret=new CoordinateSystem(_CoordinateSystemFactory.CreateFromWkt(_WktDictionary[id]));
                }
            }

            if (ret!=null)
            {
                OnCreatedCoordinateSystem(new CreatedCoordinateSystemEventArgs(id, ret));
                return ret;
            }

            throw new InvalidOperationException(
                string.Format(
                    CultureInfo.CurrentCulture,
                    SR.CouldNotFindCoordinateSystemDefinitionException,
                    id.Value
                )
            );
        }
예제 #9
0
 /// <summary>Creates a new instance of the <see cref="CreatedCoordinateSystemEventArgs" /> class.</summary>
 /// <param name="id">The identifier of the coordinate system.</param>
 /// <param name="coordinateSystem">The coordinate system instance.</param>
 public CreatedCoordinateSystemEventArgs(Srid id, ICoordinateSystem coordinateSystem)
 {
     Id=id;
     CoordinateSystem=coordinateSystem;
 }
예제 #10
0
 /// <summary>Creates a new instance of the <see cref="CreatingCoordinateSystemEventArgs" /> class.</summary>
 /// <param name="id">The identifier of the coordinate system being created.</param>
 public CreatingCoordinateSystemEventArgs(Srid id)
 {
     Id=id;
 }