// TerraLib #include #include #include #include #include #include // STL #include #include void op_contains() { { //std::unique_ptr anel_vermelho = std::make_unique(5, te::gm::LineStringType, 0); std::unique_ptr anel_vermelho( new te::gm::LinearRing(5, te::gm::LineStringType, 0) ); anel_vermelho->setPoint(0, 1, 2); anel_vermelho->setPoint(1, 1, 7); anel_vermelho->setPoint(2, 7, 7); anel_vermelho->setPoint(3, 7, 2); anel_vermelho->setPoint(4, 1, 2); te::gm::Polygon poligono_vermelho(1, te::gm::PolygonType, 0); poligono_vermelho.setRingN(0, anel_vermelho.release()); //std::unique_ptr anel_azul = std::make_unique(5, te::gm::LineStringType); std::unique_ptr anel_azul( new te::gm::LinearRing(5, te::gm::LineStringType) ); anel_azul->setPoint(0, 2, 3); anel_azul->setPoint(1, 2, 6); anel_azul->setPoint(2, 6, 6); anel_azul->setPoint(3, 6, 3); anel_azul->setPoint(4, 2, 3); te::gm::Polygon poligono_azul(1, te::gm::PolygonType, 0); poligono_azul.setRingN(0, anel_azul.release()); std::cout << "O poligono Vermelho contem o Azul? " << std::boolalpha << poligono_vermelho.contains(&poligono_azul) << std::endl; } { std::unique_ptr poligono_vermelho( te::gm::WKTReader::read("POLYGON ( (9 2, 9 7, 15 7, 15 2, 9 2) )") ); std::unique_ptr poligono_azul( te::gm::WKTReader::read("POLYGON ( (10 4, 10 7, 14 7, 14 4, 10 4) )") ); std::cout << "O poligono Vermelho contem o Azul? " << std::boolalpha << poligono_vermelho->contains( poligono_azul.get() ) << std::endl; } } void op_within() { { std::unique_ptr poligono_vermelho( te::gm::WKTReader::read("POLYGON ( (2 3, 2 6, 6 6, 6 3, 2 3) )") ); std::unique_ptr poligono_azul( te::gm::WKTReader::read("POLYGON ( (1 2, 1 7, 7 7, 7 2, 1 2) )") ); std::cout << "O poligono Vermelho esta dentro do Azul? " << std::boolalpha << poligono_vermelho->within( poligono_azul.get() ) << std::endl; } { std::unique_ptr poligono_vermelho( te::gm::WKTReader::read("POLYGON ( (10 4, 10 7, 14 7, 14 4, 10 4) )") ); std::unique_ptr poligono_azul( te::gm::WKTReader::read("POLYGON ( (9 2, 9 7, 15 7, 15 2, 9 2) )") ); std::cout << "O poligono Vermelho esta dentro do Azul? " << std::boolalpha << poligono_vermelho->within( poligono_azul.get() ) << std::endl; } } void op_touches() { { std::unique_ptr vermelho( te::gm::WKTReader::read("LINESTRING (1 5, 1 7, 3 7)") ); std::unique_ptr azul( te::gm::WKTReader::read("LINESTRING (3 5, 1 7)") ); std::cout << "A linha Vermelha toca a Azul? " << std::boolalpha << vermelho->touches( azul.get() ) << std::endl; } { std::unique_ptr vermelho( te::gm::WKTReader::read("LINESTRING (4 5, 4 7, 6 7)") ); std::unique_ptr azul( te::gm::WKTReader::read("LINESTRING (5 5, 5 8)") ); std::cout << "A linha Vermelha toca a Azul? " << std::boolalpha << vermelho->touches( azul.get() ) << std::endl; } { std::unique_ptr vermelho( te::gm::WKTReader::read("LINESTRING (1 3, 3 4)") ); std::unique_ptr azul( te::gm::WKTReader::read("LINESTRING (3 4, 5 3)") ); std::cout << "A linha Vermelha toca a Azul? " << std::boolalpha << vermelho->touches( azul.get() ) << std::endl; } { std::unique_ptr vermelho( te::gm::WKTReader::read("POLYGON ( (1 0, 1 2, 4 2, 4 0, 1 0) )") ); std::unique_ptr azul( te::gm::WKTReader::read("POLYGON ( (4 0, 4 2, 7 2, 7 0, 4 0) )") ); std::cout << "O poligono Vermelho toca o Azul? " << std::boolalpha << vermelho->touches( azul.get() ) << std::endl; } { std::unique_ptr vermelho( te::gm::WKTReader::read("POLYGON ( (8 5, 8 7, 11 7, 11 5, 8 5) )") ); std::unique_ptr azul( te::gm::WKTReader::read("POLYGON ( (11 6, 13 8, 15 6, 13 4, 11 6) )") ); std::cout << "O poligono Vermelho toca o Azul? " << std::boolalpha << vermelho->touches( azul.get() ) << std::endl; } { std::unique_ptr vermelho( te::gm::WKTReader::read("POLYGON ( (9 1, 9 3, 12 3, 12 1, 9 1) )") ); std::unique_ptr azul( te::gm::WKTReader::read("POLYGON ( (11 2, 13 3, 15 2, 13 1, 11 2) )") ); std::cout << "O poligono Vermelho toca o Azul? " << std::boolalpha << vermelho->touches( azul.get() ) << std::endl; } } void op_intersection() { { std::unique_ptr vermelho( te::gm::WKTReader::read("POLYGON ( (2 2, 2 4, 5 4, 5 2, 2 2) )") ); std::unique_ptr azul( te::gm::WKTReader::read("POLYGON ( (4 1, 4 3, 7 3, 7 1, 4 1) )") ); std::unique_ptr resultado( vermelho->intersection( azul.get() ) ); std::cout << "Qual o resultado da intersecao entre os poligonos? " << std::boolalpha << resultado->toString() << std::endl; } { std::unique_ptr vermelho( te::gm::WKTReader::read("POLYGON ( (2 5, 2 7, 5 7, 5 5, 2 5) )") ); std::unique_ptr azul( te::gm::WKTReader::read("POLYGON ( (5 5, 5 7, 8 7, 8 5, 5 5) )") ); std::unique_ptr resultado( vermelho->intersection( azul.get() ) ); std::cout << "Qual o resultado da intersecao entre os poligonos? " << std::boolalpha << resultado->toString() << std::endl; } { std::unique_ptr vermelho( te::gm::WKTReader::read("POLYGON ( (9 2, 9 4, 11 4, 11 2, 9 2) )") ); std::unique_ptr azul( te::gm::WKTReader::read("POLYGON ( (12 1, 12 3, 15 3, 15 1, 12 1) )") ); std::unique_ptr resultado( vermelho->intersection( azul.get() ) ); std::cout << "Qual o resultado da intersecao entre os poligonos? " << std::boolalpha << resultado->toString() << std::endl; } } void op_union() { { std::unique_ptr vermelho( te::gm::WKTReader::read("POLYGON ( (2 2, 2 4, 5 4, 5 2, 2 2) )") ); std::unique_ptr azul( te::gm::WKTReader::read("POLYGON ( (4 1, 4 3, 7 3, 7 1, 4 1) )") ); std::unique_ptr resultado( vermelho->Union( azul.get() ) ); std::cout << "Qual o resultado da uniao dos poligonos? " << std::boolalpha << resultado->toString() << std::endl; } { std::unique_ptr vermelho( te::gm::WKTReader::read("POLYGON ( (2 5, 2 7, 5 7, 5 5, 2 5) )") ); std::unique_ptr azul( te::gm::WKTReader::read("POLYGON ( (5 5, 5 7, 8 7, 8 5, 5 5) )") ); std::unique_ptr resultado( vermelho->Union( azul.get() ) ); std::cout << "Qual o resultado da uniao dos poligonos? " << std::boolalpha << resultado->toString() << std::endl; } { std::unique_ptr vermelho( te::gm::WKTReader::read("POLYGON ( (9 2, 9 4, 11 4, 11 2, 9 2) )") ); std::unique_ptr azul( te::gm::WKTReader::read("POLYGON ( (12 1, 12 3, 15 3, 15 1, 12 1) )") ); std::unique_ptr resultado( vermelho->Union( azul.get() ) ); std::cout << "Qual o resultado da uniao dos poligonos? " << std::boolalpha << resultado->toString() << std::endl; } } void op_buffer() { { std::unique_ptr vermelho( te::gm::WKTReader::read("POLYGON ( (6 3, 6 5, 9 5, 9 3, 6 3) )") ); std::unique_ptr resultado( vermelho->buffer(2.0) ); std::cout << "Qual o resultado do buffer? " << std::boolalpha << resultado->toString() << std::endl; } } int main(int argc, char* argv[]) { TerraLib::getInstance().initialize(); op_contains(); op_within(); op_touches(); op_intersection(); op_union(); op_buffer(); TerraLib::getInstance().finalize(); return EXIT_SUCCESS; }