Esempio n. 1
0
        public WktItem GetWktItem(string name)
        {
            WktItem item = null;

            GetWktItem(name, this, ref item);
            return(item);
        }
Esempio n. 2
0
 public GeographicCoordSystem(WktItem wktItem)
 {
     _name              = wktItem.Value.Split(',')[0].Replace("\"", string.Empty);
     _angularUnit       = new AngularUnit(wktItem.GetWktItem("UNIT"));
     _primeMeridian     = new PrimeMeridian(wktItem.GetWktItem("PRIMEM"));
     _datum             = new Datum(wktItem.GetWktItem("DATUM"));
     _oracleSpatialSRID = int.MinValue;
 }
Esempio n. 3
0
 private void GetWktItem(string name, WktItem beginWktItem, List <WktItem> items)
 {
     if (beginWktItem.Name.ToUpper() == name.ToUpper())
     {
         items.Add(beginWktItem);
     }
     if (beginWktItem.Items.Count > 0)
     {
         foreach (WktItem it in beginWktItem.Items)
         {
             GetWktItem(name, it, items);
         }
     }
 }
Esempio n. 4
0
 //SPHEROID["WGS_1984",6378137.0,298.257223563]
 public Spheroid(WktItem wktItem)
 {
     string[] vs = wktItem.Value.Split(',');
     Name          = vs[0].Replace("\"", string.Empty);
     SemimajorAxis = double.Parse(vs[1]);
     if (vs.Length == 3 || (vs.Length == 4 && vs[3] == string.Empty))
     {
         InverseFlattening = double.Parse(vs[2]);
     }
     else if (vs.Length == 4)
     {
         InverseFlattening = double.Parse(vs[3]);
     }
 }
Esempio n. 5
0
 private void GetWktItem(string name, WktItem beginWktItem, ref WktItem item)
 {
     if (beginWktItem.Name.ToUpper() == name.ToUpper())
     {
         item = beginWktItem;
         return;
     }
     if (beginWktItem.Items.Count > 0)
     {
         foreach (WktItem it in beginWktItem.Items)
         {
             GetWktItem(name, it, ref item);
         }
     }
 }
Esempio n. 6
0
        private NameMapItem GetPrjName(WktItem wktItem)
        {
            using (OGCWkt2Proj4Mapper map = new OGCWkt2Proj4Mapper())
            {
                string prjName = wktItem.Value.Split(',')[0].Replace("\"", string.Empty);
                switch (_wktSource)
                {
                case enumWKTSource.EsriPrjFile:
                    return(map.GetPrjNameFromEsriName(prjName));

                case enumWKTSource.GDAL:
                    return(map.GetPrjNameFromWKTName(prjName));

                default:
                    return(map.GetPrjNameFromWKTName(prjName));
                }
            }
        }
Esempio n. 7
0
        public WktItem Split(string wkt)
        {
            Stack <char>   stack    = new Stack <char>();
            List <WktItem> subitems = new List <WktItem>();
            bool           hasLeft  = false;

            for (int i = 0; i < wkt.Length; i++)
            {
                stack.Push(wkt[i]);
                if (wkt[i] == ']')
                {
                    string str      = null;
                    bool   passLeft = false;
                    do
                    {
                        char c = stack.Pop();
                        if (c == '[')
                        {
                            passLeft = true;
                        }
                        str = c + str;
                    }while (!(stack.Count == 0 || (passLeft && stack.Peek() == ',')));
                    //
                    WktItem it = new WktItem(str);
                    if (!hasLeft)
                    {
                        it.Items.AddRange(subitems);
                        subitems.Clear();
                    }
                    subitems.Add(it);
                    hasLeft = false;
                }
                else if (wkt[i] == '[')
                {
                    hasLeft = true;
                }
            }
            if (subitems.Count == 0)
            {
                return(null);
            }
            return(subitems[0]);
        }
