@@ -58,7 +58,7 @@ MultiQuantileLisaDlg::~MultiQuantileLisaDlg()
5858void MultiQuantileLisaDlg::CreateControls ()
5959{
6060 wxScrolledWindow* scrl = new wxScrolledWindow (this , wxID_ANY, wxDefaultPosition,
61- wxSize (800 ,560 ), wxHSCROLL|wxVSCROLL );
61+ wxSize (800 ,520 ), wxHSCROLL|wxVSCROLL );
6262 scrl->SetScrollRate (5 , 5 );
6363
6464 wxPanel *panel = new wxPanel (scrl);
@@ -108,7 +108,7 @@ void MultiQuantileLisaDlg::CreateControls()
108108 var_box->Add (gbox, 0 , wxEXPAND);
109109
110110 // list contrl
111- lst_quantile = new wxListCtrl (panel, wxID_ANY, wxDefaultPosition, wxSize (400 , 180 ), wxLC_REPORT);
111+ lst_quantile = new wxListCtrl (panel, wxID_ANY, wxDefaultPosition, wxSize (400 , 160 ), wxLC_REPORT);
112112 lst_quantile->AppendColumn (_ (" Variable" ));
113113 lst_quantile->SetColumnWidth (0 , 80 );
114114 lst_quantile->AppendColumn (_ (" Number of Quantiles" ), wxLIST_FORMAT_RIGHT);
@@ -118,7 +118,6 @@ void MultiQuantileLisaDlg::CreateControls()
118118 lst_quantile->AppendColumn (_ (" New Field" ));
119119 lst_quantile->SetColumnWidth (3 , 80 );
120120
121-
122121 // move buttons
123122 move_left = new wxButton (panel, wxID_ANY, " <" , wxDefaultPosition, wxSize (25 ,25 ));
124123 move_right = new wxButton (panel, wxID_ANY, " >" , wxDefaultPosition, wxSize (25 ,25 ));
@@ -127,7 +126,10 @@ void MultiQuantileLisaDlg::CreateControls()
127126
128127 left_box->Add (var_box);
129128 right_box->Add (lst_quantile, 1 , wxALL|wxEXPAND, 5 );
130-
129+
130+ chk_nocolocation = new wxCheckBox (panel, wxID_ANY, " No co-location" );
131+ right_box->Add (chk_nocolocation, 0 , wxALL, 5 );
132+
131133 hbox_quantile->Add (left_box);
132134 hbox_quantile->Add (middle_box);
133135 hbox_quantile->Add (right_box, 1 , wxALL|wxEXPAND);
@@ -217,6 +219,13 @@ void MultiQuantileLisaDlg::OnAddRow(wxCommandEvent& event)
217219 // check if inputs are valid
218220 if (project == NULL ) return ;
219221
222+ if (chk_nocolocation->GetValue () && lst_quantile->GetItemCount () >= 2 ) {
223+ wxString err_msg = _ (" No-colocation only works with two variables for Quantile LISA." );
224+ wxMessageDialog dlg (NULL , err_msg, _ (" Error" ), wxOK | wxICON_ERROR);
225+ dlg.ShowModal ();
226+ return ;
227+ }
228+
220229 // get selected variable
221230 int sel_var = combo_var->GetSelection ();
222231 if (sel_var < 0 ) {
@@ -343,6 +352,13 @@ void MultiQuantileLisaDlg::OnOK(wxCommandEvent& event )
343352 return ;
344353 }
345354
355+ if (chk_nocolocation->GetValue () && lst_quantile->GetItemCount () != 2 ) {
356+ wxString err_msg = _ (" No-colocation only works with two variables for Quantile LISA." );
357+ wxMessageDialog dlg (NULL , err_msg, _ (" Error" ), wxOK | wxICON_ERROR);
358+ dlg.ShowModal ();
359+ return ;
360+ }
361+
346362 std::vector<int > col_ids (num_vars);
347363 std::vector<GdaVarTools::VarInfo> var_info (num_vars);
348364 wxString var_details;
@@ -441,6 +457,63 @@ void MultiQuantileLisaDlg::OnOK(wxCommandEvent& event )
441457 }
442458 boost::uuids::uuid w_id = weights_ids[sel];
443459
460+ // check if satisfy colocation and no-colocation cases
461+ if (num_vars >= 2 ) {
462+ std::vector<d_array_type> data (num_vars); // data[variable][time][obs]
463+ std::vector<b_array_type> undef_data (num_vars);
464+ for (int i=0 ; i<var_info.size (); i++) {
465+ table_int->GetColData (col_ids[i], data[i]);
466+ table_int->GetColUndefined (col_ids[i], undef_data[i]);
467+ }
468+ GalElement* W = gw->gal ;
469+ int t = 0 ;
470+ vector<int > local_t ;
471+ for (int v=0 ; v<num_vars; v++) {
472+ if (data[v].size ()==1 ) {
473+ local_t .push_back (0 );
474+ } else {
475+ local_t .push_back (t);
476+ }
477+ }
478+ vector<bool > undefs;
479+ for (int i=0 ; i<rows; i++){
480+ bool is_undef = false ;
481+ for (int v=0 ; v<undef_data.size (); v++) {
482+ for (int var_t =0 ; var_t <undef_data[v].size (); var_t ++){
483+ is_undef = is_undef || undef_data[v][var_t ][i];
484+ }
485+ }
486+ undefs.push_back (is_undef);
487+ }
488+ int * zz = new int [rows];
489+ for (int i=0 ; i<rows; i++) zz[i] = 1 ;
490+ for (int i=0 ; i<rows; i++) {
491+ if (undefs[i] == true ) {
492+ zz[i] = 0 ;
493+ continue ;
494+ }
495+ for (int v=0 ; v<num_vars; v++) {
496+ int _t = local_t [v];
497+ int _v = data[v][_t][i];
498+ zz[i] = zz[i] * _v;
499+ }
500+ }
501+ int sum = 0 ;
502+ for (int i=0 ; i<rows; i++) {
503+ sum += zz[i];
504+ }
505+ bool nocolocation = sum == 0 ;
506+ if (nocolocation && !chk_nocolocation->GetValue ()) {
507+ wxMessageDialog dlg (this , _ (" The selected variables have no co-location. Please change your selection, or select \" No colocation\" option for bivariate case." ), _ (" Error" ), wxOK | wxICON_WARNING);
508+ dlg.ShowModal ();
509+ return ;
510+ } else if (chk_nocolocation->GetValue () && nocolocation == false ) {
511+ wxMessageDialog dlg (this , _ (" The selected variables have co-location. Please change your selection, or unselect \" No colocation\" option for bivariate case." ), _ (" Error" ), wxOK | wxICON_WARNING);
512+ dlg.ShowModal ();
513+ return ;
514+ }
515+ }
516+
444517 JCCoordinator* lc = new JCCoordinator (w_id, project, var_info, col_ids);
445518 MLJCMapFrame *sf = new MLJCMapFrame (parent, project, lc, false );
446519
0 commit comments