Beispiel #1
0
        public ActionResult AddWfsLayer(string url, WFSVersion wfsVersion)
        {
            string wfsUrl = null;

            try
            {
                wfsUrl = WFSManager.CreateGetCapabiltiesRequestUrl(url, wfsVersion);
            }
            catch (UriFormatException)
            {
                ModelState.AddModelError("", "The URL has wrong format");
            }

            if (ModelState.IsValid)
            {
                if (wfsVersion == WFSVersion.Unknown)
                {
                    wfsVersion = WFSManager.GetWFSVersionFromRequestUrl(url);
                    if (wfsVersion == WFSVersion.Unknown)
                    {
                        wfsVersion = WFSVersion.Ver110;
                    }
                }
                return(RedirectToAction("AddWfsLayer", new { @url = wfsUrl }));
            }
            var viewManager = new WfsLayersViewManager(GetCurrentUser(), SessionHandler.MySettings);
            var model       = viewManager.CreateAddWfsLayerViewModel(ModelState, url, Url.Action("UploadMapDataFile"), Url.Action("WfsLayers"));

            return(View(model));
        }
Beispiel #2
0
        /// <summary>
        /// Deletes the selected uploaded gis layers.
        /// </summary>
        /// <param name="filenames">The filenames.</param>
        /// <returns></returns>
        public JsonNetResult DeleteUploadedGisLayers(string[] filenames)
        {
            JsonModel jsonModel;

            try
            {
                jsonModel = JsonModel.CreateSuccess("Ok");

                foreach (string filename in filenames)
                {
                    if (!MySettingsManager.DeleteMapDataFile(GetCurrentUser(), filename))
                    {
                        jsonModel = JsonModel.CreateFailure("Deleting file failed.");
                    }

                    //Check if file layer is in use, if so, remove it
                    var viewManager = new WfsLayersViewManager(GetCurrentUser(), SessionHandler.MySettings);
                    var layer       = viewManager.GetWfsLayers().FirstOrDefault(l => l.Name == GetLayerName(filename));

                    if (layer != null)
                    {
                        viewManager.RemoveWfsLayer(layer.Id);
                    }
                }

                return(new JsonNetResult(jsonModel));
            }
            catch (Exception ex)
            {
                jsonModel = JsonModel.CreateFailure(ex.Message);
            }

            return(new JsonNetResult(jsonModel));
        }
Beispiel #3
0
        public RedirectToRouteResult WfsLayerEditorSaveChanges(int id, string name, string filter, string color, bool useBbox)
        {
            var viewManager = new WfsLayersViewManager(GetCurrentUser(), SessionHandler.MySettings);

            viewManager.UpdateWfsLayer(id, name, filter, color, useBbox);
            return(RedirectToAction("WfsLayers"));
        }
