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(); } } }
public virtual Capabilities CreateCapabilities(string href) { #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 #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 = GetOperation(href, "GetCapabilities"); Operation getTileOperation = GetOperation(href, "GetTile"); Operation getFeatureinfoOperation = 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 }; return(capabilities); }
public static ServiceProvider GetServiceProvider(string poroviderName, string providerSite, ResponsiblePartySubsetType serviceContact) { OnlineResourceType providerSiteType = new OnlineResourceType() { href = providerSite }; ServiceProvider serviceProvider = new ServiceProvider() { ProviderName = poroviderName, ProviderSite = providerSiteType, ServiceContact = serviceContact }; return(serviceProvider); }