-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdggridpy.cpp
686 lines (610 loc) · 24.8 KB
/
dggridpy.cpp
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
/////////////////////////////////////////////////////////////////////////
//
// (c) Copyright University of Southampton IT Innovation, 2019
//
// Copyright in this software belongs to IT Innovation Centre of
// Gamma House, Enterprise Road, Southampton SO16 7NS, UK.
//
// This software may not be used, sold, licensed, transferred, copied
// or reproduced in whole or in part in any manner or form or in or
// on any media by any person other than in accordance with the terms
// of the Licence Agreement supplied with the software, or otherwise
// without the prior written consent of the copyright owners.
//
// This software is distributed WITHOUT ANY WARRANTY, without even the
// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE, except where stated in the Licence Agreement supplied with
// the software.
//
// Created By : Gianluca Correndo
// Created Date : 2019/03/01
// Created for Project: SEDNA
//
/////////////////////////////////////////////////////////////////////////
//
// Dependancies: DGGRID
//
////////////////////////////////////////////////////////////////////////
#include <pybind11/pybind11.h>
#include <pybind11/stl_bind.h>
#include <pybind11/stl.h>
#include <pybind11/numpy.h>
#include <signal.h>
#include <stdio.h>
//#include <unistd.h>
#include <iostream>
using namespace std;
#include "DgParamList.h"
#include "DgGeoSphRF.h"
#include "DgConstants.h"
#include "DgDiscRFS.h"
#include "DgRFBase.h"
#include "DgGeoSphRF.h"
#include "DgEllipsoidRF.h"
//#include "DgIDGG.cpp"
#include "DgLocation.h"
#include "DgIDGG.h"
#include "DgIDGGS.h"
//DGGS integrated
#include "DgIDGGS4H.h"
#include "DgIDGGS4D.h"
#include "DgIDGGS4T.h"
#include "DgIDGGS43H.h"
//wrapper methods
#include "dglib.h"
namespace py = pybind11;
enum TopologyType
{
HEXAGON = 0,
DIAMOND = 1,
TRIANGLE = 2
};
std::string TopologyType_str[] = {
"HEXAGON",
"DIAMOND",
"TRIANGLE"
};
enum ProjectionType
{
ISEA = 0,
FULLER = 1
};
std::string ProjectionType_str[] = {
"ISEA",
"FULLER"
};
struct DGGSParam {
public:
long double pole_lon_deg;
long double pole_lat_deg;
long double azimuth_deg;
unsigned int aperture;
int res;
TopologyType topology;
ProjectionType projection;
DGGSParam(
const long double pole_lon_deg,
const long double pole_lat_deg,
const long double azimuth_deg,
const unsigned int aperture,
const int res,
const TopologyType topology,
const ProjectionType projection)
: pole_lon_deg(pole_lon_deg),
pole_lat_deg(pole_lat_deg),
azimuth_deg(azimuth_deg),
aperture(aperture),
res(res),
topology(topology),
projection(projection) {}
//GETTER and SETTERS
void setPoleLonDeg(const long double d ) { pole_lon_deg = d;}
long double getPoleLonDeg(){ return pole_lon_deg;}
void setPoleLatDeg(const long double d ) { pole_lat_deg = d;}
long double getPoleLatDeg(){ return pole_lat_deg;}
void setAzimuthDeg(const long double d ) { azimuth_deg = d;}
long double getAzimuthDeg(){ return azimuth_deg;}
void setAperture(const unsigned int d ) { aperture = d;}
unsigned int getAperture(){ return aperture;}
void setRes(const int d ) { res = d;}
int getRes(){ return res;}
void setTopology(const TopologyType t ) { topology = t;}
TopologyType getTopology(){ return topology;}
void setProjection(const ProjectionType p ) { projection = p;}
ProjectionType getProjection(){ return projection;}
static DGGSParam ISEA3H(){
return DGGSParam(0.0,0.0,0.0,3,0,HEXAGON,ISEA);
}
static DGGSParam ISEA4H(){
return DGGSParam(0.0,0.0,0.0,4,0,HEXAGON,ISEA);
}
static DGGSParam ISEA4T(){
return DGGSParam(0.0,0.0,0.0,3,0,TRIANGLE,ISEA);
}
};
long double M_TO_KM = 1.60934;
/**
* dgetres_res
* Returns the information for a DGGS of given topology, projection, topology, and resolution.
*
*/
std::map<std::string,double> dgetres_res (
const unsigned int aperture,
const std::string topology,
const std::string projection,
const unsigned int res
){
dglib::GridThing gt(0,0,0,aperture,res,topology,projection);
std::map<std::string,double> result;
result.insert(std::pair<std::string,double>("res" , res));
result.insert(std::pair<std::string,double>("cells" , gt.nCells(res)));
result.insert(std::pair<std::string,double>("area_km" , gt.cellAreaKM(res)));
result.insert(std::pair<std::string,double>("spacing_km" , gt.cellDistKM(res)));
result.insert(std::pair<std::string,double>("cls_km" , gt.cls(res)));
return result;
};
std::map<uint64_t, py::array_t<double>> SeqNumGrid (
const long double pole_lon_deg,
const long double pole_lat_deg,
const long double azimuth_deg,
const unsigned int aperture,
const int res,
const std::string topology,
const std::string projection,
std::vector<uint64_t> cnum
){
dglib::SeqNumGridGenerator sngg(pole_lon_deg, pole_lat_deg, azimuth_deg, aperture, res, topology, projection, cnum);
std::map<uint64_t, py::array_t<double>> result;
std::vector<long double> x;
std::vector<long double> y;
while(sngg.good()){
const auto sn = sngg(x,y);
double* aresult = new double [x.size() * 2];
for(int i=0; i<x.size() ; i++){
aresult[i*2] = x[i];
aresult[i*2+1] = y[i];
}
result[sn] = py::array_t<double>(std::vector<ptrdiff_t>{ static_cast<pybind11::ssize_t>(x.size()) , 2}, &aresult[0]);
}
return result;
};
PYBIND11_MODULE(dggridpy, m) {
m.doc() = "Python wrapping of the DGGRID API for creating and manipulating Discrete Global Grids (http://www.discreteglobalgrids.org/software/). Code modified to be wrapped in R. ";
py::class_<DGGSParam>(m, "DGGSParam")
.def(py::init<
long double ,
long double ,
long double ,
unsigned int ,
int ,
TopologyType ,
ProjectionType
>(), "Constructor for DGGSParam class")
.def("setPoleLonDeg" , &DGGSParam::setPoleLonDeg)
.def("getPoleLonDeg" , &DGGSParam::getPoleLonDeg)
.def("setPoleLatDeg" , &DGGSParam::setPoleLatDeg)
.def("getPoleLatDeg" , &DGGSParam::getPoleLatDeg)
.def("setAzimuthDeg" , &DGGSParam::setAzimuthDeg)
.def("getAzimuthDeg" , &DGGSParam::getAzimuthDeg)
.def("setAperture" , &DGGSParam::setAperture)
.def("getAperture" , &DGGSParam::getAperture)
.def("setResolution" , &DGGSParam::setRes)
.def("getResolution" , &DGGSParam::getRes)
.def("setTopology" , &DGGSParam::setTopology)
.def("getTopology" , &DGGSParam::getTopology)
.def("setProjection" , &DGGSParam::setProjection)
.def("getProjection" , &DGGSParam::getProjection)
.def("ISEA3H" , &DGGSParam::ISEA3H)
.def("ISEA4H" , &DGGSParam::ISEA4H)
.def("ISEA4T" , &DGGSParam::ISEA4T)
.def("__repr__", [](const DGGSParam &dggs){
std::ostringstream sink;
sink << "DGGS:\n\tpole longitude: " << dggs.pole_lon_deg << endl
<< "\tpole latitude: " << dggs.pole_lat_deg << endl
<< "\tazimuth: " << dggs.azimuth_deg << endl
<< "\taperture: " << dggs.aperture << endl
<< "\tresolution: " << dggs.res << endl
<< "\ttopology: " << TopologyType_str[dggs.topology] << endl
<< "\tprojection: " << ProjectionType_str[dggs.projection] << endl;
return sink.str();
});
py::enum_<TopologyType>(m, "TopologyType", py::arithmetic(), "Enumeration of topology types")
.value("HEXAGON", HEXAGON, "HEXAGON topology")
.value("TRIANGLE", TRIANGLE, "TRIANGLE topology")
.value("DIAMOND", DIAMOND, "DIAMOND topology")
.export_values();
py::enum_<ProjectionType>(m, "ProjectionType", py::arithmetic(), "Enumeration of projection types")
.value("ISEA", ISEA, "ISEA projection")
.value("FULLER", FULLER, "FULLER projection")
.export_values();
m.def("dggetres" , [](
const unsigned int aperture,
const TopologyType topology,
const ProjectionType projection,
const int target_res = 30
){
std::map<int,std::map<std::string,double>> result;
for (int res =0 ; res<target_res ; res++){
result.insert(std::pair<int,std::map<std::string,double>>(
res,
dgetres_res(aperture,TopologyType_str[topology],ProjectionType_str[projection],res))
);
}
return result;
} , "Returns a dictionary with the properties of the input DGGS for the first 'target_res' resolution levels organised by resolution level. \nThe information returned are:\n\t'ncells' number of cells;\n\t'area_km' area of each cell in this resolution expressed in squared kilometers;\n\t'spacing_km' the spacing between the center of adjacent cells expressed in kilometers;\n\t'cls' the diameter of a spherical cap of the same area as a cell of the specified resolution in the input dggs.",
py::arg("aperture"),
py::arg("topology"),
py::arg("projection"),
py::arg("target_res"));
m.def("dgconstruct" , [](
const unsigned int aperture,
const TopologyType topology,
const ProjectionType projection,
const long double pole_lon_deg,
const long double pole_lat_deg,
const long double azimuth_deg,
const long double area ,
const long double spacing ,
const long double cls ,
const std::string resround ,
const bool metric
){
if ((area + spacing + cls) == 0 ||
(area*spacing != 0) ||
(spacing*cls != 0) ||
(cls*area != 0)){
throw std::invalid_argument("No criteria (or multiple criteria) specified to construct dggs");
} else if (resround != "nearest" && resround != "down"&& resround != "up") {
throw std::invalid_argument("Invalid resolution criteria used");
}
else {
std::string key = area >0 ? "area_km" : (spacing > 0 ? "spacing_km" : "cls_km");
long double value;
if (key == "area_km"){
value = metric ? area : area*M_TO_KM*M_TO_KM;
} else if (key == "spacing_km"){
value = metric ? spacing : spacing*M_TO_KM;
} else if (key == "cls_km"){
value = metric ? cls : cls*M_TO_KM;
}
//look for the wanted DGGS
std::map<int,double> indexes;
for (int res =0 ; res<30 ; res++){
auto cvalue = dgetres_res(aperture,TopologyType_str[topology],ProjectionType_str[projection],res)[key];
indexes.insert(std::pair<int,double>( res , cvalue));
}
int down_index , up_index , index;
long double down_diff , up_diff;
for(auto element : indexes){
up_index = element.first;
if (element.second <= value){
if (element.second == value){
up_index = element.first;
down_index = element.first;
} else {
up_index = element.first-1;
down_index = element.first;
}
up_diff = indexes[up_index]-value;
down_diff = value - indexes[down_index];
break;
}
}
if (resround == "down"){
index = down_index;
} else if (resround == "up"){
index = up_index;
} else {
index = up_diff<down_diff ? up_index : down_index;
}
return DGGSParam(pole_lon_deg,
pole_lat_deg,
azimuth_deg,
aperture,
index,
topology,
projection);
}
} , "Construct a discrete global grid system (dggs) using the input parameters as constraints.",
py::arg("aperture") = 3,
py::arg("topology") = HEXAGON ,
py::arg("projection") = ISEA,
py::arg("pole_lon_deg") = 0.0,
py::arg("pole_lat_deg") = 0.0,
py::arg("azimuth_deg") = 0.0,
py::arg("area") = 0.0,
py::arg("spacing") = 0.0,
py::arg("cls") = 0.0,
py::arg("resround") = "nearest",
py::arg("metric") = true );
m.def("GEO_to_Q2DI" , [](
DGGSParam dggs,
std::vector<long double> in_lon_deg,
std::vector<long double> in_lat_deg
){
if (in_lon_deg.size() != in_lat_deg.size())
throw std::runtime_error("Input coordinates collections' size must match");
dglib::Transformer dgt(
dggs.pole_lon_deg,
dggs.pole_lat_deg,
dggs.azimuth_deg,
dggs.aperture,
dggs.res,
TopologyType_str[dggs.topology],
ProjectionType_str[dggs.projection]);
std::vector< std::vector< long int > > result (in_lon_deg.size(), std::vector< long int >(3));
for(unsigned int i=0 ; i< in_lon_deg.size() ; i++){
const long double tin_lon_deg = in_lon_deg[i];
const long double tin_lat_deg = in_lat_deg[i];
long double tout_i = result[0][i];
long double tout_j = result[1][i];
uint64_t tout_quad = result[2][i];
auto in = dgt.inGEO(tin_lon_deg, tin_lat_deg);
dgt.outQ2DI(in, tout_quad, tout_i, tout_j);
result[i][0] = tout_i;
result[i][1] = tout_j;
result[i][2] = tout_quad;
}
return result;
} , "Uses a discrete global grid system to convert between GEO and Q2DI",
py::arg("dggs"),
py::arg("in_lon_deg"),
py::arg("in_lat_deg"));
m.def("GEO_to_SEQNUM" , [](
DGGSParam dggs,
std::vector<long double> in_lon_deg,
std::vector<long double> in_lat_deg
){
dglib::Transformer dgt(
dggs.pole_lon_deg,
dggs.pole_lat_deg,
dggs.azimuth_deg,
dggs.aperture,
dggs.res,
TopologyType_str[dggs.topology],
ProjectionType_str[dggs.projection]);
std::vector<long double> out_seqnum (in_lon_deg.size());
for(unsigned int i=0 ; i< in_lon_deg.size() ; i++){
const long double tin_lon_deg = in_lon_deg[i];
const long double tin_lat_deg = in_lat_deg[i];
uint64_t tout_seqnum = out_seqnum[i];
auto in = dgt.inGEO(tin_lon_deg, tin_lat_deg);
dgt.outSEQNUM(in, tout_seqnum);
out_seqnum[i] = tout_seqnum;
}
return out_seqnum;
} , "This function uses a discrete global grid system to convert between (longitude,latitude) to sequence numbers.",
py::arg("dggs"),
py::arg("in_lon_deg"),
py::arg("in_lat_deg"));
m.def("SEQNUM_to_GEO" , [](
DGGSParam dggs,
std::vector<long double> in_seqnum
){
dglib::Transformer dgt(dggs.pole_lon_deg,
dggs.pole_lat_deg,
dggs.azimuth_deg,
dggs.aperture,
dggs.res,
TopologyType_str[dggs.topology],
ProjectionType_str[dggs.projection]);
long double* out_deg = new long double[in_seqnum.size()*2];
long double* out_lon_deg = new long double[in_seqnum.size()];
long double* out_lat_deg = new long double[in_seqnum.size()];
for(unsigned int i=0;i<in_seqnum.size();i++){
const uint64_t tin_seqnum = in_seqnum[i];
long double tout_lon_deg = out_lon_deg[i];
long double tout_lat_deg = out_lat_deg[i];
auto in = dgt.inSEQNUM(tin_seqnum);
dgt.outGEO(in, tout_lon_deg, tout_lat_deg);
out_deg[i*2] = tout_lon_deg;
out_deg[i*2 + 1] = tout_lat_deg;
}
return py::array_t<long double>(std::vector<ptrdiff_t>{ static_cast<pybind11::ssize_t>(in_seqnum.size()) , 2}, out_deg);
} , "This function uses a discrete global grid system to convert between a list of sequence numbers to (longitude,latitude).\nThe returned object is an array of shape len(in_seqnum)X2.",
py::arg("dggs"),
py::arg("in_seqnum"));
m.def("SeqNumGrid" , [](
DGGSParam dggs,
uint64_t cnum
){
std::vector<uint64_t> cseqnums = { cnum };
return SeqNumGrid( dggs.pole_lon_deg,
dggs.pole_lat_deg,
dggs.azimuth_deg,
dggs.aperture,
dggs.res,
TopologyType_str[dggs.topology],
ProjectionType_str[dggs.projection],
cseqnums);
} , "This function returns a dictionary where for each sequence number in input (key) an array of coordinates is associated (value)",
py::arg("dggs"),
py::arg("cnum"));
m.def("SeqNumGrid" , [](
DGGSParam dggs,
std::vector<uint64_t> cseqnums
){
return SeqNumGrid( dggs.pole_lon_deg,
dggs.pole_lat_deg,
dggs.azimuth_deg,
dggs.aperture,
dggs.res,
TopologyType_str[dggs.topology],
ProjectionType_str[dggs.projection],
cseqnums);
}, "This function returns a dictionary where for each sequence number in input (key) an array of coordinates is associated (value)",
py::arg("dggs"),
py::arg("cseqnums"));
//Low level API
py::bind_vector<std::vector<DgAddressBase*>>(m, "VectorDgAddressBase");
py::class_<DgIDGG>(m, "DgIDGG")
.def("convert",
[](DgIDGG &idgg, DgLocation *location) {
return idgg.convert(location);
}
, "Converts a location within the current dggs.",
py::arg("location")
).def("getVertices",
[](DgIDGG &idgg, const DgLocation& loc, int densify) {
DgPolygon vertices;
idgg.setVertices(loc, vertices, densify);
auto geoRF = idgg.geoRF();
auto addresses = vertices.addressVec();
double* aresult = new double [vertices.size() * 2];
int index = 0;
for (std::vector<DgAddressBase*>::iterator it = addresses.begin() ; it != addresses.end(); ++it){
auto va = geoRF.getVecAddress(**it);
aresult[index++] = va.x();
aresult[index++] = va.y();
}
return py::array_t<double>(std::vector<ptrdiff_t>{ vertices.size() , 2}, &aresult[0]);
}
).def("getVertices",
[](DgIDGG &idgg, const uint64_t sn, int densify) {
DgLocation *loc = idgg.bndRF().locFromSeqNum(sn);
DgPolygon vertices;
idgg.setVertices(*loc, vertices, densify);
auto geoRF = idgg.geoRF();
auto addresses = vertices.addressVec();
double* aresult = new double [vertices.size() * 2];
int index = 0;
for (std::vector<DgAddressBase*>::iterator it = addresses.begin() ; it != addresses.end(); ++it){
auto va = geoRF.getVecAddress(**it);
aresult[index++] = va.x();
aresult[index++] = va.y();
}
return py::array_t<double>(std::vector<ptrdiff_t>{ vertices.size() , 2}, &aresult[0]);
}
);
py::class_<DgIDGGS4H> iddgs4h(m, "DgIDGGS4H");
iddgs4h.def(py::init<
DgRFNetwork & ,
const DgGeoSphRF & ,
const DgGeoCoord & ,
double ,
int ,
const std::string &,
const std::string &
>() , "Constructor for the ISEA4H DGGS" ,
py::arg("networkIn"),
py::arg("backFrameIn"),
py::arg("vert0"),
py::arg("azDegs"),
py::arg("nResIn") = 1,
py::arg("nameIn") = "ISEA4H",
py::arg("projType") = "ISEA" );
iddgs4h.def("frequency" , &DgIDGGS4H::frequency);
iddgs4h.def("idgg" , &DgIDGGS4H::idgg);
py::class_<DgIDGGS4D> iddgs4d(m, "DgIDGGS4D");
iddgs4d.def(py::init<
DgRFNetwork & ,
const DgGeoSphRF & ,
const DgGeoCoord & ,
double ,
int ,
const std::string &,
const std::string &
>() , "Constructor for the DgIDGGS4D DGGS" ,
py::arg("networkIn"),
py::arg("backFrameIn"),
py::arg("vert0"),
py::arg("azDegs"),
py::arg("nResIn") = 1,
py::arg("nameIn") = "ISEA4D",
py::arg("projType") = "ISEA" );
iddgs4d.def("idgg" , &DgIDGGS4D::idgg);
py::class_<DgIDGGS4T> iddgs4t(m, "DgIDGGS4T");
iddgs4t.def(py::init<
DgRFNetwork & ,
const DgGeoSphRF & ,
const DgGeoCoord & ,
double ,
int ,
const std::string &,
const std::string &
>() , "Constructor for the DgIDGGS4T DGGS" ,
py::arg("networkIn"),
py::arg("backFrameIn"),
py::arg("vert0"),
py::arg("azDegs"),
py::arg("nResIn") = 1,
py::arg("nameIn") = "ISEA4T",
py::arg("projType") = "ISEA" );
iddgs4t.def("idgg" , &DgIDGGS4T::idgg);
py::class_<DgIDGGS43H> iddgs43h(m, "DgIDGGS43H");
iddgs43h.def(py::init<
DgRFNetwork & ,
const DgGeoSphRF & ,
const DgGeoCoord & ,
double ,
int ,
const std::string &,
const std::string &
>() , "Constructor for the DgIDGGS43H DGGS" ,
py::arg("networkIn"),
py::arg("backFrameIn"),
py::arg("vert0"),
py::arg("azDegs"),
py::arg("nResIn") = 1,
py::arg("nameIn") = "ISEA43H",
py::arg("projType") = "ISEA" );
iddgs43h.def("idgg" , &DgIDGGS43H::idgg);
py::class_<DgGeoSphRF>(m, "DgGeoSphRF")
.def(py::init<DgRFNetwork & , const std::string & , double>() , "Constructor for the DgGeoSphRF class (network, name, radius)",
py::arg("networkIn"),
py::arg("nameIn")="GeodeticSph" ,
py::arg("earthRadiusKMin")=DEFAULT_RADIUS_KM)
.def("makeLocation", &DgGeoSphRF::makeLocation)
.def("getAddress",
[](DgGeoSphRF gshprf, DgLocation loc) {
return gshprf.getAddress(loc);
}
);
py::class_<DgRFNetwork>(m, "DgRFNetwork")
.def(py::init<int>(), "Constructor for the DgRFNetwork class (chunksize)",
py::arg("chunkSize")=10)
.def(py::init<const DgRFNetwork &>() , "Copy constructor for the DgRFNetwork class")
.def("size" , &DgRFNetwork::size)
.def("update" , &DgRFNetwork::update)
.def("capacity" , &DgRFNetwork::capacity);
py::class_<DgGeoCoord>(m, "DgGeoCoord")
.def(py::init<>(), "Empty constructor for the DgGeoCoord class")
.def(py::init<const DgGeoCoord &>() , "Copy constructor for the DgGeoCoord class")
.def(py::init<double , double, bool >() , "Constructor for the DgGeoCoord class using coordinated (radians or non radians)");
py::class_<DgLocation>(m, "DgLocation")
.def(py::init<>(), "Constructor")
.def("isUndefined" , &DgLocation::isUndefined )
.def("asAddressString" , [](const DgLocation &l) {
return l.asAddressString();
})
.def("__repr__",
[](const DgLocation &l) {
return l.asString();
}
);
py::class_<DgStringParam>(m, "DgStringParam")
.def(py::init<const std::string &>() , "Basic constructor for DgStringParam using parameter name as input")
.def(py::init<const std::string & , const std::string &>(), "Basic constructor for DgStringParam using parameter name and value as input")
.def("__str__" , &DgStringParam::valToStr)
.def("valToStr" , &DgStringParam::valToStr)
.def("strToVal" , &DgStringParam::strToVal);
py::class_<DgBoolParam>(m, "DgBoolParam")
.def(py::init<const std::string &>(), "Basic constructor for DgBoolParam using parameter name as input")
.def(py::init<const std::string & , bool, bool>(), "Basic constructor for DgBoolParam using parameter name and value as input")
.def("__str__" , &DgBoolParam::valToStr)
.def("valToStr" , &DgBoolParam::valToStr)
.def("strToVal" , &DgBoolParam::strToVal)
.def("validate" , &DgBoolParam::validate);
py::class_<DgParamList>(m, "DgParamList")
.def(py::init<>(), "Empty constructor for the DgParamList class")
.def("loadParams" , &DgParamList::loadParams)
.def("setParam" , &DgParamList::setParam)
.def("insertParam" ,
[](DgParamList &pl , DgStringParam &sp) {
pl.insertParam(static_cast<DgAssoc*>(&sp));
})
.def("insertParam" ,
[](DgParamList &pl , DgBoolParam &bp) {
pl.insertParam(static_cast<DgAssoc*>(&bp));
});
}