From e507531eed6867d6cc302a110d687a4816b1f667 Mon Sep 17 00:00:00 2001 From: Xun Li Date: Wed, 19 Dec 2018 13:35:42 -0700 Subject: [PATCH] #1765 add a type "tree" for the weights manager when save a spanning tree --- DialogTools/RedcapDlg.cpp | 3 ++- DialogTools/SkaterDlg.cpp | 3 ++- ShapeOperations/GdaCache.cpp | 14 +++++++------- ShapeOperations/WeightUtils.cpp | 9 +++++++-- ShapeOperations/WeightUtils.h | 6 +++++- ShapeOperations/WeightsManPtree.cpp | 13 ++++++++++--- VarCalc/WeightsMetaInfo.cpp | 9 ++++++++- VarCalc/WeightsMetaInfo.h | 3 ++- 8 files changed, 43 insertions(+), 17 deletions(-) diff --git a/DialogTools/RedcapDlg.cpp b/DialogTools/RedcapDlg.cpp index 8799c11b4..1a4aaedcc 100644 --- a/DialogTools/RedcapDlg.cpp +++ b/DialogTools/RedcapDlg.cpp @@ -442,7 +442,8 @@ void RedcapDlg::OnSaveTree(wxCommandEvent& event ) file.Close(); // Load the weights file into Weights Manager - WeightUtils::LoadGwtInMan(w_man_int, new_txt, table_int, id); + WeightUtils::LoadGwtInMan(w_man_int, new_txt, table_int, id, + WeightsMetaInfo::WT_tree); } } diff --git a/DialogTools/SkaterDlg.cpp b/DialogTools/SkaterDlg.cpp index 660cac2ad..6424dea1a 100644 --- a/DialogTools/SkaterDlg.cpp +++ b/DialogTools/SkaterDlg.cpp @@ -279,7 +279,8 @@ void SkaterDlg::OnSaveTree(wxCommandEvent& event ) file.Close(); // Load the weights file into Weights Manager - WeightUtils::LoadGwtInMan(w_man_int, new_txt, table_int, id); + WeightUtils::LoadGwtInMan(w_man_int, new_txt, table_int, id, + WeightsMetaInfo::WT_tree); } } diff --git a/ShapeOperations/GdaCache.cpp b/ShapeOperations/GdaCache.cpp index 836bd7f9b..cd361e39e 100644 --- a/ShapeOperations/GdaCache.cpp +++ b/ShapeOperations/GdaCache.cpp @@ -192,19 +192,20 @@ bool GdaCache::CacheLayer(wxString ext_ds_name, //Setup coordinate transformation if we need it. OGRCoordinateTransformation *poCT = NULL; - bool bTransform = FALSE; + bool bTransform = FALSE; OGRSpatialReference *poSourceSRS = NULL; // todo OGRSpatialReference *poOutputSRS = new OGRSpatialReference("EPSG:4326"); // Cache - char *papszLCO[] = {"OVERWRITE=yes","FORMAT=Spatialite"}; - wxString cache_layer_name = ext_ds_name + "_"+ext_layer_proxy->name; + const char *papszLCO[255] = {"OVERWRITE=yes","FORMAT=Spatialite"}; + wxString cache_layer_name = ext_ds_name + "_" + ext_layer_proxy->name; + const char *pszName = (const char*)cache_layer_name.mb_str(wxConvUTF8); GDALDataset *poDstDS = cach_ds_proxy->ds; - OGRLayer *poDstLayer = poDstDS->CreateLayer(cache_layer_name.c_str(), + OGRLayer *poDstLayer = poDstDS->CreateLayer(pszName, poOutputSRS, (OGRwkbGeometryType)eGType, - papszLCO); + (char**)papszLCO); if (poDstLayer == NULL) { // raise create cache failed. return false; @@ -236,8 +237,7 @@ bool GdaCache::CacheLayer(wxString ext_ds_name, GIntBig nFeaturesWritten = 0; poSrcLayer->ResetReading(); - while (poFeature = poSrcLayer->GetNextFeature()) - { + while ((poFeature = poSrcLayer->GetNextFeature()) != NULL) { OGRFeature *poDstFeature = OGRFeature::CreateFeature( poDstLayer->GetLayerDefn() ); poDstFeature->SetFrom(poFeature); diff --git a/ShapeOperations/WeightUtils.cpp b/ShapeOperations/WeightUtils.cpp index 1c8def1d3..63e68db72 100644 --- a/ShapeOperations/WeightUtils.cpp +++ b/ShapeOperations/WeightUtils.cpp @@ -857,7 +857,11 @@ GalElement* WeightUtils::Gwt2Gal(GwtElement* Gwt, long obs) } -void WeightUtils::LoadGwtInMan(WeightsManInterface* w_man_int, wxString filepath, TableInterface* table_int, wxString id_field) +void WeightUtils::LoadGwtInMan(WeightsManInterface* w_man_int, + wxString filepath, + TableInterface* table_int, + wxString id_field, + WeightsMetaInfo::WeightTypeEnum type) { int rows = table_int->GetNumberRows(); @@ -885,7 +889,8 @@ void WeightUtils::LoadGwtInMan(WeightsManInterface* w_man_int, wxString filepath wmi.SetMedianNumNbrs(w->GetMedianNumNbrs()); wmi.SetSparsity(w->GetSparsity()); wmi.SetDensity(w->GetDensity()); - + wmi.SetWeightsType(type); + WeightsMetaInfo e(wmi); e.filename = filepath; diff --git a/ShapeOperations/WeightUtils.h b/ShapeOperations/WeightUtils.h index aea3a9820..e82d96639 100644 --- a/ShapeOperations/WeightUtils.h +++ b/ShapeOperations/WeightUtils.h @@ -20,6 +20,8 @@ #ifndef __GEODA_CENTER_WEIGHT_UTILS_H__ #define __GEODA_CENTER_WEIGHT_UTILS_H__ +#include "../VarCalc/WeightsMetaInfo.h" + class TableInterface; class GalWeight; class GwtWeight; @@ -35,7 +37,9 @@ namespace WeightUtils { TableInterface* table_int); GwtElement* ReadGwt(const wxString& w_fname, TableInterface* table_int); GalElement* Gwt2Gal(GwtElement* Gwt, long obs); - void LoadGwtInMan(WeightsManInterface* w_man_int, wxString filepath, TableInterface* table_int, wxString id_field); + void LoadGwtInMan(WeightsManInterface* w_man_int, wxString filepath, + TableInterface* table_int, wxString id_field, + WeightsMetaInfo::WeightTypeEnum type); } #endif diff --git a/ShapeOperations/WeightsManPtree.cpp b/ShapeOperations/WeightsManPtree.cpp index 8756e8cf1..ed62a30c2 100644 --- a/ShapeOperations/WeightsManPtree.cpp +++ b/ShapeOperations/WeightsManPtree.cpp @@ -106,6 +106,8 @@ void WeightsManPtree::ReadPtree(const boost::property_tree::ptree& pt, e.wmi.weights_type = WeightsMetaInfo::WT_knn; } else if (s == "kernel") { e.wmi.weights_type = WeightsMetaInfo::WT_kernel; + } else if (s == "tree") { + e.wmi.weights_type = WeightsMetaInfo::WT_tree; } else { // s == "custom" e.wmi.weights_type = WeightsMetaInfo::WT_custom; } @@ -304,9 +306,10 @@ void WeightsManPtree::WritePtree(boost::property_tree::ptree& pt, if (!e.title.IsEmpty()) ssub.put("title", e.title); if (e.is_default) ssub.put("default", ""); ptree& sssub = ssub.add("meta_info", ""); - if (e.wmi.weights_type == WeightsMetaInfo::WT_custom) - { + + if (e.wmi.weights_type == WeightsMetaInfo::WT_custom) { sssub.put("weights_type", "custom"); + } else if (e.wmi.weights_type == WeightsMetaInfo::WT_rook || e.wmi.weights_type == WeightsMetaInfo::WT_queen) { @@ -319,9 +322,11 @@ void WeightsManPtree::WritePtree(boost::property_tree::ptree& pt, } else { sssub.put("inc_lower_orders", "false"); } + } else if (e.wmi.weights_type == WeightsMetaInfo::WT_threshold || e.wmi.weights_type == WeightsMetaInfo::WT_knn || - e.wmi.weights_type == WeightsMetaInfo::WT_kernel) + e.wmi.weights_type == WeightsMetaInfo::WT_kernel || + e.wmi.weights_type == WeightsMetaInfo::WT_tree) { if (e.wmi.weights_type == WeightsMetaInfo::WT_knn) sssub.put("weights_type", "knn"); @@ -329,6 +334,8 @@ void WeightsManPtree::WritePtree(boost::property_tree::ptree& pt, sssub.put("weights_type", "threshold"); else if (e.wmi.weights_type == WeightsMetaInfo::WT_kernel) sssub.put("weights_type", "kernel"); + else if (e.wmi.weights_type == WeightsMetaInfo::WT_tree) + sssub.put("weights_type", "tree"); else sssub.put("weights_type", "custom"); diff --git a/VarCalc/WeightsMetaInfo.cpp b/VarCalc/WeightsMetaInfo.cpp index 8bb70eae8..085f11b0b 100644 --- a/VarCalc/WeightsMetaInfo.cpp +++ b/VarCalc/WeightsMetaInfo.cpp @@ -97,6 +97,11 @@ void WeightsMetaInfo::SetSymmetric(bool is_sym) sym_type = is_sym ? SYM_symmetric : SYM_unknown; } +void WeightsMetaInfo::SetWeightsType(WeightTypeEnum type) +{ + weights_type = type; +} + void WeightsMetaInfo::SetToRook(const wxString& idv, long order_, bool inc_lower_orders_) { SetToDefaults(); @@ -258,7 +263,9 @@ wxString WeightsMetaInfo::TypeToStr() const return "kernel"; } else if (weights_type == WT_knn) { return "k-NN"; - } + } else if (weights_type == WT_tree) { + return "tree"; + } return "custom"; } diff --git a/VarCalc/WeightsMetaInfo.h b/VarCalc/WeightsMetaInfo.h index 7c0bdc319..0efb68cf4 100644 --- a/VarCalc/WeightsMetaInfo.h +++ b/VarCalc/WeightsMetaInfo.h @@ -26,7 +26,7 @@ struct WeightsMetaInfo { enum WeightTypeEnum { - WT_custom, WT_rook, WT_queen, WT_threshold, WT_inverse, WT_kernel, WT_knn + WT_custom, WT_rook, WT_queen, WT_threshold, WT_inverse, WT_kernel, WT_knn, WT_tree }; enum SymmetryEnum { SYM_unknown, SYM_symmetric, SYM_asymmetric @@ -163,6 +163,7 @@ struct WeightsMetaInfo void SetMeanNumNbrs(double val); void SetMedianNumNbrs(double val); void SetSymmetric(bool is_sym); + void SetWeightsType(WeightTypeEnum type); }; #endif