This document is archived and information here might be outdated.  Recommended version.


IGeometryFactory.CreateGeometryFromWkbVariant Method (ArcObjects .NET 10.5 SDK)
ArcObjects Library Reference (Geometry)  

IGeometryFactory.CreateGeometryFromWkbVariant Method

Create a point, polyline, polygon, or multipoint from the specified OGIS WKB format buffer.

[Visual Basic .NET]
Public Sub CreateGeometryFromWkbVariant ( _
    ByVal wkb As Object, _
    ByRef outGeometry As IGeometry, _
    ByRef numBytesRead As Integer _
)
[C#]
public void CreateGeometryFromWkbVariant (
    object wkb,
    ref IGeometry outGeometry,
    ref int numBytesRead
);
[C++]
HRESULT CreateGeometryFromWkbVariant(
  VARIANT wkb,
  IGeometry** outGeometry,
  long* numBytesRead
);
[C++]

Parameters wkb wkb is a parameter of type VARIANT outGeometry [out]
outGeometry is a parameter of type IGeometry numBytesRead [out] numBytesRead is a parameter of type long

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.
[C#]
private void CreateGeometryFromWkbVariant()
{
  OleDbConnection connection=new OleDbConnection("Provider=ESRI.GeoDB.OLEDB.1;Data Source=   C:\\basiceditdatabase.mdb;ExtendedProperties=workspacetype=esriDataSourcesGDB.AccessWorkspaceFactory.1;Geometry=WKB");
  //create the command object with the sql query
  OleDbCommand command=new OleDbCommand("select * from line_edit", connection);
  try
  {
    connection.Open();
    //create the datareader object to connect to table
    OleDbDataReader reader=command.ExecuteReader();
   
    //Iterate through the geodatabase and add new Geometries to to GeometryBag
    IGeometryFactory2 factory=new GeometryEnvironmentClass();
    IGeometryCollection geometryCollection=new GeometryBagClass();
    IGeometry outGeometry;
    int bytesRead;
    object missing=Type.Missing;
    while (reader.Read())
    {
     int shapeColumn=reader.GetOrdinal("SHAPE");
     object byteArrayObject=reader.GetValue(shapeColumn);
     //Re-create the geometry from the WKB data 
     factory.CreateGeometryFromWkbVariant(byteArrayObject, out outGeometry, out bytesRead);
     if(outGeometry!= null)
     {
       //add the geometry to the geometryColection's end
       geometryCollection.AddGeometry(outGeometry, ref missing, ref missing);
     }
    }
    //don't forget to clean up
    reader.Close();
    connection.Close();
    System.Windows.Forms.MessageBox.Show(geometryCollection.GeometryCount + " geomtries added");
  }
  //Some usual exception handling
  catch (OleDbException e)
  {
    System.Windows.Forms.MessageBox.Show("Error: {0}", e.Errors[0].Message);
  }
}
[Visual Basic .NET]

        Dim pGFact As ESRI.ArcGIS.Geometry.IGeometryFactory
        Dim pGeoEnv As ESRI.ArcGIS.Geometry.GeometryEnvironment
        Dim pGeomCol As ESRI.ArcGIS.Geometry.IGeometryCollection
        Dim pGeom As ESRI.ArcGIS.Geometry.IGeometry
        Dim cBytesread As Long
        Dim pEnvelope As ESRI.ArcGIS.Geometry.IEnvelope
        Dim adors As ADODB.Recordset
        Dim adocon As ADODB.Connection
        Dim sConstring As String, sSQLstring As String
        Dim WKBData As Object
        pGeoEnv=New ESRI.ArcGIS.Geometry.GeometryEnvironment
        pEnvelope=New ESRI.ArcGIS.Geometry.Envelope
        pGFact=pGeoEnv
        adors=New ADODB.Recordset
        adocon=New ADODB.Connection
        sConstring="Provider=ESRI.GeoDB.OLEDB.1;" & "Data Source=   d:\temp\us_states.mdb;" & "ExtendedProperties=workspacetype=esriDataSourcesGDB.AccessWorkspaceFactory.1;Geometry=WKB"
        sSQLstring="select * from us_states"
        adocon.Open(sConstring)
        adors.Open(sSQLstring, adocon, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockOptimistic)
        Do Until adors.EOF
            pGeomCol=New ESRI.ArcGIS.Geometry.GeometryBag
            WKBData=adors("Shape").Value
            If IsNothing(WKBData) Then
                adors.MoveNext()
            Else
                '++ Re-create the geometry from the WKB data
                pGFact.CreateGeometryFromWkbVariant(WKBData, pGeom, cBytesread)
                '++ Aggregate the geom envelopes
                pEnvelope.Union(pGeom.Envelope)
                pGeomCol.AddGeometry(pGeom)
                adors.MoveNext()
            End If
        Loop

 

See Also

IGeometryFactory Interface | IGeometry Interface | IGeometryCollection Interface | IEnvelope Interface