Not Displaying a PostGIS LAyer

Topics: SharpMap v0.9 / v1.x
Feb 16, 2009 at 4:32 AM
Edited Feb 16, 2009 at 4:42 AM
I have read all discussions conducted before in which this issue was discussed bt my error is unique so plz help...code um writing is given below






using System.Collections.Generic;




using System.ComponentModel;




using System.Data;




using System.Drawing;




using System.Text;




using System.Windows.Forms;




using SharpMap.Layers;









namespace WindowsApplication1






public partial class Form1 : Form




//--> Define the SharpMap object




SharpMap.Map _sharpMap;




//--> Zoom Factor




const float ZOOM_FACTOR = 0.3f;




public Form1()  






//--> Initialize the Map 




_sharpMap =

new SharpMap.Map(new Size(1300, 750));



 _sharpMap.BackColor =





//--> Add the first Layer




SharpMap.Layers.VectorLayer myLayer = new SharpMap.Layers.VectorLayer("My layer");




string ConnStr = "Server=localhost;Port=5432;User Id=postgres;Password=tiger;Database=Geocode;";



 myLayer.DataSource =

new SharpMap.Data.Providers.PostGIS(ConnStr, "testline", "geom","OID");




//Setup linestyle




myLayer.Style.Line.Width = 2;


myLayer.Style.Line.Color =




 myLayer.Style.Line.EndCap = System.Drawing.Drawing2D.



LineCap.Round; //Round end


myLayer.Style.EnableOutline =true;



 myLayer.SmoothingMode = System.Drawing.Drawing2D.

SmoothingMode.AntiAlias; //Render smooth lines




//myLayer.MaxVisible = 40000;











System.Drawing.Image imgMap = _sharpMap.GetMap();




// _sharpMap.ZoomToExtents();




picMap.Image = _sharpMap.GetMap();




This code runs and giving me no error but does not display anything. And if un comment the second last line it gives me the following Exception:


picMap.Image = _sharpMap.GetMap();



InvalidCastException was Unhadeled
Unable to cast object of type 'System.String' to type 'System.Byte[]'

Um using SharpMap.dll which includes PostGIS.cs extension included which means i did not add PostGIS.cs in trunk and if i do with other SharpMap.dll which does not include PostGIS.cs in it and if i add this external class it gives me error in PostGIS.cs class.....
Thanx for any kinda help in advance!!!

Feb 16, 2009 at 7:08 AM
To me it seems that there is something wrong with the spatial table you are trying to access.
Could you provide columns and datatypes of the table 'testline'of database 'Geocode'
(e.g. the Create statement provided via pgAdminIII)
Apr 9, 2009 at 7:12 PM
Edited Apr 10, 2009 at 10:31 AM
I too got the same issue, but its because of PostGIS.cs file. U need to add it. It all worked for me when I add the sharpMap class library (what you get inside the zip file downloaded to add PostGIS functionality to sharMap.) as a project to my current project solution in Visual Studio.

U don't get anything because when you comment " _sharpMap.ZoomToExtents();", which is used for map rendering; map wont be displayed.

Supunmali Ahangama