如何使用带有c ++的ogr库在ESRI shapefile中提取几何体的顶点

时间:2013-09-11 17:15:25

标签: c++ visual-studio-2010 shapefile gdal ogr

  

我已经回答了这个问题并且还更改了问题的标题如何使用带有c ++ 的ogr库访问多边形图层中的顶点到如何在ESRI shapefile中提取几何体的顶点使用带有c ++的ogr库。该代码可用于显示OpenGL的形状   任何使其更好的建议将不胜感激   例如,你认为我应该使用图层的投影来增强OpenGL中的视图吗?如何使用投影并将其应用于OpenGL窗口?

到目前为止,我已经尝试过这些类来提取多边形的顶点:

  • OGRPolygon:它没有任何获取顶点数的方法, 起点和终点。
  • OGRLineString:当我使用getNumPoints()方法时,我得到1 我的图层中的多边形要素。
  • OGRLinearRing:当我使用getNumPoints()方法时,我得到1 我的图层中的多边形要素。

如何在多边形shapefile中获取顶点的数量和顶点坐标,以便在OpenGL窗口中绘制多边形。

2 个答案:

答案 0 :(得分:7)

我找到了答案:
您应该关注有关ESRI shapefile的一些信息。

  • 点图层:只能包含 wkbpoint 类型的功能。因此,您可以定义名为 MyPoint2D 的数据结构并存储 具有类型成员的向量中此图层的坐标 的 MyPoint2D 即可。

  • 多点图层:只能包含 wkbMultipoint 类型的功能。因此,您可以使用 MyPoint2D 类型的成员将每个要素存储在向量中,并且此类向量的集合将保存图层中所有要素的坐标。

  • 折线图层:可以包含 wkbLineString wkbMultiLineString 类型的功能。因此,您可以拥有一个数据结构 MyLine2D ,这是一个带有 MyPoint2D 成员的向量,一个成员类型为 MyLine2D 的向量将保留 LineFeature ,最后图层中的要素将存储在类型为 LineFeature 的成员的向量中。

  • 多边形图层:关于多边形,您应该知道每个多边形由外环和几个内部组成 戒指(这是我真正的问题,导致我问 题 )。并且该层可以具有类型的特征 wkbPolygon wkbMultiPolygon

首先我们应该定义这些数据结构:

//data structure for points
typedef struct MyPoint2D
{
double dX;
double dY;
}MyPoint2D;

//Holds Coordinates of Point Shapefile
vector<MyPoint2D>PointLayer;

//data structure for a multipoint feature
typedef struct MultipointFeature
{
vector<MyPoint2D>PointsOfFeature;
}MultipointFeature;

//Holds Coordinates of multiPoint Shapefile
vector<MultipointFeature> MultipointLayer;

//data structure for lines
typedef struct MyLine2D
{
 vector<MyPoint2D> LineString;
}MyLine2D;

//data structure for a line feature
typedef struct LineFeature
{
vector<MyLine2D>LinesOfFeature;
}LineFeature;

//Holds Coordinates of Line Shapefile
vector<LineFeature> LineLayer;

//data structure for rings
typedef struct MyRing2D
{
vector<MyPoint2D> RingString;
bool IsClockwised;
}MyRing2D;

//data structure for polygons
typedef struct MyPolygon2D
{
vector<MyRing2D>Polygon;
}MyPolygon2D;

//data structure for a polygon feature
typedef struct PolygonFeature
{
vector<MyPolygon2D>PolygonsOfFeature;
}PolygonFeature;

//Holds Coordinates of Polygon Shapefile
vector<PolygonFeature> PolygonLayer;

//data structure to hold bounding box
typedef struct SBoundingBox
{
 float fMaxX;
 float fMaxY;
 float fMinX;
 float fMinY;
 }SBoundingBox;

//Bounding Box of Shapefile 
SBoundingBox sBoundingBox;  

这是整个代码,我用它来提取ESRI的shapefile中的顶点坐标:

