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

PostGIS 1.4.1 & Box2d

Topics: SharpMap Project, SharpMap v0.9 / v1.x
Feb 12, 2010 at 2:19 PM


I have run across an issue running Postgresql v8.4 and PostGIS 1.4.1 and trying to find the extents of a vector layer in a WinForm app.  I get the error message "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index" when running the following code (breaks at layer.DataSource.ExecuteIntersectionQuery(worldQueryBox, f);):

void picMap_MouseUp(object sender, MouseEventArgs e)
            if (e.Button == MouseButtons.Right)
                SharpMap.Data.FeatureDataSet f = new SharpMap.Data.FeatureDataSet();

                SharpMap.Layers.VectorLayer layer = myMap.Layers["layer"] as SharpMap.Layers.VectorLayer;

                int screenToleranceX = 2, screenToleranceY = 2;

                System.Drawing.Point screenLowerLeft = new System.Drawing.Point(e.X - screenToleranceX, e.Y - screenToleranceY);
                System.Drawing.Point screenTopRight = new System.Drawing.Point(e.X + screenToleranceX, e.Y + screenToleranceY);

                SharpMap.Geometries.Point worldBottomLeft = myMap.ImageToWorld(screenLowerLeft);
                SharpMap.Geometries.Point worldTopRight = myMap.ImageToWorld(screenTopRight);

                SharpMap.Geometries.BoundingBox worldQueryBox = new SharpMap.Geometries.BoundingBox(worldBottomLeft, worldTopRight);
                    layer.DataSource.ExecuteIntersectionQuery(worldQueryBox, f);
                    if (f.Tables[0].Count > 0)
                        gridControl4.DataSource = f.Tables[0];
                catch (Exception ex)
I have tracked this down to an issue with the PostGIS ST_Extents return value being a Box3d_extent instead of a Box2d, as the PostGIS provider code expects.
Any ideas on how I can overcome this hurdle?
Feb 12, 2010 at 4:45 PM

hello oceanz,

I cannot reproduce your problem, for me it all works fine.

  • Did you change anything in postgis.cs?
  • Do you use Npgsql 2.0.x instead of 1.x.x?

A full stack trace would be helpful including the last sqlcommand before the exception.



Feb 12, 2010 at 11:26 PM

You gave me a clue to figuring this out.  I make a rookie mistake of using postgis2 instead of postgis when I clearly had postgis 1.4.1 installed.  Thank you!