Skip to content

v0.2.47..v0.2.48 changeset CropCmd.cpp

Garret Voltz edited this page Sep 27, 2019 · 1 revision
diff --git a/hoot-core/src/main/cpp/hoot/core/cmd/CropCmd.cpp b/hoot-core/src/main/cpp/hoot/core/cmd/CropCmd.cpp
index 4a4493c..cca621a 100644
--- a/hoot-core/src/main/cpp/hoot/core/cmd/CropCmd.cpp
+++ b/hoot-core/src/main/cpp/hoot/core/cmd/CropCmd.cpp
@@ -27,12 +27,15 @@
 
 // Hoot
 #include <hoot/core/util/Factory.h>
-#include <hoot/core/cmd/BaseCommand.h>
+#include <hoot/core/cmd/BoundedCommand.h>
 #include <hoot/core/ops/SuperfluousWayRemover.h>
 #include <hoot/core/ops/MapCropper.h>
 #include <hoot/core/ops/SuperfluousNodeRemover.h>
 #include <hoot/core/elements/OsmMap.h>
 #include <hoot/core/util/IoUtils.h>
+#include <hoot/core/io/OsmMapWriterFactory.h>
+#include <hoot/core/util/GeometryUtils.h>
+#include <hoot/core/util/ConfigOptions.h>
 
 // Qt
 #include <QStringList>
@@ -43,7 +46,7 @@ using namespace std;
 namespace hoot
 {
 
-class CropCmd : public BaseCommand
+class CropCmd : public BoundedCommand
 {
 public:
 
@@ -51,45 +54,29 @@ public:
 
   CropCmd() {}
 
-  virtual QString getName() const { return "crop"; }
+  virtual QString getName() const override { return "crop"; }
 
-  virtual QString getDescription() const { return "Crops a map to a geospatial bounds"; }
+  virtual QString getDescription() const override { return "Crops a map to a geospatial bounds"; }
 
-  int runSimple(QStringList args)
+  virtual int runSimple(QStringList& args) override
   {
-    if (args.size() != 3)
+    if (args.size() < 3 || args.size() > 4)
     {
       cout << getHelp() << endl << endl;
-      throw HootException(QString("%1 takes three parameters.").arg(getName()));
+      throw HootException(QString("%1 takes three or four parameters.").arg(getName()));
     }
 
     QString in = args[0];
     QString out = args[1];
-    QString bounds = args[2];
-
-    bool allOk = true;
-    bool ok;
-    QStringList boundsArr = bounds.split(",");
-    double left = boundsArr[0].toDouble(&ok);
-    allOk &= ok;
-    double bottom = boundsArr[1].toDouble(&ok);
-    allOk &= ok;
-    double right = boundsArr[2].toDouble(&ok);
-    allOk &= ok;
-    double top = boundsArr[3].toDouble(&ok);
-    allOk &= ok;
-
-    if (allOk == false)
-    {
-      throw HootException("Invalid bounds format.");
-    }
+    _env.reset(new Envelope(GeometryUtils::envelopeFromConfigString(args[2])));
 
-    Envelope env(left, right, bottom, top);
+    BoundedCommand::runSimple(args);
 
     OsmMapPtr map(new OsmMap());
     IoUtils::loadMap(map, in, true);
 
-    MapCropper cropper(env);
+    MapCropper cropper(*_env);
+    cropper.setConfiguration(Settings::getInstance());
     cropper.apply(map);
     SuperfluousWayRemover::removeWays(map);
     SuperfluousNodeRemover().apply(map);
@@ -98,6 +85,16 @@ public:
 
     return 0;
   }
+
+protected:
+
+  std::shared_ptr<Envelope> _env;
+
+  virtual void _writeBoundsFile() override
+  {
+    OsmMapWriterFactory::write(
+      GeometryUtils::createMapFromBounds(*_env), ConfigOptions().getBoundsOutputFile());
+  }
 };
 
 HOOT_FACTORY_REGISTER(Command, CropCmd)
Clone this wiki locally