当前位置: 首页>>代码示例>>C++>>正文


C++ GeometryFactory::createMultiPolygon方法代码示例

本文整理汇总了C++中GeometryFactory::createMultiPolygon方法的典型用法代码示例。如果您正苦于以下问题:C++ GeometryFactory::createMultiPolygon方法的具体用法?C++ GeometryFactory::createMultiPolygon怎么用?C++ GeometryFactory::createMultiPolygon使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GeometryFactory的用法示例。


在下文中一共展示了GeometryFactory::createMultiPolygon方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: build_geometry


//.........这里部分代码省略.........
                                // FIXME: This code does not work as intended
                                // It should be setting the polys[k].ring in order to update this object
                                // but the value of polys[k].polygon calculated is normally NULL

                                // Add polygon this polygon (j) to k since they intersect
				// Mark ourselfs to be dropped (2), delete the original k
                                Geometry* polyunion = polys[k].polygon->Union(polys[j].polygon);
                                delete(polys[k].polygon);
				polys[k].polygon = dynamic_cast<Polygon*>(polyunion); 
				polys[j].iscontained = 2; // Drop
                                istoplevelafterall = 2;
                                break;

                            }
#endif
                        }
                        if (istoplevelafterall == 0)
                        {
                            polys[j].iscontained = 1;
                            polys[j].containedbyid = i;
                        }
                    }
                }
#ifdef HAS_PREPARED_GEOMETRIES
		pgf.destroy(preparedtoplevelpolygon);
#endif
            }
            // polys now is a list of ploygons tagged with which ones are inside each other

            // List of polygons for multipolygon
            std::auto_ptr<std::vector<Geometry*> > polygons(new std::vector<Geometry*>);

            // For each top level polygon create a new polygon including any holes
            for (unsigned i=0 ;i < totalpolys; ++i)
            {
                if (polys[i].iscontained != 0) continue;

                // List of holes for this top level polygon
                std::auto_ptr<std::vector<Geometry*> > interior(new std::vector<Geometry*>);
                for (unsigned j=i+1; j < totalpolys; ++j)
                {
                   if (polys[j].iscontained == 1 && polys[j].containedbyid == i)
                   {
                       interior->push_back(polys[j].ring);
                   }
                }
                
                Polygon* poly(gf.createPolygon(polys[i].ring, interior.release()));
                poly->normalize();
                polygons->push_back(poly);
            }

            // Make a multipolygon if required
            if ((toplevelpolygons > 1) && enable_multi)
            {
                std::auto_ptr<MultiPolygon> multipoly(gf.createMultiPolygon(polygons.release()));
                //if (multipoly->isValid())
                //{
                    std::string text = writer.write(multipoly.get());
                    wkts.push_back(text);
                    areas.push_back(multipoly->getArea());
                    wkt_size++;
                //}
            }
            else
            {
                for(unsigned i=0; i<toplevelpolygons; i++) 
                {
                    Polygon* poly = dynamic_cast<Polygon*>(polygons->at(i));;
                    //if (poly->isValid())
                    //{
                        std::string text = writer.write(poly);
                        wkts.push_back(text);
                        areas.push_back(poly->getArea());
                        wkt_size++;
                    //}
                    delete(poly);
                }
            }
        }

        for (unsigned i=0; i < totalpolys; ++i)
        {
            delete(polys[i].polygon);
        }
        delete[](polys);
    }
    catch (std::exception& e)
      {
	std::cerr << std::endl << "Standard exception processing way_id "<< osm_id << ": " << e.what()  << std::endl;
	wkt_size = 0;
      }
    catch (...)
      {
        std::cerr << std::endl << "Exception caught processing way id=" << osm_id << std::endl;
        wkt_size = 0;
      }

    return wkt_size;
}
开发者ID:azzaxp,项目名称:osm2pgsql,代码行数:101,代码来源:build_geometry.cpp


注:本文中的GeometryFactory::createMultiPolygon方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。