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

PostGIS provider problem

Topics: SharpMap Project
May 27, 2009 at 5:13 PM
Edited May 27, 2009 at 5:40 PM

Hi all,

I used method postGIS to load to layer table from spatial DB ,it run without errors but there aren't output 

SharpMap.Map myMap = new SharpMap.Map(new Size(400, 300));
            myMap.MinimumZoom = 100; //Minimum zoom allowed
            myMap.BackColor = Color.White; //Set background
            myMap.Center = new SharpMap.Geometries.Point(725000, 6180000); //Set center of map
            myMap.Zoom = 1200; //Set zoom level
            myMap.Size = pictureBox1.Size;
            SharpMap.Layers.VectorLayer postGISLayer = new SharpMap.Layers.VectorLayer("shore");
            string ConnStrPostGIS = "Server=;Port=5432;User Id=postgres;Password=123;Database=postgis;";
            postGISLayer.DataSource = new SharpMap.Data.Providers.PostGIS(ConnStrPostGIS, "shore", "the_geom", "oid");
             //I think here should write the schema of table which its "public" ,but i don't know where I can write it        
            postGISLayer.MaxVisible = 40000;

            pictureBox1.Image = myMap.GetMap();//don't preview image


Please Help me

May 27, 2009 at 8:11 PM

Hi thabet084,

to provide the schema with the table you may pass "public.shore" to the constructor of the postgis provider. This is not necessary though with a standard postgis database.

Please try without setting zoom properties and call myMap.ZoomToExtents() and see if you get more than an empty picture.

Hth FObermaier

Jun 1, 2009 at 4:35 PM
Edited Jun 1, 2009 at 4:53 PM

Hi Hth FObermaier,

Thanks for ur help

I want to know if parameters of postgis() is correct ==>

the_geom--------> is a column  in table"shore" which its type is geometry

oid column name --------------> I have 5 columns in table shore

1- gid                          serial not null

2-gavprimary               numeric

3-sea_id                      numeric        

4-shape_leng               numeric

5-the_geom                geometry


, when I make map zoom to fullExtents , I got exception

           SharpMap.Map myMap = new SharpMap.Map(new Size(400, 300));
            SharpMap.Layers.VectorLayer postGISLayer = new SharpMap.Layers.VectorLayer("shore");
            string ConnStrPostGIS = "Server=;Port=5432;User Id=postgres;Password=123;Database=postgis;";
            postGISLayer.DataSource = new SharpMap.Data.Providers.PostGIS(ConnStrPostGIS, "public.shore", "the_geom", "gid");

            pictureBox1.Image = myMap.GetMap();


//System.InvalidCastException was unhandled
  Message="Unable to cast object of type 'System.String' to type 'System.Byte[]'."
       at SharpMap.Data.Providers.PostGIS.GetGeometriesInView(BoundingBox bbox)
       at SharpMap.Layers.VectorLayer.Render(Graphics g, Map map)
       at SharpMap.Map.GetMap()
       at Shape2Pgsql.Form1.btnPreview_Click_1(Object sender, EventArgs e) in C:\Documents and Settings\k\My Documents\Downloads\Compressed\Shape2Pgsql\Form1.cs:line 82
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at Shape2Pgsql.Program.Main() in C:\Documents and Settings\k\My Documents\Downloads\Compressed\Shape2Pgsql\Program.cs:line 17
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()


Jun 2, 2009 at 8:09 AM

Hi thabet084,

I don't see anything wrong with the construction of the postgis provider. You really don't need to specify the public schema.

Did you compile sharpmap yourself or do you use the released binaries? In case you are using the binaries, please get the
latest revision of the source and compile it yourself, since the binaries are -to say the least- a bit outdated. If you compile it
yourself, you need to add SharpMap.dll and SharpMap.Extensions.dll as references to use the postgis provider.

Hth FObermaier


Jun 2, 2009 at 2:39 PM
Edited Jun 2, 2009 at 3:11 PM

Hi Hth FObermaier,

a great thanks for ur patience for me ,I  compiled  source code depends on instructions at the following link

and I run my code , but I face a new problem

1-in case postGIS,I face the following error

'SharpMap.Map' does not contain a definition for 'numberFormat_EnUS' at method GetGeometriesInView at class postGIS



2-in case postGIS2 ,I face the following 2 errors

 'SharpMap.Data.Providers.PostGIS2' does not implement interface member 'SharpMap.Data.Providers.IProvider.GetGeometriesInView(SharpMap.Geometries.BoundingBox)'. 'SharpMap.Data.Providers.PostGIS2.GetGeometriesInView(SharpMap.Geometries.BoundingBox)' is either static, not public, or has the wrong return type. 

  'SharpMap.Data.Providers.PostGIS2' does not implement interface member 'SharpMap.Data.Providers.IProvider.GetObjectIDsInView(SharpMap.Geometries.BoundingBox)'. 'SharpMap.Data.Providers.PostGIS2.GetObjectIDsInView(SharpMap.Geometries.BoundingBox)' is either static, not public, or has the wrong return type. 


Note , I cannot get SharpMap.Extensions.dll to add it as a reference


Jun 2, 2009 at 4:06 PM
Edited Jun 2, 2009 at 4:10 PM

Hi thabet084, It sounds like you are mixing and (not) matching different versions. numberFormat_EnUS was renamed to NumberFormatEnUs but this change was propegated to everything that required it. Try downloading a fresh set of code from the source tab and build the code in the trunk directory hth jd

Jun 2, 2009 at 4:23 PM
Edited Jun 2, 2009 at 4:24 PM

Hi  johndiss,

I used sharpmap V0.9

 I cannot found method NumberFormatEnUs in sharpMap V0.9


I try to test postGIS & postGIS2 as both didn't work with me,I could not know problem

IF I use an old version or wrong please correct me with suitable link


Jun 2, 2009 at 4:26 PM

Use the code on the Source Code Tab current changeset is #49671 cheers jd

Jun 3, 2009 at 11:45 AM

Hi  johndiss,

sorry for annoyance,

but also the #49671 not work with me,and show the same error NumberFormatEnUs

I don't know what is the problem?

U told me that numberFormat_EnUS renamed to NumberFormatEnUs ,when I show postGIS.cs from #49671 I found this method not renamed

I feel now failure :S:S




Jun 3, 2009 at 12:19 PM

Hi thabet084, your Map/Map.cs file should look like note particularly the first static field.

PostGis.cs should look like note particularly the occurences of Map.NumberFormatEnUs . If your files do not match then you seem to have a different version. Note you need to use the PostGis.cs file from the SharpMap.Extensions project downloaded in the changeset but if I were you I would just reference the whole SharpMap.Extensions.dll .


hth jd 

Sep 7, 2010 at 11:56 AM

my challenge map tells me i have all ready done the mission the bank job but it wont give me any more skatebord mag challenges my best score is 620 and i took the sharp things off what do i do.?

Apr 5, 2011 at 2:59 AM
Edited Apr 15, 2011 at 1:28 AM

Hi thabet084.

I try to use your script and it works with no problems with mine.

Rocket Arabic | Pure Point Golf Swing