예제 #1
0
        public void TestAxisOrder()
        {
            if (!File.Exists(EpsgAccessDatabase))
            {
                throw new IgnoreException("Epsg Access Database not found");
            }

            var unusual = new HashSet <int>();

            using (var cn = new System.Data.OleDb.OleDbConnection(
                       //$"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={EpsgAccessDatabase};"
                       $"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={EpsgAccessDatabase};"))
            {
                cn.Open();
                var cmd = cn.CreateCommand();
                cmd.CommandText = Sql;
                using (var dr = cmd.ExecuteReader())
                {
                    if (dr != null)
                    {
                        while (dr.Read())
                        {
                            var code = dr.GetInt32(0);
                            if (code > 32767)
                            {
                                continue;
                            }
                            unusual.Add(code);
                        }
                    }
                }
            }
            var crsAxisOrderRegistry = new CrsAxisOrderRegistry();

            /*
             * foreach (var code in unusual)
             * {
             *  CrsIdentifier crs;
             *  if (CrsIdentifier.TryParse("urn:ogc:def:crs:EPSG::" + code, out crs))
             *      Assert.AreEqual(1, crsAOR[crs][0]);
             * }*/

            for (var code = 1; code < 32768; code++)
            {
                CrsIdentifier crs;
                if (CrsIdentifier.TryParse("urn:ogc:def:crs:EPSG::" + code, out crs))
                {
                    var expected = unusual.Contains(code) ? 1 : 0;
                    Assert.AreEqual(expected, crsAxisOrderRegistry[crs][0]);
                }
            }
        }
        public void TestEpsgCodeUom()
        {
            if (!File.Exists(EpsgAccessDatabase))
            {
                throw new IgnoreException("Epsg Access Database not found");
            }

            var connectionString = $"Provider=Microsoft.Jet.OLEDB.4.0; Data Source={EpsgAccessDatabase};";

            using (var connection = new System.Data.OleDb.OleDbConnection(connectionString))
            {
                connection.Open();
                var cmd = connection.CreateCommand();
                cmd.CommandText = SqlEpsgToUom;
                var uomr = new CrsUnitOfMeasureRegistry();
                using (var dr = cmd.ExecuteReader())
                {
                    if (dr != null)
                    {
                        while (dr.Read())
                        {
                            if ((int)dr[0] > 32768)
                            {
                                break;
                            }

                            CrsIdentifier crs;
                            if (CrsIdentifier.TryParse(string.Format("urn:ogc:def:crs:EPSG::{0}", dr.GetInt32(0)), out crs))
                            {
                                var uom = new UnitOfMeasure();
                                Assert.DoesNotThrow(() => uom = uomr[crs], "Getting unit of measure failed for {0}", crs);

                                var uomCode = dr.GetInt32(1);
                                if (uomCode == 9001 || uomCode == 1024)
                                {
                                    Assert.AreEqual(1d, uom.ToMeter, "Unit of measure ToMeter is not 1d: {0}", crs);
                                }
                                else
                                {
                                    Assert.AreNotEqual(1d, uom.ToMeter, "Unit of measure ToMeter should not be 1d: {0}", crs);
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #3
0
            public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
            {
                var ts = (WmtsTileSchema)obj;

                ts.Name = info.GetString("name");
                ts.Srs  = info.GetString("srs");
                var extentRef = (ExtentSurrogate.ExtentRef)info.GetValue("extent", typeof(ExtentSurrogate.ExtentRef));

                ts.Extent = (Extent)((IObjectReference)extentRef).GetRealObject(context);
                ts.Format = info.GetString("format");

                var type  = (Type)info.GetValue("resolutionsType", typeof(Type));
                var list  = (IDictionary <string, Resolution>)Activator.CreateInstance(type);
                var count = info.GetInt32("resolutionsCount");

                for (var i = 0; i < count; i++)
                {
                    var key      = info.GetString(string.Format("rk{0}", i));
                    var valueRef = (IObjectReference)
                                   info.GetValue(string.Format("rv{0}", i), typeof(ResolutionSurrogate.ResolutionRef));
                    var value = (Resolution)valueRef.GetRealObject(context);
                    list.Add(key, value);
                }
                Utility.SetPropertyValue(ref obj, "Resolutions", BindingFlags.Public | BindingFlags.Instance, list);

                ts.YAxis = (YAxis)info.GetInt32("axis");

                //Utility.SetPropertyValue(ref obj, "Identifier", BindingFlags.Instance | BindingFlags.Public, info.GetString("identifier"));
                Utility.SetPropertyValue(ref obj, "Layer", BindingFlags.Instance | BindingFlags.Public, info.GetString("layer"));
                Utility.SetPropertyValue(ref obj, "Title", BindingFlags.Instance | BindingFlags.Public, info.GetString("title"));
                Utility.SetPropertyValue(ref obj, "Abstract", BindingFlags.Instance | BindingFlags.Public, info.GetString("abstract"));
                Utility.SetPropertyValue(ref obj, "Style", BindingFlags.Instance | BindingFlags.Public, info.GetString("style"));
                Utility.SetPropertyValue(ref obj, "TileMatrixSet", BindingFlags.Instance | BindingFlags.Public, info.GetString("tileMatrixSet"));

                CrsIdentifier tmp;

                if (CrsIdentifier.TryParse(info.GetString("supportedSRS"), out tmp))
                {
                    Utility.SetPropertyValue(ref obj, "SupportedSRS", BindingFlags.Instance | BindingFlags.Public, tmp);
                }

                return(ts);
            }