Skip to content

Commit

Permalink
Merge pull request #1901 from lixun910/fix_201
Browse files Browse the repository at this point in the history
V241
  • Loading branch information
lixun910 committed Jun 18, 2019
2 parents 5e1403a + e2c9032 commit dee1592
Show file tree
Hide file tree
Showing 18 changed files with 5,099 additions and 4,897 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*.gal
*.pyc

.vscode/
deps/

swig/*.gwt
Expand Down
2 changes: 2 additions & 0 deletions BuildTools/macosx/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ build-geoda-mac:
install_name_tool -change "$(GEODA_HOME)/libraries/lib/libspatialite.5.dylib" "@executable_path/../Resources/plugins/libspatialite.5.dylib" build/GeoDa.app/Contents/Resources/plugins/libgdal.20.dylib
install_name_tool -change "$(GEODA_HOME)/libraries/lib/libfreexl.1.dylib" "@executable_path/../Resources/plugins/libfreexl.1.dylib" build/GeoDa.app/Contents/Resources/plugins/libgdal.20.dylib
install_name_tool -change "$(GEODA_HOME)/libraries/lib/libproj.0.dylib" "@executable_path/../Resources/plugins/libproj.0.dylib" build/GeoDa.app/Contents/Resources/plugins/libgdal.20.dylib
install_name_tool -change "/usr/local/opt/openssl/lib/libssl.1.0.0.dylib" "@executable_path/../Resources/plugins/libssl.1.0.0.dylib" build/GeoDa.app/Contents/Resources/plugins/libgdal.20.dylib
install_name_tool -change "/usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib" "@executable_path/../Resources/plugins/libcrypto.1.0.0.dylib" build/GeoDa.app/Contents/Resources/plugins/libgdal.20.dylib
install_name_tool -change "$(GEODA_HOME)/libraries/lib/libsqlite3.0.dylib" "@executable_path/../Resources/plugins/libsqlite3.0.dylib" build/GeoDa.app/Contents/Resources/plugins/libgdal.20.dylib
install_name_tool -change "$(GEODA_HOME)/libraries/lib/libgeos_c.1.dylib" "@executable_path/../Resources/plugins/libgeos_c.1.dylib" build/GeoDa.app/Contents/Resources/plugins/libgdal.20.dylib
install_name_tool -change "$(GEODA_HOME)/libraries/lib/libgeos-3.3.8.dylib" "@executable_path/../Resources/plugins/libgeos-3.3.8.dylib" build/GeoDa.app/Contents/Resources/plugins/libgdal.20.dylib
Expand Down
2 changes: 1 addition & 1 deletion BuildTools/ubuntu/create_deb_18.04.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fi

rm -f *.deb
if [ $# -ne 1 ]; then
dpkg -b product/ geoda_1.12-1xenial1.deb
dpkg -b product/ geoda_1.12-1bionic1.deb
else
dpkg -b product/ geoda_1.12-1$1.deb
fi
2 changes: 1 addition & 1 deletion BuildTools/ubuntu/package/DEBIAN/control1804
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: geoda
Version: 1.12-1xenial1
Version: 1.12-1bionic1
Architecture: amd64
Priority: optional
Section: graphics
Expand Down
133 changes: 45 additions & 88 deletions DataViewer/OGRColumn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <string.h>
#include <istream>
#include <time.h>
#include <sstream>
Expand All @@ -30,7 +31,7 @@
#include <wx/numformatter.h>

#include "../GenUtils.h"
#include "../GeoDa.h"
//#include "../GeoDa.h"
#include "../logger.h"
#include "../ShapeOperations/OGRDataAdapter.h"
#include "../GdaException.h"
Expand Down Expand Up @@ -789,135 +790,91 @@ OGRColumnString::~OGRColumnString()
// This column -> vector<double>
void OGRColumnString::FillData(vector<double>& data)
{
const char* thousand_sep = CPLGetConfigOption("GEODA_LOCALE_SEPARATOR", ",");
const char* decimal_sep = CPLGetConfigOption("GEODA_LOCALE_DECIMAL", ".");
bool use_custom_locale = false;
if ((strlen(thousand_sep) > 0 && strcmp(thousand_sep, ",") != 0) ||
(strlen(decimal_sep) > 0 && strcmp(decimal_sep, ".") != 0)) {
// customized locale numeric
use_custom_locale = true;
}

if (is_new) {
for (int i=0; i<rows; ++i) {
double val = 0.0;
if ( !new_data[i].ToDouble(&val) ) {
undef_markers[i] = true;
if (use_custom_locale) {
new_data[i].Replace(thousand_sep, "");
new_data[i].Replace(decimal_sep, ".");
}
wxNumberFormatter::FromString(new_data[i], &val);
data[i] = val;
}

} else {
int col_idx = GetColIndex();
wxString tmp;
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 {
// 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;
}

if (use_custom_locale) {
tmp.Replace(thousand_sep, "");
tmp.Replace(decimal_sep, ".");
}
}
if (saved_locale) {
// restore locale
setlocale(LC_NUMERIC, saved_locale);
free(saved_locale);

double val = 0.0;
wxNumberFormatter::FromString(tmp, &val);
data[i] = val;
}
}
}

// This column -> vector<wxInt64>
void OGRColumnString::FillData(vector<wxInt64> &data)
{
const char* thousand_sep = CPLGetConfigOption("GEODA_LOCALE_SEPARATOR", ",");
const char* decimal_sep = CPLGetConfigOption("GEODA_LOCALE_DECIMAL", ".");
bool use_custom_locale = false;
if ((strlen(thousand_sep) > 0 && strcmp(thousand_sep, ",") != 0) ||
(strlen(decimal_sep) > 0 && strcmp(decimal_sep, ".") != 0)) {
// customized locale numeric
use_custom_locale = true;
}

if (is_new) {
for (int i=0; i<rows; ++i) {
wxInt64 val = 0;
if (!new_data[i].ToLongLong(&val)) {
//wxString error_msg = wxString::Format("Fill data error: can't convert '%s' to integer number.", new_data[i]);
//throw GdaException(error_msg.mb_str());
double d_val;
if (new_data[i].ToDouble(&d_val)) {
val = static_cast<wxInt64>(d_val);
data[i] = val;
} else {
undef_markers[i] = true;
data[i] = 0;
}
} else {
data[i] = val;
if (use_custom_locale) {
new_data[i].Replace(thousand_sep, "");
new_data[i].Replace(decimal_sep, ".");
}
wxNumberFormatter::FromString(new_data[i], &val);
data[i] = val;
}
} else {
int col_idx = GetColIndex();
bool conv_success = true;
wxString tmp;
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;

if (tmp.IsEmpty()) {
undef_markers[i] = true;
data[i] = 0;

} else if (tmp.ToLongLong(&val)) {
data[i] = val;

} else if (tmp.ToDouble(&val_d)) {
val = static_cast<wxInt64>(val_d);
data[i] = val;

} else {
// 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_)) {
data[i] = val_;

} else if (tmp.ToDouble(&val_d_)) {
val_ = static_cast<wxInt64>(val_d_);
data[i] = val_;

} else {
data[i] = 0;
undef_markers[i] = true;
}
wxInt64 val = 0;

if (use_custom_locale) {
tmp.Replace(thousand_sep, "");
tmp.Replace(decimal_sep, ".");
}
}
if (saved_locale) {
// restore locale
setlocale(LC_NUMERIC, saved_locale);
free(saved_locale);

wxNumberFormatter::FromString(tmp, &val);
data[i] = val;
}
}
}
Expand Down
20 changes: 16 additions & 4 deletions DataViewer/OGRTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,18 @@ bool OGRTable::RenameSimpleCol(int col, int time, const wxString& new_name)
return true;
}

wxString OGRTable::GetCellString(int row, int col, int time)
int OGRTable::GetCellStringLength(int row, int col, bool use_disp_decimal)
{
int str_length = 0;
int ts = GetColTimeSteps(col);
for (int t=0; t<ts; ++t) {
wxString val = GetCellString(row, col, t, use_disp_decimal);
if (val.length() > str_length) str_length = val.length();
}
return str_length;
}

wxString OGRTable::GetCellString(int row, int col, int time, bool use_disp_decimal)
{
// NOTE: if called from wxGrid, must use row_order[row] to permute
if (row < 0 || row >= rows) return wxEmptyString;
Expand All @@ -1198,15 +1209,16 @@ wxString OGRTable::GetCellString(int row, int col, int time)
cur_type == GdaConst::unknown_type) {
return wxEmptyString;
}
// get display number of decimals
int disp_dec = GetColDispDecimals(col);

// mapping col+time to underneath OGR col
OGRColumn* ogr_col = FindOGRColumn(col, time);
if (ogr_col == NULL) {
return "";
}
return ogr_col->GetValueAt(row, disp_dec, m_wx_encoding);
// get display number of decimals
int col_dec = GetColDecimals(col, time);
if (use_disp_decimal) col_dec = GetColDispDecimals(col);
return ogr_col->GetValueAt(row, col_dec, m_wx_encoding);
}


Expand Down
5 changes: 3 additions & 2 deletions DataViewer/OGRTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,9 @@ class OGRTable : public TableInterface, TableStateObserver
virtual bool ColChangeDisplayedDecimals(int col, int new_disp_dec);
virtual bool RenameGroup(int col, const wxString& new_name);
virtual bool RenameSimpleCol(int col, int time, const wxString& new_name);
virtual wxString GetCellString(int row, int col, int time=0);
virtual bool SetCellFromString(int row, int col, int time,
virtual wxString GetCellString(int row, int col, int time=0, bool use_disp_decimal=false);
virtual int GetCellStringLength(int row, int col, bool use_disp_decimal=true);
virtual bool SetCellFromString(int row, int col, int time,
const wxString &value);
virtual int InsertCol(GdaConst::FieldType type, const wxString& name,
int pos=-1, int time_steps=1,
Expand Down
29 changes: 10 additions & 19 deletions DataViewer/TableFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,27 +113,18 @@ TableFrame::TableFrame(wxFrame *parent, Project* project,
for (int i=0, iend=table_base->GetNumberCols(); i<iend; i++) {
double cur_col_size = grid->GetColSize(i);
double cur_lbl_len = grid->GetColLabelValue(i).length();
double max_cell_len = 0;
double max_cell_len = cur_lbl_len;
for (int j=0; j<sample-1; ++j) {
wxString cv = grid->GetCellValue(j, i);
cv.Trim(true);
cv.Trim(false);
if (cv.length() > max_cell_len) max_cell_len = cv.length();
}
if (max_cell_len > cur_lbl_len &&
max_cell_len >= 1 && cur_lbl_len >= 1) {
// attempt to scale up col width based on cur_col_size
double fac = max_cell_len / cur_lbl_len;
if (fac < 1) fac = 1;
if (fac > 5) fac = 5;
fac = fac * 1.2;
grid->SetColMinimalWidth(i, cur_col_size);
grid->SetColSize(i, cur_col_size * fac);
} else {
// add a few pixels of buffer to current label
grid->SetColMinimalWidth(i, cur_col_size+6);
grid->SetColSize(i, cur_col_size+6);
//wxString cv = grid->GetCellValue(j, i);
int cv_length = table_int->GetCellStringLength(j,i,true);
if (cv_length > max_cell_len) max_cell_len = cv_length;
}
// width (pixel) per number
double pw = 10;
grid->SetColMinimalWidth(i, cur_lbl_len * pw + 8);
// attempt to scale up col width based on cur_col_size
//double fac = 1.2;
grid->SetColSize(i, max_cell_len * pw);
}
grid->ForceRefresh();

Expand Down
6 changes: 4 additions & 2 deletions DataViewer/TableInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,10 @@ class TableInterface
const wxString& new_name) = 0;
/** wxGrid will call this function to fill data in displayed part
automatically. Returns formated string (e.g. nummeric numbers) */
virtual wxString GetCellString(int row, int col, int time=0) = 0;
/** Attempts to set the wxGrid cell from a user-entered value. Returns
virtual wxString GetCellString(int row, int col, int time=0, bool use_disp_decimal = false) = 0;
virtual int GetCellStringLength(int row, int col, bool use_disp_decimal=true) = 0;

/** Attempts to set the wxGrid cell from a user-entered value. Returns
true on success. If failured, then IsCellFromStringFail() returns false
and GetSetCellFromStringFailMsg() retuns a meaningful failure message
that can be displayed to the user. */
Expand Down
14 changes: 11 additions & 3 deletions DialogTools/CreatingWeightDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ bool CreatingWeightDlg::Create(wxWindow* parent, wxWindowID id, const wxString&

SetParent(parent);
CreateControls();
GetSizer()->Fit(this);
GetSizer()->SetSizeHints(this);
//GetSizer()->Fit(this);
//GetSizer()->SetSizeHints(this);
Centre();

return true;
Expand Down Expand Up @@ -212,7 +212,15 @@ void CreatingWeightDlg::CreateControls()
m_spinn_inverse_knn = XRCCTRL(*this, "IDC_SPIN_POWER_KNN", wxSpinButton);

m_btn_ok = XRCCTRL(*this, "wxID_OK", wxButton);


wxScrolledWindow* win = wxDynamicCast(FindWindow( XRCID("ID_CREATE_WEIGHT_SCROLL_WIN")), wxScrolledWindow);

win->SetAutoLayout(true);
win->FitInside();
win->SetScrollRate(5, 5);

FitInside();

m_X_time->Show(false);
m_Y_time->Show(false);

Expand Down
6 changes: 3 additions & 3 deletions DialogTools/ExportDataDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,10 +569,10 @@ ExportDataDlg::CreateOGRLayer(wxString& ds_name, bool is_table,
OGRDataAdapter& ogr_adapter = OGRDataAdapter::GetInstance();
vector<OGRGeometry*> ogr_geometries;
OGRwkbGeometryType geom_type = wkbNone;
OGRSpatialReference new_ref = NULL;
OGRSpatialReference new_ref;
if (is_table) {
spatial_ref = NULL; // table only data, void creating e.g. prj file
} else if (spatial_ref) {
} else {
geom_type = ogr_adapter.MakeOGRGeometries(geometries, shape_type,
ogr_geometries, selected_rows);
wxString str_crs = m_crs_input->GetValue();
Expand All @@ -587,7 +587,7 @@ ExportDataDlg::CreateOGRLayer(wxString& ds_name, bool is_table,
new_ref.importFromEPSG(4326);
valid_input_crs = true;
}
if (valid_input_crs && !spatial_ref->IsSame(&new_ref)) {
if (spatial_ref && (valid_input_crs && !spatial_ref->IsSame(&new_ref))) {
OGRCoordinateTransformation *poCT;
poCT = OGRCreateCoordinateTransformation(spatial_ref, &new_ref);
for (size_t i=0; i < ogr_geometries.size(); i++) {
Expand Down
Loading

0 comments on commit dee1592

Please sign in to comment.