Click here to Skip to main content
15,884,099 members
Articles / Web Development / HTML

Add GIS and Mapping Functionality to your .NET Applications

Rate me:
Please Sign up or sign in to vote.
4.79/5 (16 votes)
28 Sep 2014CPOL3 min read 75.3K   11.9K   33   17
Add GIS and Mapping Functionality to your .NET Applications

Sample Image - maximum width is 600 pixels Sample Image - maximum width is 600 pixels

Introduction

I assume you have a basic knowledge of ASP.NET and C#.NET, and so on.
Easy GIS .NET is a suite of .NET GIS mapping tools and controls to let developers easily incorporate GIS functionality into their own applications. The Desktop Edition includes a stand-alone viewing application which can be used to open and view ESRI shapefiles. This application is built using the same .NET controls that can be included in your own applications. Easy GIS .NET is a free software released under the Lesser General Public License. You can freely use it in personal and commercial software.

Background

Presently, I am working on a project where I need to generate some map based on various distributions on Bangladesh map. I am using QGIS (A Free and Open Source Geographic Information System) which is an excellent tool to generate complex map. Then I wanted to generate some map based on my database value so I searched in Google and Easy GIS grab my attention. After some initial struggle, I am able to generate something that I think will be required by many.

How to Configure

Step 1

Download the required .dll from here.

Step 2

Start a new project as ASP.NET Web application; give the name as WebExample1. It will give you one Default.aspx and .cs file.

Step 3

Now add these references:

  • EGIS.ShapeFileLib.dll
  • EGIS.Web.Controls.dll
  • geomutil_lib.dll
  • geomutil_libx64.dll

Step 4

Add the below mentioned code in Web.config file under "system.web" section:

ASP.NET
      <httpHandlers>
 <add path="egismap.axd" verb="*"
 type="EGIS.Web.Controls.SFMapImageProvider, EGIS.Web.Controls,
 Version=4.3.0.0, Culture=neutral, PublicKeyToken=05b98c869b5ffe6a"
  validate="true" />
</httpHandlers>

Step 5

Download shapefile for Bangladesh from here.

Step 6

Add the folder in your project.

Step 7

Download bangladesh.egp here.

Step 8

Add the file in your project

Step 9

Now your Solution Explorer will look like this:

Image 3

Using the Code

Now pay some attention to the "bangladesh.egp" file:

XML
<sfproject version="1.0">
  <MapBackColor>buttonface</MapBackColor>
  <layers>
    <shapefile>
      <name>BGD_adm3.shp</name>
      <path>bangladesh/BGD_adm3</path>
      <renderer>
        <MinZoomLevel>-1</MinZoomLevel>
        <MaxZoomLevel>-1</MaxZoomLevel>
        <MinRenderLabelZoom>-1</MinRenderLabelZoom>
        <FieldName>NAME_3</FieldName>
        <Font Size="10" Name="Microsoft Sans Serif" Style="Regular">
        </Font>
        <FontColor>Black</FontColor>
        <FillColor>#FCFCFC</FillColor>
        <OutlineColor>#969696</OutlineColor>
        <PenWidthScale>0.0001355183</PenWidthScale>
        <FillInterior>True</FillInterior>
        <Selectable>False</Selectable>
        <LineType>Outline</LineType>
        <ShadowText>True</ShadowText>
        <PointSize>5</PointSize>
        <UseToolTip>True</UseToolTip>
        <ToolTipFieldName>NAME_3</ToolTipFieldName>
      </renderer>
    </shapefile>
  </layers>
</sfproject>
  1. <name> field contains the shapefile name, so change it accordingly.
  2. <path> field contains the location of the shapefile, so change it accordingly.
  3. Change rest of the fields accordingly.

Now compile and run the project. You will see your assigned map.

Now, we want to display some distribution wise data at district level.
For this purpose, I have added a column name "popu_mis" which contains district wise population in BGD_adm3.shp file.

What is shapefile

The shapefile format is now a common format for storing GIS data. Shapefiles stored non-topological vector data along with related attribute data. Developed by Esri, shapefiles can be directly read by a number of GIS software programs such as ArcGIS and QGIS. A shapefile is actually a collection of at least three basic files: .shp, .shx and .dbf. All three files must be present in the same directory for them to be viewable. There may be additional files such as a .prj with the shapefile’s projection information. Commonly, shapefiles are compressed in a .zip file for transfer such as emailing as an attachment or via a web site download.

If you want to learn more about shapefile, then click here.
If you want to download shapefile viewer, then click here.

Render with Data

C#
private void SetupPopulation()
{
    TooltipHeaderFieldNamePair[] tooltipPairs;
    tooltipPairs = new TooltipHeaderFieldNamePair[] { 
            new TooltipHeaderFieldNamePair("District: ", "NAME_3"),
            new TooltipHeaderFieldNamePair("Population: ", "popu_mis")};
    SetupCustomRenderSettings("popu_mis", 0, tooltipPairs);
}

"NAME_3" is the district field and "popu_mis" is the population field. It will create a tooltip text.