Beispiel #4
0
        /// <summary>
        /// Returns a view where the user can see an overview of map layers.
        /// </summary>
        /// <returns></returns>
        public ActionResult WfsLayers()
        {
            WfsLayersViewManager viewManager = new WfsLayersViewManager(GetCurrentUser(), SessionHandler.MySettings);
            var model = viewManager.CreateWfsLayersViewModel();

            return(View(model));
        }
        /// <summary>
        /// Creates a view model for the "~/Calculation/GridStatistics" view
        /// </summary>
        public GridStatisticsViewModel CreateGridStatisticsViewModel()
        {
            var model = new GridStatisticsViewModel();

            model.GenerateAllGridCells          = GridStatisticsSetting.GenerateAllGridCells;
            model.CalculateNumberOfObservations = GridStatisticsSetting.CalculateNumberOfObservations;
            model.GridSize              = GridStatisticsSetting.GridSize;
            model.CoordinateSystemId    = GridStatisticsSetting.CoordinateSystemId;
            model.CalculateNumberOfTaxa = GridStatisticsSetting.CalculateNumberOfTaxa;

            model.CoordinateSystems = new List <CoordinateSystemViewModel>();
            model.CoordinateSystems.Add(new CoordinateSystemViewModel((int)GridCoordinateSystem.SWEREF99_TM, "SWEREF 99", GridStatisticsSetting.CoordinateSystemId.GetValueOrDefault(-100) == (int)GridCoordinateSystem.SWEREF99_TM));
            model.CoordinateSystems.Add(new CoordinateSystemViewModel((int)GridCoordinateSystem.Rt90_25_gon_v, "RT 90", GridStatisticsSetting.CoordinateSystemId.GetValueOrDefault(-100) == (int)GridCoordinateSystem.Rt90_25_gon_v));

            // WFS Grid statistics
            WfsGridStatisticsCalculationMode wfsGridStatisticsCalculationMode;

            if (Enum.TryParse(GridStatisticsSetting.WfsGridStatisticsCalculationModeId.ToString(CultureInfo.InvariantCulture), out wfsGridStatisticsCalculationMode))
            {
                model.WfsGridStatisticsCalculationMode = wfsGridStatisticsCalculationMode;
            }
            else
            {
                model.WfsGridStatisticsCalculationMode = WfsGridStatisticsCalculationMode.Count;
            }
            model.WfsGridStatisticsLayerId = GridStatisticsSetting.WfsGridStatisticsLayerId;

            var wfsViewManager = new WfsLayersViewManager(UserContext, MySettings);

            model.WfsLayers = wfsViewManager.CreateWfsLayersList();

            model.IsSettingsDefault = GridStatisticsSetting.IsSettingsDefault();
            return(model);
        }
        public WfsGridStatisticsMapViewModel CreateViewModel()
        {
            WfsGridStatisticsMapViewModel model = new WfsGridStatisticsMapViewModel();

            model.GridSize = GridStatisticsSetting.GridSize;
            //model.CoordinateSystemId = GridStatisticsSetting.CoordinateSystemId;
            model.CoordinateSystems = new List <CoordinateSystemViewModel>();
            model.CoordinateSystems.Add(new CoordinateSystemViewModel((int)GridCoordinateSystem.Rt90_25_gon_v, "RT 90", GridStatisticsSetting.CoordinateSystemId.GetValueOrDefault(-100) == (int)GridCoordinateSystem.Rt90_25_gon_v));
            model.CoordinateSystems.Add(new CoordinateSystemViewModel((int)GridCoordinateSystem.SWEREF99_TM, "SWEREF 99", GridStatisticsSetting.CoordinateSystemId.GetValueOrDefault(-100) == (int)GridCoordinateSystem.SWEREF99_TM));

            WfsGridStatisticsCalculationMode wfsGridStatisticsCalculationMode;

            if (Enum.TryParse(GridStatisticsSetting.WfsGridStatisticsCalculationModeId.ToString(CultureInfo.InvariantCulture), out wfsGridStatisticsCalculationMode))
            {
                model.WfsGridStatisticsCalculationMode = wfsGridStatisticsCalculationMode;
            }
            else
            {
                model.WfsGridStatisticsCalculationMode = WfsGridStatisticsCalculationMode.Count;
            }
            model.WfsGridStatisticsLayerId = GridStatisticsSetting.WfsGridStatisticsLayerId;
            var wfsViewManager = new WfsLayersViewManager(UserContext, MySettings);

            model.WfsLayers = wfsViewManager.CreateWfsLayersList();

            model.AddSpartialFilterLayer = MySettings.Filter.Spatial.IsActive && MySettings.Filter.Spatial.HasSettings;

            return(model);
        }
Beispiel #7
0
        public ActionResult AddWfsLayer(string url)
        {
            var viewManager = new WfsLayersViewManager(GetCurrentUser(), SessionHandler.MySettings);
            var model       = viewManager.CreateAddWfsLayerViewModel(ModelState, url, Url.Action("UploadMapDataFile"), Url.Action("WfsLayers"));

            return(View(model));
        }
Beispiel #8
0
        public RedirectToRouteResult WfsLayerEditorCreateNewLayer(string name, string filter, string serverUrl, string typeName, string color, bool useBbox)
        {
            var             viewManager = new WfsLayersViewManager(GetCurrentUser(), SessionHandler.MySettings);
            WfsLayerSetting wfsLayer    = viewManager.CreateNewWfsLayer(name, filter, serverUrl, typeName, color, useBbox);

            viewManager.AddWfsLayer(wfsLayer);
            return(RedirectToAction("WfsLayers"));
        }
