Exemplo n.º 1
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
                )
            );
        }
Exemplo n.º 2
0
        private void OnCreatingCoordinateSystem(CreatingCoordinateSystemEventArgs e)
        {
            var eh = CreatingCoordinateSystem;

            if (eh != null)
            {
                eh(this, e);
            }
        }
Exemplo n.º 3
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
                          )
                      );
        }
Exemplo n.º 4
0
 private void OnCreatingCoordinateSystem(CreatingCoordinateSystemEventArgs e)
 {
     var eh=CreatingCoordinateSystem;
     if (eh!=null)
         eh(this, e);
 }
Exemplo n.º 5
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
                          )
                      );
        }
Exemplo n.º 6
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
                )
            );
        }