Esempio n. 1
0
void
KML_Geometry::buildChild( const Config& conf, KMLContext& cx, Style& style)
{
    if ( conf.key() == "point" )
    {
        KML_Point g;
        g.parseStyle(conf, cx, style);
        g.parseCoords(conf, cx);
        _geom = g._geom.get();
    }
    else if ( conf.key() == "linestring" )
    {
        KML_LineString g;
        g.parseStyle(conf, cx, style);
        g.parseCoords(conf, cx);
        _geom = g._geom.get();
    }
    else if ( conf.key() == "linearring" )
    {
        KML_LinearRing g;
        g.parseStyle(conf, cx, style);
        g.parseCoords(conf, cx);
        _geom = g._geom.get();
    }
    else if ( conf.key() == "polygon" || conf.key() == "gx:latlonquad" )
    {
        KML_Polygon g;
        g.parseStyle(conf, cx, style);
        g.parseCoords(conf, cx);
        _geom = g._geom.get();
    }
    else if ( conf.key() == "multigeometry" )
    {
        KML_MultiGeometry g;
        g.parseStyle(conf, cx, style);
        g.parseCoords(conf, cx);
        const ConfigSet& mgChildren = conf.children();
        
        for( ConfigSet::const_iterator i = mgChildren.begin(); i != mgChildren.end(); ++i )
        {
            const Config& mgChild = *i;
            Style subStyle = style;
            KML_Geometry subGeom;
            subGeom.parseStyle( mgChild, cx, subStyle );
            subGeom.buildChild( mgChild, cx, style );
            if ( subGeom._geom.valid() )
                dynamic_cast<MultiGeometry*>(g._geom.get())->getComponents().push_back( subGeom._geom.get() );
        }
        //g.parseCoords(conf.child("multigeometry"), cx);
        _geom = g._geom.get();
    }
    else if ( conf.key() == "model" )
    {
        KML_Model g;
        g.parseStyle(conf, cx, style);
        g.parseCoords(conf, cx);
        _geom = g._geom.get();
    }
}
Esempio n. 2
0
void
KML_Geometry::buildChild( xml_node<>* node, KMLContext& cx, Style& style)
{
	std::string name = toLower(node->name());
    if ( name == "point" )
    {
        KML_Point g;
        g.parseCoords(node, cx);
        _geom = g._geom.get();
        g.parseStyle(node, cx, style);
    }
    else if (name == "linestring" )
    {
        KML_LineString g;
        g.parseCoords(node, cx);
        _geom = g._geom.get();
        g.parseStyle(node, cx, style);
    }
    else if ( name == "linearring" || name == "gx:latlonquad" )
    {
        KML_LinearRing g;
        g.parseCoords(node, cx);
        _geom = g._geom.get();
        g.parseStyle(node, cx, style);
    }
    else if ( name == "polygon" )
    {
        KML_Polygon g;
        g.parseCoords(node, cx);
        _geom = g._geom.get();
        g.parseStyle(node, cx, style);
    }
    else if ( name == "multigeometry" )
    {
        KML_MultiGeometry g;
        g.parseCoords(node, cx);
        _geom = g._geom.get();
        
        for( xml_node<>* n = node->first_node(); n; n = n->next_sibling())
        {
            KML_Geometry subGeom;
            subGeom.buildChild( n, cx, style ); //use single style for all subgeometries
            if ( subGeom._geom.valid() )
                dynamic_cast<MultiGeometry*>(g._geom.get())->getComponents().push_back( subGeom._geom.get() );
        }
    }
    else if ( name == "model" )
    {
        KML_Model g;
        g.parseCoords(node, cx);
        _geom = g._geom.get();
        g.parseStyle(node, cx, style);
    }
}
Esempio n. 3
0
void
KML_Polygon::parseCoords( xml_node<>* node, KMLContext& cx )
{
    Polygon* poly = new Polygon();

    xml_node<>* outer = node->first_node("outerboundaryis", 0, false);
    if ( outer )
    {
        xml_node<>* outerRing = outer->first_node("linearring", 0, false);
        if ( outerRing )
        {
            KML_LinearRing outer;
            outer.parseCoords( outerRing, cx );
            if ( outer._geom.valid() )
            {
                static_cast<Ring*>(outer._geom.get())->rewind( Ring::ORIENTATION_CCW );
                poly->reserve( outer._geom->size() );
                std::copy( outer._geom->begin(), outer._geom->end(), std::back_inserter(*poly) );
            }
        }

		for (xml_node<>* n = node->first_node("innerboundaryis", 0, false); n; n = n->next_sibling("innerboundaryis", 0, false))
		{
			xml_node<>* innerRing = n->first_node("linearring", 0, false);
			if ( innerRing )
			{
				KML_LinearRing inner;
				inner.parseCoords( innerRing, cx );
				if ( inner._geom.valid() )
				{
					Geometry* innerGeom = inner._geom.get();
					static_cast<Ring*>(innerGeom)->rewind( Ring::ORIENTATION_CW );
					poly->getHoles().push_back( dynamic_cast<Ring*>(innerGeom) );
				}
			}
		}
    }

    _geom = poly;
}