コード例 #1
0
ファイル: WKTWriterTest.cpp プロジェクト: AvlWx2014/basemap
	void object::test<4>()
	{         
        GeomPtr geom ( wktreader.read("POINT(-117 33 120)") );
        std::string  result;

        wktwriter.setOutputDimension(2);
        wktwriter.setTrim( true );
        wktwriter.setOld3D( false );

        result = wktwriter.write( geom.get() );

        ensure_equals( result, std::string("POINT (-117 33)") );
    }
コード例 #2
0
ファイル: WKTReaderTest.cpp プロジェクト: BlueEyes-Lin/sunmap
    void object::test<6>()
    {         
        GeomPtr geom;

        try {
            geom.reset(wktreader.read("POLYGON( EMPTY, (1 1,2 2,1 2,1 1))"));
            ensure( !"Didn't get expected exception" );
        } catch (const geos::util::IllegalArgumentException& ex) {
            ensure( "Did get expected exception" );
            ex.what();
        } catch (...) {
            ensure( !"Got unexpected exception" );
        }
    }
コード例 #3
0
    void object::test<4>()
    {
	GeomPtr geom = fromWKT("POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0), (1 1, 2 1, 2 2, 1 2, 1 1) ))");
	Polygon* poly = dynamic_cast<Polygon*>(geom.get());
	ensure(nullptr != poly);
	const LineString* ring = poly->getInteriorRingN(0);

	const LinearRing* lr = dynamic_cast<const LinearRing*>(ring);
	ensure(nullptr != lr);

	LinearRing* nclr = const_cast<LinearRing*>(lr);

	updateNonClosedRing(*nclr);
	checkIsValid(*geom, false);
    }
コード例 #4
0
 GeomPtr
 readGeometry(const std::string& wkt)
 {
     GeomPtr g;
     if(wkt[0] == '0' || wkt[0] == '1') {
         WKBReader r;
         std::istringstream is(wkt);
         g.reset(r.readHEX(is));
     }
     else {
         WKTReader r;
         g.reset(r.read(wkt));
     }
     return g;
 }
コード例 #5
0
ファイル: WKTWriterTest.cpp プロジェクト: AvlWx2014/basemap
	void object::test<1>()
	{         
        GeomPtr geom ( wktreader.read("POINT(-117 33)") );
        std::string  result;

        wktwriter.setTrim(false);
        result = wktwriter.write( geom.get() );

        ensure_equals( result , "POINT (-117.000 33.000)" );

        wktwriter.setTrim(true);
        result = wktwriter.write( geom.get() );

        ensure_equals( result , "POINT (-117 33)" );
    }
コード例 #6
0
ファイル: WKTWriterTest.cpp プロジェクト: AvlWx2014/basemap
	void object::test<2>()
	{         
        GeomPtr geom ( wktreader.read("POINT(-117.1234567 33.1234567)") );
        std::string  result;

        wktwriter.setTrim(false);
        result = wktwriter.write( geom.get() );

        ensure_equals( result , "POINT (-117.123 33.123)" );

        wktwriter.setRoundingPrecision(2);
        result = wktwriter.write( geom.get() );

        ensure_equals( result , "POINT (-117.12 33.12)" );

    }
コード例 #7
0
    void runLineSequencer(const char * const * inputWKT,
                const std::string& expectedWKT)
    {
      readWKT(inputWKT, inpGeoms);

      LineSequencer sequencer;
      sequencer.add(inpGeoms);

      if ( ! sequencer.isSequenceable() ) {
      	ensure( expectedWKT.empty() );
      } else {  
        GeomPtr expected = readWKT(expectedWKT);
        GeomPtr result ( sequencer.getSequencedLineStrings() );
        ensure( expected->equalsExact( result.get() ) );

        bool isSequenced = LineSequencer::isSequenced(result.get());
        ensure( isSequenced );
      }
    }
コード例 #8
0
ファイル: IsValidTest.cpp プロジェクト: AvlWx2014/basemap
    void object::test<1>()
    {
	CoordinateSequence* cs = new CoordinateArraySequence();
	cs->add(Coordinate(0.0, 0.0));
	cs->add(Coordinate(1.0, DoubleNotANumber));
	GeomPtr line ( factory_.createLineString(cs) );


	IsValidOp isValidOp(line.get());
	bool valid = isValidOp.isValid();

	TopologyValidationError* err = isValidOp.getValidationError();
    ensure(0 != err);
    const Coordinate& errCoord = err->getCoordinate();

	ensure_equals( err->getErrorType(),
	               TopologyValidationError::eInvalidCoordinate );

	ensure(0 != ISNAN(errCoord.y));
	ensure_equals(valid, false);
    }
コード例 #9
0
	void object::test<13>()
	{
    Coordinate p1(-123456789, -40);
    Coordinate p2(381039468754763.0, 123456789);
    Coordinate q(0, 0);

    using geos::geom::CoordinateSequence;
    using geos::geom::GeometryFactory;
    using geos::geom::LineString;

    GeometryFactory::Ptr factory = GeometryFactory::create();
    CoordinateSequence* cs = new CoordinateArraySequence();
    cs->add(p1);
    cs->add(p2);

    GeomPtr l ( factory->createLineString(cs) );
    GeomPtr p ( factory->createPoint(q) );
    ensure(!l->intersects(p.get()));

    ensure(!CGAlgorithms::isOnLine(q, cs));
    ensure_equals(CGAlgorithms::computeOrientation(p1, p2, q), -1);

	}
