Example #1
0
/*public*/
std::auto_ptr<geom::Geometry>
GeometrySnapper::snapToSelf(double snapTolerance, bool cleanResult)
{

	using std::auto_ptr;
	using geom::util::GeometryTransformer;
	
	// Get snap points
	auto_ptr<Coordinate::ConstVect> snapPts=extractTargetCoordinates(srcGeom);

	// Apply a SnapTransformer to source geometry
	// (we need a pointer for dynamic polymorphism)
	auto_ptr<GeometryTransformer> snapTrans(new SnapTransformer(snapTolerance, *snapPts));

	GeomPtr result = snapTrans->transform(&srcGeom);
	
	if (cleanResult && ( dynamic_cast<const Polygon*>(result.get()) ||
	                     dynamic_cast<const MultiPolygon*>(result.get()) ) )
	{
		// TODO: use better cleaning approach
		result.reset(result->buffer(0));
	}

	return result;
}
 void doLineClipTest(const char* inputWKT, const std::string& expectedWKT, const Rectangle& rect, double tolerance=0)
 {
   GeomPtr g = readWKT(inputWKT);
   ensure(g.get());
   GeomPtr obt = RectangleIntersection::clipBoundary(*g,rect);
   ensure(obt.get());
   bool ok = isEqual(*readWKT(expectedWKT), *obt, tolerance);
   ensure(ok);
 }
Example #3
0
	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)" );
    }
Example #4
0
	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)" );

    }
        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
        }
Example #6
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 );
      }
    }
Example #7
0
	void object::test<3>()
	{         
        GeomPtr geom ( wktreader.read("POINT Z (-117 33 120)") );
        std::string  result;

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

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

        ensure_equals( result, std::string("POINT Z (-117 33 120)") );

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

        ensure_equals( result, std::string("POINT (-117 33 120)") );

    }
Example #8
0
  void object::test<5>()
  {         
    PrecisionModel pm3(0.001);
    GeometryFactory gf3(&pm3);
    WKTReader wktreader3(&gf3);
    GeomPtr geom ( wktreader3.read("POINT(123456 654321)") );

    std::string  result = wktwriter.write( geom.get() );
    ensure_equals( result, std::string("POINT (123000 654000)") );
  }
Example #9
0
    void object::test<1>()
    {
	GeomPtr geom = fromWKT("LINEARRING (0 0, 0 10, 10 10, 10 0, 0 0)");
	LinearRing* ring_chk = dynamic_cast<LinearRing*>(geom.get());
	ensure(nullptr != ring_chk);
	LinearRing& ring = *ring_chk;
	//cout << ring.toString() << endl;
	updateNonClosedRing(ring);
	//cout << ring.toString() << endl;
	checkIsValid(*geom, false);
    }
int
main()
{
	PrecisionModel pm;
	GeometryFactory::Ptr gf = GeometryFactory::create(&pm);
	WKTReader rdr(gf.get());

	string inputWKT =
        "POLYGON ((110 320, 190 220, 60 200, 180 120, 120 40, 290 150, 410 40, 410 230, 500 340, 320 310, 260 370, 220 310, 110 320), (220 260, 250 180, 290 220, 360 150, 350 250, 260 280, 220 260))";

        GeomPtr base ( rdr.read(inputWKT) );
	run(base.get());
}
Example #11
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);
    }
Example #12
0
    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);
    }
	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);

	}
	//
	// 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>()
	{         
		std::string wkt_in("POLYGON ((40 240, 160 241, 280 240, 280 160, \
					160 240, 40 140, 40 240))");
		
	//
	// 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))");
    
        GeomPtr g(wktreader.read(wkt));
Example #16
0
 void runIsSequenced(const std::string& inputWKT, bool exp)
 {
   GeomPtr g = readWKT(inputWKT);
   bool isSequenced = LineSequencer::isSequenced(g.get());
   ensure_equals( isSequenced, exp );
 }
Example #17
0
/*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;

}