/// <summary> /// Generates an GeoJson (.geojson) file with grid statistics on species observation counts. /// </summary> /// <returns>A .geojson file.</returns> public FileResult GridStatisticsOnSpeciesObservationCountsAsGeoJson() { SpeciesObservationGridCalculator resultCalculator = null; string geojson = null; CalculatedDataItem <FeatureCollection> result; resultCalculator = new SpeciesObservationGridCalculator(GetCurrentUser(), SessionHandler.MySettings); geojson = resultCalculator.GetSpeciesObservationGridAsGeoJson(); SetServerDone(); byte[] bytes = System.Text.Encoding.UTF8.GetBytes(geojson); return(File( bytes, "application/json", FilenameGenerator.CreateFilename("SpeciesObservationCountsGrid", FileType.GeoJSON))); }
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); }