Geometry::AutoPtr
GeometryTransformer::transformGeometryCollection(
    const GeometryCollection* geom,
    const Geometry* parent)
{
    UNREFERENCED_PARAMETER(parent);

#if GEOS_DEBUG
    std::cerr << "GeometryTransformer::transformGeometryCollection(GeometryCollection " << geom <<", Geometry " << parent << ");" << std::endl;
#endif

    vector<Geometry*>* transGeomList = new vector<Geometry*>();

    for (unsigned int i=0, n=geom->getNumGeometries(); i<n; i++)
    {
        Geometry::AutoPtr transformGeom = transform(
                                              geom->getGeometryN(i)); // no parent ?
        if ( transformGeom.get() == NULL ) continue;
        if ( pruneEmptyGeometry && transformGeom->isEmpty() ) continue;

        // If an exception is thrown we'll leak
        transGeomList->push_back(transformGeom.release());
    }

    if ( preserveGeometryCollectionType )
    {
        return Geometry::AutoPtr(factory->createGeometryCollection(
                                     transGeomList));
    }
    else
    {
        return Geometry::AutoPtr(factory->buildGeometry(transGeomList));
    }

}
Geometry::AutoPtr
GeometryTransformer::transformMultiPolygon(
    const MultiPolygon* geom,
    const Geometry* parent)
{
    UNREFERENCED_PARAMETER(parent);

#if GEOS_DEBUG
    std::cerr << "GeometryTransformer::transformMultiPolygon(MultiPolygon " << geom <<", Geometry " << parent << ");" << std::endl;
#endif

    auto_ptr< vector<Geometry*> > transGeomList( new vector<Geometry*>() );

    for (unsigned int i=0, n=geom->getNumGeometries(); i<n; i++)
    {
        assert(dynamic_cast<const Polygon*>(geom->getGeometryN(i)));
        const Polygon* p = static_cast<const Polygon*>(
                               geom->getGeometryN(i));

        Geometry::AutoPtr transformGeom = transformPolygon(p, geom);
        if ( transformGeom.get() == NULL ) continue;
        if ( transformGeom->isEmpty() ) continue;

        // If an exception is thrown we'll leak
        transGeomList->push_back(transformGeom.release());
    }

    return Geometry::AutoPtr(factory->buildGeometry(transGeomList.release()));

}
Example #3
0
Geometry::AutoPtr
GeometryTransformer::transformMultiLineString(
		const MultiLineString* geom,
		const Geometry* parent)
{

#if GEOS_DEBUG
	std::cerr << "GeometryTransformer::transformMultiLineString(MultiLineString " << geom <<", Geometry " << parent << ");" << std::endl;
#endif

	vector<Geometry*>* transGeomList = new vector<Geometry*>();

	for (unsigned int i=0, n=geom->getNumGeometries(); i<n; i++)
	{
		assert(dynamic_cast<const LineString*>(geom->getGeometryN(i)));
		const LineString* l = static_cast<const LineString*>(
				geom->getGeometryN(i));

		Geometry::AutoPtr transformGeom = transformLineString(l, geom);
		if ( transformGeom.get() == NULL ) continue;
		if ( transformGeom->isEmpty() ) continue;

		// If an exception is thrown we'll leak
		transGeomList->push_back(transformGeom.release());
	}

	return Geometry::AutoPtr(factory->buildGeometry(transGeomList));

}
Example #4
0
    void object::test<3>()
    {
        const std::string wkt("LINESTRING (100 100, 20 20, 200 20, 100 100)");
        const Geometry::AutoPtr geom(reader_.read(wkt));

        IsSimpleOp op;
        bool simple = op.isSimpleLinearGeometry(geom.get());

        ensure( true == simple );
    }
Example #5
0
    void object::test<1>()
    {
        const std::string wkt("MULTILINESTRING ((20 120, 120 20), (20 20, 120 120))");
        const Geometry::AutoPtr geom(reader_.read(wkt));

        // TODO - mloskot: What about support of new features of BoundaryNodeRule, in JTS

        IsSimpleOp op;
        bool simple = op.isSimpleLinearGeometry(geom.get());

        ensure( false == simple );

        // TODO - mloskot:
        // There are missing features not (re)implemented in IsSimpleOp, in GEOS.
        // So, all tests in this suite have been simplified in comparison to original JTS tests.
        //
        //Coordinate loc(70, 70);
        //Coordinate nonSimpleLoc = op.getNonSimpleLocation();
        //loc.distance(nonSimpleLoc) < TOLERANCE
    }
Geometry::AutoPtr
GeometryTransformer::transformPolygon(
    const Polygon* geom,
    const Geometry* parent)
{
    UNREFERENCED_PARAMETER(parent);

#if GEOS_DEBUG
    std::cerr << "GeometryTransformer::transformPolygon(Polygon " << geom <<", Geometry " << parent << ");" << std::endl;
#endif

    bool isAllValidLinearRings = true;

    assert(dynamic_cast<const LinearRing*>(geom->getExteriorRing()));
    const LinearRing* lr = static_cast<const LinearRing*>(
                               geom->getExteriorRing());

    Geometry::AutoPtr shell = transformLinearRing(lr, geom);
    if ( shell.get() == NULL
            || ! dynamic_cast<LinearRing*>(shell.get())
            || shell->isEmpty() )
    {
        isAllValidLinearRings = false;
    }

    vector<Geometry*>* holes = new vector<Geometry*>();
    for (unsigned int i=0, n=geom->getNumInteriorRing(); i<n; i++)
    {
        assert(dynamic_cast<const LinearRing*>(
                   geom->getInteriorRingN(i)));
        const LinearRing* lr = static_cast<const LinearRing*>(
                                   geom->getInteriorRingN(i));

        Geometry::AutoPtr hole(transformLinearRing(lr, geom));

        if ( hole.get() == NULL || hole->isEmpty() ) {
            continue;
        }

        if ( ! dynamic_cast<LinearRing*>(hole.get()) )
        {
            isAllValidLinearRings = false;
        }

        holes->push_back(hole.release());
    }

    if ( isAllValidLinearRings)
    {
        Geometry* sh = shell.release();
        assert(dynamic_cast<LinearRing*>(sh));
        return Geometry::AutoPtr(factory->createPolygon(
                                     static_cast<LinearRing*>(sh),
                                     holes));
    }
    else
    {
        // would like to use a manager constructor here
        vector<Geometry*>* components = new vector<Geometry*>();
        if ( shell.get() != NULL ) {
            components->push_back(shell.release());
        }

        components->insert(components->end(),
                           holes->begin(), holes->end());

        delete holes; // :(

        return Geometry::AutoPtr(factory->buildGeometry(components));
    }

}
Example #7
0
/*public*/
void
GeometryList::add(Geometry::AutoPtr geom)
{
	geoms.push_back(geom.release());
}