Skip to content

Commit

Permalink
Remove "set number separators" menu
Browse files Browse the repository at this point in the history
Set to use default en_US number formatting, which use DOT as  decimal separator internal.

If COMMA decimal separator used in data (e.g. csv),  GeoDa will read the value as string by default, and user can convert  the field from string to real by automatically detecting if DOT/COMMA used as decimal separator.
  • Loading branch information
lixun910 committed Feb 21, 2019
1 parent 9f4ba03 commit d4b8550
Show file tree
Hide file tree
Showing 8 changed files with 1,450 additions and 1,456 deletions.
5 changes: 3 additions & 2 deletions DataViewer/DataViewerAddColDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,9 @@ void DataViewerAddColDlg::OnOkClick( wxCommandEvent& ev )

int time_steps = 1; // non-space-time column by default

wxLogMessage(wxString::Format(_("Inserting new column %s into Table"),
colname));
//wxString log_msg = wxString::Format(_("Inserting new column %s into Table"),
//colname);
//wxLogMessage(log_msg);

bool success;
if (fixed_lengths) {
Expand Down
48 changes: 32 additions & 16 deletions DataViewer/OGRColumn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -795,37 +795,44 @@ void OGRColumnString::FillData(vector<double>& data)
} else {
int col_idx = GetColIndex();
wxString tmp;

// default C locale
char *old_locale, *saved_locale = 0;

for (int i=0; i<rows; ++i) {
if ( undef_markers[i] == true) {
data[i] = 0.0;
continue;
}

tmp = wxString(ogr_layer->data[i]->GetFieldAsString(col_idx));

double val;
if (tmp.IsEmpty()) {
data[i] = 0.0;
undef_markers[i] = true;
} else if (tmp.ToDouble(&val)) {
data[i] = val;
} else {
// get name of current locale
char *old_locale = setlocale(LC_NUMERIC, NULL);
// try comma as decimal point
setlocale(LC_NUMERIC, "de_DE");
// try to use different locale
if (i==0) {
// get name of current locale
old_locale = setlocale(LC_NUMERIC, NULL);
// Copy the name so it won’t be clobbered by setlocale
saved_locale = strdup (old_locale);
// try comma as decimal point
setlocale(LC_NUMERIC, "de_DE");
}
double _val;
if (tmp.ToDouble(&_val)) {
data[i] = _val;
} else {
data[i] = 0.0;
undef_markers[i] = true;
}
setlocale(LC_NUMERIC, old_locale);
}
}
if (saved_locale) {
// restore locale
setlocale(LC_NUMERIC, saved_locale);
free(saved_locale);
}
}
}

Expand Down Expand Up @@ -854,14 +861,13 @@ void OGRColumnString::FillData(vector<wxInt64> &data)
int col_idx = GetColIndex();
bool conv_success = true;
wxString tmp;

// default C locale
char *old_locale, *saved_locale = 0;

for (int i=0; i<rows; ++i) {
if ( undef_markers[i] == true) {
data[i] = 0;
continue;
}

tmp = wxString(ogr_layer->data[i]->GetFieldAsString(col_idx));
wxInt64 val;
double val_d;
Expand All @@ -878,9 +884,15 @@ void OGRColumnString::FillData(vector<wxInt64> &data)
data[i] = val;

} else {
// get name of current locale
char *old_locale = setlocale(LC_NUMERIC, NULL);
setlocale(LC_NUMERIC, "de_DE");
// try to use different locale
if (i==0) {
// get name of current locale
old_locale = setlocale(LC_NUMERIC, NULL);
// Copy the name so it won’t be clobbered by setlocale
saved_locale = strdup (old_locale);
// try comma as decimal point
setlocale(LC_NUMERIC, "de_DE");
}
wxInt64 val_;
double val_d_;
if (tmp.ToLongLong(&val_)) {
Expand All @@ -894,9 +906,13 @@ void OGRColumnString::FillData(vector<wxInt64> &data)
data[i] = 0;
undef_markers[i] = true;
}
setlocale(LC_NUMERIC, old_locale);
}
}
if (saved_locale) {
// restore locale
setlocale(LC_NUMERIC, saved_locale);
free(saved_locale);
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions DialogTools/CsvFieldConfDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,9 @@ CsvFieldConfDlg::CsvFieldConfDlg(wxWindow* parent,

fieldGrid->Connect(wxEVT_COMMAND_COMBOBOX_SELECTED,
wxCommandEventHandler(CsvFieldConfDlg::OnFieldSelected),
NULL,
this);
NULL, this);
// hide locale button, since it will be handled in Table directly
btn_locale->Hide();
}

