This project is read-only.

OGR and DotSpatial WKB

Oct 29, 2010 at 1:35 AM

Does anyone have a sample of how to convert an OGR.Geometry to a DotSpatial Geometry

Here is what I am trying:

  OSGeo.OGR.Feature f = l.GetFeature( i );
  OSGeo.OGR.Geometry g = f.GetGeometryRef( );
  OSGeo.OGR.wkbGeometryType type = g.GetGeometryType();

  WKBReader reader = new WKBReader();

  Byte[] geom = new Byte[g.WkbSize()];

  string s;
  g.ExportToWkt(out s); // correctly produces ==>  POINT (-122.082203542568 37.4222899014025 0)
  g.ExportToWkb( geom ); // produces 0,128,0,0,1,192,94,133,66,210,165,188,121,64,66,182,13,152,113,250,55,0,0,0,0,0,0,0,0 

  WKBReader reader = new WKBReader();
  IBasicGeometry newGeom =  reader.Read(r);  // crashes saying the geometry type is not valid

What am I doing wrong here?

Oct 29, 2010 at 1:53 AM

What is r?  You export the binary to a byte array named geom, but then try to read a variable called r?  It may just be a transcription error from when you were posting though.  Could we be looking at a byte order situation somehow?  I'm not sure.  We may need to set up some unit tests to ensure that expected values are coming out of the WKBReader.  I don't think this is a class that is used by our framework anywhere, so it probably is untested.  You also have the option of using a WKBFeatureReader that can produce output FeatureSets directly.  This is slightly more tested and might work where the WKBReader is larely an appendix that came from NTS.

Oct 29, 2010 at 4:01 PM

It turns out the problem is 3d data.  The WKBReader seems to only handle 2d Geometry types.  Once I tried with 2d data it worked fine.


But, while we are on the subject... Are there any samples around using the WKBFeatureReader to read from OGR or OGR or FDO datat providers?




Oct 29, 2010 at 4:37 PM

I must be going crazy.  I know I posted sample code for that because it was being used by people who were writing code to read in content from SQLSpatial databases and converting them into features.  But I can't seem to find where it went.  I will renew my efforts after work and see if I can drum it up again.



Oct 29, 2010 at 4:47 PM


Is this it?



Oct 29, 2010 at 5:37 PM
That is one of them. There is also an example that will cycle through multiple rows and add the features into three separate feature sets with polygon, line, and point features, but the WKBFeatureReader is the important part. Once you have found it, you should be able to get started.


On Fri, Oct 29, 2010 at 8:48 AM, kellison <> wrote:

From: kellison

Read the full discussion online.

To add a post to this discussion, reply to this email (

To start a new discussion for this project, email

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at

Nov 3, 2010 at 11:20 PM

OK.  Cool.  I used this sample provided and I can load WKBinary data into a feature set and display it on the map.

Next,  what is the place to add attribute data?

I've added then in the Shpawe.Attributes Property and directly to the FeatrureSet.DataTable and added them to the Feature.DatatRow

No matter what I try, when I right click the legend entry and Choose show attributes it always shows only empty cells.


Any hints?





Nov 19, 2010 at 10:32 PM

Did you find any solution where to put the attributes. I also have the same problem.

Nov 19, 2010 at 11:13 PM

Yes, you don't want to use Geometry for that.  Geometry is just the OGC simple feature specification for vector datasets.  It has no attribute information.  You need to convert them into Features via the WKBFeatureReader or else create them manually by adding new features one at a time to a FeatureSet.Features.  Care needs to be taken when adding features to a featureset.  It works best if you create

DataRow myNewRow = myFeatureSet.DataTable.NewRow(),

populate the attributes


create a feature

Feature myFeature = new Feature();

and set the geometry and row

myFeature.BasicGeometry = myGeometry;

myFeature.DataRow = myNewRow;

then add the result


I think that should work as far as adding the attribute content into the myFeatureSet.DataTable.


Nov 19, 2010 at 11:20 PM

I just posted a branch to the repository that has an example that does this very thing.   Check the OgrVectorProvider.cs on Change set 2f8770aebe94