public static LayerType AddToCapabilities(Capabilities capabilities, string name, string projectionStr, double xMin, double yMin, double xMax, double yMax) { LayerType layerType = null; if (capabilities == null || capabilities == null) { return(layerType); } if (capabilities.Contents == null) { capabilities.Contents = new ContentsType(); } DatasetDescriptionSummaryBaseType[] datasets = capabilities.Contents.DatasetDescriptionSummary; if (datasets?.Any(x => x.Identifier.Value == name) == true) { return(layerType); } int layerCount = datasets == null ? 1 : datasets.Length + 1; capabilities.Contents.DatasetDescriptionSummary = new DatasetDescriptionSummaryBaseType[layerCount]; datasets?.CopyTo(capabilities.Contents.DatasetDescriptionSummary, 0); datasets = capabilities.Contents.DatasetDescriptionSummary; #region 获取layerType layerType = GetLayerType(name); string projectName = null; double semimajor; BoundingBoxType[] boundingBoxs = GetBoundingBoxTypes(xMin, yMin, xMax, yMax); WGS84BoundingBoxType[] WGS84BoundingBoxes = null; using (OSGeo.OSR.SpatialReference srcSR = new OSGeo.OSR.SpatialReference(projectionStr)) { semimajor = srcSR.GetSemiMajor(); projectName = srcSR.GetAttrValue("PROJCS", 0); using (OSGeo.OSR.SpatialReference destSR = new OSGeo.OSR.SpatialReference("")) { destSR.SetWellKnownGeogCS("EPSG:4326"); if (srcSR.IsSame(destSR) != 1) { double[] leftBottom = { xMin, yMin }; double[] topRight = { xMax, yMax }; srcSR.CoordTransform(destSR, leftBottom, topRight); xMin = leftBottom[0]; yMin = leftBottom[1]; xMax = topRight[0]; yMax = topRight[1]; } WGS84BoundingBoxes = GetWGS84BoundingBoxTypes(xMin, yMin, xMax, yMax); } } TileMatrixSetLink[] tileMatrixSetLinks = GetTileMatrixSetLinks(projectName); layerType.BoundingBox = boundingBoxs; layerType.WGS84BoundingBox = WGS84BoundingBoxes; layerType.TileMatrixSetLink = tileMatrixSetLinks; #endregion datasets[datasets.Length - 1] = layerType; #region 设置tileMatrixSet TileMatrixSet[] tileMatrixSets = capabilities.Contents.TileMatrixSet; if (tileMatrixSets?.Any(x => x.Identifier.Value == projectName) != true) { int tileMatrixSetCount = tileMatrixSets == null ? 1 : tileMatrixSets.Length + 1; capabilities.Contents.TileMatrixSet = new TileMatrixSet[tileMatrixSetCount]; tileMatrixSets?.CopyTo(capabilities.Contents.TileMatrixSet, 0); tileMatrixSets = capabilities.Contents.TileMatrixSet; int minLevel = 0; int maxLevel = 20; TileMatrix[] tileMatrices = GetTileMatrices(semimajor, xMin, yMin, xMax, yMax, minLevel, maxLevel);; TileMatrixSet tileMatrixSet = new TileMatrixSet() { Identifier = new CodeType() { Value = projectName }, SupportedCRS = "urn:ogc:def:crs:OGC:1.3:CRS84",//TODO 待修改 TileMatrix = tileMatrices }; tileMatrixSets[tileMatrixSets.Length - 1] = tileMatrixSet; } #endregion return(layerType); }
public static LayerType AddToCapabilities(Capabilities capabilities, string name, string projectionStr, double xMin, double yMin, double xMax, double yMax, int minLevel, int maxLevel) { LayerType layerType = null; if (capabilities == null || capabilities == null || minLevel < 0 || minLevel > maxLevel) { return(layerType); } if (capabilities.Contents == null) { capabilities.Contents = new ContentsType(); } DatasetDescriptionSummaryBaseType[] datasets = capabilities.Contents.DatasetDescriptionSummary; if (datasets?.Any(x => x.Identifier.Value == name) == true) { return(layerType); } int layerCount = datasets == null ? 1 : datasets.Length + 1; capabilities.Contents.DatasetDescriptionSummary = new DatasetDescriptionSummaryBaseType[layerCount]; datasets?.CopyTo(capabilities.Contents.DatasetDescriptionSummary, 0); datasets = capabilities.Contents.DatasetDescriptionSummary; #region 获取layerType layerType = CreateLayerType(name); string projcs = null; string geogcs = null; double semimajor; BoundingBoxType[] boundingBoxs = CreateBoundingBoxTypes(xMin, yMin, xMax, yMax); WGS84BoundingBoxType[] WGS84BoundingBoxes = null; using (OSGeo.OSR.SpatialReference srcSR = new OSGeo.OSR.SpatialReference(projectionStr)) { semimajor = srcSR.GetSemiMajor(); projcs = srcSR.GetAttrValue("PROJCS", 0); if (string.IsNullOrEmpty(projcs)) { geogcs = srcSR.GetAttrValue("GEOGCS", 0); } using (OSGeo.OSR.SpatialReference destSR = new OSGeo.OSR.SpatialReference("")) { destSR.SetWellKnownGeogCS("EPSG:4326"); double WGS84XMin = xMin; double WGS84YMin = yMin; double WGS84XMax = xMax; double WGS84YMax = yMax; if (srcSR.IsSame(destSR) != 1) { double[] leftBottom = { xMin, yMin }; double[] topRight = { xMax, yMax }; srcSR.CoordTransform(destSR, leftBottom, topRight); WGS84XMin = leftBottom[0]; WGS84YMin = leftBottom[1]; WGS84XMax = topRight[0]; WGS84YMax = topRight[1]; } WGS84BoundingBoxes = CreateWGS84BoundingBoxTypes(WGS84XMin, WGS84YMin, WGS84XMax, WGS84YMax); } } string tileMatrixSetName = !string.IsNullOrEmpty(projcs) ? projcs : geogcs; TileMatrixSetLink[] tileMatrixSetLinks = CreateTileMatrixSetLinks(tileMatrixSetName); layerType.BoundingBox = boundingBoxs; layerType.WGS84BoundingBox = WGS84BoundingBoxes; layerType.TileMatrixSetLink = tileMatrixSetLinks; #endregion datasets[datasets.Length - 1] = layerType; #region 设置tileMatrixSet TileMatrixSet[] tileMatrixSets = capabilities.Contents.TileMatrixSet; if (tileMatrixSets?.Any(x => x.Identifier.Value == tileMatrixSetName) != true) { int tileMatrixSetCount = tileMatrixSets == null ? 1 : tileMatrixSets.Length + 1; capabilities.Contents.TileMatrixSet = new TileMatrixSet[tileMatrixSetCount]; tileMatrixSets?.CopyTo(capabilities.Contents.TileMatrixSet, 0); tileMatrixSets = capabilities.Contents.TileMatrixSet; bool isDegree = projcs == null; TileMatrix[] tileMatrices = CreateTileMatrices(semimajor, isDegree, xMin, yMin, xMax, yMax, minLevel, maxLevel); int?wkid = null; if (!string.IsNullOrEmpty(projcs)) { wkid = SpatialReferenceHelper.GetWellKnownWkidFromProjecs(projcs); } else if (!string.IsNullOrEmpty(geogcs)) { wkid = SpatialReferenceHelper.GetWellKnownWkidFromGeogcs(geogcs); } if (wkid.HasValue) { TileMatrixSet tileMatrixSet = new TileMatrixSet() { Identifier = new CodeType() { Value = tileMatrixSetName }, SupportedCRS = $"urn:ogc:def:crs:EPSG::{wkid.Value}",//TODO 待修改 根据名称获取EPSG,网上下载arcgis的 TileMatrix = tileMatrices }; tileMatrixSets[tileMatrixSets.Length - 1] = tileMatrixSet; } } #endregion return(layerType); }