void runIndicesOfThenExtract(string const& inputStr, string const& subLineStr) { GeomPtr input(reader.read(inputStr)); GeomPtr subLine(reader.read(subLineStr)); GeomPtr result(indicesOfThenExtract(input.get(), subLine.get())); checkExpected(result.get(), subLine.get()); }
void runIndexOfAfterTest(string const& inputStr, string const& testPtWKT) { GeomPtr input(reader.read(inputStr)); GeomPtr testPoint(reader.read(testPtWKT)); const Coordinate* testPt = testPoint->getCoordinate(); bool resultOK = indexOfAfterCheck(input.get(), *testPt); ensure(resultOK); }
void runOffsetTest(string const& inputWKT, string const& testPtWKT, double offsetDistance, string const& expectedPtWKT) { GeomPtr input(reader.read(inputWKT)); GeomPtr testPoint(reader.read(testPtWKT)); GeomPtr expectedPoint(reader.read(expectedPtWKT)); const Coordinate* testPt = testPoint->getCoordinate(); const Coordinate* expectedPt = expectedPoint->getCoordinate(); Coordinate offsetPt = extractOffsetAt(input.get(), *testPt, offsetDistance); bool isOk = offsetPt.distance(*expectedPt) < TOLERANCE_DIST; if (! isOk) cout << "Expected = " << *expectedPoint << " Actual = " << offsetPt << endl; ensure(isOk); }
void testInputOutput(const std::string& WKT, const std::string& ndrWKB, const std::string& xdrWKB) { GeomPtr gWKT(wktreader.read(WKT)); // NDR input std::stringstream ndr_in(ndrWKB); GeomPtr gWKB_ndr(wkbreader.readHEX(ndr_in)); ensure("NDR input", gWKB_ndr->equalsExact(gWKT.get()) ); // XDR input std::stringstream xdr_in(xdrWKB); GeomPtr gWKB_xdr(wkbreader.readHEX(xdr_in)); ensure("XDR input", gWKB_xdr->equalsExact(gWKT.get()) ); // Compare geoms read from NDR and XDR ensure( gWKB_xdr->equalsExact(gWKB_ndr.get()) ); // NDR output std::stringstream ndr_out; ndrwkbwriter.writeHEX(*gWKT, ndr_out); ensure_equals("NDR output", ndr_out.str(), ndr_in.str()); // XDR output std::stringstream xdr_out; xdrwkbwriter.writeHEX(*gWKT, xdr_out); ensure_equals("XDR output", xdr_out.str(), xdr_in.str()); }
void checkExtractLine(const char* wkt, double start, double end, const char* expected) { string wktstr(wkt); GeomPtr linearGeom(reader.read(wktstr)); LengthIndexedLine indexedLine(linearGeom.get()); GeomPtr result(indexedLine.extractLine(start, end)); checkExpected(result.get(), expected); }
test_polygon_data() : pm_(1), factory_(&pm_, 0), reader_(&factory_), empty_poly_(factory_.createPolygon()), poly_size_(7) { // Create non-empty LinearRing GeometryPtr geo = 0; geo = reader_.read("POLYGON((0 10, 5 5, 10 5, 15 10, 10 15, 5 15, 0 10))"); poly_ = static_cast<PolygonPtr>(geo); }
void runPtLocator(int expected, const Coordinate& pt, const std::string& wkt) { GeomPtr geom(reader.read(wkt)); geos::algorithm::PointLocator pointLocator; int loc = pointLocator.locate(pt, geom.get()); ensure_equals(loc, expected); }
void checkLengthOfLine(std::string wkt, double expectedLength) { std::unique_ptr<Geometry> lineGeom(reader_.read(wkt)); std::unique_ptr<LineString> line(dynamic_cast<LineString*>(lineGeom.release())); ensure(nullptr != line.get()); const CoordinateSequence* lineSeq = line->getCoordinatesRO(); double actual = algorithm::Length::ofLine(lineSeq); ensure_equals(actual, expectedLength); }
test_polygon_data() : pm_(1) , factory_(GeometryFactory::create(&pm_, 0)) , reader_(factory_.get()) , empty_poly_(factory_->createPolygon()), poly_size_(7) { // Create non-empty LinearRing GeometryPtr geo = nullptr; geo = reader_.read("POLYGON((0 10, 5 5, 10 5, 15 10, 10 15, 5 15, 0 10))"); poly_ = dynamic_cast<PolygonPtr>(geo); }
GeomPtr fromWKT(const std::string& wkt) { GeomPtr geom; try { geom.reset( rdr.read(wkt) ); } catch (const GEOSException& ex) { cerr << ex.what() << endl; } return geom; }
test_geometrysnapper_data() : factory(), // initialize before use! reader(&factory), src(reader.read( "POLYGON ((0 0, 0 100, 100 100, 100 0, 0 0))" )), snapper( *(src.get()) ) { }
GeomPtr readWKT(const std::string& inputWKT) { return GeomPtr(wktreader.read(inputWKT)); }
void checkExpected(Geometry* result, string const& expected) { GeomPtr subLine(reader.read(expected)); checkExpected(result, subLine.get()); }
namespace tut { // // Test Group // // dummy data, not used struct test_pointlocator_data {}; typedef test_group<test_pointlocator_data> group; typedef group::object object; group test_pointlocator_group("geos::algorithm::PointLocator"); // These are static to avoid namespace pollution // The struct test_*_data above is probably there // for the same reason... // static PrecisionModel pm; static GeometryFactory::Ptr gf = GeometryFactory::create(&pm); static geos::io::WKTReader reader(gf.get()); typedef std::unique_ptr<Geometry> GeomPtr; void runPtLocator(int expected, const Coordinate& pt, const std::string& wkt) { GeomPtr geom(reader.read(wkt)); geos::algorithm::PointLocator pointLocator; int loc = pointLocator.locate(pt, geom.get()); ensure_equals(loc, expected); } // // Test Cases // // 1 - Test box template<> template<> void object::test<1> () { runPtLocator(Location::INTERIOR, Coordinate(10, 10), "POLYGON ((0 0, 0 20, 20 20, 20 0, 0 0))"); } // 2 - Test complex ring template<> template<> void object::test<2> () { runPtLocator(Location::INTERIOR, Coordinate(0, 0), "POLYGON ((-40 80, -40 -80, 20 0, 20 -100, 40 40, 80 -80, 100 80, 140 -20, 120 140, 40 180, 60 40, 0 120, -20 -20, -40 80))"); } // 3 - Test PointLocator LinearRing LineString template<> template<> void object::test<3> () { runPtLocator(Location::BOUNDARY, Coordinate(0, 0), "GEOMETRYCOLLECTION( LINESTRING(0 0, 10 10), LINEARRING(10 10, 10 20, 20 10, 10 10))"); } // 4 - Test PointLocator Point inside LinearRing template<> template<> void object::test<4> () { runPtLocator(Location::EXTERIOR, Coordinate(11, 11), "LINEARRING(10 10, 10 20, 20 10, 10 10)"); } // 5 - TestPointLocator Point inside MultiPoint template<> template<> void object::test<5> () { runPtLocator(Location::INTERIOR, Coordinate(0, 0), "MULTIPOINT ((1 1), (0 0))"); } } // namespace tut