Beispiel #9
0
        /// <summary>
        /// Render a WFS layer editor view.
        /// </summary>
        /// <param name="url">The WFS Server URL.</param>
        /// <param name="typeName">FeatureType.</param>
        /// <param name="filter">The filter.</param>
        /// <param name="mode">The mode.</param>
        /// <param name="id">The id (used if mode is Edit).</param>
        /// <returns></returns>
        public ActionResult WfsLayerEditor(string url, string typeName, string filter, WfsLayerEditorMode?mode, int?id)
        {
            ViewBag.RenderMapScriptTags = true;
            var viewManager = new WfsLayersViewManager(GetCurrentUser(), SessionHandler.MySettings);
            WfsLayerEditorViewModel model = viewManager.CreateWfsLayerEditorViewModel(url, typeName, filter, mode, id);

            return(View(model));
        }
Beispiel #10
0
        public RedirectToRouteResult CreateWfsLayer(string url, string name, string typeName)
        {
            var viewManager = new WfsLayersViewManager(GetCurrentUser(), SessionHandler.MySettings);
            var hexColor    = SessionHandler.MySettings.DataProvider.MapLayers.CreateMapLayerHexColor();
            var wfsLayer    = viewManager.CreateNewWfsLayer(name, "", url, typeName, hexColor, false);

            viewManager.AddWfsLayer(wfsLayer);
            return(RedirectToAction("WfsLayers"));
        }
Beispiel #11
0
 public PartialViewResult EnvironmentalDataSummary()
 {
     try
     {
         var wfsViewManager = new WfsLayersViewManager(GetCurrentUser(), SessionHandler.MySettings);
         var model          = wfsViewManager.CreateWfsLayersList();
         return(PartialView("EnvironmentalDataSummary", model));
     }
     catch (Exception ex)
     {
         return(PartialView("PartialViewError", ex));
     }
 }
        /// <summary>
        /// Creates the view model and set it's data.
        /// </summary>
        /// <returns>Returns a new SummaryStatisticsViewModel.</returns>
        public SummaryStatisticsViewModel CreateViewModel()
        {
            var model = new SummaryStatisticsViewModel();

            model.CalculateNumberOfObservationsfromObsData = SummaryStatisticsSetting.CalculateNumberOfObservationsfromObsData;
            model.CalculateNumberOfSpeciesfromObsData      = SummaryStatisticsSetting.CalculateNumberOfSpeciesfromObsData;

            // WFS Grid statistics
            model.WfsGridStatisticsLayerId = SummaryStatisticsSetting.WfsSummaryStatisticsLayerId;

            var wfsViewManager = new WfsLayersViewManager(UserContext, MySettings);

            model.WfsLayers         = wfsViewManager.CreateWfsLayersList();
            model.IsSettingsDefault = SummaryStatisticsSetting.IsSettingsDefault();
            return(model);
        }
Beispiel #13
0
        public JsonNetResult GetWfsLayerSettings(int id)
        {
            JsonModel jsonModel;

            try
            {
                var viewManager         = new WfsLayersViewManager(GetCurrentUser(), SessionHandler.MySettings);
                WfsLayerViewModel model = viewManager.CreateWfsLayerViewModel(id);
                jsonModel = JsonModel.CreateFromObject(model);
            }
            catch (Exception ex)
            {
                jsonModel = JsonModel.CreateFailure(ex.Message);
            }
            return(new JsonNetResult(jsonModel));
        }
Beispiel #14
0
        /// <summary>
        /// Returns all WFS layers stored in MySettings
        /// </summary>
        /// <returns></returns>
        public JsonNetResult GetWfsLayer()
        {
            JsonModel jsonModel;

            try
            {
                var viewManager = new WfsLayersViewManager(GetCurrentUser(), SessionHandler.MySettings);
                List <WfsLayerViewModel> wfsLayers = viewManager.CreateWfsLayersList();
                jsonModel = JsonModel.Create(wfsLayers);
            }
            catch (Exception ex)
            {
                jsonModel = JsonModel.CreateFailure(ex.Message);
            }

            return(new JsonNetResult(jsonModel));
        }
