Ejemplo n.º 1
0
        public async Task RemoveLayerFromCapabilities(ServiceRecord serviceRecord, string capabilitiesPath, LayerRecord layerRecord)
        {
            if (layerRecord == null)
            {
                return;
            }
            #region  除数据库及数据
            _configContext.Layers.Remove(layerRecord);
            var ret = await _configContext.SaveChangesAsync();

            DeleteDataSet(layerRecord.Path);
            #endregion
            #region  除XML中的图层
            IOgcService ogcService = GetOgcService(serviceRecord.Type, serviceRecord.Version);
            switch (serviceRecord.Type)
            {
            case OgcServiceType.Wmts:
                IWmtsService wmtsService  = ogcService as IWmtsService;
                Capabilities capabilities = GetCapabilities(wmtsService, capabilitiesPath);
                wmtsService.RemoveLayerType(capabilities, layerRecord.Name);
                SaveCapabilities(wmtsService, capabilitiesPath, capabilities);
                break;
            }
            #endregion
        }
Ejemplo n.º 2
0
        protected IWmtsService GetWmts1Service(string version = "1.0.0")
        {
            string       serviceType  = "WMTS";
            IWmtsService wmts1Service = OgcServiceHelper.GetOgcService(serviceType, version) as IWmtsService;

            return(wmts1Service);
        }
Ejemplo n.º 3
0
 public static void SaveCapabilities(IWmtsService wmtsService, string capabilitiesPath, Capabilities capabilities)
 {
     using (StreamWriter sw = new StreamWriter(capabilitiesPath))
     {
         wmtsService.XmlSerialize(sw, capabilities);
     }
 }
Ejemplo n.º 4
0
        public bool AddLayerToCapabilities(ServiceRecord serviceRecord, string capabilitiesPath, string layerPath)
        {
            bool        ret        = false;
            IOgcService ogcService = GetOgcService(serviceRecord.Type, serviceRecord.Version);

            switch (serviceRecord.Type)
            {
            case OgcServiceType.Wmts:
                IWmtsService wmtsService  = ogcService as IWmtsService;
                Capabilities capabilities = GetCapabilities(wmtsService, capabilitiesPath);
                if (capabilities != null)
                {
                    LayerType layerType = wmtsService.AddLayerType(capabilities, layerPath);
                    if (layerType != null)
                    {
                        SaveCapabilities(wmtsService, capabilitiesPath, capabilities);
                        ret = true;
                    }
                }
                break;
            }
            if (ret)
            {
                string      destName    = Path.GetFileNameWithoutExtension(layerPath);
                LayerRecord layerRecord = new LayerRecord()
                {
                    Name    = destName,
                    Path    = layerPath,
                    Service = serviceRecord
                };
                _configContext.Layers.Add(layerRecord);
            }
            return(ret);
        }
Ejemplo n.º 5
0
        public static Capabilities GetCapabilities(IWmtsService wmtsService, string capabilitiesPath)
        {
            Capabilities capabilities = null;

            using (StreamReader sr = new StreamReader(capabilitiesPath))
            {
                capabilities = wmtsService.XmlDeSerialize(sr);
            }
            return(capabilities);
        }
