コード例 #1
0
void ForceValidityVisitor::visit( LineString& g )
{
    g.forceValidityFlag( valid_ );
    for ( size_t i = 0; i < g.numPoints(); i++ ) {
        visit( g.pointN( i ) );
    }
}
コード例 #2
0
  bool geosIntersect(const LineSegment& ls1, Meters buffer, const LineSegment& ls2,
                     LineSegment& result)
  {
    boost::shared_ptr<Geometry> g1(ls1.toGeometry(*GeometryFactory::getDefaultInstance())->clone());
    boost::shared_ptr<Geometry> g2(ls2.toGeometry(*GeometryFactory::getDefaultInstance())->clone());
    boost::shared_ptr<Geometry> g(g1->buffer(buffer, 40));

    boost::shared_ptr<Geometry> i(g->intersection(g2.get()));

    if (i->isEmpty())
    {
      result.p0 = Coordinate::getNull();
      return false;
    }
    else if (i->getGeometryTypeId() == GEOS_POINT)
    {
      Point* p = dynamic_cast<Point*>(i.get());
      result.p0 = *(p->getCoordinate());
    }
    else if (i->getGeometryTypeId() == GEOS_LINESTRING)
    {
      LineString* ls = dynamic_cast<LineString*>(i.get());
      assert(ls->getNumPoints() == 2);
      result.p0 = *ls->getPointN(0)->getCoordinate();
      result.p1 = *ls->getPointN(1)->getCoordinate();
    }
    else
    {
      throw HootException();
    }
    return true;
  }
コード例 #3
0
bool
SegmentIntersectionTester::hasIntersection(
	const LineString &line, const LineString &testLine)
{
  typedef std::size_t size_type;

	const CoordinateSequence &seq0 = *(line.getCoordinatesRO());
  size_type seq0size = seq0.getSize();

  const CoordinateSequence &seq1 = *(testLine.getCoordinatesRO());
  size_type seq1size = seq1.getSize();

  for (size_type i = 1; i<seq0size && !hasIntersectionVar; ++i)
	{
    seq0.getAt(i - 1, pt00);
    seq0.getAt(i, pt01);

    for (size_type j = 1; j < seq1size && !hasIntersectionVar; ++j)
		{
      seq1.getAt(j-1, pt10);
      seq1.getAt(j, pt11);

			li.computeIntersection(pt00, pt01, pt10, pt11);
			if (li.hasIntersection()) hasIntersectionVar = true;
		}
	}

	return hasIntersectionVar;
}
コード例 #4
0
ファイル: minkowskiSum.cpp プロジェクト: hdeeken/SFCGAL
void minkowskiSum( const LineString& gA, const Polygon_2& gB, Polygon_set_2& polygonSet )
{
    if ( gA.isEmpty() ) {
        return ;
    }

    int npt = gA.numPoints() ;

    for ( int i = 0; i < npt - 1 ; i++ ) {
        Polygon_2 P;
        P.push_back( gA.pointN( i ).toPoint_2() );
        P.push_back( gA.pointN( i+1 ).toPoint_2() );

        //
        // We want to compute the "minkowski sum" on each segment of the line string
        // This is not very well defined. But it appears CGAL supports it.
        // However we must use the explicit "full convolution" method for that particular case in CGAL >= 4.7
#if CGAL_VERSION_NR < 1040701000 // version 4.7
        Polygon_with_holes_2 part = minkowski_sum_2( P, gB );
#else
        Polygon_with_holes_2 part = minkowski_sum_by_full_convolution_2( P, gB );
#endif

        // merge into a polygon set
        if ( polygonSet.is_empty() ) {
            polygonSet.insert( part );
        }
        else {
            polygonSet.join( part );
        }
    }
}
コード例 #5
0
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()) {
        };
    }
}
コード例 #6
0
      void compute()
      {
          //Tell the calculator about the new start/end points
          _profileCalculator->setStartEnd( GeoPoint(_mapNode->getMapSRS(), _start.x(), _start.y(), 0),
                                           GeoPoint(_mapNode->getMapSRS(), _end.x(), _end.y(), 0));

          if (_featureNode.valid())
          {
              _root->removeChild( _featureNode.get() );
              _featureNode = 0;
          }

          LineString* line = new LineString();
          line->push_back( _start );
          line->push_back( _end );
          Feature* feature = new Feature(line, _mapNode->getMapSRS());
          feature->geoInterp() = GEOINTERP_GREAT_CIRCLE;    

          //Define a style for the line
          Style style;
          LineSymbol* ls = style.getOrCreateSymbol<LineSymbol>();
          ls->stroke()->color() = Color::Yellow;
          ls->stroke()->width() = 2.0f;
          ls->tessellation() = 20;

          style.getOrCreate<AltitudeSymbol>()->clamping() = AltitudeSymbol::CLAMP_TO_TERRAIN;

          feature->style() = style;

          _featureNode = new FeatureNode( _mapNode, feature );
          //Disable lighting
          _featureNode->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
          _root->addChild( _featureNode.get() );

      }
