Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

scrollbar

...

Exercise outline

The goal of this exercise is to visualize multiple data sets on one single map. This makes it possible to compare different data sets at the same geospatial location(s) and/or for the same modelling time step(s).
With this exercise it should be possible to show, as an example, both the input data and the output data of a volume model in one single map view.

...

Add to the plugin project a new folder named Layers. In this folder, create a new class named VolumeModelLayerProvidernamed DrainageBasinFeatureCollection.cs and adapt the contents as shown below:

Code Block
languagec#
using System.Collections;
using System.ComponentModel;
using DeltaShell.Plugins.VolumeModel.Models;
using NetTopologySuite.Extensions.Features;
using SharpMap.Data.Providers;
namespace DeltaShell.Plugins.VolumeModel.Layers
{
    /// <summary>
    /// Defines a feature collection (used by layers for rendering) for a DrainageBasin
    /// </summary>
    public class DrainageBasinFeatureCollection : FeatureCollection
    {
        private readonly DrainageBasin drainageBasin;
        public DrainageBasinFeatureCollection(DrainageBasin drainageBasin)
            : base((IList)drainageBasin.Catchments, typeof(Feature))
        {
            this.drainageBasin = drainageBasin;
            // copy coordinatesystem and for monitor changes of the coordinatesystem
            CoordinateSystem = (GeoAPI.Extensions.CoordinateSystems.ICoordinateSystem) drainageBasin.CoordinateSystem;
            drainageBasin.PropertyChanged += DrainageBasinPropertyChanged;
        }
        private void DrainageBasinPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "CoordinateSystem")
            {
                CoordinateSystem = (GeoAPI.Extensions.CoordinateSystems.ICoordinateSystem) drainageBasin.CoordinateSystem;
            }
        }
        public override void Dispose()
        {
            // Desubscribe from drainageBasin so this DrainageBasinFeatureCollection can be disposed
            drainageBasin.PropertyChanged -= DrainageBasinPropertyChanged;
            base.Dispose();
        }
    }
}

 

Then create a new class VolumeModelLayerProvider.cs in the same folder

Code Block
languagec#
using System.Collections.Generic;
using DelftTools.Shell.Gui;
using DeltaShell.Plugins.VolumeModel.Models;
using SharpMap.Api.Layers;
using SharpMap.Layers;

namespace DeltaShell.Plugins.VolumeModel.Layers
{
       public class VolumeModelMapLayerProvider : IMapLayerProvider
       {
               /// <summary>
               /// Defines that layers can be provided for volume models
        and DrainageBasins
        /// </summary>
               public bool CanCreateLayerFor(object data, object parentData)
               {
                       return data is Models.VolumeModel;
        }

        ||
                   data is DrainageBasin;
        }
        /// <summary>
               /// Creates a volume model group layer
        and DrainageBasin layer
        /// </summary>
               public ILayer CreateLayer(object data, object parentData)
               {
                       var volumeModel = data as Models.VolumeModel;
                       if (volumeModel != null)
                       {
                               return new GroupLayer(volumeModel.Name);
            }
            var drainageBasin = data as DrainageBasin;
            }

           
            if (drainageBasin != null)
            {
                return new VectorLayer("Drainage basin")
                    {
                        DataSource = new DrainageBasinFeatureCollection(drainageBasin)
                    };
            }
            return null;
               }

               /// <summary>
               /// Returns all children for which a child layer should be created in volume model group layers
               /// </summary>
               public IEnumerable<object> ChildLayerObjects(object data)
               {
                       var volumeModel = data as Models.VolumeModel;
                       if (volumeModel != null)
                       {
                               // In the end a child layer should be created for both the basin input data and the volume output data
                               yield return volumeModel.Basin;
                               yield return volumeModel.Volume;
                       }
               }
       }
}

Info

The map layer provider class is derived from the IMapLayerProvider interface so that it can be registered in the gui plugin (see the next step).

The comments in the code explain the different parts of the provider implementation.

...

Register the map layer provider in the gui plugin by adding the following code to VolumeModelGuiPlugin.cs:

Code Block
languagec#
using DeltaShell.Plugins.VolumeModel.Layers;

and

Code Block
languagec#
        public override IMapLayerProvider MapLayerProvider
        {
            get { return new VolumeModelMapLayerProvider(); }
        }

...

Set up a volume model as described in the results of a previous exercise (Create a simple hydrological Volume model).
After creating the volume model, the corresponding map view should have been opened automatically. However, the data will not be immediately shown in this view, even after running the volume model. Two further actions are required.

...

{scrollbar}
Info

The order of the different data layers in a map view can be adjusted using the context menus in the Map window (right click on a data layer | Order | ... ).

Additionally, WMS layers can be included to help identifying the actual geographical location of map data. Follow these steps:

  1. Add a new WMS layer to the map using the Map window (click the Add New Wms Layer ... button). In the Open web link ... dialog, select Microsoft Bing Maps - Satellite Hybrid. A new map layer will be added to the view. However, this layer is initially projected using a different coordinate system than the one for the volume output data:
    Image RemovedSelect the same coordinate systems for the different map layers in the Map window (right click on the map group layer | Change Map Coordinate System ...). In the corresponding dialog, look for the coordinate system WGS_1984_Web_Mercator and assign it to all layers in the group. The map view should now represent all layers using the same coordinate system. Zoom to the volume group layer (right click on the volume model group layer in the Map window | Zoom to Extend) to see all data at their appropriate location:
    Image Removed
Wiki Markup


  1. Image Added

scrollbar