コード例 #1
0
ファイル: sdtslinereader.cpp プロジェクト: Wedjaa/node-gdal
void SDTSLineReader::AttachToPolygons( SDTSTransfer * poTransfer,
                                       int iTargetPolyLayer )

{
/* -------------------------------------------------------------------- */
/*      We force a filling of the index because when we attach the      */
/*      lines we are just providing a pointer back to the line          */
/*      features in this readers index.  If they aren't cached in       */
/*      the index then the pointer will be invalid.                     */
/* -------------------------------------------------------------------- */
    FillIndex();

/* ==================================================================== */
/*      Loop over all lines, attaching them to the polygons they        */
/*      have as right and left faces.                                   */
/* ==================================================================== */
    Rewind();
    SDTSRawLine *poLine;
    SDTSPolygonReader *poPolyReader = NULL;
    while( (poLine = reinterpret_cast<SDTSRawLine *>( GetNextFeature()) )
           != NULL )
    {
/* -------------------------------------------------------------------- */
/*      Skip lines with the same left and right polygon face.  These    */
/*      are dangles, and will not contribute in any useful fashion      */
/*      to the resulting polygon.                                       */
/* -------------------------------------------------------------------- */
        if( poLine->oLeftPoly.nRecord == poLine->oRightPoly.nRecord )
            continue;

/* -------------------------------------------------------------------- */
/*      If we don't have our indexed polygon reader yet, try to get     */
/*      it now.                                                         */
/* -------------------------------------------------------------------- */
        if( poPolyReader == NULL )
        {
            int         iPolyLayer = -1;

            if( poLine->oLeftPoly.nRecord != -1 )
            {
                iPolyLayer = poTransfer->FindLayer(poLine->oLeftPoly.szModule);
            }
            else if( poLine->oRightPoly.nRecord != -1 )
            {
               iPolyLayer = poTransfer->FindLayer(poLine->oRightPoly.szModule);
            }

            if( iPolyLayer == -1 )
                continue;

            if( iPolyLayer != iTargetPolyLayer )
                continue;

            poPolyReader = reinterpret_cast<SDTSPolygonReader *>(
                poTransfer->GetLayerIndexedReader(iPolyLayer) );

            if( poPolyReader == NULL )
                return;
        }

/* -------------------------------------------------------------------- */
/*      Attach line to right and/or left polygons.                      */
/* -------------------------------------------------------------------- */
        if( poLine->oLeftPoly.nRecord != -1 )
        {
          SDTSRawPolygon *poPoly = reinterpret_cast<SDTSRawPolygon *>(
              poPolyReader->GetIndexedFeatureRef( poLine->oLeftPoly.nRecord ) );
            if( poPoly != NULL )
                poPoly->AddEdge( poLine );
        }

        if( poLine->oRightPoly.nRecord != -1 )
        {
            SDTSRawPolygon *poPoly = reinterpret_cast<SDTSRawPolygon *>(
                poPolyReader->GetIndexedFeatureRef(
                    poLine->oRightPoly.nRecord ) );

            if( poPoly != NULL )
                poPoly->AddEdge( poLine );
        }
    }
}