CsvFieldConfDlg::~CsvFieldConfDlg()
Expand Down
14 changes: 5 additions & 9 deletions DialogTools/LocaleSetupDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ LocaleSetupDlg::LocaleSetupDlg(wxWindow* parent,
m_txt_decimal = XRCCTRL(*this, "IDC_FIELD_DECIMAL",wxTextCtrl);
m_txt_thousands->SetMaxLength(1);
m_txt_decimal->SetMaxLength(1);
wxString thousands_sep = CPLGetConfigOption("GDAL_LOCALE_SEPARATOR", "");
wxString decimal_point = CPLGetConfigOption("GDAL_LOCALE_DECIMAL", "");

struct lconv *poLconv = localeconv();
wxString thousands_sep = poLconv->thousands_sep;
wxString decimal_point = poLconv->decimal_point;

m_txt_thousands->SetValue(thousands_sep);
m_txt_decimal->SetValue(decimal_point);
Expand All @@ -74,13 +76,7 @@ void LocaleSetupDlg::OnResetSysLocale( wxCommandEvent& event )
{
wxLogMessage("Click LocaleSetupDlg::OnResetSysLocale");

setlocale(LC_ALL, "");
struct lconv *poLconv = localeconv();
CPLSetConfigOption("GDAL_LOCALE_SEPARATOR", poLconv->thousands_sep);
CPLSetConfigOption("GDAL_LOCALE_DECIMAL", poLconv->decimal_point);
// forcing to C locale, which is used internally in GeoDa
setlocale(LC_ALL, "C");

struct lconv *poLconv = localeconv();
wxString thousands_sep = poLconv->thousands_sep;
wxString decimal_point = poLconv->decimal_point;

Expand Down
19 changes: 6 additions & 13 deletions GeoDa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,20 +215,10 @@ bool GdaApp::OnInit(void)
{
if (!wxApp::OnInit())
return false;

// initialize OGR connection
OGRDataAdapter::GetInstance();

// By defaut, GDAL will use user's system locale to read any input datasource
// However, user can change the Separators in GeoDa, after re-open the
// datasource, CSV reader will use the Separators
struct lconv *poLconv = localeconv();
CPLSetConfigOption("GDAL_LOCALE_SEPARATOR", poLconv->thousands_sep);
CPLSetConfigOption("GDAL_LOCALE_DECIMAL", poLconv->decimal_point);

// forcing to UTF-8 locale, which is used internally in GeoDa
setlocale(LC_ALL, "en_US.UTF-8");

// load preferences
PreferenceDlg::ReadFromCache();

Expand All @@ -244,7 +234,9 @@ bool GdaApp::OnInit(void)
m_TranslationHelper = new wxTranslationHelper(*this, search_path, use_native_config);
m_TranslationHelper->SetConfigPath(config_path);
m_TranslationHelper->Load();

// forcing numeric settings to en_US, which is used internally in GeoDa
setlocale(LC_NUMERIC, "en_US");

// Other GDAL configurations
if (GdaConst::hide_sys_table_postgres == false) {
CPLSetConfigOption("PG_LIST_ALL_TABLES", "YES");
Expand All @@ -253,7 +245,8 @@ bool GdaApp::OnInit(void)
CPLSetConfigOption("SQLITE_LIST_ALL_TABLES", "YES");
}
if (GdaConst::gdal_http_timeout >= 0 ) {
CPLSetConfigOption("GDAL_HTTP_TIMEOUT", wxString::Format("%d", GdaConst::gdal_http_timeout));
CPLSetConfigOption("GDAL_HTTP_TIMEOUT",
wxString::Format("%d", GdaConst::gdal_http_timeout));
}
CPLSetConfigOption("OGR_XLS_HEADERS", "FORCE");
CPLSetConfigOption("OGR_XLSX_HEADERS", "FORCE");
Expand Down
Loading

0 comments on commit d4b8550

Please sign in to comment.