コード例 #7
0
ファイル: LineString.cpp プロジェクト: hjanetzek/SFCGAL
LineString::LineString( const LineString& other ):
    Geometry()
{
    for ( size_t i = 0; i < other.numPoints(); i++ ) {
        _points.push_back( other.pointN( i ).clone() ) ;
    }
}
コード例 #8
0
Handle<Value> LineStringPoints::count(const Arguments& args)
{
	HandleScope scope;

	Handle<Object> parent = args.This()->GetHiddenValue(String::NewSymbol("parent_"))->ToObject();
	LineString *geom = ObjectWrap::Unwrap<LineString>(parent);

	return scope.Close(Integer::New(geom->get()->getNumPoints()));
}
コード例 #9
0
void WktWriter::writeInner( const LineString & g )
{
	_s << "(";
	for ( size_t i = 0; i < g.numPoints(); i++ ){
		if ( i != 0 )
			_s << ",";

		write( g.pointN(i).coordinates() );
	}
	_s << ")";
}
コード例 #10
0
Handle<Value> LineStringPoints::reverse(const Arguments& args)
{
	HandleScope scope;

	Handle<Object> parent = args.This()->GetHiddenValue(String::NewSymbol("parent_"))->ToObject();
	LineString *geom = ObjectWrap::Unwrap<LineString>(parent);

	geom->get()->reversePoints();

	return Undefined();
}
コード例 #11
0
ファイル: Geometry.cpp プロジェクト: 3dcl/osgearth
Geometry*
Ring::cloneAs( const Geometry::Type& newType ) const
{
    if ( newType == TYPE_LINESTRING )
    {
        LineString* line = new LineString( &this->asVector() );
        if ( line->size() > 1 && line->front() != line->back() )
            line->push_back( front() );
        return line;
    }
    else return Geometry::cloneAs( newType );
}
コード例 #12
0
ファイル: WKBWriter.cpp プロジェクト: libgeos/libgeos
void
WKBWriter::writeLineString(const LineString& g)
{
    writeByteOrder();

    writeGeometryType(WKBConstants::wkbLineString, g.getSRID());
    writeSRID(g.getSRID());

    const CoordinateSequence* cs = g.getCoordinatesRO();
    assert(cs);
    writeCoordinateSequence(*cs, true);
}
コード例 #13
0
ファイル: MultiLineString.cpp プロジェクト: AvlWx2014/basemap
bool MultiLineString::isClosed() const {
	if (isEmpty()) {
		return false;
	}
	for (size_t i = 0, n = geometries->size(); i < n; ++i) {
		LineString *ls = dynamic_cast<LineString*>((*geometries)[i]);
		if ( ! ls->isClosed() ) {
			return false;
		}
	}
	return true;
}
コード例 #14
0
std::unordered_map<std::string, std::vector<Feature>> Source::Impl::queryRenderedFeatures(const QueryParameters& parameters) const {
    std::unordered_map<std::string, std::vector<Feature>> result;
    if (renderTiles.empty() || parameters.geometry.empty()) {
        return result;
    }

    LineString<double> queryGeometry;

    for (const auto& p : parameters.geometry) {
        queryGeometry.push_back(TileCoordinate::fromScreenCoordinate(
            parameters.transformState, 0, { p.x, parameters.transformState.getSize().height - p.y }).p);
    }

    mapbox::geometry::box<double> box = mapbox::geometry::envelope(queryGeometry);


    auto sortRenderTiles = [](const RenderTile& a, const RenderTile& b) {
        return a.id.canonical.z != b.id.canonical.z ? a.id.canonical.z < b.id.canonical.z :
               a.id.canonical.y != b.id.canonical.y ? a.id.canonical.y < b.id.canonical.y :
               a.id.wrap != b.id.wrap ? a.id.wrap < b.id.wrap : a.id.canonical.x < b.id.canonical.x;
    };
    std::vector<std::reference_wrapper<const RenderTile>> sortedTiles;
    std::transform(renderTiles.cbegin(), renderTiles.cend(), std::back_inserter(sortedTiles),
                   [](const auto& pair) { return std::ref(pair.second); });
    std::sort(sortedTiles.begin(), sortedTiles.end(), sortRenderTiles);

    for (const auto& renderTileRef : sortedTiles) {
        const RenderTile& renderTile = renderTileRef.get();
        GeometryCoordinate tileSpaceBoundsMin = TileCoordinate::toGeometryCoordinate(renderTile.id, box.min);
        if (tileSpaceBoundsMin.x >= util::EXTENT || tileSpaceBoundsMin.y >= util::EXTENT) {
            continue;
        }

        GeometryCoordinate tileSpaceBoundsMax = TileCoordinate::toGeometryCoordinate(renderTile.id, box.max);
        if (tileSpaceBoundsMax.x < 0 || tileSpaceBoundsMax.y < 0) {
            continue;
        }

        GeometryCoordinates tileSpaceQueryGeometry;
        tileSpaceQueryGeometry.reserve(queryGeometry.size());
        for (const auto& c : queryGeometry) {
            tileSpaceQueryGeometry.push_back(TileCoordinate::toGeometryCoordinate(renderTile.id, c));
        }

        renderTile.tile.queryRenderedFeatures(result,
                                              tileSpaceQueryGeometry,
                                              parameters.transformState,
                                              parameters.layerIDs);
    }

    return result;
}
コード例 #15
0
Handle<Value> LineStringPoints::resize(const Arguments& args)
{
	HandleScope scope;

	Handle<Object> parent = args.This()->GetHiddenValue(String::NewSymbol("parent_"))->ToObject();
	LineString *geom = ObjectWrap::Unwrap<LineString>(parent);

	int count;
	NODE_ARG_INT(0, "point count", count)
	geom->get()->setNumPoints(count);

	return Undefined();
}
コード例 #16
0
ファイル: MultiLineString.cpp プロジェクト: AvlWx2014/basemap
MultiLineString*
MultiLineString::reverse() const
{
	size_t nLines = geometries->size();
	Geometry::NonConstVect *revLines = new Geometry::NonConstVect(nLines);
	for (size_t i=0; i<nLines; ++i)
	{
		LineString *iLS = dynamic_cast<LineString*>((*geometries)[i]);
		assert(iLS);
		(*revLines)[nLines-1-i] = iLS->reverse();
	}
	return getFactory()->createMultiLineString(revLines);
}
コード例 #17
0
ファイル: distance3d.cpp プロジェクト: Oslandia/SFCGAL
double distanceLineStringLineString3D( const LineString& gA, const LineString& gB )
{
    if ( gA.isEmpty() || gB.isEmpty() ) {
        return std::numeric_limits< double >::infinity() ;
    }

    size_t nsA = gA.numSegments() ;
    size_t nsB = gB.numSegments() ;

    double dMin = std::numeric_limits< double >::infinity() ;

    for ( size_t i = 0; i < nsA; i++ ) {
        for ( size_t j = 0; j < nsB; j++ ) {
            dMin = std::min(
                       dMin,
                       distanceSegmentSegment3D(
                           gA.pointN( i ), gA.pointN( i+1 ),
                           gB.pointN( j ), gB.pointN( j+1 )
                       )
                   ) ;
        }
    }

    return dMin ;
}
コード例 #18
0
ファイル: distance3d.cpp プロジェクト: Oslandia/SFCGAL
double distancePointLineString3D( const Point& gA, const LineString& gB )
{
    if ( gA.isEmpty() || gB.isEmpty() ) {
        return std::numeric_limits< double >::infinity() ;
    }

    double dMin = std::numeric_limits< double >::infinity() ;

    for ( size_t i = 0; i < gB.numSegments(); i++ ) {
        dMin = std::min( dMin, distancePointSegment3D( gA, gB.pointN( i ), gB.pointN( i+1 ) ) );
    }

    return dMin ;
}
コード例 #19
0
ファイル: orientation.cpp プロジェクト: Ezio47/SFCGAL
bool isCounterClockWiseOriented( const LineString& ls )
{
    // Compute the 'z' part of the Newell's formula
    // and test against 0
    Kernel::FT z = 0 ;

    for ( size_t i = 0; i < ls.numSegments(); ++i ) {
        const Point& pi = ls.pointN( i );
        const Point& pj = ls.pointN( i+1 );
        z += ( pi.x() - pj.x() ) * ( pi.y() + pj.y() );
    }

    return z > 0;
}
コード例 #20
0
ファイル: offset.cpp プロジェクト: amutu/SFCGAL
/**
 * @brief build LineString offset
 */
