Skip to content

Commit

Permalink
Add GeosOp options --select and --selectNot (#1100)
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-jts authored May 23, 2024
1 parent 1476165 commit 152e6f7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
12 changes: 12 additions & 0 deletions util/geosop/GeometryOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,18 @@ Result::isGeometry() {
return typeCode == typeGeometry;
}

bool
Result::isBool() {
return typeCode == typeBool;
}

bool
Result::toBool() {
if (typeCode == typeBool)
return valBool;
return false;
}

bool
Result::isGeometryList() {
return typeCode == typeGeomList;
Expand Down
3 changes: 3 additions & 0 deletions util/geosop/GeometryOp.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class Result {

static std::string code(int typeCode);

bool isBool();
bool toBool();

bool isGeometry();
bool isGeometryList();
std::string metadata();
Expand Down
21 changes: 17 additions & 4 deletions util/geosop/GeosOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ int main(int argc, char** argv) {
("p,precision", "Set number of decimal places in output coordinates", cxxopts::value<int>( cmdArgs.precision ) )
("q,quiet", "Disable result output", cxxopts::value<bool>( cmdArgs.isQuiet ) )
("r,repeat", "Repeat operation N times", cxxopts::value<int>( cmdArgs.repeatNum ) )
("select", "Select geometries where op result is true", cxxopts::value<bool>( cmdArgs.isSelect ) )
("selectNot", "Select geometries where op result is false", cxxopts::value<bool>( cmdArgs.isSelectNot ) )
("t,time", "Print execution time", cxxopts::value<bool>( cmdArgs.isShowTime ) )
("v,verbose", "Verbose output", cxxopts::value<bool>( cmdArgs.isVerbose )->default_value("false"))
("h,help", "Print help")
Expand Down Expand Up @@ -439,8 +441,7 @@ void GeosOp::executeUnary(GeometryOp * op, OpArguments& opArgs) {
for (unsigned i = 0; i < geomA.size(); i++) {
vertexCount += geomA[i]->getNumPoints();
Result* result = executeOpRepeat(op, i, geomA[i], 0, nullptr, opArgs);

output(result);
output(result, geomA[i].get());
delete result;
}
}
Expand All @@ -452,7 +453,7 @@ void GeosOp::executeBinary(GeometryOp * op, OpArguments& opArgs) {
vertexCount += geomB[ib]->getNumPoints();
Result* result = executeOpRepeat(op, ia, geomA[ia], ib, geomB[ib], opArgs);

output(result);
output(result, geomA[ia].get());
delete result;
}
}
Expand Down Expand Up @@ -512,7 +513,7 @@ Result* GeosOp::executeOp(GeometryOp * op,
return result;
}

void GeosOp::output(Result* result) {
void GeosOp::output(Result* result, Geometry* geom) {
//---- print result if format specified
if (args.isQuiet)
return;
Expand All @@ -528,6 +529,18 @@ void GeosOp::output(Result* result) {
else if (result->isGeometryList() ) {
outputGeometryList( result->valGeomList );
}
else if (result->isBool() ) {
if (args.isSelect || args.isSelectNot) {
bool isSelected = (args.isSelect && result->toBool())
|| (args.isSelectNot && ! result->toBool());
if (isSelected) {
outputGeometry( geom );
}
}
else {
std::cout << result->toString() << std::endl;
}
}
else {
// output as text/WKT
std::cout << result->toString() << std::endl;
Expand Down
4 changes: 3 additions & 1 deletion util/geosop/GeosOp.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class GeosOpArgs {
int offsetA = -1;
bool isCollect = true;
bool isExplode = false;
bool isSelect = false;
bool isSelectNot = false;

std::string srcB;

Expand Down Expand Up @@ -91,7 +93,7 @@ class GeosOp {
unsigned int indexA, const std::unique_ptr<Geometry>& geomA,
unsigned int indexB, const std::unique_ptr<Geometry>& geomB,
OpArguments& opArgs);
void output(Result* result);
void output(Result* result, Geometry* geom);
void outputExplode(std::unique_ptr<Geometry>& geom);
void outputGeometry( const Geometry* geom);
void outputGeometryList(std::vector<std::unique_ptr<const Geometry>> & val);
Expand Down

0 comments on commit 152e6f7

Please sign in to comment.