[Qgis-developer] geos help(union polygons)
vinayan
vinayan123 at gmail.com
Wed Jan 23 21:32:12 PST 2013
Hi,
I am trying to find gaps inside a polygon layer much like the ESRI
topology rule("must not have gaps"). I did this initially by making an
extent polygon and then subtracting the union of all geometries from
this extent polygon.
All this worked well and for around 100 polygons in the extent the
performance is ok. But when the count goes up, the performance is
drastically down. The issue, I think is because I am creating the union
iteratively as below.
for ( it = mFeatureList1.begin(); it != FeatureListEnd; ++it )
{
g2 = it->feature.geometry();
g1 = g1->combine( g2 );
}
From what I read from Martin Davis'
blog(http://lin-ear-th-inking.blogspot.in/2007/11/fast-polygon-merging-in-jts-using.html),
the cascaded polygon union improves the performance of union by a large
ratio.
I want to use the below method that exist in Geos. But I am not sure how
to use it.
I got this far(also pasted in pastebin http://pastebin.com/rniMLuZW),
std::vector<geos::geom::Polygon*> geomCollection;
QList<FeatureLayer>::ConstIterator FeatureListEnd = mFeatureList1.end();
for ( it = mFeatureList1.begin(); it != FeatureListEnd; ++it )
{
g1 = it->feature.geometry();
const std::string wkt = g1->exportToWkt().toStdString();
geos::geom::Polygon* geom =
dynamic_cast<geos::geom::Polygon*>(geos::io::WKTReader().read(wkt));
//error is here....
geomCollection.push_back(geom);
}
geos::geom::Geometry* unionedPoly =
geos::operation::geounion::CascadedPolygonUnion::Union(&geomCollection);
The error is,
/home/vinayan/QgisGitWorking/Quantum-GIS/src/plugins/topology/topolTest.cpp:746:
error: cannot dynamic_cast
‘geos::io::WKTReader().geos::io::WKTReader::read((* & wkt))’ (of type
‘struct geos::geom::Geometry*’) to type ‘struct geos::geom::Polygon*’
(target is not pointer or reference to complete type)
This has more to do with my c++ knowledge than anything i guess..but if
anyone can help where I am going wrong, it would be a good step forward
for me. If it works well, I am sure this function would find use in
other parts of Qgis where slow unions are involved.
Thanks in advance,
Vinayan
More information about the Qgis-developer
mailing list