DotSpatial Tutorials_DotSpatial_Tutorial_3
DotSpatial Tutorials_DotSpatial_Tutorial_3
Purpose of this tutorial: Become familiar with the following raster operations in DotSpatial:
6. Get the mouse clicked point values on the raster data layer.
Step 2: Add the DotSpatial reference and change the compile option.
Step 3: Add the DotSpatial Controls into the Visual Studio Toolbox.
Step 4: Copy the Data Extensions folder to the debugs folder of the current project
Step 2: Add the DotSpatial reference and change the compile option.
Teva ~ VeluppillaiPage 1
Introduction to Programming with DotSpatial
Change the compile option from .Net Framework 4 Client Profile to .Net Framework4.
Step 3: Add the DotSpatial Controls into the Visual Studio Toolbox.
Step 4: Copy the Data Extension folder from your downloaded folder to your current project bin/debug
folder. The .dlls from this folder is necessary for GDAL data provider access.
Teva ~ VeluppillaiPage 2
Introduction to Programming with DotSpatial
Teva ~ VeluppillaiPage 3
Introduction to Programming with DotSpatial
6. Drag a “Legend” control from the DotSpatial tab under toolbox and drop it on pnlLegend. Legend
properties should be as follows:
7. Drag a “Map” control from the DotSpatial tab under toolbox and drop it on pnlMap. Map properties
should be as follows:
8. Drag an "AppManager" control from DotSpatial tab under toolbox and drop it on the form.
Note: This control is necessary for loading different formats of raster data.
Teva ~ VeluppillaiPage 4
Introduction to Programming with DotSpatial
Fig. 4 AppManager
//Required namespaces
using DotSpatial.Symbology;
using DotSpatial.Controls;
using DotSpatial.Data;
using DotSpatial.Topology;
Teva ~ VeluppillaiPage 5
Introduction to Programming with DotSpatial
if (map1.Layers.Count > 0)
{
if (layer == null)
{
MessageBox.Show("Please select a raster layer");
return;
}
layer.Symbolizer.ShadedRelief.ElevationFactor = 1;
layer.Symbolizer.ShadedRelief.IsUsed = true;
layer.WriteBitmap();
}
else
{
MessageBox.Show("Please add a layer to the map.");
}
}
if (layer == null)
{
MessageBox.Show("Please add a raster layer.");
return;
}
scheme.AddCategory(category2);
}
else
{
MessageBox.Show("Please add a layer to the map.");
}
Teva ~ VeluppillaiPage 7
Introduction to Programming with DotSpatial
if (layer == null)
{
MessageBox.Show("Please select a raster layer");
}
newRaster.NoDataValue = demRaster.NoDataValue;
newRaster.Projection = demRaster.Projection;
else
{
MessageBox.Show("Please add a layer to the map.");
}
Teva ~ VeluppillaiPage 8
Introduction to Programming with DotSpatial
if (layer == null)
{
MessageBox.Show("Please select a raster layer.");
}
else
{
//get the raster dataset
IRaster demRaster = layer.DataSet;
//reclassify raster.
// values >= specified value will have new value 1
// values < specified value will have new value 0
double oldValue = 0;
Teva ~ VeluppillaiPage 9
Introduction to Programming with DotSpatial
newRaster.Save();
map1.Layers.Add(newRaster);
}
}
Get the mouse clicked point values on the raster data layer.
Teva ~ VeluppillaiPage 10
Introduction to Programming with DotSpatial
{
IMapRasterLayer rasterLayer = map1.Layers.SelectedLayer as
IMapRasterLayer ;
if ((rasterLayer != null))
{
//set the map cursor to cross
map1.Cursor = Cursors.Cross;
}
else
{
//if no raster layer is selected, uncheck the checkbox
MessageBox.Show("Please select a raster layer.");
chbRasterValue.Checked = false;
}
}
else
{
//change map cursor back to arrow
map1.Cursor = Cursors.Arrow;
}
Teva ~ VeluppillaiPage 11
Introduction to Programming with DotSpatial
if ((rasterLayer != null))
{
Teva ~ VeluppillaiPage 12
Introduction to Programming with DotSpatial
Teva ~ VeluppillaiPage 13
Introduction to Programming with DotSpatial
Teva ~ VeluppillaiPage 14
Introduction to Programming with DotSpatial
Teva ~ VeluppillaiPage 15
Introduction to Programming with DotSpatial
Fig.12 Getting the mouse click point value on the raster data file.
Teva ~ VeluppillaiPage 16