public void GetFeatureRequestUrl() { string url = "http://slwgeo.artdata.slu.se:8080/geoserver/wfs"; string bbox = "6400000,1400000, 6500000,1500000"; string parameter = string.Empty; string parametervalue = string.Empty; string resultUrl = string.Empty; WfsTypeName typeName = new WfsTypeName(); typeName.Namespace = "SLW:Sverigekarta_med_lan"; string srsName = string.Empty; resultUrl = WFSManager.CreateGetFeatureRequestUrl(url, WFSVersion.Ver110, bbox, typeName, srsName, parameter, parametervalue); Assert.AreEqual("http://slwgeo.artdata.slu.se:8080/geoserver/wfs?&service=wfs&request=GetFeature&version=1.1.0&bbox=6400000,1400000, 6500000,1500000&typeName=SLW:Sverigekarta_med_lan&outputFormat=json", resultUrl); }
public void GetWfsFeaturesWithBoundingBox() { WfsTypeName typeName = new WfsTypeName(); WFSVersion version = WFSVersion.Ver110; string serverUrl = "http://slwgeo.artdata.slu.se:8080/geoserver/wfs"; string parameter = string.Empty; string parameterValue = string.Empty; string bbox = "6400000,1400000, 6500000,1500000"; typeName.Namespace = "SLW:Sverigekarta_med_lan"; string srsName = string.Empty; FeatureCollection featureCollection; featureCollection = WFSManager.GetWfsFeatures(serverUrl, version, bbox, typeName, srsName, parameter, parameterValue); Assert.IsNotNull(featureCollection); Assert.IsTrue(featureCollection.Features.Count == 5); }
public void GetWfsFeatures() { WfsTypeName typeName = new WfsTypeName(); WFSVersion version = WFSVersion.Ver110; string serverUrl = "http://slwgeo.artdata.slu.se:8080/geoserver/SLW/wfs"; string parameter = string.Empty; string parameterValue = string.Empty; string bbox = string.Empty;//&BBOX=133499, 628499, 154501, 635501;//&BBOX=628499,133499,635501,154501"; typeName.Namespace = "SLW:Sverigekarta_med_lan"; string srsName = string.Empty; FeatureCollection featureCollection; featureCollection = WFSManager.GetWfsFeatures(serverUrl, version, bbox, typeName, srsName, parameter, parameterValue); Assert.IsNotNull(featureCollection); Assert.IsTrue(featureCollection.Features.Count == 22); }
public void GetWfsFeaturesWithFilter() { WfsTypeName typeName = new WfsTypeName(); WFSVersion version = WFSVersion.Ver110; string serverUrl = "http://slwgeo.artdata.slu.se:8080/geoserver/wfs"; string bbox = string.Empty; string parameter = "SLW:LänSKOD"; string parameterValue = "17"; //Todo: vilken är det:? typeName.Namespace = "SLW:Sverigekarta_med_lan"; //typeName.Name = "SLW:Sverigekarta_med_lan"; string srsName = string.Empty; FeatureCollection featureCollection; featureCollection = WFSManager.GetWfsFeatures(serverUrl, version, bbox, typeName, srsName, parameter, parameterValue); Assert.IsNotNull(featureCollection); Assert.IsTrue(featureCollection.Features.Count == 1); }
public void GetWfsFeaturesWithBoundingBoxUsingMsFakes() { using (ShimsContext.Create()) { ShimWebClient.AllInstances.DownloadStringString = (client, url) => File.ReadAllText(@"Sample files\SLW_Sverigekarta_med_lan - BBox Filter.json"); WfsTypeName typeName = new WfsTypeName(); WFSVersion version = WFSVersion.Ver110; string serverUrl = "http://slwgeo.artdata.slu.se:8080/geoserver/wfs"; string parameter = string.Empty; string parameterValue = string.Empty; string bbox = "6400000,1400000, 6500000,1500000"; typeName.Namespace = "SLW:Sverigekarta_med_lan"; string srsName = string.Empty; FeatureCollection featureCollection; featureCollection = WFSManager.GetWfsFeatures(serverUrl, version, bbox, typeName, srsName, parameter, parameterValue); Assert.IsNotNull(featureCollection); Assert.AreEqual(5, featureCollection.Features.Count); } }
public void GetWfsFeaturesUsingMsFakes() { using (ShimsContext.Create()) { ShimWebClient.AllInstances.DownloadStringString = (client, url) => File.ReadAllText(@"Sample files\SLW_Sverigekarta_med_lan - All Features.json"); WfsTypeName typeName = new WfsTypeName(); WFSVersion version = WFSVersion.Ver110; string serverUrl = "http://slwgeo.artdata.slu.se:8080/geoserver/SLW/wfs"; string parameter = string.Empty; string parameterValue = string.Empty; string bbox = string.Empty; // &BBOX=133499, 628499, 154501, 635501;//&BBOX=628499,133499,635501,154501"; typeName.Namespace = "SLW:Sverigekarta_med_lan"; string srsName = string.Empty; FeatureCollection featureCollection; featureCollection = WFSManager.GetWfsFeatures(serverUrl, version, bbox, typeName, srsName, parameter, parameterValue); Assert.IsNotNull(featureCollection); Assert.IsTrue(featureCollection.Features.Count == 22); } }
/// <summary> /// /// </summary> /// <param name="serverUrl">The WFS server URL.</param> /// <param name="version">The WFS version.</param> /// <param name="bbox">The bounding box in which the analysyis should be done.</param> /// <param name="typeName">The features layer names you want info about.</param> /// <param name="srsName">The spatial reference system (SRID) in the format of EPSG:XXXX </param> /// <param name="parameter"></param> /// <param name="parameterValue"></param> /// <returns></returns> public static FeatureCollection GetWfsFeatures(string serverUrl, WFSVersion version, string bbox, WfsTypeName typeName, string srsName, string parameter, string parameterValue) { string requestUrl = ""; requestUrl = CreateGetFeatureRequestUrl(serverUrl, version, bbox, typeName, srsName, parameter, parameterValue); using (WebClient wc = new WebClient()) { wc.Encoding = Encoding.UTF8; string strJson = wc.DownloadString(requestUrl); // Make a Json string to a featue collection type FeatureCollection featureCollection = JsonConvert.DeserializeObject(strJson, typeof(FeatureCollection)) as FeatureCollection; return(featureCollection); } }
/// <summary> /// Creates a WFS DescribeFeatureType request URL. /// </summary> /// <param name="serverUrl">The WFS server URL.</param> /// <param name="version">The WFS version.</param> /// <param name="bbox">The bounding box given as bottom left and top right corner coordinates.</param> /// <param name="typeName">Name of the feature type to describe.</param> /// <param name="srsName">The spatial reference system (SRID) in the format of EPSG:XXXX </param> /// <param name="parameter"></param> /// <param name="parameterValue"></param> /// <returns></returns> public static string CreateGetFeatureRequestUrl(string serverUrl, WFSVersion version, string bbox, WfsTypeName typeName, string srsName, string parameter, string parameterValue) { // As for now only polygon features and output format json are supported // const string outputFormat = "json"; string strFilter = ""; if (version == WFSVersion.Unknown) { throw new Exception("WFSVersion is unknown"); } //The query should specify either typeName, featureId filter(, or a stored query id) // if (typeName.Namespace.IsEmpty() && parameter.IsEmpty()) { throw new Exception("Missing TypeName and filter in url, wich is not allowed."); } //The query should not specify both bounding box and filter at the same time // if (parameter.IsNotEmpty() && bbox.IsNotEmpty()) { throw new Exception("There is a filter and a bounding box defined at the same time: filter and bbox both specified but are mutually exclusive"); //Todo: Or make the filter with the bounding box } string strVersion = GetWFSVersionStringFromEnum(version); var uriBuilder = new UriBuilder(serverUrl); Uri uri = uriBuilder.Uri; string baseUrl = uri.GetLeftPart(UriPartial.Path); var strReq = new StringBuilder(baseUrl); strReq.Append("?"); strReq.AppendFormat("&service=wfs"); strReq.AppendFormat("&request=GetFeature"); strReq.AppendFormat("&version=" + strVersion); if (parameter.IsNotEmpty()) { strFilter = CreateWFSFilter(parameter, parameterValue); strReq.AppendFormat("&filter=" + strFilter); } if (bbox.IsNotEmpty()) { strReq.AppendFormat("&bbox=" + bbox); } if (typeName.Namespace.IsNotEmpty()) { strReq.AppendFormat("&typeName=" + typeName.Namespace); } if (srsName.IsNotEmpty()) { strReq.AppendFormat("&srs=" + srsName); } //Todo Hantera Parameter och parameterValue // strReq.AppendFormat("&outputFormat=" + outputFormat); return(strReq.ToString()); }