コード例 #10
0
        void doClipTest(const char* inputWKT, const std::string& expectedWKT, const Rectangle& rect, double tolerance=0)
        {
          GeomPtr g = readWKT(inputWKT);
          ensure(g.get());
          GeomPtr obt = RectangleIntersection::clip(*g,rect);
          ensure(obt.get());
          bool ok = isEqual(*readWKT(expectedWKT), *obt, tolerance);
          ensure(ok);
// Compare with GEOSIntersection output
#if 0
          GeomPtr g2 ( rect.toPolygon(*g->getFactory()) );
          obt.reset(g->intersection(g2.get()));
          ensure(obt.get());
          ok = isEqual(*readWKT(expectedWKT), *obt, tolerance);
          ensure(ok);
#endif
        }
コード例 #11
0
		bool
		pointsWithinDistance(vector<Coordinate>& coords, double dist)
		{
			// we expect some numerical instability here
			// OffsetPointGenerator could produce points
			// at *slightly* farther locations then
			// requested
			//
			dist *= 1.0000001;

			for (size_t i=0, n=coords.size(); i<n; ++i)
			{
				const Coordinate& c = coords[i];
				auto_ptr<Geometry> pg(gf.createPoint(c));
				double rdist =  g->distance(pg.get());
				if ( rdist > dist )
				{
					return false;
				}
			}
			return true;
		}
コード例 #12
0
	group test_dpsimp_group("geos::simplify::DouglasPeuckerSimplifier");

	//
	// Test Cases
	//

	// 1 - PolygonNoReduction
	template<>
	template<>
	void object::test<1>()
	{         
		std::string wkt("POLYGON((20 220, 40 220, 60 220, 80 220, 100 220, \
					120 220, 140 220, 140 180, 100 180, 60 180, 20 180, 20 220))");

		GeomPtr g(wktreader.read(wkt));

		GeomPtr simplified = DouglasPeuckerSimplifier::simplify(
			g.get(), 10.0);

		ensure( simplified->isValid() );

		// topology is unchanged
		ensure( simplified->equals(g.get()) );
	}

	// 2 - PolygonReductionWithSplit
	template<>
	template<>
	void object::test<2>()
	{         
コード例 #13
0
	group test_tpsimp_group("geos::simplify::TopologyPreservingSimplifier");

	//
	// Test Cases
	//

	// PolygonNoReduction
	template<>
	template<>
	void object::test<1>()
	{         
		std::string wkt("POLYGON((20 220, 40 220, 60 220, 80 220, \
                    100 220, 120 220, 140 220, 140 180, 100 180, \
                    60 180, 20 180, 20 220))");

		GeomPtr g(wktreader.read(wkt));
		GeomPtr simplified = TopologyPreservingSimplifier::simplify(g.get(), 10.0);

		ensure( "Simplified geometry is invalid!", simplified->isValid() );
		ensure( "Simplified and original geometry inequal", simplified->equals(g.get()) );
        ensure_equals_geometry( g.get(), simplified.get() );
	}

    // PolygonNoReductionWithConflicts
	template<>
	template<>
	void object::test<2>()
	{
        std::string wkt("POLYGON ((40 240, 160 241, 280 240, 280 160, \
                        160 240, 40 140, 40 240))");
    
コード例 #14
0
 void runIsSequenced(const std::string& inputWKT, bool exp)
 {
   GeomPtr g = readWKT(inputWKT);
   bool isSequenced = LineSequencer::isSequenced(g.get());
   ensure_equals( isSequenced, exp );
 }
コード例 #15
0
ファイル: UnaryUnionOp.cpp プロジェクト: libgeos/libgeos
/*public*/
std::unique_ptr<geom::Geometry>
UnaryUnionOp::Union()
{
    using geom::Puntal;
    typedef std::unique_ptr<geom::Geometry> GeomPtr;

    GeomPtr ret;
    if(! geomFact) {
        return ret;
    }

    /**
     * For points and lines, only a single union operation is
     * required, since the OGC model allowings self-intersecting
     * MultiPoint and MultiLineStrings.
     * This is not the case for polygons, so Cascaded Union is required.
     */

    GeomPtr unionPoints;
    if(!points.empty()) {
        GeomPtr ptGeom = geomFact->buildGeometry(points.begin(),
                         points.end());
        unionPoints = unionNoOpt(*ptGeom);
    }

    GeomPtr unionLines;
    if(!lines.empty()) {
        /* JTS compatibility NOTE:
         * we use cascaded here for robustness [1]
         * but also add a final unionNoOpt step to deal with
         * self-intersecting lines [2]
         *
         * [1](http://trac.osgeo.org/geos/ticket/392
         * [2](http://trac.osgeo.org/geos/ticket/482
         *
         */
        unionLines.reset(CascadedUnion::Union(lines.begin(),
                                              lines.end()));
        if(unionLines.get()) {
            unionLines = unionNoOpt(*unionLines);
        }
    }

    GeomPtr unionPolygons;
    if(!polygons.empty()) {
        unionPolygons.reset(CascadedPolygonUnion::Union(polygons.begin(),
                            polygons.end()));
    }

    /**
     * Performing two unions is somewhat inefficient,
     * but is mitigated by unioning lines and points first
     */

    GeomPtr unionLA = unionWithNull(std::move(unionLines), std::move(unionPolygons));
    assert(!unionLines.get());
    assert(!unionPolygons.get());

    if(! unionPoints.get()) {
        ret = std::move(unionLA);
        assert(!unionLA.get());
    }
    else if(! unionLA.get()) {
        ret = std::move(unionPoints);
        assert(!unionPoints.get());
    }
    else {
        Puntal& up = dynamic_cast<Puntal&>(*unionPoints);
        ret = PointGeometryUnion::Union(up, *unionLA);
    }

    if(! ret.get()) {
        ret.reset(geomFact->createGeometryCollection());
    }

    return ret;

}