Skip to content

Commit

Permalink
issue #450 add supports to GeoPackage
Browse files Browse the repository at this point in the history
  • Loading branch information
lixun910 committed Jul 13, 2016
1 parent f62dbd0 commit 3a5fd16
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 11 deletions.
4 changes: 4 additions & 0 deletions DataViewer/DataSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ bool IDataSource::IsWritable(GdaConst::DataSourceType ds_type)
ds_type == GdaConst::ds_gml ||
ds_type == GdaConst::ds_mapinfo ||
ds_type == GdaConst::ds_sqlite ||
ds_type == GdaConst::ds_gpkg ||
ds_type == GdaConst::ds_mysql ||
ds_type == GdaConst::ds_oci ||
ds_type == GdaConst::ds_postgresql )
Expand Down Expand Up @@ -87,6 +88,8 @@ wxString IDataSource::GetDataTypeNameByExt(wxString ext)
ds_format = "GeoJSON";
else if(ext.CmpNoCase("sqlite")==0)
ds_format = "SQLite";
else if(ext.CmpNoCase("gpkg")==0)
ds_format = "GPKG";
else if(ext.CmpNoCase("xls")==0)
ds_format = "XLS";
else if(ext.CmpNoCase("xlsx")==0)
Expand Down Expand Up @@ -182,6 +185,7 @@ IDataSource* IDataSource::CreateDataSource(wxString data_type_name,
type == GdaConst::ds_esri_personal_gdb ||
type == GdaConst::ds_odbc ||
type == GdaConst::ds_sqlite ||
type == GdaConst::ds_gpkg ||
type == GdaConst::ds_xls ||
type == GdaConst::ds_xlsx ||
type == GdaConst::ds_geo_json )
Expand Down
5 changes: 4 additions & 1 deletion DataViewer/DataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ class FileDataSource : public IDataSource {

virtual IDataSource* Clone();

virtual bool IsFileDataSource() { return ds_type == GdaConst::ds_sqlite ? false : true;}
virtual bool IsFileDataSource() {
return ds_type == GdaConst::ds_sqlite || ds_type == GdaConst::ds_gpkg ? false : true;
}

/**
* Return file path.
*/
Expand Down
1 change: 1 addition & 0 deletions DialogTools/ConnectDatasourceDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ IDataSource* ConnectDatasourceDlg::CreateDataSource()
// a special case: sqlite is a file based database, so we need to get
// avalible layers and prompt for user selecting
if (datasource->GetType() == GdaConst::ds_sqlite ||
datasource->GetType() == GdaConst::ds_gpkg||
datasource->GetType() == GdaConst::ds_osm ||
datasource->GetType() == GdaConst::ds_esri_personal_gdb||
datasource->GetType() == GdaConst::ds_esri_file_geodb)
Expand Down
1 change: 1 addition & 0 deletions DialogTools/DatasourceDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ void DatasourceDlg::Init()
ds_names.Add("GeoJSON (*.geojson;*.json)|*.geojson;*.json|"
"GeoJSON (*.geojson)|*.geojson|"
"GeoJSON (*.json)|*.json");
ds_names.Add("GeoPackage (*.gpkg)|*.gpkg");
ds_names.Add("SQLite/SpatiaLite (*.sqlite)|*.sqlite");

if( GeneralWxUtils::isWindows()){
Expand Down
4 changes: 3 additions & 1 deletion DialogTools/SaveAsDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ void SaveAsDlg::OnBrowseDatasourceBtn ( wxCommandEvent& event )
ds_type != GdaConst::ds_geo_json &&
ds_type != GdaConst::ds_mapinfo &&
ds_type != GdaConst::ds_sqlite &&
ds_type != GdaConst::ds_csv) {
ds_type != GdaConst::ds_gpkg &&
ds_type != GdaConst::ds_csv)
{
msg << "Save is not supported on current data source type: "
<< ds_format << ". Please try to use \"File->Save As\" other data source. "
<< "However, the project file can still be saved as other project file.";
Expand Down
28 changes: 22 additions & 6 deletions GdaConst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,16 @@ void GdaConst::init()
datasrc_field_illegal_regex[ds_sqlite] = wxEmptyString;
datasrc_field_casesensitive[ds_sqlite] = true;

datasrc_str_to_type["GPKG"] = ds_gpkg;
datasrc_type_to_prefix[ds_gpkg] = "";
datasrc_type_to_fullname[ds_gpkg] = "GeoPackage";
datasrc_table_lens[ds_gpkg] = 128;
datasrc_field_lens[ds_gpkg] = 128;
datasrc_field_warning[ds_gpkg] = no_field_warning;
datasrc_field_regex[ds_gpkg] = wxEmptyString;
datasrc_field_illegal_regex[ds_gpkg] = wxEmptyString;
datasrc_field_casesensitive[ds_gpkg] = true;

datasrc_str_to_type["WFS"] = ds_wfs;
datasrc_type_to_prefix[ds_wfs] = "WFS:";
datasrc_type_to_fullname[ds_wfs] = "OGC Web Feature Service";
Expand Down Expand Up @@ -670,23 +680,29 @@ void GdaConst::init()
for (ds_fld_map::iterator it=datasrc_req_flds.begin();
it != datasrc_req_flds.end(); it++) {
DataSourceType type = it->first;
if (type == ds_esri_file_geodb || type == ds_csv || type == ds_dbf ||
type == ds_gml || type == ds_kml || type == ds_mapinfo ||
type == ds_shapefile || type == ds_sqlite || type == ds_xls ||
type == ds_geo_json || type == ds_osm) {
if (type == ds_esri_file_geodb || type == ds_csv ||
type == ds_dbf || type == ds_gml ||
type == ds_kml || type == ds_mapinfo ||
type == ds_shapefile || type == ds_sqlite ||
type == ds_gpkg || type == ds_xls ||
type == ds_geo_json || type == ds_osm)
{
// These are simple files, and a file name must be supplied
it->second.insert("file");
} else if (type == ds_esri_arc_obj || type == ds_esri_personal_gdb ||
type == ds_esri_arc_sde || type == ds_mysql ||
type == ds_ms_sql || type == ds_oci || type == ds_odbc) {
type == ds_esri_arc_sde || type == ds_mysql ||
type == ds_ms_sql || type == ds_oci || type == ds_odbc)
{
it->second.insert("user");
it->second.insert("pwd");
it->second.insert("host");
it->second.insert("port");
it->second.insert("db_name");
} else if ( type == ds_wfs) {

it->second.insert("url");
} else if (type == ds_postgresql) {

it->second.insert("db_name");
}
}
Expand Down
2 changes: 1 addition & 1 deletion GdaConst.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class GdaConst {
ds_esri_personal_gdb, ds_esri_arc_sde,
ds_csv, ds_dbf, ds_geo_json, ds_gml, ds_kml,
ds_mapinfo, ds_mysql, ds_ms_sql, ds_oci, ds_odbc, ds_postgresql,
ds_shapefile, ds_sqlite, ds_wfs, ds_xls, ds_xlsx, ds_osm, ds_ods, ds_cartodb, ds_unknown };
ds_shapefile, ds_sqlite, ds_gpkg, ds_wfs, ds_xls, ds_xlsx, ds_osm, ds_ods, ds_cartodb, ds_unknown };

static std::map<std::string, DataSourceType> datasrc_str_to_type;
static std::map<DataSourceType, std::string> datasrc_type_to_str;
Expand Down
7 changes: 5 additions & 2 deletions ShapeOperations/OGRLayerProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,11 @@ bool OGRLayerProxy::AddGeometries(Shapefile::Main& p_main)
{
// NOTE: OGR/GDAL 2.0 is still implementing addGeomField feature.
// So, we only support limited datasources for adding geometries.
if ( !(ds_type == GdaConst::ds_geo_json || ds_type == GdaConst::ds_gml
|| ds_type == GdaConst::ds_kml || ds_type == GdaConst::ds_sqlite) )
if ( !(ds_type == GdaConst::ds_geo_json ||
ds_type == GdaConst::ds_gml ||
ds_type == GdaConst::ds_kml ||
ds_type == GdaConst::ds_sqlite ||
ds_type == GdaConst::ds_gpkg) )
{
return false;
}
Expand Down

0 comments on commit 3a5fd16

Please sign in to comment.