예제 #1
0
파일: GEOS.cpp 프로젝트: omega-hub/osgearth
Symbology::Geometry*
GEOSContext::exportGeometry(const geom::Geometry* input)
{
    Symbology::GeometryCollection parts;

    if ( dynamic_cast<const geom::Point*>( input ) )
    {
        OE_NOTICE << "GEOS 'Point' NYI" << std::endl;        
    }
    else if ( dynamic_cast<const geom::MultiPoint*>( input ) )
    {
        const geom::MultiPoint* mp = dynamic_cast<const geom::MultiPoint*>( input );
        Symbology::PointSet* part = new Symbology::PointSet( mp->getNumPoints() );
        for( unsigned int i=0; i < mp->getNumPoints(); i++ )
        {
            const geom::Geometry* g = mp->getGeometryN(i);
            if ( g )
            {
                const geom::Coordinate* c = mp->getCoordinate();
                if ( c )
                {
                    part->push_back( osg::Vec3d( c->x, c->y, c->z ) ); //p->getX(), p->getY(), 0 ) );
                }
            }
        }
        parts.push_back( part );
    }
    else if ( dynamic_cast<const geom::LineString*>( input ) )
    {
        const geom::LineString* line = dynamic_cast<const geom::LineString*>( input );
        Symbology::LineString* part = new Symbology::LineString( line->getNumPoints() );
        for( unsigned int i=0; i<line->getNumPoints(); i++ )
        {
            const geom::Coordinate& c = line->getCoordinateN(i);
            part->push_back( osg::Vec3d( c.x, c.y, c.z ) ); //0 ) );
        }
        parts.push_back( part );
    }
    else if ( dynamic_cast<const geom::MultiLineString*>( input ) )
    {
        const geom::MultiLineString* m = dynamic_cast<const geom::MultiLineString*>( input );
        for( unsigned int i=0; i<m->getNumGeometries(); i++ ) 
        {
            Symbology::Geometry* part = exportGeometry( m->getGeometryN(i) );
            if ( part ) parts.push_back( part );
        }
    }
    else if ( dynamic_cast<const geom::Polygon*>( input ) )
    {
        const geom::Polygon* poly = dynamic_cast<const geom::Polygon*>( input );
        Symbology::Geometry* part = exportPolygon( poly );
        if ( part ) parts.push_back( part );
    }
    else if ( dynamic_cast<const geom::MultiPolygon*>( input ) )
    {
        //OE_NOTICE << "Multipolygon" << std::endl;
        const geom::MultiPolygon* mpoly = dynamic_cast<const geom::MultiPolygon*>( input );
        for( unsigned int i=0; i<mpoly->getNumGeometries(); i++ )
        {
            Symbology::Geometry* part = exportPolygon( dynamic_cast<const geom::Polygon*>( mpoly->getGeometryN(i) ) );
            if ( part ) parts.push_back( part );
        }        
    }

    if ( parts.size() == 1 )
    {
        osg::ref_ptr<Symbology::Geometry> part = parts.front().get();
        parts.clear();
        return part.release();
    }
    else if ( parts.size() > 1 )
    {
        return new Symbology::MultiGeometry( parts );
    }
    else
    {
        return 0L;
    }
}
예제 #2
0
Symbology::Geometry*
GEOSUtils::exportGeometry( const geom::Geometry* input )
{
    //// first verify that the input is valid.
    //valid::IsValidOp validator( input );
    //if ( !validator.isValid() )
    //{
    //    OE_NOTICE << "GEOS: discarding invalid geometry" << std::endl;
    //    return 0L;
    //}

    Symbology::GeometryCollection parts;

    if ( dynamic_cast<const geom::Point*>( input ) )
    {
        OE_NOTICE << "GEOS 'Point' NYI" << std::endl;        
    }
    else if ( dynamic_cast<const geom::MultiPoint*>( input ) )
    {
        const geom::MultiPoint* mp = static_cast<const geom::MultiPoint*>( input );
        Symbology::PointSet* part = new Symbology::PointSet( mp->getNumPoints() );
        for( int i=0; i < mp->getNumPoints(); i++ )
        {
            geom::Point* p = (geom::Point*)( mp->getGeometryN(i) );
            part->push_back( osg::Vec3d( p->getX(), p->getY(), 0 ) );
        }
        parts.push_back( part );
    }
    else if ( dynamic_cast<const geom::LineString*>( input ) )
    {
        const geom::LineString* line = static_cast<const geom::LineString*>( input );
        Symbology::LineString* part = new Symbology::LineString( line->getNumPoints() );
        for( int i=0; i<line->getNumPoints(); i++ )
        {
            const geom::Coordinate& c = line->getCoordinateN(i);
            part->push_back( osg::Vec3d( c.x, c.y, 0 ) );
        }
        parts.push_back( part );
    }
    else if ( dynamic_cast<const geom::MultiLineString*>( input ) )
    {
        const geom::MultiLineString* m = static_cast<const geom::MultiLineString*>( input );
        for( int i=0; i<m->getNumGeometries(); i++ ) 
        {
            Symbology::Geometry* part = exportGeometry( m->getGeometryN(i) );
            if ( part ) parts.push_back( part );
        }
    }
    else if ( dynamic_cast<const geom::Polygon*>( input ) )
    {
        const geom::Polygon* poly = static_cast<const geom::Polygon*>( input );
        Symbology::Geometry* part = exportPolygon( poly );
        if ( part ) parts.push_back( part );
    }
    else if ( dynamic_cast<const geom::MultiPolygon*>( input ) )
    {
        //OE_NOTICE << "Multipolygon" << std::endl;
        const geom::MultiPolygon* mpoly = static_cast<const geom::MultiPolygon*>( input );
        for( int i=0; i<mpoly->getNumGeometries(); i++ )
        {
            Symbology::Geometry* part = exportPolygon( static_cast<const geom::Polygon*>( mpoly->getGeometryN(i) ) );
            if ( part ) parts.push_back( part );
        }        
    }

    if ( parts.size() == 1 )
    {
        osg::ref_ptr<Symbology::Geometry> part = parts.front();
        parts.clear();
        return part.release();
    }
    else if ( parts.size() > 1 )
    {
        return new Symbology::MultiGeometry( parts );
    }
    else
    {
        return 0L;
    }
}