[gdal-dev] Reading error with dwg and dxf files

Even Rouault even.rouault at mines-paris.org
Mon Aug 5 13:23:07 PDT 2013


Selon Xian Chen/³ÂÏÛ <chenxian at walkinfo.com.cn>:

> Thanks Even.
>
> After checking the code under dwg and dxf, I believe the relevant error code
> to my original error report should be in
> ogr/ogrsf_frmts/dxf/ogrdxf_polyline_smooth.cpp. The code in EmitArc() must
> consider the case when ogrArcStartAngle > ogrArcEndAngle and bClockWise is
> true before calling OGRGeometryFactory::approximateArcAngles() (around line
> 265). Here I increase the value of ogrArcEndAngle by 360 degree as follows:
>     if( bClockwise && (ogrArcStartAngle > ogrArcEndAngle) )
>         ogrArcEndAngle += 360.0;
>
> Then the reported error is corrected.
>
> Similarly, there are error codes in both ogrdxf_hatch.cpp and
> ogrdwg_hatch.cpp as you mentioned.
> Line 286-294 in ogrdxf_hatch.cpp are quite suspicious:
>             if( bCounterClockwise )
>             {
>                 double dfTemp = dfStartAngle;
>                 dfStartAngle = dfEndAngle;
>                 dfEndAngle = dfTemp;
>             }
>             if( dfStartAngle > dfEndAngle )
>                 dfEndAngle += 360.0;
>
> Can anyone explain to me why switching Start Angle and End Angle (this will
> reverse the order of the line string!!). Also, if bCounterClockwise, you
> won't want to increase dfEndAngle by 360..
>
> I've fixed the above code with something like:
>             if( bCounterClockwise )
>             {
>                dfStartAngle *= -1;
>                dfEndAngle *= -1;
>             }
>             else if( dfStartAngle > dfEndAngle )
>                 dfEndAngle += 360.0;
>
> Similar fix-up is made in ogrdwg_hatch.cpp
>
> Not sure if these are sufficient, yet at least work well with my couple of
> sample dwg/dxf files.
>
> I may want to submit a patch if you and other developers are okay with my
> fix-up.

Xian,

I'm not familiar with that code, so I am not sure about your proposed fix, but
it could be helpful if you attach it to a ticket so it doesn't get lost.
Attaching sample .dxf and .dwg files that have the issue that the patch fixes
would also be helpfull.

Best regards,

Even


More information about the gdal-dev mailing list