/// <summary> /// Calculates the combined grid result. /// </summary> /// <param name="calculationCoordinateSystemId">The calculation coordinate system id.</param> /// <param name="gridCellSize">Size of the grid cell.</param> /// <param name="wfsLayerId">The WFS layer id.</param> /// <returns>Combined grid cell statistics.</returns> public CombinedGridStatisticsResult CalculateCombinedGridResult(int calculationCoordinateSystemId, int gridCellSize, int wfsLayerId) { GridSpecification gridSpecification = new GridSpecification(); CoordinateSystem displayCoordinateSystem = MySettings.Presentation.Map.DisplayCoordinateSystem; gridSpecification.GridCoordinateSystem = (GridCoordinateSystem)calculationCoordinateSystemId; gridSpecification.GridCellSize = gridCellSize; gridSpecification.IsGridCellSizeSpecified = true; gridSpecification.GridCellGeometryType = GridCellGeometryType.Polygon; if (MySettings.Filter.Spatial.IsActive) { // Create bounding box from spatial filter ObservableCollection <DataPolygon> polygons = MySettings.Filter.Spatial.Polygons; if (polygons.Count > 0) { BoundingBox boundingBox = polygons.GetBoundingBox(); CoordinateSystem toCoordinateSystem = CoordinateSystemHelper.GetCoordinateSystemFromGridCoordinateSystem(gridSpecification.GridCoordinateSystem); IPolygon convertedBoundingBoxPolygon = GisTools.CoordinateConversionManager.GetConvertedBoundingBox(boundingBox, MySettings.Filter.Spatial.PolygonsCoordinateSystem, toCoordinateSystem); BoundingBox convertedBoundingBox = convertedBoundingBoxPolygon.GetBoundingBox(); gridSpecification.BoundingBox = convertedBoundingBox; } } WfsLayerSetting wfsLayer = SessionHandler.MySettings.DataProvider.MapLayers.WfsLayers.FirstOrDefault(l => l.Id == wfsLayerId); string featuresUrl = ""; string featureCollectionJson = null; if (wfsLayer.IsFile) { featureCollectionJson = JObject.FromObject(MySettingsManager.GetMapDataFeatureCollection(UserContext, wfsLayer.GeometryName, gridSpecification.GridCoordinateSystem.GetCoordinateSystemId())).ToString(); } else { if (string.IsNullOrEmpty(wfsLayer.Filter)) { featuresUrl = string.Format("{0}?service=wfs&version=1.1.0&request=GetFeature&typeName={1}", wfsLayer.ServerUrl, wfsLayer.TypeName); } else { featuresUrl = string.Format("{0}?service=wfs&version=1.1.0&request=GetFeature&typeName={1}&filter={2}", wfsLayer.ServerUrl, wfsLayer.TypeName, wfsLayer.Filter); } } var speciesObservationSearchCriteriaManager = new SpeciesObservationSearchCriteriaManager(UserContext); SpeciesObservationSearchCriteria searchCriteria = speciesObservationSearchCriteriaManager.CreateSearchCriteria(MySettings); IList <IGridCellCombinedStatistics> gridCells = CoreData.AnalysisManager.GetGridCellFeatureStatisticsCombinedWithSpeciesObservationCounts(UserContext, gridSpecification, searchCriteria, null, featuresUrl, featureCollectionJson, displayCoordinateSystem); if (MySettings.Calculation.GridStatistics.GenerateAllGridCells) { gridCells = AddEmptyGridCells(gridCells, gridSpecification, displayCoordinateSystem); gridCells = RemoveGridCellsOutsideBounds(gridCells, gridSpecification); } gridCells = gridCells.OrderBy(x => x.Identifier).ToList(); return(CombinedGridStatisticsResult.Create( (CoordinateSystemId)calculationCoordinateSystemId, displayCoordinateSystem.Id, gridCellSize, gridCells)); }
public string Index() { var srsName = Request["srsName"]; var typeName = Request["typeName"]; if (string.IsNullOrEmpty(typeName) && Request.HttpMethod == "POST") { XDocument payload; try { //Try to load xml from payload using (var input = Request.InputStream) { payload = XDocument.Load(input); input.Close(); } } catch { return(null); } if (payload == null || payload.Root == null) { return(null); } var outputFormatAttribute = payload.Root.Attribute("outputFormat"); if (outputFormatAttribute == null || outputFormatAttribute.Value != "json") { return(null); } var wfsQuery = payload.Root.Descendants(XName.Get("Query", payload.Root.Name.Namespace.NamespaceName)) .FirstOrDefault(); if (wfsQuery == null) { return(null); } srsName = wfsQuery.Attribute("srsName").Value; typeName = wfsQuery.Attribute("typeName").Value; } typeName = Server.UrlDecode(typeName); var fileName = typeName.Substring(typeName.LastIndexOf(":", StringComparison.CurrentCulture) + 1); var requestedCoordinateSystemId = GisTools.GeoJsonUtils.FindCoordinateSystemId(new NamedCRS(srsName)); return(JObject.FromObject(MySettingsManager.GetMapDataFeatureCollection(GetCurrentUser(), fileName, requestedCoordinateSystemId)).ToString()); }
/// <summary> /// Adds selected uploaded gis layers to WFS layers. /// </summary> /// <param name="filenames">The filenames.</param> /// <returns></returns> public JsonNetResult AddUploadedGisLayers(string[] filenames) { JsonModel jsonModel = JsonModel.CreateSuccess("Ok"); try { foreach (string filename in filenames) { if (string.IsNullOrEmpty(filename)) { jsonModel = JsonModel.CreateFailure("No file selected."); return(new JsonNetResult(jsonModel)); } try { var featureCollection = MySettingsManager.GetMapDataFeatureCollection( GetCurrentUser(), filename, CoordinateSystemId.None); if (featureCollection == null) { jsonModel = JsonModel.CreateFailure("File not found."); return(new JsonNetResult(jsonModel)); } if (AddFileWfsLayer(filename, featureCollection)) { jsonModel = JsonModel.CreateSuccess("Ok"); } else { jsonModel = JsonModel.CreateFailure(Resource.SharedLayerAlreadyExists); break; } } catch (Exception) { jsonModel = JsonModel.CreateFailure(Resource.FilterSpatialUnableToParseGeoJsonFile); break; } } } catch (Exception ex) { jsonModel = JsonModel.CreateFailure(ex.Message); } return(new JsonNetResult(jsonModel)); }
public WfsStatisticsGridResult CalculateGridResult(IUserContext userContext, int coordinateSystemId, int gridSize, int wfsLayerId) { var requestedGridCoordinateSystem = (GridCoordinateSystem)coordinateSystemId; var gridSpecification = new GridSpecification { GridCoordinateSystem = requestedGridCoordinateSystem, GridCellSize = gridSize, IsGridCellSizeSpecified = true, GridCellGeometryType = GridCellGeometryType.Polygon }; if (MySettings.Filter.Spatial.IsActive) { // Create bounding box from spatial filter var polygons = MySettings.Filter.Spatial.Polygons; if (polygons.Count > 0) { var boundingBox = polygons.GetBoundingBox(); var toCoordinateSystem = CoordinateSystemHelper.GetCoordinateSystemFromGridCoordinateSystem(gridSpecification.GridCoordinateSystem); var convertedBoundingBoxPolygon = GisTools.CoordinateConversionManager.GetConvertedBoundingBox(boundingBox, MySettings.Filter.Spatial.PolygonsCoordinateSystem, toCoordinateSystem); gridSpecification.BoundingBox = convertedBoundingBoxPolygon.GetBoundingBox(); } } var displayCoordinateSystem = MySettings.Presentation.Map.DisplayCoordinateSystem; var wfsLayer = SessionHandler.MySettings.DataProvider.MapLayers.WfsLayers.FirstOrDefault(l => l.Id == wfsLayerId); string featuresUrl = null; string featureCollectionJson = null; if (wfsLayer.IsFile) { featureCollectionJson = JObject.FromObject(MySettingsManager.GetMapDataFeatureCollection(userContext, wfsLayer.GeometryName, requestedGridCoordinateSystem.GetCoordinateSystemId())).ToString(); } else { if (string.IsNullOrEmpty(wfsLayer.Filter)) { featuresUrl = string.Format("{0}?service=wfs&version=1.1.0&request=GetFeature&typeName={1}", wfsLayer.ServerUrl, wfsLayer.TypeName); } else { featuresUrl = string.Format("{0}?service=wfs&version=1.1.0&request=GetFeature&typeName={1}&filter={2}", wfsLayer.ServerUrl, wfsLayer.TypeName, wfsLayer.Filter); } } var list = CoreData.AnalysisManager.GetGridFeatureStatistics(UserContext, null, featuresUrl, featureCollectionJson, gridSpecification, displayCoordinateSystem); return(WfsStatisticsGridResult.Create(list)); }
/// <summary> /// Gets feature collection based on selected WFS layer in SummaryStatistics. /// </summary> /// <returns>A feature collection or null.</returns> private FeatureCollection GetFeatureCollection() { if (!MySettings.Calculation.SummaryStatistics.WfsSummaryStatisticsLayerId.HasValue) { return(null); } int wfsLayerId = MySettings.Calculation.SummaryStatistics.WfsSummaryStatisticsLayerId.Value; WfsLayerSetting wfsLayer = MySettings.DataProvider.MapLayers.WfsLayers.FirstOrDefault(l => l.Id == wfsLayerId); string featuresUrl; string srsName = MySettings.Presentation.Map.PresentationCoordinateSystemId.EpsgCode(); FeatureCollection featureCollection = null; if (wfsLayer.IsFile) { featureCollection = MySettingsManager.GetMapDataFeatureCollection( UserContext, wfsLayer.GeometryName, MySettings.Presentation.Map.PresentationCoordinateSystemId); } else { if (string.IsNullOrEmpty(wfsLayer.Filter)) { featuresUrl = string.Format("{0}?service=wfs&version=1.1.0&request=GetFeature&typeName={1}&srsName={2}", wfsLayer.ServerUrl, wfsLayer.TypeName, srsName); } else { featuresUrl = string.Format( "{0}?service=wfs&version=1.1.0&request=GetFeature&typeName={1}&filter={2}&srsName={3}", wfsLayer.ServerUrl, wfsLayer.TypeName, wfsLayer.Filter, srsName); } featureCollection = WFSManager.GetWfsFeaturesUsingHttpPost(featuresUrl); } return(featureCollection); }
public static string GetLayerGeojson( IUserContext currentUser, int layerId, CoordinateSystemId coordinateSystemId, IDictionary <string, object> parameters, out string layerName, MapExportModel.Extent mapExtent) { string geoJson = null; layerName = null; if (layerId == null) { return(null); } if (layerId >= CustomLayersStartLayerId) { var viewManager = new WfsLayersViewManager(currentUser, SessionHandler.MySettings); var layer = viewManager.GetWfsLayers().FirstOrDefault(l => l.Id == layerId); layerName = layer.Name; if (layer.IsFile) { geoJson = JsonConvert.SerializeObject(MySettingsManager.GetMapDataFeatureCollection(currentUser, layer.GeometryName, coordinateSystemId)); } else { var url = WFSFilterUtils.GetResultingUrl(layer.ServerUrl, layer.TypeName, "1.1.0", layer.Filter, "application%2Fjson", null, string.Format("EPSG%3A{0}", coordinateSystemId.Srid())); var request = WebRequest.Create(url); request.Credentials = CredentialCache.DefaultCredentials; // Get the response. using (var response = request.GetResponse()) { using (var dataStream = response.GetResponseStream()) { using (var reader = new StreamReader(dataStream)) { geoJson = reader.ReadToEnd(); reader.Close(); } } response.Close(); } } } else { switch (layerId) { case SpeciesRichnessGridLayerId: var taxonGridCalculator = new TaxonGridCalculator(currentUser, SessionHandler.MySettings); geoJson = taxonGridCalculator.GetTaxonGridAsGeoJson(); var attribute = (string)(parameters.ContainsKey("attribute") ? parameters["attribute"] : null); layerName = Resource.ResultViewSpeciesRichnessGridMapLayerName; if (attribute != null) { switch (attribute.ToLower().Trim()) { case "speciescount": layerName = Resource.ResultDownloadSpeciesRichnessGridMap; break; case "observationcount": layerName = Resource.ResultDownloadObservationsGridMap; break; } } break; case SpeciesObservationGridMapLayerId: case EooConvexHullLayerId: case EooConcaveHullLayerId: var speciesObservationGridCalculator = new SpeciesObservationGridCalculator(currentUser, SessionHandler.MySettings); if (layerId == SpeciesObservationGridMapLayerId) { geoJson = speciesObservationGridCalculator.GetSpeciesObservationGridAsGeoJson(); layerName = Resource.ResultViewSpeciesObservationGridMap; } else { var alphaValue = (int?)(parameters.ContainsKey("alphaValue") ? parameters["alphaValue"] : null); var useCenterPoint = (bool?)(parameters.ContainsKey("useCenterPoint") ? parameters["useCenterPoint"] : null); geoJson = speciesObservationGridCalculator.GetSpeciesObservationAOOEOOAsGeoJson( layerId == EooConcaveHullLayerId ? alphaValue : 0, useCenterPoint ?? true); layerName = Resource.MapEOOLayer; } break; case ObservationsLayerId: //Observations case SpeciesObservationClusterPointMapLayerId: SpeciesObservationResultCalculator resultCalculator = null; try { var displayCoordinateSystemId = SessionHandler.MySettings.Presentation.Map.PresentationCoordinateSystemId; resultCalculator = new SpeciesObservationResultCalculator(currentUser, SessionHandler.MySettings); geoJson = resultCalculator.GetSpeciesObservationsAsGeoJson(displayCoordinateSystemId); layerName = Resource.MapLayerObservations; } catch (Exception) { } break; } } return(geoJson); }