DISPLACE  1.0
A spatial model of fisheries to help sustainable fishing and maritime spatial planning
graphbuilder_shp.h
Go to the documentation of this file.
1 #ifndef GRAPHBUILDER_SHP_H
2 #define GRAPHBUILDER_SHP_H
3 
4 #include <ogrsf_frmts.h>
5 #include <QPoint>
6 #include <QList>
7 #include <QString>
8 
9 #include <chrono>
10 
11 #if defined (__GNUC__)
12 #pragma GCC diagnostic push
13 #pragma GCC diagnostic ignored "-Wpragmas"
14 #pragma GCC diagnostic ignored "-Wshift-negative-value"
15 #pragma GCC diagnostic ignored "-Wunused-parameter"
16 #endif
17 
18 #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
19 #include <CGAL/Triangulation_vertex_base_with_info_2.h>
20 #include <CGAL/Delaunay_triangulation_2.h>
21 #include <CGAL/Constrained_Delaunay_triangulation_2.h>
22 
23 #if defined (__GNUC__)
24 #pragma GCC diagnostic pop
25 #endif
26 
27 namespace displace {
28 namespace graphbuilders {
29 class GeographicGridBuilder;
30 }
31 }
32 
34 {
35 public:
36  class Feedback {
37  public:
38  virtual void setMax(int m) = 0;
39  virtual void setStep(int step) = 0;
40  virtual void setMainMessage (QString) = 0;
41  virtual void setPartMessage (QString) = 0;
42  };
43 
45 
46  class Node {
47  public:
48  QPointF point;
49  int harbour = 0;
50  QList<int> adiacencies;
51  QList<double> weight;
52  bool good = false;
53 
54  Node()
55  : point(), harbour(0), adiacencies(), weight(), good(false) {
56  }
57  };
58 
59  GraphBuilder();
60 
61  void actionCreate();
62  void actionLoad(QString path);
63 
64  void setType (Type type) {
65  mType = type;
66  }
67 
68  void setDefaultDistance (double distance) {
69  mStep = distance;
70  }
71 
72  void setDistance1 (double distance) {
73  mStep1 = distance;
74  }
75 
76  void setDistance2 (double distance) {
77  mStep2 = distance;
78  }
79 
80  void setFeedback (Feedback *feedback) {
81  mFeedback = feedback;
82  }
83 
84  void setLimits (double lonMin, double lonMax, double latMin, double latMax) ;
85  void setIncludingShapefile1 (std::shared_ptr<GDALDataset> src);
86  void setIncludingShapefile2 (std::shared_ptr<GDALDataset> src);
87  void setExcludingShapefile (std::shared_ptr<GDALDataset> src);
89  mRemoveEdgesInExcludeZone = en;
90  }
91  void setMaxLinks(int num = -1) {
92  mMaxLinks = num;
93  }
94  void setMinLinks(int num = -1) {
95  mMinLinks = num;
96  }
97 
98  QList<Node> buildGraph();
99 
100  static const double earthRadius;
101 
102  bool outsideEnabled() const;
104  void setLinkLimits(double limit_km);
105 
106 private:
107  bool mCreateMode = false;
108  QString mLoadPath;
109  std::shared_ptr<displace::graphbuilders::GeographicGridBuilder> createBuilder (Type type, double step);
110 
111 
112  void createMainGrid(GDALDriver *memdriver, GDALDataset *outdataset, OGRLayer *&resultLayer);
113  void loadMainGrid(GDALDriver *memdriver, GDALDataset *memdataset, OGRLayer *&resultLayer);
114 
115  void createGrid(GDALDataset *tempDatasource,
116  std::shared_ptr<displace::graphbuilders::GeographicGridBuilder> builder,
117  OGRLayer *lyOut,
118  OGRLayer *lyGrid,
119  OGRLayer *lyIncluded, OGRLayer *lyExclusion1, OGRLayer *lyExclusion2);
120 
121  void clip(OGRLayer *in, OGRLayer *feature, OGRLayer *out, GDALDataset *tempds);
122  void diff(OGRLayer *in1, OGRLayer *in2, OGRLayer *out, GDALDataset *tempds);
123  void diffEdges(OGRLayer *in1, OGRLayer *in2, OGRLayer *out, GDALDataset *tempds);
124  void copyLayerContent(OGRLayer *src, OGRLayer *dst);
125  void makePartProgress(double x);
126  void startNewPartProgress(QString msg);
127  OGRLayer *createGridLayer(GDALDataset *datasource, const char *const name);
128  OGRLayer *createEdgesLayer(GDALDataset *datasource, const char *const name);
129  void deleteLayer(GDALDataset *src, OGRLayer *layer);
130 
131  int getFromFieldIndex (OGRLayer *layer);
132  int getToFieldIndex (OGRLayer *layer);
133  int getWeightFieldIndex (OGRLayer *layer);
134  int getPointFieldIndex (OGRLayer *layer);
135 
136 // void fillWithNodes(displace::graphbuilders::GeographicGridBuilder *builder, QList<Node> &res, CDT &tri, std::vector<std::shared_ptr<OGRDataSource> > including, std::vector<std::shared_ptr<OGRDataSource> > excluding, bool outside, int &progress);
137 // void pushAd(QList<Node> &node, int source, int target);
138 
139  Type mType;
140  bool mOutsideEnabled, mRemoveEdgesInExcludeZone;
141  double mStep, mStep1, mStep2;
142  double mLatMin, mLatMax, mLonMin, mLonMax;
143  double mLinkLimits;
144  int mMaxLinks, mMinLinks;
145  int progress = 0;
146  int mId = 0;
147  OGRSpatialReference mSpatialReference;
148 
149  std::shared_ptr<GDALDataset> mShapefileInc1;
150  std::shared_ptr<GDALDataset> mShapefileInc2;
151  std::shared_ptr<GDALDataset> mShapefileExc;
152 
153  Feedback *mFeedback = 0;
154 
155  using Timer = std::chrono::system_clock;
156  std::chrono::time_point<Timer> mFeedbackStartTime;
157  QString mFeedbackProgressMsg;
158  long mFeedbackPreviousETC;
159 
160  static int waitfunc(double progress, const char *msg, void *thiz);
161 };
162 
163 #endif // GRAPHBUILDER_SHP_H
void setOutsideEnabled(bool outsideEnabled)
Definition: graphbuilder_shp.cpp:700
GraphBuilder()
Definition: graphbuilder_shp.cpp:53
Definition: decisiontreemanager.h:13
virtual void setMainMessage(QString)=0
Definition: graphbuilder_shp.h:33
QList< Node > buildGraph()
Definition: graphbuilder_shp.cpp:199
static const double earthRadius
Definition: graphbuilder_shp.h:100
void setDistance2(double distance)
Definition: graphbuilder_shp.h:76
virtual void setStep(int step)=0
Node()
Definition: graphbuilder_shp.h:54
Definition: graphbuilder_shp.h:46
void setLimits(double lonMin, double lonMax, double latMin, double latMax)
Definition: graphbuilder_shp.cpp:64
void setFeedback(Feedback *feedback)
Definition: graphbuilder_shp.h:80
void setDistance1(double distance)
Definition: graphbuilder_shp.h:72
void actionLoad(QString path)
Definition: graphbuilder_shp.cpp:736
void setIncludingShapefile2(std::shared_ptr< GDALDataset > src)
Definition: graphbuilder_shp.cpp:77
Definition: graphbuilder_shp.h:36
void setLinkLimits(double limit_km)
Definition: graphbuilder_shp.cpp:705
QList< int > adiacencies
Definition: graphbuilder_shp.h:50
int harbour
Definition: graphbuilder_shp.h:49
Definition: graphbuilder_shp.h:44
void setDefaultDistance(double distance)
Definition: graphbuilder_shp.h:68
virtual void setMax(int m)=0
void setMinLinks(int num=-1)
Definition: graphbuilder_shp.h:94
void setType(Type type)
Definition: graphbuilder_shp.h:64
bg::model::point< double, 2, bg::cs::cartesian > point
Definition: diffusion.cpp:28
void setExcludeZoneEdgeRemovalEnabled(bool en)
Definition: graphbuilder_shp.h:88
QPointF point
Definition: graphbuilder_shp.h:48
void setExcludingShapefile(std::shared_ptr< GDALDataset > src)
Definition: graphbuilder_shp.cpp:82
bool outsideEnabled() const
Definition: graphbuilder_shp.cpp:695
Definition: graphbuilder_shp.h:44
Definition: graphbuilder_shp.h:44
void actionCreate()
Definition: graphbuilder_shp.cpp:731
void setMaxLinks(int num=-1)
Definition: graphbuilder_shp.h:91
void setIncludingShapefile1(std::shared_ptr< GDALDataset > src)
Definition: graphbuilder_shp.cpp:72
Type
Definition: graphbuilder_shp.h:44
Definition: graphbuilder_shp.h:44
QList< double > weight
Definition: graphbuilder_shp.h:51
bool good
Definition: graphbuilder_shp.h:52
virtual void setPartMessage(QString)=0