我正在尝试使用GDAL创建一个3D shapefile。我的代码用于创建3D块,如下所示:
OGRLayer *poLayer = ds->CreateLayer("Floor", NULL, wkbPolygon25D, NULL);
OGRFeature *poFeature;
poFeature = OGRFeature::CreateFeature( poLayer->GetLayerDefn() );
OGRLinearRing ring1, ring2;
OGRPolygon poly;
double x0=y0=z0 = 0;
double x1=y1=z1 = 1;
ring1.addPoint(x0, y0, z0);
ring1.addPoint(x1, y0, z0);
ring1.addPoint(x1, y1, z0);
ring1.addPoint(x0, y1, z0);
ring1.addPoint(x0, y0, z0);
ring1.closeRings();
ring2.addPoint(x0, y0, z1);
ring2.addPoint(x1, y0, z1);
ring2.addPoint(x1, y1, z1);
ring2.addPoint(x0, y1, z1);
ring2.addPoint(x0, y0, z1);
ring2.closeRings();
poly.addRing(&ring1);
poly.addRing(&ring2);
poFeature->SetGeometry(&poly);
poLayer->CreateFeature(poFeature);
但是,当我稍后打开文件并查询要素中的一个点时:
OGRGeometry* pGeometry = pFeature->GetGeometryRef();
OGRSpatialReference* pSpaRef = pGeometry->getSpatialReference();
OGRPoint point(0.5, 0.5,0.5);
point.assignSpatialReference(pSpaRef);
OGRBoolean bContains = pGeometry->Contains(&point);
我得到了一个 FALSE 的结果。
我已经搜索过 GDAL 文档和其他许多地方,但找不到任何构建三维对象的示例,所以我猜想如果你创建了顶部和底部面,它们会相连。
因此,总之,问题是...如何在 GDAL 中创建一个三维块对象(如立方体)?