This tutorial was designed to give new users a quick (relatively speaking) introduction to the concepts behind SharpMap. It is arranged in examples with increasing complexity. Users can jump to any section at any time although it is recommended that absolute beginners work on sections sequentially.

The examples uses Visual Studio. I you use any other development environment you can probably do similar tasks.

TestData
Download this zipfile to get the testdata used in this tutorial
states_ugl.zip

  1. Tutorial - Creating a Form with a MapControl
  2. Tutorial - Example 1: Adding 1 layer to the Map
  3. Tutorial - Example 2: Styling the layer with UniqueValueRenderer
  4. Tutorial - Example 3: Adding a WMS-layer to the map
  5. Tutorial - Example 4: Adding a Tiled layer as Background

Last edited Jun 28, 2012 at 10:12 AM by petlof, version 8

Comments

Pablo_PERU Feb 11, 2013 at 7:02 PM 
PROBLEM:
Postgresql + Postgis + SharpMap, NOT display a map in the Mapbox Control.
Source:
Dim vlay As SharpMap.Layers.VectorLayer = New SharpMap.Layers.VectorLayer("States", New SharpMap.Data.Providers.PostGIS("Server=192.168.x.x;Port=5432;UserId=postgres;Password=xxx;Database=template_postgis_20;", "states_ugl", "geom", "gid"))
MapBox1.Map.Layers.Add(vlay)
MapBox1.Map.ZoomToExtents()
MapBox1.Refresh()

SOLUTION:
Sharpmap is encoded with legacy funtions: extent() and asbinary(), are actually: st_extent() and st_asbinary() (only the st_ prefix). You can add this st_ prefix on the sources and recompile Sharpmap, OR agregate this functions to you postgis schema, finding C:\Program Files\PostgreSQL\9.2\share\contrib\postgis-2.0\legacy.sql.
Execute this SQL queries (replace "public." by your schema name:

CREATE OR REPLACE FUNCTION public.AsBinary(geometry)
RETURNS bytea
AS '$libdir/postgis-2.0','LWGEOM_asBinary'
LANGUAGE 'c' IMMUTABLE STRICT;

CREATE OR REPLACE FUNCTION public.AsBinary(geometry,text)
RETURNS bytea
AS '$libdir/postgis-2.0','LWGEOM_asBinary'
LANGUAGE 'c' IMMUTABLE STRICT;

CREATE AGGREGATE public.Extent(
sfunc = ST_combine_bbox,
basetype = geometry,
finalfunc = box2d,
stype = box3d
);