首页 > 其他分享 >OGRMultiPolygon使用范例

OGRMultiPolygon使用范例

时间:2023-03-10 09:33:18浏览次数:41  
标签:范例 szWKT pmp pGeom OGRMultiPolygon pMultiPolygon 使用 NULL

最近在做OGRMultiPolygon相关开发的时候,遇到了新建OGRMultiPolygon对象无法正确释放的问题,后来找到示例代码,发现该对象不能直接new,以下为错误代码和正确代码的示例。

/*********error code********* OGRMultiPolygon* pmp = new OGRMultiPolygon; delete pmp; pmp = nullptr; *********error code*********/ //蓝色多边形 char* szWKT_1 = "POLYGON ((113.885 22.6815, 113.9425 22.6585, 113.91 22.7, 113.885 22.6815))"; //橙色多边形 char* szWKT_2 = "POLYGON ((113.91 22.7, 113.9425 22.6585, 113.9675 22.689, 113.91 22.7))"; OGRGeometry* pGeom_1 = NULL; OGRGeometry* pGeom_2 = NULL; OGRGeometryFactory::createFromWkt(&szWKT_1, NULL, &pGeom_1); OGRGeometryFactory::createFromWkt(&szWKT_2, NULL, &pGeom_2); OGRMultiPolygon* pMultiPolygon = (OGRMultiPolygon*)OGRGeometryFactory::createGeometry(wkbMultiPolygon); pMultiPolygon->addGeometryDirectly(pGeom_1); pMultiPolygon->addGeometryDirectly(pGeom_2); //用Buffer替代Union,缓冲距离设置为0 //pUnion为紫色多边形 OGRGeometry* pUnion = pMultiPolygon->Buffer(0); delete pMultiPolygon; pMultiPolygon = nullptr; return 0;

 

标签:范例,szWKT,pmp,pGeom,OGRMultiPolygon,pMultiPolygon,使用,NULL
From: https://www.cnblogs.com/autumoonchina/p/17202296.html

相关文章