C#
double[] samples = new double[numRecords];
//find the range of population values and obtain the quintile quantiles
for (int n = 0; n < numRecords; n++)
{
    if (String.IsNullOrEmpty(dbfReader.GetField(n, fieldIndex)) == false)
    {
        string tmp = dbfReader.GetField(n, fieldIndex);
        int value;
        if (int.TryParse(tmp, out value))
        {
            double d = double.Parse(dbfReader.GetField(n, fieldIndex), System.Globalization.CultureInfo.InvariantCulture);
            samples[n] = d;
        }
    }
}

This code creates an array of population distribution value from shapefile.

C#
private static double[] GetQuintiles(double[] samples)
{
    Array.Sort(samples);
    double[] quintiles = new double[4];

    quintiles[0] = samples[10];
    quintiles[1] = samples[30];
    quintiles[2] = samples[50];
    quintiles[3] = samples[60];
    return quintiles;
}

This code creates an array of range value. eg. 10000-20000, 20000-40000, 40000-80000, etc.

C#
Color[] cols = new Color[] { 
        Color.FromArgb(96,169, 108), 
        Color.FromArgb(201, 200, 123), 
        Color.FromArgb(157, 135, 151), 
        Color.FromArgb(112, 155, 235),
        Color.FromArgb(192,94,113)};
}

This code creates an array of colors. There will be 1 more color than the number of elements in quantiles.

After running the code, you will see the below MAP with tooltip population and district name value.

Image 4

References

Conclusion

Easy GIS is fast and easy to implement for basic mapping functionality. Still I am unable to display the legend.

 

 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) icddr,b
Bangladesh Bangladesh
More than 8 years experience on Programming and Project implementation, I was primarily involved with projects for private organization,Govt.(Bangladesh Army,DG Health,RJSC), NGO (SEDF,WFP). Presently I am working at ICDDR,B and enhancing Hospital Management System developed by Microsoft Dynamic NAV and Windows Mobile Application 5.0

An active supporter of Open Source technology, my interested areas are ERP, IT Audit, Data warehouse, BI etc.

Playing Guitar for 15 years, my interested music style is Blues Rock,Neo Classical.

Certification

70-540:Microsoft® Windows Mobile® 5.0 - Application Development
MB7-514:Microsoft Dynamics™ NAV 5.0 C/SIDE Introduction
MB7-516:Microsoft Dynamics™ NAV 5.0 Solution Development
MB7-517:Microsoft Dynamics™ NAV 5.0 Installation and Configuration
MB7-515:Microsoft Dynamics™ NAV 5.0 Financials
70-432:Microsoft SQL Server 2008 - Implementation and Maintenance
70-450:PRO: Designing, Optimizing and Maintaining a Database Administrative Solution Using Microsoft SQL Server 2008
70-448:Microsoft SQL Server 2008, Business Intelligence Development and Maintenance
312-50:Certified Ethical Hacker

Web :http://masudparvezshabuz.appspot.com
Blog :http://masudparvezshabuz.wordpress.com
linkedin :http://www.linkedin.com/in/masudparvez

Comments and Discussions

 
Questionhttphandler not working Pin
giopx30-Jun-20 7:28
giopx30-Jun-20 7:28 
Questionno map found - check egismap.axd handler added to web.config Pin
shivi.gothi15-Jun-20 5:10
shivi.gothi15-Jun-20 5:10 
AnswerRe: no map found - check egismap.axd handler added to web.config Pin
bstinson29-Nov-20 9:37
bstinson29-Nov-20 9:37 
QuestionGis Mapping in mvc project Pin
Member 1236309412-Jan-17 19:33
Member 1236309412-Jan-17 19:33 
GeneralEGP File Pin
Member 1264240819-Jul-16 2:44
Member 1264240819-Jul-16 2:44 
QuestionDLL Questions Pin
pravee michael30-Sep-15 0:25
pravee michael30-Sep-15 0:25 
QuestionDLL reference not adding Pin
santosh_100221-Aug-15 2:50
santosh_100221-Aug-15 2:50 
QuestionHow do i continuous drawing a shapefile when the geographic coordinates wrap around from 180 degrees to -180 Pin
Savic7uk5-Aug-15 13:47
Savic7uk5-Aug-15 13:47 
QuestionUnable to run using VS2013 and .NET 4.5 Pin
deskcheck121-Jan-15 8:00
deskcheck121-Jan-15 8:00 
AnswerRe: Unable to run using VS2013 and .NET 4.5 Pin
mparvez24-Jan-15 16:30
mparvez24-Jan-15 16:30 
QuestionASP.Net 2.0 or 4.0 Pin
johnSDNHM2-Oct-14 7:39
johnSDNHM2-Oct-14 7:39 
AnswerRe: ASP.Net 2.0 or 4.0 Pin
johnSDNHM22-Oct-14 7:49
johnSDNHM22-Oct-14 7:49 
QuestionMy vote of 1 Pin
Member 188040329-Sep-14 3:07
Member 188040329-Sep-14 3:07 
GeneralMy vote of 1 Pin
Member 188040329-Sep-14 3:03
Member 188040329-Sep-14 3:03 
QuestionVote 4. Pin
Maxim Rylov29-Sep-14 0:04
Maxim Rylov29-Sep-14 0:04 
AnswerRe: Vote 4. Pin
mparvez29-Sep-14 7:27
mparvez29-Sep-14 7:27 
GeneralMy vote of 5 Pin
Humayun Kabir Mamun28-Sep-14 19:17
Humayun Kabir Mamun28-Sep-14 19:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.