void ForceValidityVisitor::visit( MultiLineString& g )
{
    g.forceValidityFlag( valid_ );
    for ( size_t i = 0; i < g.numGeometries(); i++ ) {
        visit( g.lineStringN( i ) );
    }
}
Exemple #2
0
	std::auto_ptr<Geometry> collect( const Geometry& ga, const Geometry& gb )
	{
		if ( ga.geometryTypeId() == gb.geometryTypeId() ) {
			if ( ga.geometryTypeId() == TYPE_POINT ) {
				MultiPoint *mp = new MultiPoint;
				mp->addGeometry( ga );
				mp->addGeometry( gb );
				return std::auto_ptr<Geometry>(mp);
			}
			else if ( ga.geometryTypeId() == TYPE_LINESTRING ) {
				MultiLineString *mls = new MultiLineString();
				mls->addGeometry(ga);
				mls->addGeometry(gb);
				return std::auto_ptr<Geometry>( mls );
			}
			else if ( ga.geometryTypeId() == TYPE_POLYGON ) {
				MultiPolygon *mp = new MultiPolygon();
				mp->addGeometry(ga);
				mp->addGeometry(gb);
				return std::auto_ptr<Geometry>( mp );
			}
			else if ( ga.geometryTypeId() == TYPE_SOLID ) {
				MultiSolid *mp = new MultiSolid();
				mp->addGeometry(ga);
				mp->addGeometry(gb);
				return std::auto_ptr<Geometry>( mp );
			}
		}

		// else
		GeometryCollection* coll = new GeometryCollection();
		coll->addGeometry(ga);
		coll->addGeometry(gb);
		return std::auto_ptr<Geometry>( coll );
	}
mapnik::geometry::multi_line_string<double> geowave_featureset::create_multi_line_string(MultiLineString multi_line_string)
{
    mapnik::geometry::multi_line_string<double> multi_line_string_out;
    for (int geom_idx = 0; geom_idx < multi_line_string.getNumGeometries(); ++geom_idx)
        multi_line_string_out.push_back(create_line_string(java_cast<LineString>(multi_line_string.getGeometryN(geom_idx))));
    return multi_line_string_out;
}
Handle<Value> MultiLineString::New(const Arguments& args)
{
	HandleScope scope;
	MultiLineString *f;

	if (!args.IsConstructCall()) {
		return NODE_THROW("Cannot call constructor as function, you need to use 'new' keyword");
	}

	if (args[0]->IsExternal()) {
		Local<External> ext = Local<External>::Cast(args[0]);
		void* ptr = ext->Value();
		f = static_cast<MultiLineString *>(ptr);

	} else {
		if (args.Length() != 0) {
			return NODE_THROW("MultiLineString constructor doesn't take any arguments");
		}
		f = new MultiLineString(new OGRMultiLineString());
	}

	Handle<Value> children = GeometryCollectionChildren::New(args.This()); 
	args.This()->SetHiddenValue(String::NewSymbol("children_"), children); 

	f->Wrap(args.This());
	return args.This();
}
TEST(TileCover, DISABLED_FuzzLine) {
    while(1)
    {
        std::srand (time(NULL));
        std::size_t len = std::rand() % 10000 + 3;
        MultiLineString<double> mls;

        std::size_t num_lines = 1;
        num_lines += std::rand() % 5;
        while (num_lines > 0) {
            LineString<double> line;
            for (std::size_t i = 0; i < len; ++i) {
                double x = std::rand() % 180;
                double y = std::rand() % 90;

                line.push_back({x,y});
            }
            mls.emplace_back(line);
            --num_lines;
        }
        
        std::clog << ".";
        util::TileCover tc(mls, 5);
        while(tc.next()) {
        };
    }
}
void WktWriter::write( const MultiLineString & g )
{
	_s << "MULTILINESTRING" ;
	if ( g.isEmpty() ){
		_s << " EMPTY" ;
		return ;
	}

	_s << "(";
	for ( size_t i = 0; i < g.numGeometries(); i++ ){
		if ( i != 0 )
			_s << "," ;
		writeInner( g.geometryN(i).as< LineString >() );
	}
	_s << ")";
}
Exemple #7
0
void straightSkeletonToMultiLineString(
	const CGAL::Straight_skeleton_2<K> & ss,
	MultiLineString& result
)
{
	typedef CGAL::Straight_skeleton_2<K> Ss ;

	typedef typename Ss::Vertex_const_handle     Vertex_const_handle ;
	typedef typename Ss::Halfedge_const_handle   Halfedge_const_handle ;
	typedef typename Ss::Halfedge_const_iterator Halfedge_const_iterator ;

	Halfedge_const_handle null_halfedge ;
	Vertex_const_handle   null_vertex ;

	for ( Halfedge_const_iterator it = ss.halfedges_begin(); it != ss.halfedges_end(); ++it ){
		// skip contour edge
		if ( ! it->is_bisector() ){
			continue ;
		}

		// avoid duplicates
		if ( it->opposite() < it ){
			continue ;
		}

		result.addGeometry( new LineString(
			Point( it->opposite()->vertex()->point() ),
			Point( it->vertex()->point() )
		) );
	}
}
Exemple #8
0
void BoundaryVisitor::visit( const MultiLineString& g )
{
    if ( g.isEmpty() ) {
        _boundary.reset();
        return ;
    }

    /*
     * create a GeometryGraph and rely on vertex degree (1 means boundary)
     */
    graph::GeometryGraph        graph ;
    graph::GeometryGraphBuilder graphBuilder( graph ) ;

    for ( size_t i = 0; i < g.numGeometries(); i++ ) {
        graphBuilder.addLineString( g.lineStringN( i ) );
    }

    getBoundaryFromLineStrings( graph ) ;
}
Exemple #9
0
void GetPointsVisitor::visit( const MultiLineString& g )
{
    for ( size_t i = 0; i < g.numGeometries(); i++ ) {
        visit( g.lineStringN( i ) );
    }
}
 inline MultiLineStringBaseType::const_iterator range_end(const MultiLineString& mls) {return mls.end();}
 inline MultiLineStringBaseType::const_iterator range_begin(const MultiLineString& mls) {return mls.begin();}
