Пример #1
0
Geometry*
MultiGeometry::cloneAs( const Geometry::Type& newType ) const
{
    MultiGeometry* multi = new MultiGeometry();
    for( GeometryCollection::const_iterator i = _parts.begin(); i != _parts.end(); ++i )
    {
        Geometry* part = i->get()->cloneAs( i->get()->getType() );
        if ( part ) multi->getComponents().push_back( part );
    }
    return multi;
}
Пример #2
0
void
ConstGeometryIterator::fetchNext()
{
    _next = 0L;
    if ( _stack.size() == 0 )
        return;

    const Geometry* current = _stack.top();
    _stack.pop();

    if ( current->getType() == Geometry::TYPE_MULTI && _traverseMulti )
    {
        const MultiGeometry* m = static_cast<const MultiGeometry*>(current);
        for( GeometryCollection::const_iterator i = m->getComponents().begin(); i != m->getComponents().end(); ++i )
            _stack.push( i->get() );
        fetchNext();
    }
    else if ( current->getType() == Geometry::TYPE_POLYGON && _traversePolyHoles )
    {
        const Polygon* p = static_cast<const Polygon*>(current);
        for( RingCollection::const_iterator i = p->getHoles().begin(); i != p->getHoles().end(); ++i )
            _stack.push( i->get() );
        _next = current;
    }
    else
    {
        _next = current;
    }    
}
Пример #3
0
// opens and rewinds the polygon to the specified orientation.
void 
MultiGeometry::rewind( Orientation orientation )
{
    for( GeometryCollection::const_iterator i = _parts.begin(); i != _parts.end(); ++i )
    {
        i->get()->rewind( orientation );
    }
}
Пример #4
0
unsigned
MultiGeometry::getNumGeometries() const
{
    unsigned total = 0;
    for( GeometryCollection::const_iterator i = _parts.begin(); i != _parts.end(); ++i )
        total += i->get()->getNumGeometries();
    return total;
}
Пример #5
0
double
MultiGeometry::getLength() const
{
    double total = 0.0;
    for( GeometryCollection::const_iterator i = _parts.begin(); i != _parts.end(); ++i )
        total += i->get()->getLength();
    return total;
}
Пример #6
0
int
MultiGeometry::getTotalPointCount() const
{
    int total = 0;
    for( GeometryCollection::const_iterator i = _parts.begin(); i != _parts.end(); ++i )
        total += i->get()->getTotalPointCount();
    return total;
}
Пример #7
0
Bounds
MultiGeometry::getBounds() const
{
    Bounds bounds;
    for( GeometryCollection::const_iterator i = _parts.begin(); i != _parts.end(); ++i )
    {
        bounds.expandBy( i->get()->getBounds() );
    }
    return bounds;
}
Пример #8
0
bool
MultiGeometry::isValid() const
{
    if ( _parts.size() == 0 )
        return false;

    bool valid = true;
    for( GeometryCollection::const_iterator i = _parts.begin(); i != _parts.end() && valid; ++i )
    {
        if ( !i->get()->isValid() )
            valid = false;
    }
    return valid;
}
Пример #9
0
MultiGeometry::MultiGeometry( const MultiGeometry& rhs ) :
Geometry( rhs )
{
    for( GeometryCollection::const_iterator i = rhs._parts.begin(); i != rhs._parts.end(); ++i )
        _parts.push_back( i->get()->clone() ); //i->clone() ); //osg::clone<Geometry>( i->get() ) );
}
Пример #10
0
OGRGeometryH
OgrUtils::createOgrGeometry(const osgEarth::Symbology::Geometry* geometry, OGRwkbGeometryType requestedType)
{
    if (!geometry) return NULL;

    if (requestedType == wkbUnknown)
    {
        osgEarth::Symbology::Geometry::Type geomType = geometry->getType();
        switch( geomType)
        {
        case osgEarth::Symbology::Geometry::TYPE_POLYGON:  
            requestedType = wkbPolygon;
            break;
        case osgEarth::Symbology::Geometry::TYPE_POINTSET:  
            requestedType = wkbPoint;
            break;
        case osgEarth::Symbology::Geometry::TYPE_LINESTRING:
            requestedType = wkbLineString;
            break;
        case osgEarth::Symbology::Geometry::TYPE_RING:
            requestedType = wkbLinearRing;
            break;            
        case Geometry::TYPE_UNKNOWN: break;
        case Geometry::TYPE_MULTI: 
            {
                const osgEarth::Symbology::MultiGeometry* multi = dynamic_cast<const MultiGeometry*>(geometry);
                osgEarth::Symbology::Geometry::Type componentType = multi->getComponentType();
                requestedType = componentType == Geometry::TYPE_POLYGON ? wkbMultiPolygon : 
                    componentType == Geometry::TYPE_POINTSET ? wkbMultiPoint :
                    componentType == Geometry::TYPE_LINESTRING ? wkbMultiLineString :
                    wkbNone;                    
            }
            break;
        }
    }

    OGRwkbGeometryType shape_type =
        requestedType == wkbPolygon || requestedType == wkbMultiPolygon ? wkbPolygon :
        requestedType == wkbPolygon25D || requestedType == wkbMultiPolygon25D? wkbPolygon25D :
        requestedType == wkbLineString || requestedType == wkbMultiLineString? wkbMultiLineString :
        requestedType == wkbLineString25D || requestedType == wkbMultiLineString25D? wkbMultiLineString25D :
        requestedType == wkbPoint || requestedType == wkbMultiPoint? wkbMultiPoint :
        requestedType == wkbPoint25D || requestedType == wkbMultiPoint25D? wkbMultiPoint25D :
        wkbNone;

    OGRwkbGeometryType part_type =
        shape_type == wkbPolygon || shape_type == wkbPolygon25D? wkbLinearRing :
        shape_type == wkbMultiLineString? wkbLineString :
        shape_type == wkbMultiLineString25D? wkbLineString25D :
        shape_type == wkbMultiPoint? wkbPoint :
        shape_type == wkbMultiPoint25D? wkbPoint25D :
        wkbNone;

    //OE_NOTICE << "shape_type = " << shape_type << " part_type=" << part_type << std::endl;


    const osgEarth::Symbology::MultiGeometry* multi = dynamic_cast<const MultiGeometry*>(geometry);

    if ( multi )
    {
        OGRGeometryH group_handle = OGR_G_CreateGeometry( wkbGeometryCollection );

        for (GeometryCollection::const_iterator itr = multi->getComponents().begin(); itr != multi->getComponents().end(); ++itr)
        {
            OGRGeometryH shape_handle = encodeShape( itr->get(), shape_type, part_type );
            if ( shape_handle )
            {
                OGRErr error = OGR_G_AddGeometryDirectly( group_handle, shape_handle );
                if ( error != OGRERR_NONE )
                {
                    OE_WARN << "OGR_G_AddGeometryDirectly failed! " << error << std::endl;
                    OE_WARN << "shape_type = " << shape_type << " part_type=" << part_type << std::endl;
                }                    
            }
        }

        return group_handle;
    }
    else
    {
        OGRGeometryH shape_handle = encodeShape( geometry, shape_type, part_type );
        return shape_handle;
    }
}