Exemplo n.º 1
0
        public async Task <bool> CreateService(string serviceName, string serviceType, string version, IEnumerable <string> files)
        {
            bool   ret = false;
            string url = null;

            if (string.IsNullOrEmpty(serviceName) || string.IsNullOrEmpty(serviceType) || string.IsNullOrEmpty(version) || files == null || files.Count() == 0)
            {
                return(ret);
            }
            bool isExisted = await ExistedService(serviceName, serviceType, version);

            if (isExisted)
            {
                return(ret);
            }
            string      href             = JsonSettings.DefaultSettings.GetValue <string>("href");
            string      capabilitiesPath = null;
            IOgcService ogcService       = OgcServiceHelper.GetOgcService(serviceType, version);
            Dictionary <string, string> layerNameAndPathes = new Dictionary <string, string>();

            if (ogcService is IWmtsService wmts1Service)
            {
                href = $"{href}/SharpMapServer/Services/{serviceName}/MapServer/Wmts";
                Capabilities capabilities = wmts1Service.CreateCapabilities(href);
                string       directory    = null;
                foreach (var file in files)
                {
                    if (directory == null)
                    {
                        directory = Path.GetDirectoryName(file);
                    }
                    LayerType layerType = wmts1Service.AddContent(capabilities, file);
                    string    name      = Path.GetFileNameWithoutExtension(file);
                    layerNameAndPathes[name] = file;
                }
                capabilitiesPath = Path.Combine(directory, "WMTSCapabilities.xml");
                using (StreamWriter sw = new StreamWriter(capabilitiesPath))
                {
                    wmts1Service.XmlSerialize(sw, capabilities);
                }
                url = $"{href}/1.0.0/WMTSCapabilities.xml";
            }
            else
            {
                return(ret);
            }
            ret = await AddServiceRecord(serviceName, serviceType, version, capabilitiesPath);

            ServiceRecord serviceRecord = await GetServiceRecord(serviceName, serviceType, version);

            foreach (var item in layerNameAndPathes)
            {
                bool result = await AddLayerRecord(serviceRecord, item.Key, item.Value);
            }
            if (!ret)
            {
                File.Delete(capabilitiesPath);
            }
            return(ret);
        }
Exemplo n.º 2
0
        protected IWmtsService GetWmts1Service(string version = "1.0.0")
        {
            string       serviceType  = "WMTS";
            IWmtsService wmts1Service = OgcServiceHelper.GetOgcService(serviceType, version) as IWmtsService;

            return(wmts1Service);
        }
Exemplo n.º 3
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();
                }
            }
        }