static Feature::geometry_type convertGeometry(const GeometryTileFeature& geometryTileFeature, const CanonicalTileID& tileID) {
    const double size = util::EXTENT * std::pow(2, tileID.z);
    const double x0 = util::EXTENT * tileID.x;
    const double y0 = util::EXTENT * tileID.y;

    auto tileCoordinatesToLatLng = [&] (const Point<int16_t>& p) {
        double y2 = 180 - (p.y + y0) * 360 / size;
        return Point<double>(
            (p.x + x0) * 360 / size - 180,
            360.0 / M_PI * std::atan(std::exp(y2 * M_PI / 180)) - 90.0
        );
    };

    GeometryCollection geometries = geometryTileFeature.getGeometries();

    switch (geometryTileFeature.getType()) {
        case FeatureType::Unknown: {
            assert(false);
            return Point<double>(NAN, NAN);
        }

        case FeatureType::Point: {
            MultiPoint<double> multiPoint;
            for (const auto& p : geometries.at(0)) {
                multiPoint.push_back(tileCoordinatesToLatLng(p));
            }
            if (multiPoint.size() == 1) {
                return multiPoint[0];
            } else {
                return multiPoint;
            }
        }

        case FeatureType::LineString: {
            MultiLineString<double> multiLineString;
            for (const auto& g : geometries) {
                LineString<double> lineString;
                for (const auto& p : g) {
                    lineString.push_back(tileCoordinatesToLatLng(p));
                }
                multiLineString.push_back(std::move(lineString));
            }
            if (multiLineString.size() == 1) {
                return multiLineString[0];
            } else {
                return multiLineString;
            }
        }

        case FeatureType::Polygon: {
            MultiPolygon<double> multiPolygon;
            for (const auto& pg : classifyRings(geometries)) {
                Polygon<double> polygon;
                for (const auto& r : pg) {
                    LinearRing<double> linearRing;
                    for (const auto& p : r) {
                        linearRing.push_back(tileCoordinatesToLatLng(p));
                    }
                    polygon.push_back(std::move(linearRing));
                }
                multiPolygon.push_back(std::move(polygon));
            }
            if (multiPolygon.size() == 1) {
                return multiPolygon[0];
            } else {
                return multiPolygon;
            }
        }
    }

    // Unreachable, but placate GCC.
    return Point<double>();
}