Skip to content

Commit af03fbf

Browse files
authored
Merge pull request #451 from lixun910/master
GeoDa 1.8.9.3
2 parents 377f88b + ead0f75 commit af03fbf

File tree

14 files changed

+130
-76
lines changed

14 files changed

+130
-76
lines changed

DataViewer/DataSource.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ bool IDataSource::IsWritable(GdaConst::DataSourceType ds_type)
4444
ds_type == GdaConst::ds_gml ||
4545
ds_type == GdaConst::ds_mapinfo ||
4646
ds_type == GdaConst::ds_sqlite ||
47+
ds_type == GdaConst::ds_gpkg ||
4748
ds_type == GdaConst::ds_mysql ||
4849
ds_type == GdaConst::ds_oci ||
4950
ds_type == GdaConst::ds_postgresql )
@@ -87,6 +88,8 @@ wxString IDataSource::GetDataTypeNameByExt(wxString ext)
8788
ds_format = "GeoJSON";
8889
else if(ext.CmpNoCase("sqlite")==0)
8990
ds_format = "SQLite";
91+
else if(ext.CmpNoCase("gpkg")==0)
92+
ds_format = "GPKG";
9093
else if(ext.CmpNoCase("xls")==0)
9194
ds_format = "XLS";
9295
else if(ext.CmpNoCase("xlsx")==0)
@@ -182,6 +185,7 @@ IDataSource* IDataSource::CreateDataSource(wxString data_type_name,
182185
type == GdaConst::ds_esri_personal_gdb ||
183186
type == GdaConst::ds_odbc ||
184187
type == GdaConst::ds_sqlite ||
188+
type == GdaConst::ds_gpkg ||
185189
type == GdaConst::ds_xls ||
186190
type == GdaConst::ds_xlsx ||
187191
type == GdaConst::ds_geo_json )

