Changeset 12517

Show
Ignore:
Timestamp:
10/23/07 11:07:35 (1 year ago)
Author:
mloskot
Message:

Ported fix of anti-clockwise order of coordinates in KML polygon to branches/1.4 (Ticket #1704).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.4/gdal/ogr/ogr_geometry.h

    r10646 r12517  
    334334    virtual OGRGeometry *clone() const; 
    335335    virtual int isClockwise() const; 
     336    virtual void reverseWindingOrder(); 
    336337    virtual void closeRings(); 
    337338    virtual double get_Area() const; 
  • branches/1.4/gdal/ogr/ogrlinearring.cpp

    r11695 r12517  
    358358} 
    359359 
     360/************************************************************************/  
     361/*                             reverseWindingOrder()                    */  
     362/************************************************************************/  
     363 
     364void OGRLinearRing::reverseWindingOrder()  
     365 
     366{  
     367    int pos = 0;  
     368    OGRPoint tempPoint;  
     369 
     370    for( int i = 0; i < nPointCount / 2; i++ )  
     371    {  
     372        getPoint( i, &tempPoint );  
     373        pos = nPointCount - i - 1;  
     374        setPoint( i, getX(pos), getY(pos), getZ(pos) );  
     375        setPoint( pos, tempPoint.getX(), tempPoint.getY(), tempPoint.getZ() );  
     376    }  
     377}  
     378 
    360379/************************************************************************/ 
    361380/*                             closeRing()                              */ 
  • branches/1.4/gdal/ogr/ogrsf_frmts/kml/ogr2kmlgeometry.cpp

    r10646 r12517  
    236236                      "<Polygon>" ); 
    237237 
    238         if( poPolygon->getExteriorRing() != NULL ) 
    239         { 
     238        OGRLinearRing *poExteriorRing = poPolygon->getExteriorRing();  
     239        if( poExteriorRing != NULL ) 
     240        { 
     241            /* Test if we need to reverse the winding order. The KML specification 
     242             * defines the front of a face as a LinearRing with anti-clockwise 
     243             * winding order. Full 3D implementations of KML, such as Google Earth, 
     244             * light the front of the face, not the rear. 
     245             * For the present case it's safe to assume that all faces exported 
     246             * from OGR should have anti-clockwise winding orders.  
     247             */ 
     248            if ( poExteriorRing->isClockwise() ) 
     249            {  
     250                poExteriorRing->reverseWindingOrder();  
     251            }  
     252 
    240253            AppendString( ppszText, pnLength, pnMaxLength, 
    241254                          "<outerBoundaryIs>" ); 
    242255 
    243             if( !OGR2KMLGeometryAppend( poPolygon->getExteriorRing(),  
     256            if( !OGR2KMLGeometryAppend( poExteriorRing, 
    244257                                        ppszText, pnLength, pnMaxLength ) ) 
     258            { 
    245259                return FALSE; 
    246              
     260            } 
     261 
    247262            AppendString( ppszText, pnLength, pnMaxLength, 
    248263                          "</outerBoundaryIs>" ); 
     
    252267        { 
    253268            OGRLinearRing *poRing = poPolygon->getInteriorRing(iRing); 
     269 
     270            /* Perform the winding test again. */ 
     271            if( poRing->isClockwise() )  
     272            {  
     273                poRing->reverseWindingOrder();  
     274            }  
    254275 
    255276            AppendString( ppszText, pnLength, pnMaxLength,