[Qgis-developer] Create Multiple Polygons from Polygon and Polylines

Matthew Denno mgdenno at gmail.com
Tue Sep 15 23:10:45 EDT 2009


Update:  So I thought that QgsPolyline->at(int).x() and
QgsPolyline->at(int).y() methods were working but upon further
investigation, they aren't working either.  It only returns the correct x
value for x1.  All of the other values are very small i.e. 1e-308

On Tue, Sep 15, 2009 at 10:09 PM, Matthew Denno <mgdenno at gmail.com> wrote:

> Thank you everyone for your help.  I really apprecand iate it as I am
> trying to learn the QGIS API and C++.  I think that I have a solid plan to
> achieve my goal now.  However, I seem to be stuck on something that I think
> should be simple, looping through the points of a QgsPolyline.  If I iterate
> through the Polylines and print out the point coordinates using
> ->at(int).x() I can print out x1, y1, x2, and y2 with out problems.  But, if
> I try to iterate through the points of the polyline and print out the
> coordinates, I get x1, y1 and then a bunch of junk values for the first 3
> polylines and then eventually it ends unexpectedly.  Below is the code I am
> trying to use.
>
>  //now iterate through each polyline feature
>
> while (mypPolylineLayer->nextFeature(currentPolylineFeat))
>
> {
>
> qDebug("feature = %i",f);
>
> ++f;
>
>
>  //get point geometry for current feature
>
> QgsGeometry * currentPolylineGeom = currentPolylineFeat.geometry();
>
> QgsPolyline * currentPolyline;
>
> currentPolyline = &currentPolylineGeom->asPolyline();
>
>  //this part works
>
> qDebug() << "x1 = " << currentPolyline->at(0).x();
>
> qDebug() << "y1 = " << currentPolyline->at(0).y();
>
> qDebug() << "x2 = " << currentPolyline->at(1).x();
>
> qDebug() << "y2 = " << currentPolyline->at(1).y();
>
>
>  QgsPolyline::const_iterator it = currentPolyline->constBegin();
>
> for(; it != currentPolyline->constEnd(); ++it)
>
> {
>
> //this part doesn't
>
> qDebug() << "x = " << (*it).x();
>
> qDebug() << "y = " << (*it).y();
>
> }
>
> }
>
>
> On Tue, Sep 15, 2009 at 5:48 AM, Carson Farmer <carson.farmer at gmail.com>wrote:
>
>> Basically the polylines need to be "dissolved" first.  Is there an
>>> existing function to acheive this?
>>
>>
>> You will likely need to do this yourself by finding segments that share a
>> node, and creating a single line from all the associated QgsPoints.
>>
>>
>>> Also, is there an enexisting function to union polygons programaticlly?
>>>
>>
>> Certainly, check out QgsGeometry.combine() in the docs.
>>
>> Carson
>>
>>
>> --
>> Carson Farmer
>> National Centre for Geocomputation
>> John Hume Building,
>> National University of Ireland, Maynooth,
>> Maynooth,
>> Co. Kildare,
>> Ireland.
>> www.carsonfarmer.com
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20090915/18cf8561/attachment.html


More information about the Qgis-developer mailing list