Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
otb
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main Repositories
otb
Commits
3dd9998d
Commit
3dd9998d
authored
7 years ago
by
Antoine Regimbeau
Browse files
Options
Downloads
Patches
Plain Diff
REFAC: 80 char / line remove file from old merge
parent
c288f6d8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!24
Handle extended filename for DataSource class
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Modules/Adapters/GdalAdapters/src/otbOGRDataSourceWrapper.cxx
+53
-34
53 additions, 34 deletions
...les/Adapters/GdalAdapters/src/otbOGRDataSourceWrapper.cxx
with
53 additions
and
34 deletions
Modules/Adapters/GdalAdapters/src/otbOGRDataSourceWrapper.cxx
+
53
−
34
View file @
3dd9998d
...
@@ -124,11 +124,13 @@ otb::ogr::DataSource::DataSource()
...
@@ -124,11 +124,13 @@ otb::ogr::DataSource::DataSource()
{
{
Drivers
::
Init
();
Drivers
::
Init
();
ogr
::
version_proxy
::
GDALDriverType
*
d
=
ogr
::
version_proxy
::
GetDriverByName
(
"Memory"
);
ogr
::
version_proxy
::
GDALDriverType
*
d
=
ogr
::
version_proxy
::
GetDriverByName
(
"Memory"
);
assert
(
d
&&
"OGR Memory driver not found"
);
assert
(
d
&&
"OGR Memory driver not found"
);
m_DataSource
=
ogr
::
version_proxy
::
Create
(
d
,
"in-memory"
);
m_DataSource
=
ogr
::
version_proxy
::
Create
(
d
,
"in-memory"
);
if
(
!
m_DataSource
)
{
if
(
!
m_DataSource
)
{
itkExceptionMacro
(
<<
"Failed to create OGRMemDataSource: "
<<
CPLGetLastErrorMsg
());
itkExceptionMacro
(
<<
"Failed to create OGRMemDataSource: "
<<
CPLGetLastErrorMsg
());
}
}
}
}
...
@@ -169,15 +171,18 @@ otb::ogr::DataSource::Pointer otb::ogr::DataSource::OpenDataSource(std::string c
...
@@ -169,15 +171,18 @@ otb::ogr::DataSource::Pointer otb::ogr::DataSource::OpenDataSource(std::string c
char
const
*
driverName
=
DeduceDriverName
(
datasourceName
);
char
const
*
driverName
=
DeduceDriverName
(
datasourceName
);
if
(
!
driverName
)
if
(
!
driverName
)
{
{
itkGenericExceptionMacro
(
<<
"No OGR driver known to OTB to create and handle a DataSource named <"
itkGenericExceptionMacro
(
<<
"No OGR driver known to OTB to create and "
"handle a DataSource named <"
<<
datasourceName
<<
">."
);
<<
datasourceName
<<
">."
);
}
}
ogr
::
version_proxy
::
GDALDriverType
*
d
=
ogr
::
version_proxy
::
GetDriverByName
(
driverName
);
ogr
::
version_proxy
::
GDALDriverType
*
d
=
ogr
::
version_proxy
::
GetDriverByName
(
driverName
);
if
(
!
d
)
if
(
!
d
)
{
{
itkGenericExceptionMacro
(
<<
"Could not create OGR driver "
<<
driverName
<<
", check your OGR configuration for available drivers."
);
itkGenericExceptionMacro
(
<<
"Could not create OGR driver "
<<
driverName
<<
", check your OGR configuration for available drivers."
);
}
}
source
=
ogr
::
version_proxy
::
Create
(
source
=
ogr
::
version_proxy
::
Create
(
...
@@ -185,11 +190,12 @@ otb::ogr::DataSource::Pointer otb::ogr::DataSource::OpenDataSource(std::string c
...
@@ -185,11 +190,12 @@ otb::ogr::DataSource::Pointer otb::ogr::DataSource::OpenDataSource(std::string c
simpleFileName
.
c_str
()
,
simpleFileName
.
c_str
()
,
fileNameHelper
->
GetGDALCreationOptions
()
);
fileNameHelper
->
GetGDALCreationOptions
()
);
if
(
!
source
)
{
if
(
!
source
)
{
itkGenericExceptionMacro
(
<<
"Failed to create GDALDataset <"
<<
datasourceName
itkGenericExceptionMacro
(
<<
"Failed to create GDALDataset <"
<<
"> (driver name: <"
<<
driverName
<<
">: "
<<
CPLGetLastErrorMsg
());
<<
datasourceName
<<
"> (driver name: <"
<<
driverName
<<
">: "
<<
CPLGetLastErrorMsg
());
}
}
}
}
return
otb
::
ogr
::
DataSource
::
New
(
source
,
mode
);
return
otb
::
ogr
::
DataSource
::
New
(
source
,
mode
);
}
}
void
DeleteDataSource
(
std
::
string
const
&
datasourceName
)
void
DeleteDataSource
(
std
::
string
const
&
datasourceName
)
...
@@ -207,12 +213,13 @@ otb::ogr::DataSource::New(std::string const& datasourceName, Modes::type mode)
...
@@ -207,12 +213,13 @@ otb::ogr::DataSource::New(std::string const& datasourceName, Modes::type mode)
{
{
if
(
mode
<
Modes
::
Read
||
mode
>=
Modes
::
MAX__
)
if
(
mode
<
Modes
::
Read
||
mode
>=
Modes
::
MAX__
)
{
{
itkGenericExceptionMacro
(
<<
"Wrong mode when opening "
<<
datasourceName
);
itkGenericExceptionMacro
(
<<
"Wrong mode when opening "
<<
datasourceName
);
}
}
Drivers
::
Init
();
Drivers
::
Init
();
ogr
::
version_proxy
::
GDALDatasetType
*
ds
=
ogr
::
version_proxy
::
Open
(
datasourceName
.
c_str
(),
true
);
ogr
::
version_proxy
::
GDALDatasetType
*
ds
=
ogr
::
version_proxy
::
Open
(
datasourceName
.
c_str
()
,
true
);
bool
ds_exists
=
(
ds
!=
ITK_NULLPTR
);
bool
ds_exists
=
(
ds
!=
ITK_NULLPTR
);
...
@@ -277,7 +284,8 @@ otb::ogr::Layer otb::ogr::DataSource::CreateLayer(
...
@@ -277,7 +284,8 @@ otb::ogr::Layer otb::ogr::DataSource::CreateLayer(
if
(
m_OpenMode
==
Modes
::
Read
)
if
(
m_OpenMode
==
Modes
::
Read
)
{
{
otb
::
ogr
::
Layer
l
=
GetLayerChecked
(
name
);
// will throw if not existing
otb
::
ogr
::
Layer
l
=
GetLayerChecked
(
name
);
// will throw if not existing
itkGenericOutputMacro
(
<<
"Requesting layer creation in read-only GDALDataset. Returning the existing layer"
);
itkGenericOutputMacro
(
<<
"Requesting layer creation in read-only "
"GDALDataset. Returning the existing layer"
);
return
l
;
return
l
;
}
}
...
@@ -310,7 +318,7 @@ otb::ogr::Layer otb::ogr::DataSource::CreateLayer(
...
@@ -310,7 +318,7 @@ otb::ogr::Layer otb::ogr::DataSource::CreateLayer(
if
(
!
ol
)
if
(
!
ol
)
{
{
itkGenericExceptionMacro
(
<<
"Failed to create the layer <"
<<
name
itkGenericExceptionMacro
(
<<
"Failed to create the layer <"
<<
name
<<
"> in the GDALDataset file <"
<<
GetDatasetDescription
()
<<
"> in the GDALDataset file <"
<<
GetDatasetDescription
()
<<
">: "
<<
CPLGetLastErrorMsg
());
<<
">: "
<<
CPLGetLastErrorMsg
());
}
}
...
@@ -337,7 +345,7 @@ otb::ogr::Layer otb::ogr::DataSource::CreateLayer(
...
@@ -337,7 +345,7 @@ otb::ogr::Layer otb::ogr::DataSource::CreateLayer(
if
(
!
ol
)
if
(
!
ol
)
{
{
itkGenericExceptionMacro
(
<<
"Failed to create the layer <"
<<
name
itkGenericExceptionMacro
(
<<
"Failed to create the layer <"
<<
name
<<
"> in the GDALDataset file <"
<<
GetDatasetDescription
()
<<
"> in the GDALDataset file <"
<<
GetDatasetDescription
()
<<
">: "
<<
CPLGetLastErrorMsg
());
<<
">: "
<<
CPLGetLastErrorMsg
());
}
}
...
@@ -365,7 +373,7 @@ otb::ogr::Layer otb::ogr::DataSource::CreateLayer(
...
@@ -365,7 +373,7 @@ otb::ogr::Layer otb::ogr::DataSource::CreateLayer(
if
(
!
ol
)
if
(
!
ol
)
{
{
itkGenericExceptionMacro
(
<<
"Failed to create the layer <"
<<
name
itkGenericExceptionMacro
(
<<
"Failed to create the layer <"
<<
name
<<
"> in the GDALDataset file <"
<<
GetDatasetDescription
()
<<
"> in the GDALDataset file <"
<<
GetDatasetDescription
()
<<
">: "
<<
CPLGetLastErrorMsg
());
<<
">: "
<<
CPLGetLastErrorMsg
());
}
}
...
@@ -397,7 +405,8 @@ otb::ogr::Layer otb::ogr::DataSource::CopyLayer(
...
@@ -397,7 +405,8 @@ otb::ogr::Layer otb::ogr::DataSource::CopyLayer(
itkGenericExceptionMacro
(
<<
"Invalid GDALDataset opening mode"
);
itkGenericExceptionMacro
(
<<
"Invalid GDALDataset opening mode"
);
break
;
break
;
case
Modes
::
Read
:
case
Modes
::
Read
:
itkGenericExceptionMacro
(
<<
"GDALDataset is opened in Read mode : cannot create a layer"
);
itkGenericExceptionMacro
(
<<
"GDALDataset is opened in Read mode : "
"cannot create a layer"
);
break
;
break
;
default:
default:
break
;
break
;
...
@@ -417,12 +426,12 @@ otb::ogr::Layer otb::ogr::DataSource::CopyLayer(
...
@@ -417,12 +426,12 @@ otb::ogr::Layer otb::ogr::DataSource::CopyLayer(
if
(
!
ol
)
if
(
!
ol
)
{
{
itkGenericExceptionMacro
(
<<
"Failed to copy the layer <"
itkGenericExceptionMacro
(
<<
"Failed to copy the layer <"
<<
srcLayer
.
GetName
()
<<
"> into the new layer <"
<<
newName
<<
srcLayer
.
GetName
()
<<
"> into the new layer <"
<<
newName
<<
"> in the GDALDataset file <"
<<
GetDatasetDescription
()
<<
"> in the GDALDataset file <"
<<
GetDatasetDescription
()
<<
">: "
<<
CPLGetLastErrorMsg
());
<<
">: "
<<
CPLGetLastErrorMsg
());
}
}
const
bool
modifiable
=
true
;
const
bool
modifiable
=
true
;
Layer
l
(
ol
,
modifiable
);
Layer
l
(
ol
,
modifiable
);
return
l
;
return
l
;
}
}
...
@@ -437,10 +446,12 @@ void otb::ogr::DataSource::DeleteLayer(size_t i)
...
@@ -437,10 +446,12 @@ void otb::ogr::DataSource::DeleteLayer(size_t i)
itkGenericExceptionMacro
(
<<
"Invalid GDALDataset opening mode"
);
itkGenericExceptionMacro
(
<<
"Invalid GDALDataset opening mode"
);
break
;
break
;
case
Modes
::
Read
:
case
Modes
::
Read
:
itkGenericExceptionMacro
(
<<
"GDALDataset is opened in Read mode : cannot delete a layer"
);
itkGenericExceptionMacro
(
<<
"GDALDataset is opened in Read mode : "
"cannot delete a layer"
);
break
;
break
;
case
Modes
::
Update_LayerCreateOnly
:
case
Modes
::
Update_LayerCreateOnly
:
itkGenericExceptionMacro
(
<<
"GDALDataset is opened in Update_LayerCreateOnly mode : cannot delete a layer"
);
itkGenericExceptionMacro
(
<<
"GDALDataset is opened in "
"Update_LayerCreateOnly mode : cannot delete a layer"
);
break
;
break
;
default:
default:
break
;
break
;
...
@@ -449,14 +460,16 @@ void otb::ogr::DataSource::DeleteLayer(size_t i)
...
@@ -449,14 +460,16 @@ void otb::ogr::DataSource::DeleteLayer(size_t i)
const
int
nb_layers
=
GetLayersCount
();
const
int
nb_layers
=
GetLayersCount
();
if
(
int
(
i
)
>=
nb_layers
)
if
(
int
(
i
)
>=
nb_layers
)
{
{
itkExceptionMacro
(
<<
"Cannot delete "
<<
i
<<
"th layer in the GDALDataset <"
itkExceptionMacro
(
<<
"Cannot delete "
<<
i
<<
GetDatasetDescription
()
<<
"> as it contains only "
<<
nb_layers
<<
"layers."
);
<<
"th layer in the GDALDataset <"
<<
GetDatasetDescription
()
<<
"> as it contains only "
<<
nb_layers
<<
"layers."
);
}
}
const
OGRErr
err
=
m_DataSource
->
DeleteLayer
(
int
(
i
));
const
OGRErr
err
=
m_DataSource
->
DeleteLayer
(
int
(
i
));
if
(
err
!=
OGRERR_NONE
)
if
(
err
!=
OGRERR_NONE
)
{
{
itkExceptionMacro
(
<<
"Cannot delete "
<<
i
<<
"th layer in the GDALDataset <"
itkExceptionMacro
(
<<
"Cannot delete "
<<
i
<<
GetDatasetDescription
()
<<
">: "
<<
CPLGetLastErrorMsg
());
<<
"th layer in the GDALDataset <"
<<
GetDatasetDescription
()
<<
">: "
<<
CPLGetLastErrorMsg
());
}
}
}
}
...
@@ -513,7 +526,7 @@ size_t otb::ogr::DataSource::GetLayerID(std::string const& name) const
...
@@ -513,7 +526,7 @@ size_t otb::ogr::DataSource::GetLayerID(std::string const& name) const
if
(
id
<
0
)
if
(
id
<
0
)
{
{
itkExceptionMacro
(
<<
"Cannot fetch any layer named <"
<<
name
itkExceptionMacro
(
<<
"Cannot fetch any layer named <"
<<
name
<<
"> in the GDALDataset <"
<<
GetDatasetDescription
()
<<
">: "
<<
"> in the GDALDataset <"
<<
GetDatasetDescription
()
<<
">: "
<<
CPLGetLastErrorMsg
());
<<
CPLGetLastErrorMsg
());
}
}
return
0
;
// keep compiler happy
return
0
;
// keep compiler happy
...
@@ -526,13 +539,15 @@ otb::ogr::Layer otb::ogr::DataSource::GetLayerChecked(size_t i)
...
@@ -526,13 +539,15 @@ otb::ogr::Layer otb::ogr::DataSource::GetLayerChecked(size_t i)
if
(
int
(
i
)
>=
nb_layers
)
if
(
int
(
i
)
>=
nb_layers
)
{
{
itkExceptionMacro
(
<<
"Cannot fetch "
<<
i
<<
"th layer in the GDALDataset <"
itkExceptionMacro
(
<<
"Cannot fetch "
<<
i
<<
"th layer in the GDALDataset <"
<<
GetDatasetDescription
()
<<
"> as it contains only "
<<
nb_layers
<<
"layers."
);
<<
GetDatasetDescription
()
<<
"> as it contains only "
<<
nb_layers
<<
"layers."
);
}
}
OGRLayer
*
layer_ptr
=
m_DataSource
->
GetLayer
(
int
(
i
));
OGRLayer
*
layer_ptr
=
m_DataSource
->
GetLayer
(
int
(
i
));
if
(
!
layer_ptr
)
if
(
!
layer_ptr
)
{
{
itkExceptionMacro
(
<<
"Unexpected error: cannot fetch "
<<
i
<<
"th layer in the GDALDataset <"
itkExceptionMacro
(
<<
"Unexpected error: cannot fetch "
<<
i
<<
GetDatasetDescription
()
<<
">: "
<<
CPLGetLastErrorMsg
());
<<
"th layer in the GDALDataset <"
<<
GetDatasetDescription
()
<<
">: "
<<
CPLGetLastErrorMsg
());
}
}
return
otb
::
ogr
::
Layer
(
layer_ptr
,
IsLayerModifiable
(
i
));
return
otb
::
ogr
::
Layer
(
layer_ptr
,
IsLayerModifiable
(
i
));
}
}
...
@@ -582,8 +597,9 @@ otb::ogr::Layer otb::ogr::DataSource::ExecuteSQL(
...
@@ -582,8 +597,9 @@ otb::ogr::Layer otb::ogr::DataSource::ExecuteSQL(
if
(
!
layer_ptr
)
if
(
!
layer_ptr
)
{
{
#if defined(PREFER_EXCEPTION)
#if defined(PREFER_EXCEPTION)
itkExceptionMacro
(
<<
"Unexpected error: cannot execute the SQL request <"
<<
statement
itkExceptionMacro
(
<<
"Unexpected error: cannot execute the SQL request <"
<<
"> in the GDALDataset <"
<<
GetDatasetDescription
()
<<
">: "
<<
CPLGetLastErrorMsg
());
<<
statement
<<
"> in the GDALDataset <"
<<
GetDatasetDescription
()
<<
">: "
<<
CPLGetLastErrorMsg
());
#else
#else
// Cannot use the deleter made for result sets obtained from
// Cannot use the deleter made for result sets obtained from
// GDALDataset::ExecuteSQL because it checks for non-nullity....
// GDALDataset::ExecuteSQL because it checks for non-nullity....
...
@@ -659,7 +675,8 @@ OGREnvelope otb::ogr::DataSource::GetGlobalExtent(bool force/* = false */, std::
...
@@ -659,7 +675,8 @@ OGREnvelope otb::ogr::DataSource::GetGlobalExtent(bool force/* = false */, std::
if
(
lit
==
this
->
end
())
if
(
lit
==
this
->
end
())
{
{
itkGenericExceptionMacro
(
<<
"Cannot compute global extent because there are no layers in the DataSource"
);
itkGenericExceptionMacro
(
<<
"Cannot compute global extent because there "
"are no layers in the DataSource"
);
}
}
const
OGRSpatialReference
*
ref_srs
=
lit
->
GetSpatialRef
();
const
OGRSpatialReference
*
ref_srs
=
lit
->
GetSpatialRef
();
...
@@ -763,16 +780,18 @@ void otb::ogr::DataSource::SyncToDisk()
...
@@ -763,16 +780,18 @@ void otb::ogr::DataSource::SyncToDisk()
if
(
!
ret
)
if
(
!
ret
)
{
{
itkExceptionMacro
(
<<
"Cannot flush the pending of the OGRDataSource <"
itkExceptionMacro
(
<<
"Cannot flush the pending of the OGRDataSource <"
<<
GetDatasetDescription
()
<<
">: "
<<
CPLGetLastErrorMsg
());
<<
GetDatasetDescription
()
<<
">: "
<<
CPLGetLastErrorMsg
());
}
}
}
}
std
::
string
otb
::
ogr
::
DataSource
::
GetDatasetDescription
()
const
std
::
string
otb
::
ogr
::
DataSource
::
GetDatasetDescription
()
const
{
{
std
::
vector
<
std
::
string
>
files
=
otb
::
ogr
::
version_proxy
::
GetFileListAsStringVector
(
m_DataSource
);
std
::
vector
<
std
::
string
>
files
=
otb
::
ogr
::
version_proxy
::
GetFileListAsStringVector
(
m_DataSource
);
std
::
string
description
=
""
;
std
::
string
description
=
""
;
for
(
std
::
vector
<
std
::
string
>::
const_iterator
it
=
files
.
begin
();
it
!=
files
.
end
();
++
it
)
for
(
std
::
vector
<
std
::
string
>::
const_iterator
it
=
files
.
begin
()
;
it
!=
files
.
end
()
;
++
it
)
description
+=
(
*
it
)
+
", "
;
description
+=
(
*
it
)
+
", "
;
return
description
;
return
description
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment