Unable to connect to postgis database

Topics: SharpMap v0.9 / v1.x, SharpMap v2.0
Oct 22, 2009 at 5:33 AM

Hi all,

Recently I have started working with sharpmap.I am using SharpMap.dll and SharpMap.UI.dll which I have kept in the Bin folder.I am succesfully able to work with shape files.Now I wan't to connect to the postgis database.I have kept the postgis.cs file into the AppCode folder.I am getting the postgis control but getting an error aswell "NumberFormat". I have seen in previous discussions that I have to use recent sharpmap to avoid the error.I have downloaded the change set '60134'.Now my question is that to connect to postgis is it required to compile this source code because I am not having VS2008.I am using vs2005.

Or else is their any other way i can use the postgis.cs file to connect to the database?? My target is just to add layers from database so I just need to get the control over postgis.

Please help.

Sayan

 

Coordinator
Oct 22, 2009 at 10:18 AM

Hi Sayan - please see updated binaries on downloads page. hth jd

Coordinator
Oct 22, 2009 at 11:31 AM

Hi Sayan, for postgis support you have to add a reference to SharpMap.Extensions, too.

Hth FObermaier

Oct 22, 2009 at 11:32 AM

Hi Sayan,

In my case, i did add sharpMap project to my  VS solution and then did add the references to other projects in my solution. Then I replaced postgis.cs file in Data/providers folder. It worked fine for me.

In VS 2005 as well as in VS2008.

 

Oct 23, 2009 at 10:03 AM

Hi Jondiss,

Thanks for the support. I am able to get the handle over the postgis using the sharpmap.extension,dll file. For shape file it was running fine but with postgis I am getting an error which is -

Method 'GetGeometriesInView' in type 'SharpMap.Data.Providers.PostGIS' from assembly 'SharpMap.Extensions, Version=0.9.3575.26260, Culture=neutral, PublicKeyToken=null' does not have an implementation.

I am getting this in the line :

myMap = InitializeMap(

new System.Drawing.Size((int)imgMap.Width.Value, (int)imgMap.Height.Value));

My as code is as below-

using System;

using System.Net;

using System.Globalization;

using System.IO;

using SharpMap.Data.Providers;

using System.Collections.Generic;

using System.Drawing;

using SharpMap.Data;

using System.Data;

using System.Text;

using SharpMap.Geometries;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using SharpMap.Layers;

 

public partial class Default : System.Web.UI.Page

{

private SharpMap.Map myMap;

protected void Page_Load(object sender, EventArgs e)

{

//Set up the map

myMap = InitializeMap(new System.Drawing.Size((int)imgMap.Width.Value, (int)imgMap.Height.Value));

if (Page.IsPostBack)

{

//Page is post back. Restore center and zoom-values from viewstate

myMap.Center = (SharpMap.Geometries.Point)ViewState["mapCenter"];

myMap.Zoom = (double)ViewState["mapZoom"];

}

else

{

//This is the initial view of the map. Zoom to the extents of the map:

myMap.ZoomToExtents();

//Save the current mapcenter and zoom in the viewstate

ViewState.Add("mapCenter", myMap.Center);

ViewState.Add("mapZoom", myMap.Zoom);

//Create the map

CreateMap();

}

}

protected void imgMap_Click(object sender, ImageClickEventArgs e)

{

 

CreateMap();

}

private SharpMap.Map InitializeMap(System.Drawing.Size outputsize)

{

SharpMap.Map map = new SharpMap.Map(outputsize);

SharpMap.Layers.VectorLayer laystateboundary = new SharpMap.Layers.VectorLayer("state");

laystateboundary.DataSource = new SharpMap.Data.Providers.PostGIS("Server=172.16.177.4;Port=5432;User Id=postgres;Password=satyam@123;Database=postgis", "apstateboundary","gid");

laystateboundary.Style.Fill = new SolidBrush(Color.Green);

laystateboundary.Style.Outline = System.Drawing.Pens.DarkCyan;

laystateboundary.Style.EnableOutline = true;

map.Layers.Add(laystateboundary);

return map;

}

private void CreateMap()

{

System.Drawing.Image img = myMap.GetMap();

string imgID = SharpMap.Web.Caching.InsertIntoCache(1, img);

imgMap.ImageUrl = "getmap.aspx?ID=" + HttpUtility.UrlEncode(imgID);

}

}

 

Please help,

Hi Jondiss,

Thanks for the support. I am able to get the handle over the postgis using the sharpmap.extension,dll file. For shape file it was running fine but with postgis I am getting an error which is -

Method 'GetGeometriesInView' in type 'SharpMap.Data.Providers.PostGIS' from assembly 'SharpMap.Extensions, Version=0.9.3575.26260, Culture=neutral, PublicKeyToken=null' does not have an implementation.

I am getting this in the line :

<font size="2">

myMap = InitializeMap(

</font>

new System.Drawing.Size((int)imgMap.Width.Value, (int)imgMap.Height.Value));

My as code is as below-

using System;

using System.Net;

using System.Globalization;

using System.IO;

using SharpMap.Data.Providers;

using System.Collections.Generic;

using System.Drawing;

using SharpMap.Data;

using System.Data;

using System.Text;

using SharpMap.Geometries;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using SharpMap.Layers;

 

public partial class Default : System.Web.UI.Page

{

private SharpMap.Map myMap;

protected void Page_Load(object sender, EventArgs e)

{

//Set up the map

myMap = InitializeMap(new System.Drawing.Size((int)imgMap.Width.Value, (int)imgMap.Height.Value));

if (Page.IsPostBack)

{

//Page is post back. Restore center and zoom-values from viewstate

myMap.Center = (SharpMap.Geometries.Point)ViewState["mapCenter"];

myMap.Zoom = (double)ViewState["mapZoom"];

}

else

{

//This is the initial view of the map. Zoom to the extents of the map:

myMap.ZoomToExtents();

//Save the current mapcenter and zoom in the viewstate

ViewState.Add("mapCenter", myMap.Center);

ViewState.Add("mapZoom", myMap.Zoom);

//Create the map

CreateMap();

}

}

protected void imgMap_Click(object sender, ImageClickEventArgs e)

{

 

CreateMap();

}

private SharpMap.Map InitializeMap(System.Drawing.Size outputsize)

{

SharpMap.Map map = new SharpMap.Map(outputsize);

SharpMap.Layers.VectorLayer laystateboundary = new SharpMap.Layers.VectorLayer("state");

laystateboundary.DataSource = new SharpMap.Data.Providers.PostGIS("Server=172.16.177.4;Port=5432;User Id=postgres;Password=satyam@123;Database=postgis", "apstateboundary","gid");

laystateboundary.Style.Fill = new SolidBrush(Color.Green);

laystateboundary.Style.Outline = System.Drawing.Pens.DarkCyan;

laystateboundary.Style.EnableOutline = true;

map.Layers.Add(laystateboundary);

return map;

}

private void CreateMap()

{

System.Drawing.Image img = myMap.GetMap();

string imgID = SharpMap.Web.Caching.InsertIntoCache(1, img);

imgMap.ImageUrl = "getmap.aspx?ID=" + HttpUtility.UrlEncode(imgID);

}

}

 

Please help,

Thanks - Sayan

<font face="Arial" size="2"><font face="Arial" size="2"></font></font><font face="Arial" size="2"></font> 

 

<font face="Courier New" size="2"><font face="Courier New" size="2">

 

 

</font></font>

<font face="Courier New" size="2">

 

</font>

 

Coordinator
Oct 24, 2009 at 12:15 PM

Can you post a full stack trace?

Oct 25, 2009 at 5:59 PM

Thanks Johndiss. I have made it. Was having some trouble initially but now working fine.

 

Regards,

Sayan