DataViewer/DataSource.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@ class FileDataSource : public IDataSource {
148148

149149
virtual IDataSource* Clone();
150150

151-
virtual bool IsFileDataSource() { return ds_type == GdaConst::ds_sqlite ? false : true;}
151+
virtual bool IsFileDataSource() {
152+
return ds_type == GdaConst::ds_sqlite || ds_type == GdaConst::ds_gpkg ? false : true;
153+
}
154+
152155
/**
153156
* Return file path.
154157
*/

DialogTools/ConnectDatasourceDlg.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ IDataSource* ConnectDatasourceDlg::CreateDataSource()
290290
// a special case: sqlite is a file based database, so we need to get
291291
// avalible layers and prompt for user selecting
292292
if (datasource->GetType() == GdaConst::ds_sqlite ||
293+
datasource->GetType() == GdaConst::ds_gpkg||
293294
datasource->GetType() == GdaConst::ds_osm ||
294295
datasource->GetType() == GdaConst::ds_esri_personal_gdb||
295296
datasource->GetType() == GdaConst::ds_esri_file_geodb)

DialogTools/DatasourceDlg.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ void DatasourceDlg::Init()
6060
ds_names.Add("GeoJSON (*.geojson;*.json)|*.geojson;*.json|"
6161
"GeoJSON (*.geojson)|*.geojson|"
6262
"GeoJSON (*.json)|*.json");
63+
ds_names.Add("GeoPackage (*.gpkg)|*.gpkg");
6364
ds_names.Add("SQLite/SpatiaLite (*.sqlite)|*.sqlite");
6465

6566
if( GeneralWxUtils::isWindows()){

DialogTools/ExportDataDlg.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ void ExportDataDlg::OnOkClick( wxCommandEvent& event )
326326
// cases: e.g. sqlite, ESRI FileGDB
327327
if (datasource_type == 0) {
328328
if (wxFileExists(ds_name)) {
329-
if (ds_name.EndsWith(".sqlite")) {
329+
if (ds_name.EndsWith(".sqlite") || ds_name.EndsWith(".gpkg")) {
330330
// add new layer to existing sqlite
331331
is_update = true;
332332
} else {
@@ -394,9 +394,13 @@ void ExportDataDlg::OnOkClick( wxCommandEvent& event )
394394
} catch (GdaException& e) {
395395
if (e.type() == GdaException::NORMAL)
396396
return;
397+
397398
// special clean up for file datasource
398399
if ( !tmp_ds_name.empty() ) {
399-
if ( wxFileExists(tmp_ds_name) && !tmp_ds_name.EndsWith(".sqlite")){
400+
if ( wxFileExists(tmp_ds_name) &&
401+
!tmp_ds_name.EndsWith(".sqlite") &&
402+
!tmp_ds_name.EndsWith(".gpkg") )
403+
{
400404
wxRemoveFile(ds_name);
401405
wxCopyFile(tmp_ds_name, ds_name);
402406
wxRemoveFile(tmp_ds_name);

DialogTools/SaveAsDlg.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ void SaveAsDlg::OnBrowseDatasourceBtn ( wxCommandEvent& event )
122122
ds_type != GdaConst::ds_geo_json &&
123123
ds_type != GdaConst::ds_mapinfo &&
124124
ds_type != GdaConst::ds_sqlite &&
125-
ds_type != GdaConst::ds_csv) {
125+
ds_type != GdaConst::ds_gpkg &&
126+
ds_type != GdaConst::ds_csv)
127+
{
126128
msg << "Save is not supported on current data source type: "
127129
<< ds_format << ". Please try to use \"File->Save As\" other data source. "
128130
<< "However, the project file can still be saved as other project file.";

GdaConst.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,16 @@ void GdaConst::init()
600600
datasrc_field_illegal_regex[ds_sqlite] = wxEmptyString;
601601
datasrc_field_casesensitive[ds_sqlite] = true;
602602

603+
datasrc_str_to_type["GPKG"] = ds_gpkg;
604+
datasrc_type_to_prefix[ds_gpkg] = "";
605+
datasrc_type_to_fullname[ds_gpkg] = "GeoPackage";
606+
datasrc_table_lens[ds_gpkg] = 128;
607+
datasrc_field_lens[ds_gpkg] = 128;
608+
datasrc_field_warning[ds_gpkg] = no_field_warning;
609+
datasrc_field_regex[ds_gpkg] = wxEmptyString;
610+
datasrc_field_illegal_regex[ds_gpkg] = wxEmptyString;
611+
datasrc_field_casesensitive[ds_gpkg] = true;
612+
603613
datasrc_str_to_type["WFS"] = ds_wfs;
604614
datasrc_type_to_prefix[ds_wfs] = "WFS:";
605615
datasrc_type_to_fullname[ds_wfs] = "OGC Web Feature Service";
@@ -670,23 +680,29 @@ void GdaConst::init()
670680
for (ds_fld_map::iterator it=datasrc_req_flds.begin();
671681
it != datasrc_req_flds.end(); it++) {
672682
DataSourceType type = it->first;
673-
if (type == ds_esri_file_geodb || type == ds_csv || type == ds_dbf ||
674-
type == ds_gml || type == ds_kml || type == ds_mapinfo ||
675-
type == ds_shapefile || type == ds_sqlite || type == ds_xls ||
676-
type == ds_geo_json || type == ds_osm) {
683+
if (type == ds_esri_file_geodb || type == ds_csv ||
684+
type == ds_dbf || type == ds_gml ||
685+
type == ds_kml || type == ds_mapinfo ||
686+
type == ds_shapefile || type == ds_sqlite ||
687+
type == ds_gpkg || type == ds_xls ||
688+
type == ds_geo_json || type == ds_osm)
689+
{
677690
// These are simple files, and a file name must be supplied
678691
it->second.insert("file");
679692
} else if (type == ds_esri_arc_obj || type == ds_esri_personal_gdb ||
680-
type == ds_esri_arc_sde || type == ds_mysql ||
681-
type == ds_ms_sql || type == ds_oci || type == ds_odbc) {
693+
type == ds_esri_arc_sde || type == ds_mysql ||
694+
type == ds_ms_sql || type == ds_oci || type == ds_odbc)
695+
{
682696
it->second.insert("user");
683697
it->second.insert("pwd");
684698
it->second.insert("host");
685699
it->second.insert("port");
686700
it->second.insert("db_name");
687701
} else if ( type == ds_wfs) {
702+
688703
it->second.insert("url");
689704
} else if (type == ds_postgresql) {
705+
690706
it->second.insert("db_name");
691707
}
692708
}

GdaConst.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class GdaConst {
7070
ds_esri_personal_gdb, ds_esri_arc_sde,
7171
ds_csv, ds_dbf, ds_geo_json, ds_gml, ds_kml,
7272
ds_mapinfo, ds_mysql, ds_ms_sql, ds_oci, ds_odbc, ds_postgresql,
73-
ds_shapefile, ds_sqlite, ds_wfs, ds_xls, ds_xlsx, ds_osm, ds_ods, ds_cartodb, ds_unknown };
73+
ds_shapefile, ds_sqlite, ds_gpkg, ds_wfs, ds_xls, ds_xlsx, ds_osm, ds_ods, ds_cartodb, ds_unknown };
7474

7575
static std::map<std::string, DataSourceType> datasrc_str_to_type;
7676
static std::map<DataSourceType, std::string> datasrc_type_to_str;

GeoDa.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ EVT_CHAR_HOOK(GdaFrame::OnKeyEvent)
457457

458458
EVT_MENU(XRCID("ID_NEW_PROJ_FROM_SHP"), GdaFrame::OnNewProjectFromShp)
459459
EVT_MENU(XRCID("ID_NEW_PROJ_FROM_SQLITE"), GdaFrame::OnNewProjectFromSqlite)
460+
EVT_MENU(XRCID("ID_NEW_PROJ_FROM_GPKG"), GdaFrame::OnNewProjectFromGpkg)
460461
EVT_MENU(XRCID("ID_NEW_PROJ_FROM_CSV"), GdaFrame::OnNewProjectFromCsv)
461462
EVT_MENU(XRCID("ID_NEW_PROJ_FROM_DBF"), GdaFrame::OnNewProjectFromDbf)
462463
EVT_MENU(XRCID("ID_NEW_PROJ_FROM_GDB"), GdaFrame::OnNewProjectFromGdb)
@@ -1223,6 +1224,7 @@ void GdaFrame::UpdateToolbarAndMenus()
12231224

12241225
GeneralWxUtils::EnableMenuItem(mb, "File", XRCID("ID_NEW_PROJ_FROM_SHP"), !proj_open);
12251226
GeneralWxUtils::EnableMenuItem(mb, "File", XRCID("ID_NEW_PROJ_FROM_SQLITE"), !proj_open);
1227+
GeneralWxUtils::EnableMenuItem(mb, "File", XRCID("ID_NEW_PROJ_FROM_GPKG"), !proj_open);
12261228
GeneralWxUtils::EnableMenuItem(mb, "File", XRCID("ID_NEW_PROJ_FROM_CSV"), !proj_open);
12271229
GeneralWxUtils::EnableMenuItem(mb, "File", XRCID("ID_NEW_PROJ_FROM_DBF"), !proj_open);
12281230
GeneralWxUtils::EnableMenuItem(mb, "File", XRCID("ID_NEW_PROJ_FROM_GDB"), !proj_open);
@@ -1874,6 +1876,14 @@ void GdaFrame::OnNewProjectFromSqlite(wxCommandEvent& event)
18741876
NewProjectFromFile(dlg.GetPath());
18751877
}
18761878

1879+
void GdaFrame::OnNewProjectFromGpkg(wxCommandEvent& event)
1880+
{
1881+
wxString wc = "GeoPacakge (*.gpkg)|*.gpkg";
1882+
wxFileDialog dlg(this,"New Project From GeoPackage", "", "", wc);
1883+
if (dlg.ShowModal() != wxID_OK) return;
1884+
NewProjectFromFile(dlg.GetPath());
1885+
}
1886+
18771887
void GdaFrame::OnNewProjectFromCsv(wxCommandEvent& event)
18781888
{
18791889
wxString wc = "Comma Separated Value (*.csv)|*.csv";

GeoDa.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class GdaFrame: public wxFrame
9999
void OnNewProject(wxCommandEvent& event);
100100
void OnNewProjectFromShp(wxCommandEvent& event);
101101
void OnNewProjectFromSqlite(wxCommandEvent& event);
102+
void OnNewProjectFromGpkg(wxCommandEvent& event);
102103
void OnNewProjectFromCsv(wxCommandEvent& event);
103104
void OnNewProjectFromDbf(wxCommandEvent& event);
104105
void OnNewProjectFromGdb(wxCommandEvent& event);

0 commit comments

Comments
 (0)