Skip to content

Commit

Permalink
Merge pull request #5057 from boundlessgeo/gpkg-raster-import2
Browse files Browse the repository at this point in the history
Geopackage: handle raster drop in browser
  • Loading branch information
elpaso committed Aug 29, 2017
2 parents c3a737b + 487adb4 commit daa60d1
Show file tree
Hide file tree
Showing 15 changed files with 564 additions and 180 deletions.
2 changes: 1 addition & 1 deletion INSTALL
Expand Up @@ -102,7 +102,7 @@ Required build dependencies:
- Sqlite3 >= 3.0.0
- SpatiaLite
- libspatialindex
- GDAL/OGR >= 2.0
- GDAL/OGR >= 2.1
- Qwt >= 5.0 & (< 6.1 with internal QwtPolar)
- expat >= 1.95
- QScintilla2
Expand Down
12 changes: 9 additions & 3 deletions cmake/FindGDAL.cmake
Expand Up @@ -62,8 +62,11 @@ ELSE(WIN32)
STRING(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\1" GDAL_VERSION_MAJOR "${GDAL_VERSION}")
STRING(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\2" GDAL_VERSION_MINOR "${GDAL_VERSION}")
IF (GDAL_VERSION_MAJOR LESS 2)
MESSAGE (FATAL_ERROR "GDAL version is too old (${GDAL_VERSION}). Use 2.0 or higher.")
MESSAGE (FATAL_ERROR "GDAL version is too old (${GDAL_VERSION}). Use 2.1 or higher.")
ENDIF (GDAL_VERSION_MAJOR LESS 2)
IF ( (GDAL_VERSION_MAJOR EQUAL 2) AND (GDAL_VERSION_MINOR LESS 1) )
MESSAGE (FATAL_ERROR "GDAL version is too old (${GDAL_VERSION}). Use 2.1 or higher.")
ENDIF( (GDAL_VERSION_MAJOR EQUAL 2) AND (GDAL_VERSION_MINOR LESS 1) )

ENDIF (GDAL_LIBRARY)
SET (CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK_save} CACHE STRING "" FORCE)
Expand Down Expand Up @@ -101,10 +104,13 @@ ELSE(WIN32)

# check for gdal version
# version 1.2.5 is known NOT to be supported (missing CPL_STDCALL macro)
# According to INSTALL, 2.0+ is required
# According to INSTALL, 2.1+ is required
IF (GDAL_VERSION_MAJOR LESS 2)
MESSAGE (FATAL_ERROR "GDAL version is too old (${GDAL_VERSION}). Use 2.0 or higher.")
MESSAGE (FATAL_ERROR "GDAL version is too old (${GDAL_VERSION}). Use 2.1 or higher.")
ENDIF (GDAL_VERSION_MAJOR LESS 2)
IF ( (GDAL_VERSION_MAJOR EQUAL 2) AND (GDAL_VERSION_MINOR LESS 1) )
MESSAGE (FATAL_ERROR "GDAL version is too old (${GDAL_VERSION}). Use 2.1 or higher.")
ENDIF( (GDAL_VERSION_MAJOR EQUAL 2) AND (GDAL_VERSION_MINOR LESS 1) )

# set INCLUDE_DIR to prefix+include
EXEC_PROGRAM(${GDAL_CONFIG}
Expand Down
8 changes: 8 additions & 0 deletions python/core/qgsmimedatautils.sip
Expand Up @@ -48,6 +48,14 @@ Returns encoded representation of the object
:rtype: QgsVectorLayer
%End

QgsRasterLayer *rasterLayer( bool &owner, QString &error ) const;
%Docstring
Get raster layer from uri if possible, otherwise returns 0 and error is set
\param owner set to true if caller becomes owner
\param error set to error message if cannot get raster
:rtype: QgsRasterLayer
%End

QString layerType;
%Docstring
Type of URI. Recognized types: "vector" / "raster" / "plugin" / "custom"
Expand Down
12 changes: 12 additions & 0 deletions src/core/qgsmimedatautils.cpp
Expand Up @@ -100,6 +100,18 @@ QgsVectorLayer *QgsMimeDataUtils::Uri::vectorLayer( bool &owner, QString &error
return new QgsVectorLayer( uri, name, providerKey );
}

QgsRasterLayer *QgsMimeDataUtils::Uri::rasterLayer( bool &owner, QString &error ) const
{
owner = false;
if ( layerType != QLatin1String( "raster" ) )
{
error = QObject::tr( "%1: Not a raster layer." ).arg( name );
return nullptr;
}
owner = true;
return new QgsRasterLayer( uri, name, providerKey );
}

// -----

bool QgsMimeDataUtils::isUriList( const QMimeData *data )
Expand Down
7 changes: 7 additions & 0 deletions src/core/qgsmimedatautils.h
Expand Up @@ -23,6 +23,7 @@
class QgsLayerItem;
class QgsLayerTreeNode;
class QgsVectorLayer;
class QgsRasterLayer;

/** \ingroup core
* \class QgsMimeDataUtils
Expand Down Expand Up @@ -51,6 +52,12 @@ class CORE_EXPORT QgsMimeDataUtils
*/
QgsVectorLayer *vectorLayer( bool &owner, QString &error ) const;

/** Get raster layer from uri if possible, otherwise returns 0 and error is set
* \param owner set to true if caller becomes owner
* \param error set to error message if cannot get raster
*/
QgsRasterLayer *rasterLayer( bool &owner, QString &error ) const;

//! Type of URI. Recognized types: "vector" / "raster" / "plugin" / "custom"
QString layerType;
//! For "vector" / "raster" type: provider id.
Expand Down
15 changes: 0 additions & 15 deletions src/core/qgsvectorfilewriter.cpp
Expand Up @@ -808,15 +808,9 @@ QMap<QString, QgsVectorFileWriter::MetaData> QgsVectorFileWriter::initMetaData()
"Can be one of NULL for a simple .dbf file with no .shp file, POINT, "
"ARC, POLYGON or MULTIPOINT for 2D, or POINTZ, ARCZ, POLYGONZ or "
"MULTIPOINTZ for 3D;" ) +
#if defined(GDAL_COMPUTE_VERSION) && GDAL_VERSION_NUM < GDAL_COMPUTE_VERSION(2,1,0)
QObject::tr( " Shapefiles with measure values are not supported,"
" nor are MULTIPATCH files." ) +
#endif
#if defined(GDAL_COMPUTE_VERSION) && GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,1,0)
QObject::tr( " POINTM, ARCM, POLYGONM or MULTIPOINTM for measured geometries"
" and POINTZM, ARCZM, POLYGONZM or MULTIPOINTZM for 3D measured"
" geometries." ) +
#endif
#if defined(GDAL_COMPUTE_VERSION) && GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,2,0)
QObject::tr( " MULTIPATCH files are supported since GDAL 2.2." ) +
#endif
Expand All @@ -831,7 +825,6 @@ QMap<QString, QgsVectorFileWriter::MetaData> QgsVectorFileWriter::initMetaData()
<< QStringLiteral( "ARCZ" )
<< QStringLiteral( "POLYGONZ" )
<< QStringLiteral( "MULTIPOINTZ" )
#if defined(GDAL_COMPUTE_VERSION) && GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,1,0)
<< QStringLiteral( "POINTM" )
<< QStringLiteral( "ARCM" )
<< QStringLiteral( "POLYGONM" )
Expand All @@ -840,7 +833,6 @@ QMap<QString, QgsVectorFileWriter::MetaData> QgsVectorFileWriter::initMetaData()
<< QStringLiteral( "ARCZM" )
<< QStringLiteral( "POLYGONZM" )
<< QStringLiteral( "MULTIPOINTZM" )
#endif
#if defined(GDAL_COMPUTE_VERSION) && GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,2,0)
<< QStringLiteral( "MULTIPATCH" )
#endif
Expand Down Expand Up @@ -1330,23 +1322,19 @@ QMap<QString, QgsVectorFileWriter::MetaData> QgsVectorFileWriter::initMetaData()
true // Allow None
) );

