我正在尝试使用 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 文档和许多其他地方,找不到任何关于如何构建 3D 对象的示例,所以我猜如果您创建了顶面和底面,它将连接它们。
所以,总而言之,问题是......如何在 GDAL 中创建 3D 块对象(如立方体)?