forked from GeoDaCenter/geoda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProject.h
296 lines (250 loc) · 10.3 KB
/
Project.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
/**
* GeoDa TM, Copyright (C) 2011-2015 by Luc Anselin - all rights reserved
*
* This file is part of GeoDa.
*
* GeoDa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GeoDa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GEODA_CENTER_PROJECT_H__
#define __GEODA_CENTER_PROJECT_H__
#undef check // macro undefine needed for Xcode compilation with Boost.Geometry
//#include <boost/geometry/geometry.hpp>
//#include <boost/geometry/geometries/point_xy.hpp>
#include <list>
#include <map>
#include <set>
#include <utility>
#include <vector>
#include <boost/multi_array.hpp>
#include <boost/property_tree/ptree_fwd.hpp>
#include <boost/shared_ptr.hpp>
#include <wx/filename.h>
#include "DataViewer/DataSource.h"
#include "DataViewer/PtreeInterface.h"
#include "DataViewer/VarOrderPtree.h"
#include "ShpFile.h"
#include "ShapeOperations/OGRLayerProxy.h"
#include "SpatialIndTypes.h"
#include "HighlightState.h"
#include "Explore/DistancesCalc.h"
#include "VarCalc/WeightsMetaInfo.h"
#include "ProjectConf.h"
typedef boost::multi_array<int, 2> i_array_type;
//using namespace boost::geometry;
class OGRTable;
class DbfTable;
class TableInterface;
class TableBase;
class CatClassifManager;
class FramesManager;
class TableState;
class TimeState;
class WeightsManager;
class WeightsManInterface;
class WeightsManState;
class SaveButtonManager;
class GalElement;
class TimeChooserDlg;
class GdaPoint;
class GdaPolygon;
class GdaShape;
class wxGrid;
class DataSource;
class CovSpHLStateProxy;
class Project {
public:
Project(const wxString& proj_fname);
Project(const wxString& project_title,
const wxString& layername,
IDataSource* p_datasource);
virtual ~Project();
bool IsValid() { return is_project_valid; }
wxString GetOpenErrorMessage() { return open_err_msg; }
IDataSource* GetDataSource() { return datasource; }
wxString GetProjectTitle(); /// assumed to be primary layer name
GdaConst::DataSourceType GetDatasourceType();
bool IsTableOnlyProject();
bool isTableOnly; // variable data only, no geometry layers
bool IsDataTypeChanged();
bool IsFileDataSource();
bool HasUnsavedChange();
/** Get the current project filename with absolute path. If project
file is not set, then empty string is returned. */
wxString GetProjectFullPath();
/** Indicate the location and name of the project file. The filename
must be an absolute path. The path will be decomposed into
a new Working Directory (SetWorkingDir is automatically called) and
a name part. */
void SetProjectFullPath(const wxString& proj_full_path);
/** To convert returned value to a wxString use, GetFullPath(). If
value is empty, then no directory has been set or no default could
be determined. When a project file exists, the Working Directory
is the location of the project file. */
wxFileName GetWorkingDir() { return working_dir; }
/** Set the current working directory. Directory must be an absolute
path. If path refers to a file, the filename will be dropped.
False is returned on failure. */
bool SetWorkingDir(const wxString& path);
void UpdateProjectConf(ProjectConfiguration* project_conf);
void SpecifyProjectConfFile(const wxString& proj_fname);
void SaveProjectConf();
void SaveDataSourceData();
/** SaveAs in-memory Table+Geometries to OGR DataSource */
void SaveDataSourceAs(const wxString& new_ds_name, bool is_update=false);
int GetNumRecords() { return num_records; }
HighlightState* GetHighlightState() { return highlight_state; }
HighlightState* GetConMapHlightState() { return con_map_hl_state; }
CovSpHLStateProxy* GetPairsHLState();
TableInterface* GetTableInt() { return table_int; }
CatClassifManager* GetCatClassifManager() { return cat_classif_manager; }
WeightsManInterface* GetWManInt() { return w_man_int; }
WeightsManState* GetWManState() { return w_man_state; }
SaveButtonManager* GetSaveButtonManager() { return save_manager; }
FramesManager* GetFramesManager() { return frames_manager; }
TableState* GetTableState() { return table_state; }
TimeState* GetTimeState() { return time_state; }
TimeChooserDlg* GetTimeChooser() { return time_chooser; }
TableBase* FindTableBase();
wxGrid* FindTableGrid();
ProjectConfiguration* GetProjectConf() { return project_conf; }
OGRSpatialReference* GetSpatialReference();
void AddNeighborsToSelection(boost::uuids::uuid weights_id);
void ExportVoronoi();
void ExportCenters(bool is_mean_centers);
void SaveVoronoiDupsToTable();
bool IsPointDuplicates();
void DisplayPointDupsWarning();
void GetVoronoiRookNeighborMap(std::vector<std::set<int> >& nbr_map);
void GetVoronoiQueenNeighborMap(std::vector<std::set<int> >& nbr_map);
GalElement* GetVoronoiRookNeighborGal();
void AddMeanCenters();
void AddCentroids();
void GetSelectedRows(vector<int>& rowids);
/// centroids by default
const std::vector<GdaPoint*>& GetMeanCenters();
void GetMeanCenters(std::vector<double>& x, std::vector<double>& y);
const std::vector<GdaPoint*>& GetCentroids();
void GetCentroids(std::vector<double>& x, std::vector<double>& y);
void GetCentroids(std::vector<wxRealPoint>& pts);
const std::vector<GdaShape*>& GetVoronoiPolygons();
double GetMin1nnDistEuc();
double GetMax1nnDistEuc();
double GetMaxDistEuc(); // diameter of convex hull
double GetMin1nnDistArc(); // returned as radians
double GetMax1nnDistArc(); // returned as radians
double GetMaxDistArc(); // returned as radians
rtree_pt_2d_t& GetEucPlaneRtree();
rtree_pt_3d_t& GetUnitSphereRtree();
// default variables
wxString GetDefaultVarName(int var);
void SetDefaultVarName(int var, const wxString& v_name);
int GetDefaultVarTime(int var);
void SetDefaultVarTime(int var, int time);
WeightsMetaInfo::DistanceMetricEnum GetDefaultDistMetric();
void SetDefaultDistMetric(WeightsMetaInfo::DistanceMetricEnum dm);
WeightsMetaInfo::DistanceUnitsEnum GetDefaultDistUnits();
void SetDefaultDistUnits(WeightsMetaInfo::DistanceUnitsEnum du);
// Fill Distances according to order specified in shared project
// pairs order mapping.
void FillDistances(std::vector<double>& D,
WeightsMetaInfo::DistanceMetricEnum dm,
WeightsMetaInfo::DistanceUnitsEnum du);
const pairs_bimap_type& GetSharedPairsBimap();
void CleanupPairsHLState();
i_array_type* GetSharedCategoryScratch(int num_cats, int num_obs);
/** NOTE: This function needs a better home. */
static bool CanModifyGrpAndShowMsgIfNot(TableState* table_state,
const wxString& grp_nm);
public:
/// main_data is the only public remaining attribute in Project
Shapefile::Main main_data;
OGRSpatialReference* sourceSR;
wxString project_unit;
// ".gda" project file data
wxString layer_title; // optional project::layers::layer::title field
wxString layername; // optional project::layers::layer::layername field
wxString project_title; // optional project::title field;
// active project filename if exists. Filename only, no directory
// or ".gda" extension. working_dir is the directory location of the
// project file.
wxString proj_file_no_ext;
wxFileName working_dir;
private:
bool CommonProjectInit();
int InitFromShapefileLayer();
bool InitFromOgrLayer();
int OpenShpFile(wxFileName shp_fname);
/** Save in-memory Table+Geometries to OGR DataSource */
void SaveOGRDataSource();
void UpdateProjectConf();
Shapefile::ShapeType GetGdaGeometries(vector<GdaShape*>& geometries);
void CalcEucPlaneRtreeStats();
void CalcUnitSphereRtreeStats();
// XXX for multi-layer support, ProjectConfiguration is a container for
// multi LayerConfiguration (layers), and each LayerConfiguration is defined
// by a IDataSource to specify which data it connects to.
// But, here we only support single layer, so we ignore LayerConfiguration
// and use IDataSource directly.
ProjectConfiguration *project_conf;
IDataSource *datasource;
std::vector<wxString> default_var_name;
std::vector<int> default_var_time;
OGRLayerProxy* layer_proxy;
bool is_project_valid; // true if project Shapefile created successfully
wxString open_err_msg; // error message for project open failure.
// without Shapefile.
int num_records;
TableInterface* table_int;
CatClassifManager* cat_classif_manager;
WeightsManInterface* w_man_int;
WeightsManState* w_man_state;
SaveButtonManager* save_manager;
FramesManager* frames_manager;
HighlightState* highlight_state;
HighlightState* con_map_hl_state;
CovSpHLStateProxy* pairs_hl_state;
TableState* table_state;
TimeState* time_state;
TimeChooserDlg* time_chooser;
// Voronoi Diagram related
std::vector<GdaPoint*> mean_centers;
std::vector<GdaPoint*> centroids;
std::vector<GdaShape*> voronoi_polygons;
bool point_duplicates_initialized;
bool point_dups_warn_prev_displayed;
std::list<std::list<int> > point_duplicates;
GalElement* voronoi_rook_nbr_gal;
double voronoi_bb_xmin;
double voronoi_bb_ymin;
double voronoi_bb_xmax;
double voronoi_bb_ymax;
// Rtree Related
double min_1nn_dist_euc;
double max_1nn_dist_euc;
double max_dist_euc;
double min_1nn_dist_arc; // radians
double max_1nn_dist_arc; // radians
double max_dist_arc; // radians
rtree_pt_2d_t rtree_2d; // 2d Cartesian points
rtree_pt_3d_t rtree_3d; // lon/lat points projected to unit sphere
/** The following array is not thread safe since it is shared by
every TemplateCanvas instance in a given project. */
static std::map<wxString, i_array_type*> shared_category_scratch;
WeightsMetaInfo::DistanceMetricEnum dist_metric;
WeightsMetaInfo::DistanceUnitsEnum dist_units;
pairs_bimap_type pairs_bimap;
dist_map_type cached_eucl_dist;
dist_map_type cached_arc_dist;
};
#endif