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

Matthew Denno mgdenno at gmail.com
Tue Oct 6 22:40:55 EDT 2009


Hello All,

So, I have made quite a bit of progress with this function, but I am having
a little problem.  It does not work with all datasets.

For debuging, the program outputs the point coordinates using the toString()
function each time it checks for coincident points (when checking if
polyline segments touch end to end).  Some points show as being equal using
toString() but don't return true when checked using ==.  I suspect that this
is due to rounding errors maybe, but that doesn't quite seem right because
the source data are equal double values.  Does the toString() function show
all the decimal points for the point coordinates?  Is there a better way to
check if points are coincident (better than ==)?

I can send out the code if anyone is interested.

Thanks for all your help.

Matt


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

> 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/20091006/7df2d1ab/attachment-0001.html


More information about the Qgis-developer mailing list