void OpenShapeFile(char* filename)
{
OGRErr error;
OGRDataSource *poDataSource;
poDataSource = OGRSFDriverRegistrar::Open(filename,false);
OGRLayer *poLayer;
poLayer = poDataSource ->GetLayer(0);
OGREnvelope Envelope;
error = poLayer ->GetExtent(&Envelope,true);
sBoundingBox.fMaxX = Envelope.MaxX;
sBoundingBox.fMaxY = Envelope.MaxY;
sBoundingBox.fMinX = Envelope.MinX;
sBoundingBox.fMinY = Envelope.MinY;  

OGRwkbGeometryType LayerGeometryType = poLayer ->GetGeomType();
int NumberOfFeatures = poLayer ->GetFeatureCount(true);
poLayer ->ResetReading();  

//Point Shapefile
if ( wkbFlatten ( LayerGeometryType ) == wkbPoint )
{
   OGRFeature *poFeature;
   for ( int i = 0; i < NumberOfFeatures; i++ )
   {
       poFeature = poLayer ->GetNextFeature();
       OGRGeometry *poGeometry;
       poGeometry = poFeature ->GetGeometryRef();
       if ( poGeometry != NULL && wkbFlatten ( poGeometry ->getGeometryType() ) == wkbPoint )
       {
           OGRPoint *poPoint = ( OGRPoint * )poGeometry;
           MyPoint2D pt;
           pt.dX = poPoint ->getX();
           pt.dY = poPoint ->getY();
           PointLayer.push_back(pt);
       }
       OGRFeature::DestroyFeature(poFeature);
   }
}  

//Multipoint Shapefile
if ( wkbFlatten ( LayerGeometryType ) == wkbMultiPoint )
{
   OGRFeature *poFeature;
   MultipointFeature MultiPoint;
   for ( int i = 0; i < NumberOfFeatures; i++ )
   {
       poFeature = poLayer ->GetNextFeature();
       OGRGeometry *poGeometry;
       poGeometry = poFeature ->GetGeometryRef();
       if ( poGeometry != NULL && wkbFlatten ( poGeometry ->getGeometryType() ) == wkbMultiPoint )
       {
           OGRMultiPoint *poMultipoint = ( OGRMultiPoint * )poGeometry;
           int NumberOfGeometries = poMultipoint ->getNumGeometries();
           MultiPoint.PointsOfFeature.resize( NumberOfGeometries );
           for ( int j = 0; j < NumberOfGeometries; j++ )
           {
               OGRGeometry *poPointGeometry = poMultipoint ->getGeometryRef(j);
               OGRPoint *poPoint = ( OGRPoint * )poPointGeometry;
               MyPoint2D pt;
               pt.dX = poPoint ->getX();
               pt.dY = poPoint ->getY();
               MultiPoint.PointsOfFeature.at(j) = pt;
           }
           MultipointLayer.push_back(MultiPoint);
       }
       OGRFeature::DestroyFeature(poFeature);
   }
}  

//Polyline Shapefile
if ( wkbFlatten ( LayerGeometryType ) == wkbLineString )
{
   OGRFeature *poFeature;
   LineFeature Polyline;
   OGRPoint ptTemp;
   for ( int i = 0; i < NumberOfFeatures; i++ )
   {
       poFeature = poLayer ->GetNextFeature();
       OGRGeometry *poGeometry;
       poGeometry = poFeature ->GetGeometryRef();
       if ( poGeometry != NULL && wkbFlatten ( poGeometry ->getGeometryType() ) == wkbLineString  )
       {
           OGRLineString *poLineString = ( OGRLineString * )poGeometry;
           Polyline.LinesOfFeature.resize(1);
           int NumberOfVertices = poLineString ->getNumPoints();
           Polyline.LinesOfFeature.at(0).LineString.resize(NumberOfVertices);
           for ( int k = 0; k < NumberOfVertices; k++ )
           {
               poLineString ->getPoint(k,&ptTemp);
               MyPoint2D pt;
               pt.dX = ptTemp.getX();
               pt.dY = ptTemp.getY();
               Polyline.LinesOfFeature.at(0).LineString.at(k) = pt;
           }
           LineLayer.push_back(Polyline);
       }
       else if ( poGeometry != NULL && wkbFlatten ( poGeometry ->getGeometryType() ) == wkbMultiLineString )
       {
           OGRMultiLineString *poMultiLineString = ( OGRMultiLineString * )poGeometry;
           int NumberOfGeometries = poMultiLineString ->getNumGeometries();
           Polyline.LinesOfFeature.resize(NumberOfGeometries);
           for ( int j = 0; j < NumberOfGeometries; j++ )
           {
               OGRGeometry *poLineGeometry = poMultiLineString ->getGeometryRef(j);
               OGRLineString *poLineString = ( OGRLineString * )poLineGeometry;
               int NumberOfVertices = poLineString ->getNumPoints();
               Polyline.LinesOfFeature.at(j).LineString.resize(NumberOfVertices);
               for ( int k = 0; k < NumberOfVertices; k++ )
               {
                   poLineString ->getPoint(k,&ptTemp);
                   MyPoint2D pt;
                   pt.dX = ptTemp.getX();
                   pt.dY = ptTemp.getY();
                   Polyline.LinesOfFeature.at(j).LineString.at(k) = pt;
               }
           }
           LineLayer.push_back(Polyline);
       }
       OGRFeature::DestroyFeature(poFeature);
   }
}  

//Polygon Shapefile
if ( wkbFlatten ( LayerGeometryType ) == wkbPolygon )
{
   OGRFeature *poFeature;
   PolygonFeature Polygon;
   OGRPoint ptTemp;
   for ( int i = 0; i < NumberOfFeatures; i++ )
   {
       poFeature = poLayer ->GetNextFeature();
       OGRGeometry *poGeometry;
       poGeometry = poFeature ->GetGeometryRef();
       if ( poGeometry != NULL && wkbFlatten ( poGeometry ->getGeometryType() ) == wkbPolygon )
       {
           OGRPolygon *poPolygon = ( OGRPolygon * )poGeometry;
           Polygon.PolygonsOfFeature.resize(1);
           int NumberOfInnerRings = poPolygon ->getNumInteriorRings();
           OGRLinearRing *poExteriorRing = poPolygon ->getExteriorRing();
           Polygon.PolygonsOfFeature.at(0).Polygon.resize(NumberOfInnerRings+1);
           Polygon.PolygonsOfFeature.at(0).Polygon.at(0).IsClockwised = poExteriorRing ->isClockwise();
           int NumberOfExteriorRingVertices = poExteriorRing ->getNumPoints();
           Polygon.PolygonsOfFeature.at(0).Polygon.at(0).RingString.resize(NumberOfExteriorRingVertices);
           for ( int k = 0; k < NumberOfExteriorRingVertices; k++ )
           {
               poExteriorRing ->getPoint(k,&ptTemp);
               MyPoint2D pt;
               pt.dX = ptTemp.getX();
               pt.dY = ptTemp.getY();
               Polygon.PolygonsOfFeature.at(0).Polygon.at(0).RingString.at(k) = pt;
           }
           for ( int h = 1; h <= NumberOfInnerRings; h++ )
           {
               OGRLinearRing *poInteriorRing = poPolygon ->getInteriorRing(h-1);
               Polygon.PolygonsOfFeature.at(0).Polygon.at(h).IsClockwised = poInteriorRing ->isClockwise();
               int NumberOfInteriorRingVertices = poInteriorRing ->getNumPoints();
               Polygon.PolygonsOfFeature.at(0).Polygon.at(h).RingString.resize(NumberOfInteriorRingVertices);
               for ( int k = 0; k < NumberOfInteriorRingVertices; k++ )
               {
                   poInteriorRing ->getPoint(k,&ptTemp);
                   MyPoint2D pt;
                   pt.dX = ptTemp.getX();
                   pt.dY = ptTemp.getY();
                   Polygon.PolygonsOfFeature.at(0).Polygon.at(h).RingString.at(k) = pt;
               }
           }
               PolygonLayer.push_back(Polygon);
       }
       else if ( poGeometry != NULL && wkbFlatten ( poGeometry ->getGeometryType() ) == wkbMultiPolygon )
       {
           OGRMultiPolygon *poMultiPolygon = ( OGRMultiPolygon * )poGeometry;
           int NumberOfGeometries = poMultiPolygon ->getNumGeometries();
           Polygon.PolygonsOfFeature.resize(NumberOfGeometries);
           for ( int j = 0; j < NumberOfGeometries; j++ )
           {
               OGRGeometry *poPolygonGeometry = poMultiPolygon ->getGeometryRef(j);
               OGRPolygon *poPolygon = ( OGRPolygon * )poPolygonGeometry;
               int NumberOfInnerRings = poPolygon ->getNumInteriorRings();
               OGRLinearRing *poExteriorRing = poPolygon ->getExteriorRing();
               Polygon.PolygonsOfFeature.at(j).Polygon.resize(NumberOfInnerRings+1);
               Polygon.PolygonsOfFeature.at(j).Polygon.at(0).IsClockwised = poExteriorRing ->isClockwise();
               int NumberOfExteriorRingVertices = poExteriorRing ->getNumPoints();
               Polygon.PolygonsOfFeature.at(j).Polygon.at(0).RingString.resize(NumberOfExteriorRingVertices);
               for ( int k = 0; k < NumberOfExteriorRingVertices; k++ )
               {
                   poExteriorRing ->getPoint(k,&ptTemp);
                   MyPoint2D pt;
                   pt.dX = ptTemp.getX();
                   pt.dY = ptTemp.getY();
                   Polygon.PolygonsOfFeature.at(j).Polygon.at(0).RingString.at(k) = pt;
               }
               for ( int h = 1; h <= NumberOfInnerRings; h++ )
               {
                   OGRLinearRing *poInteriorRing = poPolygon ->getInteriorRing(h-1);
                   Polygon.PolygonsOfFeature.at(j).Polygon.at(h).IsClockwised = poInteriorRing ->isClockwise();
                   int NumberOfInteriorRingVertices = poInteriorRing ->getNumPoints();
                   Polygon.PolygonsOfFeature.at(j).Polygon.at(h).RingString.resize(NumberOfInteriorRingVertices);
                   for ( int k = 0; k < NumberOfInteriorRingVertices; k++ )
                   {
                       poInteriorRing ->getPoint(k,&ptTemp);
                       MyPoint2D pt;
                       pt.dX = ptTemp.getX();
                       pt.dY = ptTemp.getY();
                       Polygon.PolygonsOfFeature.at(j).Polygon.at(h).RingString.at(k) = pt;
                   }
               }
           }
           PolygonLayer.push_back(Polygon);
       }
   }
   OGRFeature::DestroyFeature(poFeature);
}  

OGRDataSource::DestroyDataSource(poDataSource);
}

