Skip to content

Commit

Permalink
#1765 add a type "tree" for the weights manager when save a spanning …
Browse files Browse the repository at this point in the history
…tree
  • Loading branch information
lixun910 committed Dec 19, 2018
1 parent fc80380 commit e507531
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 17 deletions.
3 changes: 2 additions & 1 deletion DialogTools/RedcapDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
3 changes: 2 additions & 1 deletion DialogTools/SkaterDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
14 changes: 7 additions & 7 deletions ShapeOperations/GdaCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 7 additions & 2 deletions ShapeOperations/WeightUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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;

Expand Down
6 changes: 5 additions & 1 deletion ShapeOperations/WeightUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
13 changes: 10 additions & 3 deletions ShapeOperations/WeightsManPtree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
{
Expand All @@ -319,16 +322,20 @@ 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");
else if (e.wmi.weights_type == WeightsMetaInfo::WT_threshold)
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");

Expand Down
9 changes: 8 additions & 1 deletion VarCalc/WeightsMetaInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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";
}

Expand Down
3 changes: 2 additions & 1 deletion VarCalc/WeightsMetaInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -163,6 +163,7 @@ struct WeightsMetaInfo
void SetMeanNumNbrs(double val);
void SetMedianNumNbrs(double val);
void SetSymmetric(bool is_sym);
void SetWeightsType(WeightTypeEnum type);
};

#endif
Expand Down

0 comments on commit e507531

Please sign in to comment.