Beispiel #15
0
        /// <summary>
        /// Gets the logged in users all uploaded gis layers.
        /// </summary>
        /// <returns></returns>
        public JsonNetResult GetAllUploadedGisLayers()
        {
            JsonModel jsonModel;

            try
            {
                var viewManager       = new WfsLayersViewManager(GetCurrentUser(), SessionHandler.MySettings);
                var uploadedGisLayers = viewManager.GetAllUploadedGisFiles();
                jsonModel = JsonModel.Create(uploadedGisLayers);
            }
            catch (Exception ex)
            {
                jsonModel = JsonModel.CreateFailure(ex.Message);
            }

            return(new JsonNetResult(jsonModel));
        }
Beispiel #16
0
        /// <summary>
        /// Removes the specified WFS layers.
        /// </summary>
        /// <param name="wfsLayerIds">WFS layer ids.</param>
        /// <returns></returns>
        public JsonNetResult RemoveWfsLayers(int[] wfsLayerIds)
        {
            JsonModel jsonModel;

            try
            {
                var viewManager = new WfsLayersViewManager(GetCurrentUser(), SessionHandler.MySettings);
                viewManager.RemoveWfsLayers(wfsLayerIds);

                jsonModel = JsonModel.CreateSuccess("");
            }
            catch (Exception ex)
            {
                jsonModel = JsonModel.CreateFailure(ex.Message);
            }

            return(new JsonNetResult(jsonModel));
        }
Beispiel #17
0
        /// <summary>
        /// Removes the specified WFS layer.
        /// </summary>
        /// <param name="data">WfsLayer Id as JSON.</param>
        /// <returns></returns>
        public JsonNetResult RemoveWfsLayer(string data)
        {
            JsonModel jsonModel;

            try
            {
                var javascriptSerializer            = new JavaScriptSerializer();
                WfsLayerViewModel wfsLayerViewModel = javascriptSerializer.Deserialize <WfsLayerViewModel>(data);
                var viewManager = new WfsLayersViewManager(GetCurrentUser(), SessionHandler.MySettings);
                viewManager.RemoveWfsLayer(wfsLayerViewModel.Id);
                jsonModel = JsonModel.CreateSuccess("");
            }
            catch (Exception ex)
            {
                jsonModel = JsonModel.CreateFailure(ex.Message);
            }
            return(new JsonNetResult(jsonModel));
        }
Beispiel #18
0
        public JsonNetResult DeleteMapDataFile(string fileName)
        {
            var jsonModel = JsonModel.CreateSuccess("Ok");

            if (!MySettingsManager.DeleteMapDataFile(GetCurrentUser(), fileName))
            {
                jsonModel = JsonModel.CreateFailure("Deleting file failed.");
            }

            //Check if file layer is in use, if so, remove it
            var viewManager = new WfsLayersViewManager(GetCurrentUser(), SessionHandler.MySettings);
            var layer       = viewManager.GetWfsLayers().FirstOrDefault(l => l.Name == GetLayerName(fileName));

            if (layer != null)
            {
                viewManager.RemoveWfsLayer(layer.Id);
            }

            return(new JsonNetResult(jsonModel));
        }
Beispiel #19
0
        private bool AddFileWfsLayer(string fileName, FeatureCollection featureCollection)
        {
            var layerName = GetLayerName(fileName);

            var action = Url.Action("", "Wfs");
            var url    = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, action);

            var viewManager = new WfsLayersViewManager(GetCurrentUser(), SessionHandler.MySettings);

            var layer = viewManager.GetWfsLayers().FirstOrDefault(l => l.Name == layerName);

            if (layer == null)
            {
                var hexColor = SessionHandler.MySettings.DataProvider.MapLayers.CreateMapLayerHexColor();
                var wfsLayer = viewManager.CreateNewWfsFileLayer(layerName, fileName, Server.UrlEncode(fileName), "", url, featureCollection.Features[0].Geometry.Type.ToGeometryType(), hexColor, false);

                viewManager.AddWfsLayer(wfsLayer);

                return(true);
            }

            return(false);
        }
        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);
        }