This project has moved and is read-only. For the latest updates, please go here.

Rendering X and Y columns from a database as points

The OleDbPoint provider is used for rendering point data from an OleDb compatible datasource

The data source will need to have two double-type columns, xColumn and yColumn that contains the coordinates of the point, and an integer-type column containing a unique identifier for each row.

To get good performance, make sure you have applied indexes on ID, xColumn and yColumn in your datasource table.

//Connection string
string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=database.mdb";
//Name of table in database
string tablename = "pointsTable"; 
//Name of object ID column - MUST be integer!
string oid = "ID"; 
//Name of X coordinate column - MUST be double!
string xColumn = "X";
//Name of Y coordinate column - MUST be double!
string yColumn = "Y";

//Initialize map object
SharpMap.Map myMap = new SharpMap.Map(new System.Drawing.Size(500,250));
//Create layer
SharpMap.Layers.VectorLayer layAddresses = new SharpMap.Layers.VectorLayer("Addresses"); 
//Set the datasource to the database
layAddresses.DataSource = 
    new SharpMap.Data.Providers.OleDbPoint(connStr, tablename, oid, xColumn, yColumn);
//Add layer to map

//Zoom to extents

System.Drawing.Image img = myMap.GetMap(); //Render map

Last edited Oct 2, 2013 at 6:48 AM by FObermaier, version 4