#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,0,2)
datasetOptions.insert( QStringLiteral( "BLOCK_SIZE" ), new IntOption(
QObject::tr( "(multiples of 512): Block size for .map files. Defaults "
"to 512. MapInfo 15.2 and above creates .tab files with a "
"blocksize of 16384 bytes. Any MapInfo version should be "
"able to handle block sizes from 512 to 32256." ),
512
) );
#endif
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,0,0)
layerOptions.insert( QStringLiteral( "BOUNDS" ), new StringOption(
QObject::tr( "xmin,ymin,xmax,ymax: Define custom layer bounds to increase the "
"accuracy of the coordinates. Note: the geometry of written "
"features must be within the defined box." ),
QLatin1String( "" ) // Default value
) );
#endif

driverMetadata.insert( QStringLiteral( "MapInfo File" ),
MetaData(
Expand Down Expand Up @@ -1894,9 +1882,6 @@ QStringList QgsVectorFileWriter::defaultLayerOptions( const QString &driverName

OGRwkbGeometryType QgsVectorFileWriter::ogrTypeFromWkbType( QgsWkbTypes::Type type )
{
#if GDAL_VERSION_NUM < GDAL_COMPUTE_VERSION(2,1,0)
type = QgsWkbTypes::dropM( type );
#endif

OGRwkbGeometryType ogrType = static_cast<OGRwkbGeometryType>( type );

Expand Down
3 changes: 3 additions & 0 deletions src/providers/ogr/CMakeLists.txt
Expand Up @@ -8,6 +8,8 @@ SET (OGR_SRCS
qgsogrsourceselect.cpp
qgsgeopackagedataitems.cpp
qgsgeopackageconnection.cpp
qgsgeopackagerasterwriter.cpp
qgsgeopackagerasterwritertask.cpp
)

SET(OGR_MOC_HDRS
Expand All @@ -17,6 +19,7 @@ SET(OGR_MOC_HDRS
qgsogrsourceselect.h
qgsgeopackagedataitems.h
qgsgeopackageconnection.h
qgsgeopackagerasterwritertask.h
)

########################################################
Expand Down
48 changes: 48 additions & 0 deletions src/providers/ogr/qgscplerrorhandler.h
@@ -0,0 +1,48 @@
/***************************************************************************
qgscplerrorhandler.h - QgsCplErrorHandler
---------------------
begin : Oct 29, 2003
copyright : (C) 2003 by Gary E.Sherman
email : sherman at mrcc.com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSCPLERRORHANDLER_H
#define QGSCPLERRORHANDLER_H

#include "gdal.h"
#include "qgsmessagelog.h"

class QgsCPLErrorHandler
{
static void CPL_STDCALL showError( CPLErr errClass, int errNo, const char *msg )
{
if ( errNo != OGRERR_NONE )
QgsMessageLog::logMessage( QObject::tr( "OGR[%1] error %2: %3" ).arg( errClass ).arg( errNo ).arg( msg ), QObject::tr( "OGR" ) );
}

public:
QgsCPLErrorHandler()
{
CPLPushErrorHandler( showError );
}

~QgsCPLErrorHandler()
{
CPLPopErrorHandler();
}

private:
QgsCPLErrorHandler( const QgsCPLErrorHandler &other );
QgsCPLErrorHandler &operator=( const QgsCPLErrorHandler &other );

};


#endif // QGSCPLERRORHANDLER_H

0 comments on commit daa60d1

Please sign in to comment.