void offset( const LineString & lineString, const double& radius, Offset_polygon_set_2 & polygonSet ){
	for ( size_t i = 0; i < lineString.numSegments(); i++ ){
		Polygon_2 P ;
		P.push_back( lineString.pointN(i).toPoint_2() );
		P.push_back( lineString.pointN(i+1).toPoint_2() );
		Offset_polygon_with_holes_2  offset = CGAL::approximated_offset_2( P, radius, SFCGAL_OFFSET_ACCURACY ) ;

		if ( polygonSet.is_empty() ){
			polygonSet.insert( offset );
		}else{
			polygonSet.join( offset );
		}
	}
}
コード例 #21
0
mapnik::geometry::line_string<double> geowave_featureset::create_line_string(LineString line_string)
{
    mapnik::geometry::line_string<double> line_string_out;
    for (int point_idx = line_string.getNumPoints()-1; point_idx >= 0; --point_idx)
    {
        Coordinate coord = line_string.getPointN(point_idx).getCoordinate();
        line_string_out.add_coord(coord.x(), coord.y());
    }
    if (line_string.isClosed())
    {
        Coordinate coord = line_string.getPointN(line_string.getNumPoints()-1).getCoordinate();
        line_string_out.add_coord(coord.x(), coord.y());
    }
    return line_string_out;
}
コード例 #22
0
void
RectangleIntersectionBuilder::reverseLines()
{
  std::list<geom::LineString *> new_lines;
  for (std::list<geom::LineString *>::reverse_iterator i=lines.rbegin(), e=lines.rend(); i!=e; ++i)
  {
    LineString *ol = *i;
    new_lines.push_back(dynamic_cast<LineString*>(ol->reverse()));
    delete ol;
  }
  lines = new_lines;
#if GEOS_DEBUG
  std::cout << "After lines reverse, parts are " << *this << std::endl;
#endif
}
コード例 #23
0
ファイル: LineString.cpp プロジェクト: h4ck3rm1k3/geos
/*protected*/
LineString::LineString(const LineString &ls)
	:
	Geometry(ls.getFactory()),
	points(ls.points->clone())
{
	//points=ls.points->clone();
}
コード例 #24
0
ファイル: BoundaryVisitor.cpp プロジェクト: hjanetzek/SFCGAL
void BoundaryVisitor::visit( const LineString& g )
{
    if ( g.isEmpty() ) {
        _boundary.reset();
        return ;
    }

    if ( g.startPoint().coordinate() == g.endPoint().coordinate() ) {
        _boundary.reset() ;
    }
    else {
        std::auto_ptr< MultiPoint > boundary( new MultiPoint );
        boundary->addGeometry( g.startPoint() );
        boundary->addGeometry( g.endPoint() );
        _boundary.reset( boundary.release() );
    }
}
コード例 #25
0
ファイル: building.cpp プロジェクト: hjanetzek/SFCGAL
void _buildingWall( const Polygon_2& ring, const Kernel::FT& wallHeight, PolyhedralSurface& shell )
{
    size_t npt = ring.size() ;

    for ( size_t i = 0; i < npt; i++ ) {
        const Point_2& a = ring.vertex( i ) ;
        const Point_2& b = ring.vertex( ( i+1 ) % npt ) ;

        LineString wallRing ;
        wallRing.addPoint( new Point( a.x(), a.y(), Kernel::FT( 0 ) ) );
        wallRing.addPoint( new Point( b.x(), b.y(), Kernel::FT( 0 ) ) );
        wallRing.addPoint( new Point( b.x(), b.y(), wallHeight ) );
        wallRing.addPoint( new Point( a.x(), a.y(), wallHeight ) );
        wallRing.addPoint( new Point( a.x(), a.y(), Kernel::FT( 0 ) ) );
        shell.addPolygon( Polygon( wallRing ) );
    }
}
コード例 #26
0
ファイル: PolyhedralSurface.cpp プロジェクト: HEShuang/SFCGAL
PolyhedralSurface::PolyhedralSurface( const MarkedPolyhedron& poly ) :
    Surface()
{
    for ( MarkedPolyhedron::Facet_const_iterator fit = poly.facets_begin(); fit != poly.facets_end(); ++fit ) {
        LineString* face = new LineString();
        MarkedPolyhedron::Halfedge_around_facet_const_circulator hit = fit->facet_begin();

        do {
            face->addPoint( hit->vertex()->point() );
            ++hit;
        }
        while ( hit != fit->facet_begin() );

        // close the ring
        face->addPoint( hit->vertex()->point() );
        _polygons.push_back( new Polygon( face ) );
    }
}
コード例 #27
0
void WktWriter::write( const LineString & g )
{
	_s << "LINESTRING" ;
	if ( g.isEmpty() ){
		_s << " EMPTY" ;
		return ;
	}
	writeInner(g);
}
コード例 #28
0
ファイル: distance3d.cpp プロジェクト: Oslandia/SFCGAL
double distanceLineStringTriangle3D( const LineString& gA, const Triangle& gB )
{
    if ( gA.isEmpty() || gB.isEmpty() ) {
        return std::numeric_limits< double >::infinity() ;
    }

    double dMin = std::numeric_limits< double >::infinity() ;

    const Point& tA = gB.vertex( 0 ) ;
    const Point& tB = gB.vertex( 1 ) ;
    const Point& tC = gB.vertex( 2 ) ;

    for ( size_t i = 0; i < gA.numSegments(); i++ ) {
        dMin = std::min( dMin, distanceSegmentTriangle3D( gA.pointN( i ), gA.pointN( i+1 ), tA, tB, tC ) );
    }

    return dMin ;
}
コード例 #29
0
Handle<Value> LineStringPoints::get(const Arguments& args)
{
	HandleScope scope;

	Handle<Object> parent = args.This()->GetHiddenValue(String::NewSymbol("parent_"))->ToObject();
	LineString *geom = ObjectWrap::Unwrap<LineString>(parent);

	OGRPoint *pt = new OGRPoint();
	int i;

	NODE_ARG_INT(0, "index", i);
	if(i < 0 || i >= geom->get()->getNumPoints()) {
		return scope.Close(Null());
	}

	geom->get()->getPoint(i, pt);

	return scope.Close(Point::New(pt));
}
コード例 #30
0
ファイル: distance3d.cpp プロジェクト: Oslandia/SFCGAL
double distanceLineStringPolygon3D( const LineString& gA, const Polygon& gB )
{
    if ( gA.isEmpty() || gB.isEmpty() ) {
        return std::numeric_limits< double >::infinity() ;
    }

    TriangulatedSurface triangulateSurfaceB ;
    triangulate::triangulatePolygon3D( gB, triangulateSurfaceB ) ;
    return distanceGeometryCollectionToGeometry3D( triangulateSurfaceB, gA );
}