Ejemplo n.º 6
0
        private async Task <ContentResult> GetCapabilities(string serviceName, GetCapabilities getCapabilities)
        {
            ContentResult result = new ContentResult()
            {
                ContentType = "application/xml"
            };
            int             statusCode = 200;
            ExceptionReport exception  = null;

            if (string.IsNullOrWhiteSpace(serviceName))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "serviceName", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            string version = null;

            if (getCapabilities.AcceptVersions?.Length > 0)
            {
                version = getCapabilities.AcceptVersions[0];
            }
            if (string.IsNullOrWhiteSpace(version))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "version", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            if (version != "1.0.0")
            {
                exception  = ExceptionReportHelper.GetExceptionReport("InvalidParameterValue", "version", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            ServiceRecord serviceRecord = await GetServiceRecord(serviceName, version);

            if (serviceRecord == null)
            {
                exception  = ExceptionReportHelper.GetExceptionReport("InvalidParameterValue", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            if (!System.IO.File.Exists(serviceRecord.Path))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error");
                statusCode = 500;
                goto Exception;
            }
            IWmtsService wmts1Service = GetWmts1Service(version);
            Capabilities capabilities = wmts1Service.GetCapabilities(serviceRecord.Path, getCapabilities);

            if (getCapabilities.AcceptFormats?.Length > 0)
            {
                result.ContentType = getCapabilities.AcceptFormats[0].Trim();
            }
            StringBuilder sb = new StringBuilder();

            using (StringWriter sw = new StringWriter(sb))
            {
                wmts1Service.XmlSerialize(sw, capabilities);
                sw.Close();
            }
            result.Content = sb.ToString();
            goto Success;
Exception:
            result.Content = XmlHelper.XmlSerialize(exception, Encoding, null);
Success:
            result.StatusCode = statusCode;
            return(result);
        }
Ejemplo n.º 7
0
        private async Task <ContentResult> GetFeatureInfo(string serviceName, GetFeatureInfo getFeatureInfo)
        {
            GetTile         getTile    = getFeatureInfo.GetTile;
            string          content    = null;
            ExceptionReport exception  = null;
            int             statusCode = 200;

            #region Validate parameters
            if (string.IsNullOrWhiteSpace(serviceName))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "serviceName", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            string serviceType = getTile.service;
            if (string.IsNullOrWhiteSpace(serviceType))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "service", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            if (serviceType != "wmts")
            {
                exception  = ExceptionReportHelper.GetExceptionReport("InvalidParameterValue", "version", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            string version = getTile.version;
            if (string.IsNullOrWhiteSpace(version))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "version", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            if (version != "1.0.0")
            {
                exception  = ExceptionReportHelper.GetExceptionReport("InvalidParameterValue", "version", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            string layerName = getTile.Layer;
            if (string.IsNullOrWhiteSpace(layerName))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "layer", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            string style = getTile.Style;
            if (string.IsNullOrWhiteSpace(style))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "style", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            string format = getTile.Format;
            if (string.IsNullOrWhiteSpace(format))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "format", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            string tileMatrixSet = getTile.TileMatrixSet;
            if (string.IsNullOrWhiteSpace(tileMatrixSet))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "tileMatrixSet", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            string tileMatrix = getTile.TileMatrix;
            if (string.IsNullOrWhiteSpace(tileMatrix))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "tileMatrix", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            ServiceRecord serviceRecord = await GetServiceRecord(serviceName, version);

            if (serviceRecord == null)
            {
                exception  = ExceptionReportHelper.GetExceptionReport("InvalidParameterValue", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            if (!System.IO.File.Exists(serviceRecord.Path))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error");
                statusCode = 500;
                goto Exception;
            }
            LayerRecord layerRecord = await GetLayerRecord(serviceRecord, layerName);

            if (layerRecord == null)
            {
                exception  = ExceptionReportHelper.GetExceptionReport("InvalidParameterValue", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            if (!System.IO.File.Exists(layerRecord.Path))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error");
                statusCode = 500;
                goto Exception;
            }
            #endregion
            GetCapabilities getCapabilities = new GetCapabilities();
            IWmtsService    wmts1Service    = GetWmts1Service(version);
            Capabilities    capabilities    = wmts1Service.GetCapabilities(serviceRecord.Path, getCapabilities);
            if (capabilities == null)
            {
                exception  = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error");
                statusCode = 500;
                goto Exception;
            }
            LayerType layerType = capabilities.Contents?.DatasetDescriptionSummary?.FirstOrDefault(x => x.Identifier?.Value == layerName && x is LayerType) as LayerType;
            if (layerType == null)
            {
                exception  = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error");
                statusCode = 500;
                goto Exception;
            }
            if (!layerType.Format.Contains(format))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("InvalidParameterValue", "format", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            if (layerType.TileMatrixSetLink == null || layerType.TileMatrixSetLink.Length == 0)
            {
                exception  = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error");
                statusCode = 500;
                goto Exception;
            }
            string layerTileMatrixSetStr = layerType.TileMatrixSetLink[0].TileMatrixSet;
            if (layerTileMatrixSetStr != null)
            {
                TileMatrixSet layerTileMatrixSet = capabilities.Contents.TileMatrixSet?.FirstOrDefault(x => x.Identifier?.Value == layerTileMatrixSetStr);
                if (layerTileMatrixSet != null)
                {
                    TileMatrix layerTileMatrix = layerTileMatrixSet.TileMatrix?.FirstOrDefault(x => x.Identifier.Value == getTile.TileMatrix);
                    if (layerTileMatrix != null)
                    {
                        bool ret = layerTileMatrix.TopLeftCorner.ToPosition(out double left, out double top);
                        if (!ret)
                        {
                            exception  = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error");
                            statusCode = 500;
                            goto Exception;
                        }
                        BoundingBoxType boundingBoxType = layerType.BoundingBox?.Length > 0 ? layerType.BoundingBox[0] : layerType.WGS84BoundingBox?.Length > 0 ? layerType.WGS84BoundingBox[0] : null;
                        if (boundingBoxType == null)
                        {
                            exception  = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error");
                            statusCode = 500;
                            goto Exception;
                        }
                        bool ret1 = boundingBoxType.LowerCorner.ToPosition(out double xMin, out double yMin);
                        bool ret2 = boundingBoxType.UpperCorner.ToPosition(out double xMax, out double yMax);
                        if (!ret1 || !ret2)
                        {
                            exception  = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error");
                            statusCode = 500;
                            goto Exception;
                        }
                        double tileXMin = 0, tileYMin = 0, tileXMax = 0, tileYMax = 0;
                        int    tileWidth  = Convert.ToInt32(layerTileMatrix.TileWidth);
                        int    tileHeight = Convert.ToInt32(layerTileMatrix.TileHeight);
                        tileXMin = left + getTile.TileCol * tileWidth * layerTileMatrix.ScaleDenominator;
                        tileXMax = left + (getTile.TileCol + 1) * tileWidth * layerTileMatrix.ScaleDenominator;
                        tileYMax = top - getTile.TileRow * tileHeight * layerTileMatrix.ScaleDenominator;
                        tileYMin = top - (getTile.TileRow + 1) * tileHeight * layerTileMatrix.ScaleDenominator;
                        if (tileXMax <= xMin || tileXMin >= xMax || tileYMax <= yMin || tileYMin >= yMax)
                        {
                            exception  = ExceptionReportHelper.GetExceptionReport("TileOutOfRange", exceptionText: "Bad request");
                            statusCode = 400;
                            goto Exception;
                        }
                        if (getFeatureInfo.I < 0 || getFeatureInfo.I >= tileWidth || getFeatureInfo.J < 0 || getFeatureInfo.J >= tileHeight)
                        {
                            exception  = ExceptionReportHelper.GetExceptionReport("PointIJOutOfRange", exceptionText: "Bad request");
                            statusCode = 400;
                            goto Exception;
                        }
                    }
                }
            }
            FeatureInfoResponse featureInfoResponse = wmts1Service.GetFeatureInfo(serviceRecord.Path, getFeatureInfo);
            content = XmlHelper.XmlSerialize(featureInfoResponse, Encoding, null);
            goto Success;
Exception:
            content = XmlHelper.XmlSerialize(exception, Encoding, null);
Success:
            ContentResult result = new ContentResult()
            {
                StatusCode = statusCode,
                Content    = content
            };
            return(result);
        }
Ejemplo n.º 8
0
        private async Task <ActionResult> GetTile(string serviceName, GetTile getTile)
        {
            ActionResult    result     = null;
            ExceptionReport exception  = null;
            int             statusCode = 200;

            #region Validate parameters
            if (string.IsNullOrWhiteSpace(serviceName))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "serviceName", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            string serviceType = getTile.service;
            if (string.IsNullOrWhiteSpace(serviceType))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "service", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            if (serviceType.ToLower() != "wmts")
            {
                exception  = ExceptionReportHelper.GetExceptionReport("InvalidParameterValue", "version", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            string version = getTile.version;
            if (string.IsNullOrWhiteSpace(version))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "version", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            if (version != "1.0.0")
            {
                exception  = ExceptionReportHelper.GetExceptionReport("InvalidParameterValue", "version", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            string layerName = getTile.Layer;
            if (string.IsNullOrWhiteSpace(layerName))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "layer", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            string style = getTile.Style;
            if (string.IsNullOrWhiteSpace(style))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "style", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            string format = getTile.Format;
            if (string.IsNullOrWhiteSpace(format))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "format", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            string tileMatrixSet = getTile.TileMatrixSet;
            if (string.IsNullOrWhiteSpace(tileMatrixSet))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "tileMatrixSet", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            string tileMatrix = getTile.TileMatrix;
            if (string.IsNullOrWhiteSpace(tileMatrix))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "tileMatrix", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            ServiceRecord serviceRecord = await GetServiceRecord(serviceName, version);

            if (serviceRecord == null)
            {
                exception  = ExceptionReportHelper.GetExceptionReport("InvalidParameterValue", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            if (!System.IO.File.Exists(serviceRecord.Path))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error");
                statusCode = 500;
                goto Exception;
            }
            LayerRecord layerRecord = await GetLayerRecord(serviceRecord, layerName);

            if (layerRecord == null)
            {
                exception  = ExceptionReportHelper.GetExceptionReport("InvalidParameterValue", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            #endregion
            GetCapabilities getCapabilities = new GetCapabilities(version);
            IWmtsService    wmts1Service    = GetWmts1Service(version);
            Capabilities    capabilities    = wmts1Service.GetCapabilities(serviceRecord.Path, getCapabilities);
            if (capabilities == null)
            {
                exception  = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error");
                statusCode = 500;
                goto Exception;
            }
            LayerType layerType = capabilities.GetLayerType(layerRecord.Name);
            if (layerType == null)
            {
                exception  = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error");
                statusCode = 500;
                goto Exception;
            }
            if (!layerType.Format.Contains(format))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("InvalidParameterValue", "format", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            if (layerType.TileMatrixSetLink == null || layerType.TileMatrixSetLink.Length == 0)
            {
                exception  = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error");
                statusCode = 500;
                goto Exception;
            }
            string layerTileMatrixSetStr = layerType.TileMatrixSetLink[0].TileMatrixSet;
            if (layerTileMatrixSetStr != null)
            {
                TileMatrixSet layerTileMatrixSet = capabilities.Contents.TileMatrixSet?.FirstOrDefault(x => x.Identifier?.Value == layerTileMatrixSetStr);
                if (layerTileMatrixSet != null)
                {
                    TileMatrix layerTileMatrix = layerTileMatrixSet.TileMatrix?.FirstOrDefault(x => x.Identifier.Value == getTile.TileMatrix);
                    if (layerTileMatrix != null)
                    {
                        bool ret = layerTileMatrix.TopLeftCorner.ToPosition(out double left, out double top);
                        if (!ret)
                        {
                            exception  = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error");
                            statusCode = 500;
                            goto Exception;
                        }
                        BoundingBoxType boundingBoxType = layerType.BoundingBox?.Length > 0 ? layerType.BoundingBox[0] : layerType.WGS84BoundingBox?.Length > 0 ? layerType.WGS84BoundingBox[0] : null;
                        if (boundingBoxType == null)
                        {
                            exception  = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error");
                            statusCode = 500;
                            goto Exception;
                        }
                        bool ret0 = boundingBoxType.LowerCorner.ToPosition(out double xMin, out double yMin);
                        bool ret1 = boundingBoxType.UpperCorner.ToPosition(out double xMax, out double yMax);
                        if (!ret0 || !ret1)
                        {
                            exception  = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error");
                            statusCode = 500;
                            goto Exception;
                        }
                        bool isDegree = layerTileMatrixSet.GetIsDegreeByLocalDb();
                        layerTileMatrix.GetTileIndex(isDegree, xMin, yMax, out int startCol, out int startRow);
                        int matrixWidth  = Convert.ToInt32(layerTileMatrix.MatrixWidth);
                        int matrixHeight = Convert.ToInt32(layerTileMatrix.MatrixHeight);
                        if (getTile.TileCol < startCol || getTile.TileCol >= startCol + matrixWidth || getTile.TileRow < startRow || getTile.TileRow >= startRow + matrixHeight)
                        {
                            exception  = ExceptionReportHelper.GetExceptionReport("TileOutOfRange", exceptionText: "Bad request");
                            statusCode = 400;
                            goto Exception;
                        }
                    }
                }
            }
            try
            {
                byte[] tileBuffer = wmts1Service.GetTile(capabilities, layerRecord.Path, getTile);
                result = new FileContentResult(tileBuffer, getTile.Format);
            }
            catch (Exception e)
            {
                Debug.WriteLine($"获取瓦片{getTile.TileMatrix}_{getTile.TileCol}_{getTile.TileRow}失败:{e.Message}");
            }
            goto Success;
Exception:
            string content = XmlHelper.XmlSerialize(exception, Encoding, null);
            result         = new ContentResult()
            {
                StatusCode = statusCode,
                Content    = content
            };
Success:
            return(result);
        }
Ejemplo n.º 9
0
        static void TestWmts()
        {
            XmlAttributeOverrides attrOverrides = new XmlAttributeOverrides();

            XmlAttributes       ddsAttrs  = new XmlAttributes();
            XmlElementAttribute layerAttr = new XmlElementAttribute
            {
                ElementName = "Layer",
                Type        = typeof(LayerType)
            };

            ddsAttrs.XmlElements.Add(layerAttr);
            attrOverrides.Add(typeof(ContentsBaseType), "DatasetDescriptionSummary", ddsAttrs);

            #region ServiceIdentification
            LanguageStringType[] titles = new LanguageStringType[]
            {
                new LanguageStringType()
                {
                    Value = "Web Map Tile Service"
                }
            };
            LanguageStringType[] abstracts = new LanguageStringType[]
            {
                new LanguageStringType()
                {
                    Value = "Service that contrains the map access interface to some TileMatrixSets"
                }
            };
            LanguageStringType[] keyword1 = new LanguageStringType[]
            {
                new LanguageStringType()
                {
                    Value = "tile"
                }
            };
            KeywordsType keywordsType1 = new KeywordsType()
            {
                Keyword = keyword1
            };
            LanguageStringType[] keyword2 = new LanguageStringType[]
            {
                new LanguageStringType()
                {
                    Value = "map"
                }
            };
            KeywordsType keywordsType2 = new KeywordsType()
            {
                Keyword = keyword2
            };
            KeywordsType[] keywords = new KeywordsType[]
            {
                keywordsType1, keywordsType2
            };
            CodeType serviceType = new CodeType()
            {
                Value = "OGC WMTS"
            };
            string[] serviceTypeVersion = new string[]
            {
                "1.0.0"
            };
            string   fees = "none";
            string[] accessConstraints = new string[]
            {
                "none"
            };
            ServiceIdentification serviceIdentification = new ServiceIdentification()
            {
                Title              = titles,
                Abstract           = abstracts,
                Keywords           = keywords,
                ServiceType        = serviceType,
                ServiceTypeVersion = serviceTypeVersion,
                Fees = fees,
                AccessConstraints = accessConstraints
            };
            #endregion
            string href = "http://123";
            #region ServiceProvider
            string             poroviderName    = "SharpMapServer";
            OnlineResourceType providerSiteType = new OnlineResourceType()
            {
                href = href
            };
            string[]      voices     = new string[] { "0000-00000000" };
            string[]      facsimiles = new string[] { "0001-00000001" };
            TelephoneType phone      = new TelephoneType()
            {
                Voice     = voices,
                Facsimile = facsimiles
            };
            string[]    deliveryPoints        = new string[] { "jinjiang" };
            string      city                  = "chengdu";
            string      administrativeArea    = "sichuan";
            string      country               = "china";
            string[]    electronicMailAddress = new string[] { "*****@*****.**" };
            string      postalCode            = "123456";
            AddressType address               = new AddressType()
            {
                DeliveryPoint         = deliveryPoints,
                City                  = city,
                AdministrativeArea    = administrativeArea,
                Country               = country,
                ElectronicMailAddress = electronicMailAddress,
                PostalCode            = postalCode
            };
            ContactType contactInfo = new ContactType()
            {
                Phone   = phone,
                Address = address
            };
            string individualName = "lc";
            string positionName   = "Senior Software Engineer";
            ResponsiblePartySubsetType serviceContact = new ResponsiblePartySubsetType()
            {
                IndividualName = individualName,
                PositionName   = positionName,
                ContactInfo    = contactInfo
            };
            ServiceProvider serviceProvider = new ServiceProvider()
            {
                ProviderName   = poroviderName,
                ProviderSite   = providerSiteType,
                ServiceContact = serviceContact
            };
            #endregion

            #region OperationsMetadata
            Operation   getCapabilitiesOperation = CapabilitiesHelper.GetOperation(href, "GetCapabilities");
            Operation   getTileOperation         = CapabilitiesHelper.GetOperation(href, "GetTile");
            Operation   getFeatureinfoOperation  = CapabilitiesHelper.GetOperation(href, "GetFeatureinfo");
            Operation[] operations = new Operation[]
            {
                getCapabilitiesOperation,
                getTileOperation,
                getFeatureinfoOperation
            };
            OperationsMetadata operationsMetadata = new OperationsMetadata()
            {
                Operation = operations
            };
            #endregion
            Capabilities capabilities = new Capabilities()
            {
                ServiceIdentification = serviceIdentification,
                ServiceProvider       = serviceProvider,
                OperationsMetadata    = operationsMetadata
            };
            IWmtsService wmts1Service = OgcServiceHelper.GetOgcService("WMTS", "1.0.0") as IWmtsService;
            wmts1Service.AddContent(capabilities, @"E:\LC\数据\双流\2014年遥感影像.img");

            List <object> objs = new List <object>();
            capabilities.Themes = new Themes[]
            {
                new Themes()
                {
                    Theme = new Theme[]
                    {
                        new Theme()
                        {
                            Identifier = new CodeType()
                            {
                                Value = "123"
                            }
                        }
                    }
                }
            };
            objs.Add(capabilities);
            StringBuilder sb = new StringBuilder();
            using (TextWriter tw = new StringWriter(sb))
            {
                foreach (var item in objs)
                {
                    if (item == null)
                    {
                        continue;
                    }
                    var serializer = new XmlSerializer(item.GetType(), attrOverrides);
                    serializer.Serialize(tw, item);
                    var val = sb.ToString();
                    File.WriteAllText("123.xml", val);
                    sb.Clear();
                }
            }
        }