答案 1 :(得分:1)

scott_f想要一个C#实现,将来可能还会有人使用它,因此我将其发布为答案。我很懒惰,不想使用嵌套列表和与Rhino/Grasshopper提供的数据结构不同的数据结构来重写整个内容,因为此实现是插件的一部分(GH_Structure, IGH_GeometricGoo, IGH_Goo是{{ 1}} API)。但是基本上Rhino/Grasshopper在这种情况下是指IGH_Goobools到可以同时包含IGH_GeometricGooPolylinePoint3d的几何类多维数据结构(列表列表),它通过GH_Structure方法“添加”项目,其中第一个参数是要添加的数据,第二个参数是“路径”,因此.Append()会将.Append( item, new GH_Path( 0, 3 ) )添加到第4个索引的第一个列表中。进行item可能是一个好主意,这样可以在wkbType的维数不同时起作用,但是我将其留给读者,因为我不需要它来实现。请注意,wkbFlatten作为参数传递,因此,如果需要文件中的所有数据,则应遍历所有层。

layer

您可以通过类似方式进行调用(请确保您致电

class WKBToRhinoGeoUtilities
{

    private string input;
    private int layerNumber;
    private int EPSGCode;
    private int InEPSGCode;
    private OSGeo.OGR.Driver driver;
    OSGeo.OGR.DataSource dataSource;

    private GH_Path path;
    private double[] pointList = { 0, 0, 0 };

    private long numberOfFeatures;
    private int layerCount;
    private OSGeo.OGR.Layer layer;
    private OSGeo.OGR.wkbGeometryType wkbGeoType;
    private int currentProjection;
    private OSGeo.OSR.CoordinateTransformation transform;
    private OSGeo.OGR.Feature feature;
    private OSGeo.OGR.Geometry geo, ring;

    public string debug = "Working!";

    public WKBToRhinoGeoUtilities( string input, int layerNumber, int EPSGCode, 
                                   int InEPSGCode, OSGeo.OGR.DataSource dataSource )
    {

        this.input = input;
        this.layerNumber = layerNumber;
        this.EPSGCode = EPSGCode;
        this.InEPSGCode = InEPSGCode;
        this.dataSource = dataSource;

    }

    public string Setup()
    {

        GetDataSourceAttributes();

        IdentifyEPSG();

        return debug;

    }

    public GH_Structure<IGH_GeometricGoo> Run( ref GH_Structure<IGH_Goo> cullPattern )
    {

        switch( wkbGeoType )
        {

            case OSGeo.OGR.wkbGeometryType.wkbUnknown:

                return WKBUnknown( ref cullPattern );

            case OSGeo.OGR.wkbGeometryType.wkbPolygon:

                return WKBPolygon( ref cullPattern );

            case OSGeo.OGR.wkbGeometryType.wkbLineString:

                return WKBLineString( ref cullPattern );

            case OSGeo.OGR.wkbGeometryType.wkbPoint:

                return WKBPoint( ref cullPattern );

            case OSGeo.OGR.wkbGeometryType.wkbPoint25D:

                return WKBPoint( ref cullPattern );

            case OSGeo.OGR.wkbGeometryType.wkbMultiPolygon:

                return WKBMultiPolygon( ref cullPattern );

            case OSGeo.OGR.wkbGeometryType.wkbMultiLineString:

                return WKBMultiLineString( ref cullPattern );

            case OSGeo.OGR.wkbGeometryType.wkbGeometryCollection:

                return WKBGeometryCollection( ref cullPattern );

            default:

                return null;

        }

    }

    private void GetDataSourceAttributes()
    {

        if( dataSource != null )
        { 

            layerCount = dataSource.GetLayerCount();
            layer = dataSource.GetLayerByIndex( layerNumber % layerCount );
            wkbGeoType = layer.GetGeomType();
            numberOfFeatures = unchecked( ( int ) layer.GetFeatureCount( 0 ) );

        }

        else
        {

            debug = "Data Source is null!";

        }

    }

    private void IdentifyEPSG()
    {

        // Source projections, try to get it automatically otherwise resort to user input.
        OSGeo.OSR.SpatialReference source = null;
        int identifyEPSG = 0;

        try
        {

            source = layer.GetSpatialRef();
            identifyEPSG = source.AutoIdentifyEPSG();

        }

        catch
        {

            debug = "The file's EPSG code couldn't be found automatically, it will default to EPSG:3857, make sure you input the correct one!";
            source = new OSGeo.OSR.SpatialReference( "" );
            identifyEPSG = source.ImportFromEPSG( InEPSGCode );

        }

        currentProjection = Convert.ToInt32( source.GetAttrValue( "AUTHORITY", 1 ) );

        // Reprojections.
        OSGeo.OSR.SpatialReference target = new OSGeo.OSR.SpatialReference( "" );

        if( currentProjection != EPSGCode )
        { 

            target.ImportFromEPSG( EPSGCode );
            transform = new OSGeo.OSR.CoordinateTransformation( source, target );

        }

    }

    private GH_Structure<IGH_GeometricGoo> WKBUnknown( ref GH_Structure<IGH_Goo> cullPattern )
    {

        GH_Structure<IGH_GeometricGoo>  geoOutput = new GH_Structure<IGH_GeometricGoo>();
        cullPattern = new GH_Structure<IGH_Goo>();

        double[] pointList = { 0, 0, 0 };

        int counter = 0;

        do
        {

            path = new GH_Path( counter );

            feature = layer.GetNextFeature();

            bool pattern = false;

            if( feature != null )
            { 

                OSGeo.OGR.Geometry geo = feature.GetGeometryRef();

                if( geo != null )
                {

                    if( currentProjection != EPSGCode )
                    {

                        geo.Transform( transform );

                    }

                    pattern = true;

                    int pointCount = geo.GetPointCount();

                    IGH_GeometricGoo geoGoo = null;

                    Point3d[] tempPointArray = new Point3d[pointCount];

                    for( int i = 0; i < pointCount; ++i )
                    {

                        geo.GetPoint( i, pointList );

                        tempPointArray[i] = new Point3d( pointList[0], pointList[1], pointList[2] );

                    }

                    if( tempPointArray.Length > 2 )
                    {

                        Polyline tempPoly = new Polyline( tempPointArray );
                        geoGoo = GH_Convert.ToGeometricGoo( tempPoly );
                        geoOutput.Append( geoGoo, path );

                    }

                    else if( tempPointArray.Length > 0 )
                    {

                        geoGoo = GH_Convert.ToGeometricGoo( tempPointArray[0] );
                        geoOutput.Append( geoGoo, path );

                    }

                }

            }

            IGH_Goo patternGoo = GH_Convert.ToGoo( pattern );
            cullPattern.Append( patternGoo, path );

            counter++;

        } while( feature != null );

        return geoOutput;

    }

    private GH_Structure<IGH_GeometricGoo> WKBPolygon( ref GH_Structure<IGH_Goo> cullPattern )
    {

        GH_Structure<IGH_GeometricGoo> geoOutput = new GH_Structure<IGH_GeometricGoo>();
        cullPattern = new GH_Structure<IGH_Goo>();

        if ( numberOfFeatures != -1 )
        { 

            for( int i = 0; i < numberOfFeatures; ++i )
            {

                path = new GH_Path(i);

                feature = layer.GetFeature(i);

                bool pattern = false;

                if( feature != null )
                {

                    geo = feature.GetGeometryRef();

                    if( geo != null )
                    {

                        IGH_GeometricGoo geoGoo = WKBPolygonSingle( geo, ref pattern );
                        geoOutput.Append( geoGoo, path );

                    }

                }

                IGH_Goo gooPattern = GH_Convert.ToGoo( pattern );
                cullPattern.Append( gooPattern, path );

            }

        }

        else
        {

            feature = layer.GetNextFeature();

            int counter = 0;

            while( feature != null )
            {

                path = new GH_Path( counter );

                geo = feature.GetGeometryRef();

                bool pattern = false;

                if( geo != null )
                {

                    IGH_GeometricGoo geoGoo = WKBPolygonSingle( geo, ref pattern );
                    geoOutput.Append( geoGoo, path );

                }

                IGH_Goo gooPattern = GH_Convert.ToGoo( pattern );

                cullPattern.Append( gooPattern, path );

                feature = layer.GetNextFeature();

                counter++;

            }

        }

        return geoOutput;

    }

    private GH_Structure<IGH_GeometricGoo> WKBLineString( ref GH_Structure<IGH_Goo> cullPattern )
    {

        GH_Structure<IGH_GeometricGoo> geoOutput = new GH_Structure<IGH_GeometricGoo>();
        cullPattern = new GH_Structure<IGH_Goo>();

        if ( numberOfFeatures != -1 )
        { 

            for( int i = 0; i < numberOfFeatures; ++i )
            {

                path = new GH_Path(i);
                feature = layer.GetFeature(i);

                bool pattern = false;

                if( feature != null )
                {

                    geo = feature.GetGeometryRef();

                    if( geo != null )
                    { 

                        IGH_GeometricGoo geoGoo = WKBLineStringSingle( geo, ref pattern );
                        geoOutput.Append( geoGoo, path );

                    } 

                }

                IGH_Goo gooPattern = GH_Convert.ToGoo( pattern );
                cullPattern.Append( gooPattern, path );

            }

        }

        else
        {

            int counter = 0;

            feature = layer.GetNextFeature();

            while( feature != null )
            {

                path = new GH_Path( counter );

                geo = feature.GetGeometryRef();

                bool pattern = false;

                if( geo != null )
                { 

                    IGH_GeometricGoo geoGoo = WKBLineStringSingle( geo, ref pattern );
                    geoOutput.Append( geoGoo, path );

                }

                IGH_Goo gooPattern = GH_Convert.ToGoo( pattern );
                cullPattern.Append( gooPattern, path );

                feature = layer.GetNextFeature();
                counter++;

            }

        }

        return geoOutput;

    }

    private GH_Structure<IGH_GeometricGoo> WKBPoint( ref GH_Structure<IGH_Goo> cullPattern )
    {

        GH_Structure<IGH_GeometricGoo> geoOutput = new GH_Structure<IGH_GeometricGoo>();
        cullPattern = new GH_Structure<IGH_Goo>();

        if ( numberOfFeatures != -1 )
        { 

            for( int i = 0; i < numberOfFeatures; ++i )
            {

                path = new GH_Path(i);

                feature = layer.GetFeature(i);

                bool tempPattern = feature != null ? true : false;

                IGH_Goo gooPattern = GH_Convert.ToGoo( tempPattern );

                cullPattern.Append( gooPattern, path );

                if( feature != null )
                {

                    geo = feature.GetGeometryRef();

                    IGH_GeometricGoo geoGoo = WKBPointSingle( geo );

                    geoOutput.Append( geoGoo, path );

                }

            }

        }

        else
        {

            int counter = 0;

            feature = layer.GetNextFeature();

            while( feature != null )
            {

                path = new GH_Path( counter );

                bool tempPattern = feature != null ? true : false;

                IGH_Goo gooPattern = GH_Convert.ToGoo( tempPattern );

                cullPattern.Append( gooPattern, path );

                geo = feature.GetGeometryRef();

                IGH_GeometricGoo geoGoo = WKBPointSingle( geo );

                geoOutput.Append( geoGoo, path );

                feature = layer.GetNextFeature();

                counter++;

            }

        }

        return geoOutput;

    }

    private GH_Structure<IGH_GeometricGoo> WKBMultiPolygon( ref GH_Structure<IGH_Goo> cullPattern )
    {

        GH_Structure<IGH_GeometricGoo> geoOutput = new GH_Structure<IGH_GeometricGoo>();
        cullPattern = new GH_Structure<IGH_Goo>();

        if ( numberOfFeatures != -1 )
        { 

            for( int i = 0; i < numberOfFeatures; ++i )
            {

                path = new GH_Path(i);

                feature = layer.GetFeature(i);

                bool pattern = false;

                if( feature != null )
                {

                    geo = feature.GetGeometryRef();

                    for( int j = 0; j < geo.GetGeometryCount(); ++j )
                    {

                        OSGeo.OGR.Geometry inGeo = geo.GetGeometryRef(j);

                        IGH_GeometricGoo geoGoo = WKBPolygonSingle( inGeo, ref pattern );
                        geoOutput.Append( geoGoo, path );

                    }

                }

                IGH_Goo gooPattern = GH_Convert.ToGoo( pattern );
                cullPattern.Append( gooPattern, path );

            }

        }

        else
        {

            int counter = 0;
            feature = layer.GetNextFeature();

            while( feature != null )
            {

                bool pattern = false;

                path = new GH_Path( counter );

                geo = feature.GetGeometryRef();

                for( int j = 0; j < geo.GetGeometryCount(); ++j )
                {

                    OSGeo.OGR.Geometry inGeo = geo.GetGeometryRef(j);                                        

                    if( inGeo != null )
                    { 

                        IGH_GeometricGoo geoGoo = WKBPolygonSingle( inGeo, ref pattern );
                        geoOutput.Append( geoGoo, path );

                    }

                }

                IGH_Goo gooPattern = GH_Convert.ToGoo( pattern );
                cullPattern.Append( gooPattern, path );

                counter++;
                feature = layer.GetNextFeature();

            }

        }

        return geoOutput;

    }

    private GH_Structure<IGH_GeometricGoo> WKBMultiLineString( ref GH_Structure<IGH_Goo> cullPattern )
    {

        GH_Structure<IGH_GeometricGoo> geoOutput = new GH_Structure<IGH_GeometricGoo>();
        cullPattern = new GH_Structure<IGH_Goo>();

        if ( numberOfFeatures != -1 )
        { 

            for( int i = 0; i < numberOfFeatures; ++i )
            {

                path = new GH_Path(i);
                feature = layer.GetFeature(i);

                bool pattern = false;

                if( feature != null )
                {

                    geo = feature.GetGeometryRef();

                    if( geo != null )
                    { 

                        for( int j = 0; j < geo.GetGeometryCount(); ++j )
                        {

                            ring = geo.GetGeometryRef(j);

                            IGH_GeometricGoo geoGoo = WKBLineStringSingle( ring, ref pattern );
                            geoOutput.Append( geoGoo, path );

                        }

                    }

                }

                IGH_Goo gooPattern = GH_Convert.ToGoo( pattern );
                cullPattern.Append( gooPattern, path );

            }

        }

        else
        {

            feature = layer.GetNextFeature();
            int counter = 0;

            while( feature != null )
            {

                path = new GH_Path( counter );

                geo = feature.GetGeometryRef();

                bool pattern = false;

                if( geo != null )
                { 

                    for( int j = 0; j < geo.GetGeometryCount(); ++j )
                    {

                        ring = geo.GetGeometryRef(j);

                        IGH_GeometricGoo geoGoo = WKBLineStringSingle( ring, ref pattern );
                        geoOutput.Append( geoGoo, path );

                    }

                }

                IGH_Goo gooPattern = GH_Convert.ToGoo( pattern );
                cullPattern.Append( gooPattern, path );

                feature = layer.GetNextFeature();

                counter++;

            }

        }

        return geoOutput;

    }

    private GH_Structure<IGH_GeometricGoo> WKBGeometryCollection( ref GH_Structure<IGH_Goo> cullPattern )
    {

        GH_Structure<IGH_GeometricGoo> geoOutput = new GH_Structure<IGH_GeometricGoo>();
        cullPattern = new GH_Structure<IGH_Goo>();
        GH_Structure<IGH_Goo> cullPatternTemp = new GH_Structure<IGH_Goo>();

        if ( numberOfFeatures != -1 )
        {

            for( int i = 0; i < numberOfFeatures; ++i )
            {

                path = new GH_Path(i);
                feature = layer.GetFeature(i);

                if( feature != null )
                {

                    geo = feature.GetGeometryRef();

                    if( geo != null )
                    {

                        bool tempPattern = feature != null ? true : false;

                        IGH_GeometricGoo geoGoo = null;

                        if( geo != null )
                        {

                            for( int j = 0; j < geo.GetGeometryCount(); ++j )
                            {

                                path = new GH_Path( j, i );

                                ring = geo.GetGeometryRef(i);

                                OSGeo.OGR.wkbGeometryType geoType = ring.GetGeometryType();

                                switch( geoType )
                                {

                                    case OSGeo.OGR.wkbGeometryType.wkbPoint:

                                        geoGoo = WKBPointSingle( ring );

                                        break;

                                    case OSGeo.OGR.wkbGeometryType.wkbPoint25D:

                                        geoGoo = WKBPointSingle( ring );

                                        break;

                                    case OSGeo.OGR.wkbGeometryType.wkbPolygon:

                                        geoGoo = WKBPolygonSingle( ring, ref tempPattern );

                                        break;

                                    case OSGeo.OGR.wkbGeometryType.wkbLineString:

                                        geoGoo = WKBLineStringSingle( ring, ref tempPattern );

                                        break;

                                }

                                geoOutput.Append( geoGoo, path );

                                IGH_Goo gooPattern = GH_Convert.ToGoo( tempPattern );
                                cullPattern.Append( gooPattern, path );

                            }

                        }

                    }

                }

            }

        }

        else
        {

            int counter = 0;

            feature = layer.GetNextFeature();

            while( feature != null )
            {

                geo = feature.GetGeometryRef();

                bool tempPattern = feature != null ? true : false;

                IGH_GeometricGoo geoGoo = null;

                if( geo != null )
                {

                    for( int i = 0; i < geo.GetGeometryCount(); ++i )
                    {

                        path = new GH_Path( counter, i );

                        ring = geo.GetGeometryRef(i);

                        OSGeo.OGR.wkbGeometryType geoType = ring.GetGeometryType();

                        switch( geoType )
                        {

                            case OSGeo.OGR.wkbGeometryType.wkbPoint:

                                geoGoo = WKBPointSingle( ring );

                                break;

                            case OSGeo.OGR.wkbGeometryType.wkbPoint25D:

                                geoGoo = WKBPointSingle( ring );

                                break;

                            case OSGeo.OGR.wkbGeometryType.wkbPolygon:

                                geoGoo = WKBPolygonSingle( ring, ref tempPattern );

                                break;

                            case OSGeo.OGR.wkbGeometryType.wkbLineString:

                                geoGoo = WKBLineStringSingle( ring, ref tempPattern );

                                break;

                        }

                        geoOutput.Append( geoGoo, path );

                        IGH_Goo gooPattern = GH_Convert.ToGoo( tempPattern );
                        cullPattern.Append( gooPattern, path );

                    }

                }

                feature = layer.GetNextFeature();

                counter++;

            }

        }

        return geoOutput;

    }

    private IGH_GeometricGoo WKBPointSingle( OSGeo.OGR.Geometry geo )
    {

        IGH_GeometricGoo geoGoo = null;

        if( currentProjection != EPSGCode )
        {

            geo.Transform( transform );

        }

        geo.GetPoint( 0, pointList );

        Point3d tempPoint = new Point3d( pointList[0], pointList[1], pointList[2] );
        geoGoo = GH_Convert.ToGeometricGoo( tempPoint );

        return geoGoo;

    }

    private IGH_GeometricGoo WKBPolygonSingle( OSGeo.OGR.Geometry geo, ref bool pattern )
    {

        IGH_GeometricGoo geoGoo = null;

        ring = geo.GetGeometryRef( 0 );

        if( currentProjection != EPSGCode )
        {

            ring.Transform( transform );

        }

        int pointCount = ring.GetPointCount();

        Point3d[] tempPointArray = new Point3d[pointCount];

        for (int j = 0; j < pointCount; ++j)
        {

            ring.GetPoint( j, pointList );

            tempPointArray[j] = new Point3d( pointList[0], pointList[1], pointList[2] );

        }

        if( tempPointArray.Length > 1 )
        { 

            Polyline polyOut = new Polyline( tempPointArray );

            geoGoo = GH_Convert.ToGeometricGoo( polyOut );

            pattern = true;

        }

        return geoGoo;

    }

    private IGH_GeometricGoo WKBLineStringSingle( OSGeo.OGR.Geometry geo, ref bool pattern )
    {

        IGH_GeometricGoo geoGoo = null;

        if( currentProjection != EPSGCode )
        {

            geo.Transform( transform );

        }

        int pointCount = geo.GetPointCount();

        Point3d[] tempPointArray = new Point3d[pointCount];

        for( int j = 0; j < pointCount; ++j )
        {

            geo.GetPoint( j, pointList );

            tempPointArray[j] = new Point3d( pointList[0], pointList[1], pointList[2] );

        }

        if( tempPointArray.Length > 1 )
        { 

            Polyline polyOut = new Polyline( tempPointArray );
            geoGoo = GH_Convert.ToGeometricGoo( polyOut );

            pattern = true;

        }

        IGH_Goo gooPattern = GH_Convert.ToGoo( pattern );

        return geoGoo;

    }

}

):

GdalConfiguration.ConfigureOgr();
GdalConfiguration.ConfigureGdal();

在我有一个带有此静态方法的OSGeo.OGR.Driver driver = Utilities.GetExtractorDriver( input, ref debug ); OSGeo.OGR.DataSource dataSource = driver.Open( input, 0 ); WKBToRhinoGeoUtilities wkbToRhino = new WKBToRhinoGeoUtilities( input, layerNumber, EPSGCode, InEPSGCode, dataSource ); debug = wkbToRhino.Setup(); AddRuntimeMessage( GH_RuntimeMessageLevel.Blank, debug ); if( debug != "Driver is null!" || debug != "Data Source is null!" || debug != "File does not exist!" ) { GH_Structure<IGH_Goo> cullPattern = new GH_Structure<IGH_Goo>(); GH_Structure<IGH_GeometricGoo> geoOutput = wkbToRhino.Run( ref cullPattern ); DA.SetDataTree( 0, geoOutput ); DA.SetDataTree( 1, cullPattern ); } 类的地方:

Utilities