コード例 #1
0
ファイル: WmtsParser.cs プロジェクト: bertt/BruTile
        private static List<ITileSchema> GetTileMatrixSets(IEnumerable<TileMatrixSet> tileMatrixSets)
        {
            // Get a set of well known scale sets. For these we don't need to have
            var wkss = new WellKnownScaleSets();

            // Axis order registry
            var crsAxisOrder = new CrsAxisOrderRegistry();
            // Unit of measure registry
            var crsUnitOfMeasure = new CrsUnitOfMeasureRegistry();

            var tileSchemas = new List<ITileSchema>();
            foreach (var tileMatrixSet in tileMatrixSets)
            {
                // Check if a Well-Known scale set is used, either by Identifier or WellKnownScaleSet property
                var ss = wkss[tileMatrixSet.Identifier.Value];
                if (ss == null && !string.IsNullOrEmpty(tileMatrixSet.WellKnownScaleSet))
                    ss = wkss[tileMatrixSet.WellKnownScaleSet.Split(':').Last()];

                // Try to parse the Crs
                var supportedCrs = tileMatrixSet.SupportedCRS;

                // Hack to fix broken crs spec
                supportedCrs = supportedCrs.Replace("6.18:3", "6.18.3");

                CrsIdentifier crs;
                if (!CrsIdentifier.TryParse(supportedCrs, out crs))
                {
                    // If we cannot parse the crs, we cannot compute tile schema, thus ignore.
                    // ToDo: Log this
                    continue;
                }

                // Get the ordinate order for the crs (x, y) or (y, x) aka (lat, long)
                var ordinateOrder = crsAxisOrder[crs];
                // Get the unit of measure for the crs
                var unitOfMeasure = crsUnitOfMeasure[crs];

                // Create a new WMTS tile schema
                var tileSchema = new WmtsTileSchema();

                // Add the resolutions
                foreach (var tileMatrix in tileMatrixSet.TileMatrix)
                {
                    tileSchema.Resolutions.Add(ToResolution(tileMatrix, ordinateOrder, unitOfMeasure.ToMeter, ss));
                }

                tileSchema.Extent = ToExtent(tileMatrixSet, tileSchema, ordinateOrder);

                // Fill in the remaining properties
                tileSchema.Name = tileMatrixSet.Identifier.Value;
                tileSchema.YAxis = YAxis.OSM;
                tileSchema.Srs = supportedCrs;
                tileSchema.SupportedSRS = crs;

                // record the tile schema
                tileSchemas.Add(tileSchema);
            }
            return tileSchemas;
        }
コード例 #2
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(
                string.Format("Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0};", 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 crsAOR = 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, crsAOR[crs][0]);
                }
            }
        }
コード例 #3
0
ファイル: WmtsParser.cs プロジェクト: wclwksn/BruTile
        private static List <ITileSchema> GetTileMatrixSets(IEnumerable <TileMatrixSet> tileMatrixSets,
                                                            BoundingBoxAxisOrderInterpretation bbaoi)
        {
            // Get a set of well known scale sets. For these we don't need to have
            var wkss = new WellKnownScaleSets();

            // Axis order registry
            var crsAxisOrder = new CrsAxisOrderRegistry();
            // Unit of measure registry
            var crsUnitOfMeasure = new CrsUnitOfMeasureRegistry();

            var tileSchemas = new List <ITileSchema>();

            foreach (var tileMatrixSet in tileMatrixSets)
            {
                // Check if a Well-Known scale set is used, either by Identifier or WellKnownScaleSet property
                var ss = wkss[tileMatrixSet.Identifier.Value];
                if (ss == null && !string.IsNullOrEmpty(tileMatrixSet.WellKnownScaleSet))
                {
                    ss = wkss[tileMatrixSet.WellKnownScaleSet.Split(':').Last()];
                }

                // Try to parse the Crs
                var supportedCrs = tileMatrixSet.SupportedCRS;

                // Hack to fix broken crs spec
                supportedCrs = supportedCrs.Replace("6.18:3", "6.18.3");

                CrsIdentifier crs;
                if (!CrsIdentifier.TryParse(supportedCrs, out crs))
                {
                    // If we cannot parse the crs, we cannot compute tile schema, thus ignore.
                    // ToDo: Log this
                    continue;
                }

                // Get the ordinate order for the crs (x, y) or (y, x) aka (lat, long)
                var ordinateOrder = crsAxisOrder[crs];
                // Get the unit of measure for the crs
                var unitOfMeasure = crsUnitOfMeasure[crs];

                // Create a new WMTS tile schema
                var tileSchema = new WmtsTileSchema();

                // Add the resolutions
                foreach (var tileMatrix in tileMatrixSet.TileMatrix)
                {
                    tileSchema.Resolutions.Add(ToResolution(tileMatrix, ordinateOrder, unitOfMeasure.ToMeter, ss));
                }

                tileSchema.Extent = ToExtent(tileMatrixSet, tileSchema, GetOrdinateOrder(bbaoi, ordinateOrder));

                // Fill in the remaining properties
                tileSchema.Name         = tileMatrixSet.Identifier.Value;
                tileSchema.YAxis        = YAxis.OSM;
                tileSchema.Srs          = supportedCrs;
                tileSchema.SupportedSRS = crs;

                // record the tile schema
                tileSchemas.Add(tileSchema);
            }
            return(tileSchemas);
        }