Esempio n. 8
0
        /*
         * PROJECTION["Mercator"],
         * PARAMETER["False_Easting",0.0],
         * PARAMETER["False_Northing",0.0],
         * PARAMETER["Central_Meridian",0.0],
         * PARAMETER["Standard_Parallel_1",0.0],
         * UNIT["Meter",1.0]
         */
        protected override IProjectionCoordSystem ParseProjectionCoordSystem(WktItem wktItem)
        {
            if (wktItem == null)//Is Graphics Coordinate System
            {
                return(null);
            }
            string      name    = wktItem.Value.Split(',')[0].Replace("\"", string.Empty);
            NameMapItem prjName = GetPrjName(wktItem.GetWktItem("PROJECTION"));  //5ms

            if (prjName == null)
            {
                throw new Exception("投影坐标系统\"" + name + "\"没有在系统中预先配置。");
            }
            NameValuePair[]       parameters = GetPrjParameters(wktItem.GetWktItems("PARAMETER"));
            AngularUnit           unit       = new AngularUnit(wktItem.GetWktItem("UNIT"));
            ProjectionCoordSystem prj        = new ProjectionCoordSystem(prjName, parameters, unit);

            prj.NameDes = name;
            return(prj);
        }
Esempio n. 9
0
        public ISpatialReference Parse(string wkt)
        {
            _rootWktItem = new WktSpliter().Split(wkt);  //2ms
            if (_rootWktItem == null)
            {
                return(null);
            }
            bool isPrj = IsProjectionCoordSystem();
            bool isGeo = IsGeographicCoordSystem();

            if (!isPrj && !isGeo)
            {
                throw new Exception("本系统只支持地理坐标系统与投影坐标系统,坐标系统\"" + _rootWktItem.Name + "\"不受支持。");
            }
            IGeographicCoordSystem _geoCoordSystem = null;
            IProjectionCoordSystem _prjCoordSystem = null;

            _geoCoordSystem = ParseGeoCoordSystem(_rootWktItem.GetWktItem(cstGeoCoordSystem));
            _prjCoordSystem = ParseProjectionCoordSystem(_rootWktItem.GetWktItem(cstPrjCoordSystem));  //8ms
            return(new SpatialReference(_geoCoordSystem, _prjCoordSystem));
        }
Esempio n. 10
0
        private NameValuePair[] GetPrjParameters(WktItem[] wktItems)
        {
            List <NameValuePair> values = new List <NameValuePair>();

            using (OGCWkt2Proj4Mapper map = new OGCWkt2Proj4Mapper())
            {
                for (int i = 0; i < wktItems.Length; i++)
                {
                    NameMapItem name   = null;
                    WktItem     witem  = wktItems[i];
                    string[]    vs     = witem.Value.Split(',');
                    string      pname  = vs[0].Replace("\"", string.Empty);
                    double      pvalue = double.Parse(vs[1]);
                    try
                    {
                        switch (_wktSource)
                        {
                        case enumWKTSource.EsriPrjFile:
                            name = map.GetParameterFromEsriName(pname);
                            break;

                        case enumWKTSource.GDAL:
                            name = map.GetParameterFromWKTName(pname);
                            break;

                        default:
                            name = map.GetParameterFromWKTName(pname);
                            break;
                        }
                        if (name != null)
                        {
                            values.Add(new NameValuePair(name, pvalue));
                        }
                    }
                    catch { continue; }
                }
            }
            return(values.Count > 0 ? values.ToArray() : null);
        }
Esempio n. 11
0
 public void Add(WktItem it)
 {
     Items.Add(it);
 }
Esempio n. 12
0
 //DATUM["D_WGS_1984",
 //             SPHEROID["WGS_1984",6378137.0,298.257223563]
 //            ]
 public Datum(WktItem wktItem)
 {
     Spheroid = new Spheroid(wktItem.GetWktItem("SPHEROID"));
     Name     = (wktItem.Value.Split(',')[0]).Replace("\"", string.Empty);
 }
Esempio n. 13
0
 //UNIT["Degree",0.0174532925199433]
 public AngularUnit(WktItem wktItem)
 {
     string[] vs = wktItem.Value.Split(',');
     Name  = vs[0].Replace("\"", string.Empty);
     Value = double.Parse(vs[1]);
 }
Esempio n. 14
0
 //PRIMEM["Greenwich",0.0]
 public PrimeMeridian(WktItem wktItem)
 {
     string[] vs = wktItem.Value.Split(',');
     Name  = vs[0].Replace("\"", string.Empty);
     Value = double.Parse(vs[1]);
 }
Esempio n. 15
0
 protected IGeographicCoordSystem ParseGeoCoordSystem(WktItem wktItem)
 {
     return(new GeographicCoordSystem(wktItem));
 }
Esempio n. 16
0
 protected abstract IProjectionCoordSystem ParseProjectionCoordSystem(WktItem wktItem);