示例#1
0
        /// <summary>
        /// Gets the axis order for *all* EPSG defined coordinate reference systems with an srid less than 32768
        /// </summary>
        /// <param name="identifier">The identifier</param>
        /// <returns>The axis order</returns>
        public int[] this[CrsIdentifier identifier]
        {
            get
            {
                switch (identifier.Authority.ToUpper())
                {
                //case "OGC":
                default:
                    return(Natural);

                case "EPSG":
                    var code = int.Parse(identifier.Identifier);
                    if (code == 900913)
                    {
                        code = 3857;
                    }
                    if (code < 0)
                    {
                        throw new ArgumentException("Invalid Epsg identifier");
                    }

                    var byteIndex = code / 8;
                    var bitIndex  = code % 8;
                    var flag      = 1 << bitIndex;//1 << (7 - bitIndex);
                    return((EpsgAxisOrderBitField[byteIndex] & flag) == flag ? Geographic : Natural);
                }
            }
        }
示例#2
0
        public UnitOfMeasure this[CrsIdentifier identifier]
        {
            get
            {
                switch (identifier.Authority.ToUpper())
                {
                case "OGC":
                    if (identifier.Equals(WellKnownScaleSets.CRS84))
                    {
                        return(this[9102]);
                    }
                    return(this[9001]);

                case "EPSG":
                    return(this[SeekUom(int.Parse(identifier.Identifier))]);
                }
                throw new ArgumentException("identifier");
            }
        }
        /// <summary>
        /// Gets the axis order for *all* EPSG defined coordinate reference systems with an srid less than 32768
        /// </summary>
        /// <param name="identifier">The identifier</param>
        /// <returns>The axis order</returns>
        public int[] this[CrsIdentifier identifier]
        {
            get
            {
                const int
                    maxSrid = 32767; // PDD: I don't know where this number comes from. I based it on the comment below.

                switch (identifier.Authority.ToUpper())
                {
                //case "OGC":
                default:
                    return(Natural);

                case "EPSG":
                    var code = int.Parse(identifier.Identifier);
                    if (code == 900913)
                    {
                        code = 3857;
                    }
                    if (code < 0)
                    {
                        throw new ArgumentException("Invalid Epsg identifier");
                    }
                    if (code > maxSrid)
                    {
                        return(Natural);    // Default to Natural because this is the most common case.
                    }
                    else
                    {
                        var byteIndex = code / 8;
                        var bitIndex  = code % 8;
                        var flag      = 1 << bitIndex; //1 << (7 - bitIndex);
                        return((EpsgAxisOrderBitField[byteIndex] & flag) == flag ? Geographic : Natural);
                    }
                }
            }
        }
示例#4
0
 /// <summary>
 /// Creates an instance for this class
 /// </summary>
 /// <param name="name"></param>
 /// <param name="crs"></param>
 /// <param name="items"></param>
 public ScaleSet(string name, CrsIdentifier crs, IEnumerable <ScaleSetItem> items)
 {
     Name   = name;
     Crs    = crs;
     _items = items.ToArray();
 }
示例#5
0
        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);
        }