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;
 }
Example #2
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;
}
Example #3
0
    void object::test<7>()
    {         
        GeomPtr geom;

        try
        {
            // use FLOATING model
            namespace ggm = geos::geom;
            namespace gio = geos::io;
            ggm::PrecisionModel pm(ggm::PrecisionModel::FLOATING);
            ggm::GeometryFactory gf(&pm);
            gio::WKTReader wktReader(&gf);
            const std::string str = " POINT (0 0) ";
            geom.reset(wktReader.read(str)); //HERE IT FAILS

            geos::geom::CoordinateSequence *coords = geom->getCoordinates();
            ensure_equals(coords->getDimension(), 2U);
            ensure_distance(coords->getX(0), 0.0, 1e-12);
            ensure_distance( coords->getY(0), 0.0, 1e-12);
            delete coords;
        }
        catch (const geos::util::IllegalArgumentException& ex)
        {
            ensure( "Did get expected exception" );
            ex.what();
        }
        catch (...)
        {
            ensure( !"Got unexpected exception" );
        }
    }
Example #4
0
	GeomPtr fromWKT(const std::string& wkt)
	{
		GeomPtr geom;
		try {
			geom.reset( rdr.read(wkt) );
		}
		catch (const GEOSException& ex) {
			cerr << ex.what() << endl;
		}
		return geom;
	}
Example #5
0
    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" );
        }
    }
        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 #7
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;

}