Saturday, April 18, 2009

Rendering ESRI shapefile

Follow these steps to parse ESRI shapefile and render it using any programming languages like C++,C# or Java.The procedure discussed assumes working knowledge of GIS and Qt/Visual Studio 6.Knowledge on Graphics programming using GDI/GDI+ or OpenGL is an advantage.There are plenty of opensource tools like JUMP,SharpMap FWTools etc to render various GIS Raster and Vector file formats.This article is to help beginner level GIS programmers who like to create their own stuff.Let's begin with the following steps.

1) Grab shepelib by Frank Warmerdam and build the library from source .You can also make use of pre-built binaries.

2) Use your shapefiles in your possession or those available at shepelib

3)I used OpenGL and Visual Studio 6 for rendering.The GLUT library is used for rendering context.

4)Include the shapelib.h in your C++ program for parsing shapefiles.Link to shapelib.dll and shapelib.lib

-Declare variables to store points,lines or polygons

-Query the bounding box of every shapefile that is being opened.Readjust the rendering area to accommodate the bounding box with largest area.

-Render the point,line polygon shapefiles using drawing primitives like GL_POINTS,GL_LINES,GL_LINELOOP.

That is all to to have a decent beginning.The same logic holds good for other GIS vector formats like MIF,DGN etc, provided the relevant libraries to parse them are used.

You can have a peek at my Article for the detailed version of the same topic.It includes sample VS6 workspace to experiment on.

Creating Custom Line Styles in GIS Applications

Have a look at an article on creating custom lines styles . http://www.codeproject.com/KB/GDI/AestheticLines.aspx.