You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 34 Next »

Contents

The root page TOOLS:Tutorial could not be found in space Delta Shell.

Exercise outline

The goal of this exercise is to visualize multiple data sets on one single map; doing so, different data sets can be compared at the same geospatial position(s) and/or for the same modeling time step(s).

As an example, after this exercise it should be possible to show both the input data and the output data of a volume model in one and the same map view.

Create a new map layer provider

Add a new folder to the plugin project named Layers. In this folder, create a new class named VolumeModelLayerProvider.cs and add the following code:

using System.Collections.Generic;
using DelftTools.Shell.Gui;
using DeltaShell.Plugin.DemoApp.Models;
using SharpMap.Api.Layers;
using SharpMap.Layers;

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

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

            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 VolumeModel;
            if (volumeModel != null)
            {
                // In the end a child layer should be created for both the catchment input data and the volume output data
                yield return volumeModel.Basin;
                yield return volumeModel.Volume;
            }
        }
    }
}

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

Furthermore, the comments in the code should explain the different parts of the provider implementation.

A description on the backgrounds and usage of (group) layers is not part of this tutorial.

[TODO]

Add links to some wiki pages?

Register the map layer provider in the gui plugin class

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

using DeltaShell.Plugin.DemoApp.Layers;

and

        public override IMapLayerProvider MapLayerProvider
        {
            get { return new VolumeModelMapLayerProvider(); }
        }

Delta Shell should now be able to open a map view for volume models, containing both their catchment input data and their volume output data (if present).

Exercise results

Setup a volume model as described in the results of a previous exercise (see Create a simple hydrological model).

Directly after creating the volume model, a corresponding map view should have been opened automatically.

Even after running the volume model, though, no data will be visible in the view; two more actions are needed.

First of all, part of the volume model data is already present but just

  • No labels