mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-16 00:05:45 -04:00
Address review (miscellaneous): Scale parameter from long to double; use processing API to create temp files
This commit is contained in:
parent
0583b3ddb2
commit
9e67aca98f
@ -7,7 +7,7 @@ except (NameError, AttributeError):
|
|||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
QgsProcessingRasterLayerDefinition.__attribute_docs__ = {'source': "Source definition. Usually a static property set to a source layer's ID or file name.", 'referenceScale': 'If set to a value > 0, sets a scale at which a raster (e.g., a WMS) should be requested or rendered.', 'dpi': 'Indicates the resolution of the raster source (e.g., a WMS server). By default 96 DPI.'}
|
QgsProcessingRasterLayerDefinition.__attribute_docs__ = {'source': "Source definition. Usually a static property set to a source layer's ID or file name.", 'referenceScale': 'If set to a value > 0, sets a scale at which a raster (e.g., a WMS) should be requested or rendered.', 'dpi': 'Indicates the resolution of the raster source (e.g., a WMS server). By default 96 DPI.'}
|
||||||
QgsProcessingRasterLayerDefinition.__annotations__ = {'source': 'QgsProperty', 'referenceScale': int, 'dpi': int}
|
QgsProcessingRasterLayerDefinition.__annotations__ = {'source': 'QgsProperty', 'referenceScale': float, 'dpi': int}
|
||||||
QgsProcessingRasterLayerDefinition.__group__ = ['processing']
|
QgsProcessingRasterLayerDefinition.__group__ = ['processing']
|
||||||
except (NameError, AttributeError):
|
except (NameError, AttributeError):
|
||||||
pass
|
pass
|
||||||
|
@ -135,7 +135,7 @@ algorithm.
|
|||||||
%End
|
%End
|
||||||
public:
|
public:
|
||||||
|
|
||||||
QgsProcessingRasterLayerDefinition( const QString &source = QString(), const long referenceScale = 0, const int dpi = 96 );
|
QgsProcessingRasterLayerDefinition( const QString &source = QString(), const double referenceScale = 0, const int dpi = 96 );
|
||||||
%Docstring
|
%Docstring
|
||||||
Constructor for QgsProcessingRasterLayerDefinition, accepting a static
|
Constructor for QgsProcessingRasterLayerDefinition, accepting a static
|
||||||
string ``source``.
|
string ``source``.
|
||||||
@ -148,7 +148,7 @@ The optional ``dpi`` argument can be used to specify the resolution a
|
|||||||
raster provider (e.g., a WMS server) is using to generate the raster.
|
raster provider (e.g., a WMS server) is using to generate the raster.
|
||||||
%End
|
%End
|
||||||
|
|
||||||
QgsProcessingRasterLayerDefinition( const QgsProperty &source, const long referenceScale = 0, const int dpi = 96 );
|
QgsProcessingRasterLayerDefinition( const QgsProperty &source, const double referenceScale = 0, const int dpi = 96 );
|
||||||
%Docstring
|
%Docstring
|
||||||
Constructor for QgsProcessingRasterLayerDefinition, accepting a
|
Constructor for QgsProcessingRasterLayerDefinition, accepting a
|
||||||
QgsProperty source.
|
QgsProperty source.
|
||||||
@ -163,7 +163,7 @@ raster provider (e.g., a WMS server) is using to generate the raster.
|
|||||||
|
|
||||||
QgsProperty source;
|
QgsProperty source;
|
||||||
|
|
||||||
long referenceScale;
|
double referenceScale;
|
||||||
|
|
||||||
int dpi;
|
int dpi;
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ except (NameError, AttributeError):
|
|||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
QgsProcessingRasterLayerDefinition.__attribute_docs__ = {'source': "Source definition. Usually a static property set to a source layer's ID or file name.", 'referenceScale': 'If set to a value > 0, sets a scale at which a raster (e.g., a WMS) should be requested or rendered.', 'dpi': 'Indicates the resolution of the raster source (e.g., a WMS server). By default 96 DPI.'}
|
QgsProcessingRasterLayerDefinition.__attribute_docs__ = {'source': "Source definition. Usually a static property set to a source layer's ID or file name.", 'referenceScale': 'If set to a value > 0, sets a scale at which a raster (e.g., a WMS) should be requested or rendered.', 'dpi': 'Indicates the resolution of the raster source (e.g., a WMS server). By default 96 DPI.'}
|
||||||
QgsProcessingRasterLayerDefinition.__annotations__ = {'source': 'QgsProperty', 'referenceScale': int, 'dpi': int}
|
QgsProcessingRasterLayerDefinition.__annotations__ = {'source': 'QgsProperty', 'referenceScale': float, 'dpi': int}
|
||||||
QgsProcessingRasterLayerDefinition.__group__ = ['processing']
|
QgsProcessingRasterLayerDefinition.__group__ = ['processing']
|
||||||
except (NameError, AttributeError):
|
except (NameError, AttributeError):
|
||||||
pass
|
pass
|
||||||
|
@ -135,7 +135,7 @@ algorithm.
|
|||||||
%End
|
%End
|
||||||
public:
|
public:
|
||||||
|
|
||||||
QgsProcessingRasterLayerDefinition( const QString &source = QString(), const long referenceScale = 0, const int dpi = 96 );
|
QgsProcessingRasterLayerDefinition( const QString &source = QString(), const double referenceScale = 0, const int dpi = 96 );
|
||||||
%Docstring
|
%Docstring
|
||||||
Constructor for QgsProcessingRasterLayerDefinition, accepting a static
|
Constructor for QgsProcessingRasterLayerDefinition, accepting a static
|
||||||
string ``source``.
|
string ``source``.
|
||||||
@ -148,7 +148,7 @@ The optional ``dpi`` argument can be used to specify the resolution a
|
|||||||
raster provider (e.g., a WMS server) is using to generate the raster.
|
raster provider (e.g., a WMS server) is using to generate the raster.
|
||||||
%End
|
%End
|
||||||
|
|
||||||
QgsProcessingRasterLayerDefinition( const QgsProperty &source, const long referenceScale = 0, const int dpi = 96 );
|
QgsProcessingRasterLayerDefinition( const QgsProperty &source, const double referenceScale = 0, const int dpi = 96 );
|
||||||
%Docstring
|
%Docstring
|
||||||
Constructor for QgsProcessingRasterLayerDefinition, accepting a
|
Constructor for QgsProcessingRasterLayerDefinition, accepting a
|
||||||
QgsProperty source.
|
QgsProperty source.
|
||||||
@ -163,7 +163,7 @@ raster provider (e.g., a WMS server) is using to generate the raster.
|
|||||||
|
|
||||||
QgsProperty source;
|
QgsProperty source;
|
||||||
|
|
||||||
long referenceScale;
|
double referenceScale;
|
||||||
|
|
||||||
int dpi;
|
int dpi;
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@ __date__ = "September 2013"
|
|||||||
__copyright__ = "(C) 2013, Alexander Bruy"
|
__copyright__ = "(C) 2013, Alexander Bruy"
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import tempfile
|
|
||||||
|
|
||||||
from qgis.PyQt.QtGui import QIcon
|
from qgis.PyQt.QtGui import QIcon
|
||||||
|
|
||||||
@ -37,6 +36,7 @@ from qgis.core import (
|
|||||||
QgsProcessingParameterBoolean,
|
QgsProcessingParameterBoolean,
|
||||||
QgsProcessingParameterRasterDestination,
|
QgsProcessingParameterRasterDestination,
|
||||||
QgsProcessingRasterLayerDefinition,
|
QgsProcessingRasterLayerDefinition,
|
||||||
|
QgsProcessingUtils,
|
||||||
)
|
)
|
||||||
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
|
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
|
||||||
from processing.algs.gdal.GdalUtils import GdalConnectionDetails, GdalUtils
|
from processing.algs.gdal.GdalUtils import GdalConnectionDetails, GdalUtils
|
||||||
@ -212,7 +212,9 @@ class ClipRasterByExtent(GdalAlgorithm):
|
|||||||
width, height = GdalUtils._wms_dimensions_for_scale(
|
width, height = GdalUtils._wms_dimensions_for_scale(
|
||||||
bbox, inLayer.crs(), scale, dpi, distanceArea
|
bbox, inLayer.crs(), scale, dpi, distanceArea
|
||||||
)
|
)
|
||||||
wms_description_file_path = tempfile.mktemp("_wms_description_file.xml")
|
wms_description_file_path = QgsProcessingUtils.generateTempFilename(
|
||||||
|
"wms_description_file.xml", context
|
||||||
|
)
|
||||||
res_xml_wms, xml_wms_error = GdalUtils.gdal_wms_xml_description_file(
|
res_xml_wms, xml_wms_error = GdalUtils.gdal_wms_xml_description_file(
|
||||||
inLayer,
|
inLayer,
|
||||||
GdalUtils._get_wms_version(inLayer),
|
GdalUtils._get_wms_version(inLayer),
|
||||||
|
@ -20,7 +20,6 @@ __date__ = "September 2013"
|
|||||||
__copyright__ = "(C) 2013, Alexander Bruy"
|
__copyright__ = "(C) 2013, Alexander Bruy"
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import tempfile
|
|
||||||
|
|
||||||
from qgis.PyQt.QtGui import QIcon
|
from qgis.PyQt.QtGui import QIcon
|
||||||
|
|
||||||
@ -40,6 +39,7 @@ from qgis.core import (
|
|||||||
QgsProcessingParameterBoolean,
|
QgsProcessingParameterBoolean,
|
||||||
QgsProcessingParameterRasterDestination,
|
QgsProcessingParameterRasterDestination,
|
||||||
QgsProcessingRasterLayerDefinition,
|
QgsProcessingRasterLayerDefinition,
|
||||||
|
QgsProcessingUtils,
|
||||||
)
|
)
|
||||||
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
|
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
|
||||||
from processing.algs.gdal.GdalUtils import GdalConnectionDetails, GdalUtils
|
from processing.algs.gdal.GdalUtils import GdalConnectionDetails, GdalUtils
|
||||||
@ -328,7 +328,9 @@ class ClipRasterByMask(GdalAlgorithm):
|
|||||||
width, height = GdalUtils._wms_dimensions_for_scale(
|
width, height = GdalUtils._wms_dimensions_for_scale(
|
||||||
_bbox, inLayer.crs(), scale, dpi, distanceArea
|
_bbox, inLayer.crs(), scale, dpi, distanceArea
|
||||||
)
|
)
|
||||||
wms_description_file_path = tempfile.mktemp("_wms_description_file.xml")
|
wms_description_file_path = QgsProcessingUtils.generateTempFilename(
|
||||||
|
"wms_description_file.xml", context
|
||||||
|
)
|
||||||
res_xml_wms, xml_wms_error = GdalUtils.gdal_wms_xml_description_file(
|
res_xml_wms, xml_wms_error = GdalUtils.gdal_wms_xml_description_file(
|
||||||
inLayer,
|
inLayer,
|
||||||
GdalUtils._get_wms_version(inLayer),
|
GdalUtils._get_wms_version(inLayer),
|
||||||
|
@ -54,6 +54,7 @@ from qgis.core import (
|
|||||||
from qgis.PyQt.QtCore import (
|
from qgis.PyQt.QtCore import (
|
||||||
QCoreApplication,
|
QCoreApplication,
|
||||||
QFile,
|
QFile,
|
||||||
|
QIODevice,
|
||||||
QProcess,
|
QProcess,
|
||||||
QTextStream,
|
QTextStream,
|
||||||
)
|
)
|
||||||
@ -699,7 +700,7 @@ class GdalUtils:
|
|||||||
xml_file = QFile(out_path)
|
xml_file = QFile(out_path)
|
||||||
res = False
|
res = False
|
||||||
error_msg = ""
|
error_msg = ""
|
||||||
if xml_file.open(QFile.WriteOnly):
|
if xml_file.open(QIODevice.OpenModeFlag.WriteOnly):
|
||||||
file_stream = QTextStream(xml_file)
|
file_stream = QTextStream(xml_file)
|
||||||
doc.save(file_stream, 2)
|
doc.save(file_stream, 2)
|
||||||
res = True
|
res = True
|
||||||
|
@ -24,7 +24,7 @@ import os
|
|||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
from qgis.PyQt.QtCore import QFile
|
from qgis.PyQt.QtCore import QFile, QIODevice
|
||||||
from qgis.PyQt.QtXml import QDomDocument
|
from qgis.PyQt.QtXml import QDomDocument
|
||||||
|
|
||||||
from qgis.core import (
|
from qgis.core import (
|
||||||
@ -430,7 +430,7 @@ class TestGdalAlgorithms(QgisTestCase):
|
|||||||
|
|
||||||
# Compare obtained file with and expected data
|
# Compare obtained file with and expected data
|
||||||
out_file = QFile(out_path)
|
out_file = QFile(out_path)
|
||||||
self.assertTrue(out_file.open(QFile.ReadOnly))
|
self.assertTrue(out_file.open(QIODevice.OpenModeFlag.ReadOnly))
|
||||||
|
|
||||||
doc = QDomDocument()
|
doc = QDomDocument()
|
||||||
self.assertTrue(doc.setContent(out_file))
|
self.assertTrue(doc.setContent(out_file))
|
||||||
@ -495,7 +495,7 @@ class TestGdalAlgorithms(QgisTestCase):
|
|||||||
|
|
||||||
# Compare obtained file with and expected data
|
# Compare obtained file with and expected data
|
||||||
out_file = QFile(out_path)
|
out_file = QFile(out_path)
|
||||||
self.assertTrue(out_file.open(QFile.ReadOnly))
|
self.assertTrue(out_file.open(QIODevice.OpenModeFlag.ReadOnly))
|
||||||
|
|
||||||
doc = QDomDocument()
|
doc = QDomDocument()
|
||||||
self.assertTrue(doc.setContent(out_file))
|
self.assertTrue(doc.setContent(out_file))
|
||||||
@ -561,7 +561,7 @@ class TestGdalAlgorithms(QgisTestCase):
|
|||||||
|
|
||||||
# Compare obtained file with and expected data
|
# Compare obtained file with and expected data
|
||||||
out_file = QFile(out_path)
|
out_file = QFile(out_path)
|
||||||
self.assertTrue(out_file.open(QFile.ReadOnly))
|
self.assertTrue(out_file.open(QIODevice.OpenModeFlag.ReadOnly))
|
||||||
|
|
||||||
doc = QDomDocument()
|
doc = QDomDocument()
|
||||||
self.assertTrue(doc.setContent(out_file))
|
self.assertTrue(doc.setContent(out_file))
|
||||||
|
@ -75,7 +75,7 @@ QVariant QgsProcessingRasterLayerDefinition::toVariant() const
|
|||||||
{
|
{
|
||||||
QVariantMap map;
|
QVariantMap map;
|
||||||
map.insert( QStringLiteral( "source" ), source.toVariant() );
|
map.insert( QStringLiteral( "source" ), source.toVariant() );
|
||||||
map.insert( QStringLiteral( "reference_scale" ), QVariant::fromValue( referenceScale ) );
|
map.insert( QStringLiteral( "reference_scale" ), referenceScale );
|
||||||
map.insert( QStringLiteral( "dpi" ), dpi );
|
map.insert( QStringLiteral( "dpi" ), dpi );
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
@ -83,7 +83,7 @@ QVariant QgsProcessingRasterLayerDefinition::toVariant() const
|
|||||||
bool QgsProcessingRasterLayerDefinition::loadVariant( const QVariantMap &map )
|
bool QgsProcessingRasterLayerDefinition::loadVariant( const QVariantMap &map )
|
||||||
{
|
{
|
||||||
source.loadVariant( map.value( QStringLiteral( "source" ) ) );
|
source.loadVariant( map.value( QStringLiteral( "source" ) ) );
|
||||||
referenceScale = map.value( QStringLiteral( "reference_scale" ), 0 ).toLongLong();
|
referenceScale = map.value( QStringLiteral( "reference_scale" ), 0 ).toDouble();
|
||||||
dpi = map.value( QStringLiteral( "dpi" ), 0 ).toInt();
|
dpi = map.value( QStringLiteral( "dpi" ), 0 ).toInt();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -212,7 +212,7 @@ class CORE_EXPORT QgsProcessingRasterLayerDefinition
|
|||||||
* The optional \a dpi argument can be used to specify the resolution a raster provider
|
* The optional \a dpi argument can be used to specify the resolution a raster provider
|
||||||
* (e.g., a WMS server) is using to generate the raster.
|
* (e.g., a WMS server) is using to generate the raster.
|
||||||
*/
|
*/
|
||||||
QgsProcessingRasterLayerDefinition( const QString &source = QString(), const long referenceScale = 0, const int dpi = 96 )
|
QgsProcessingRasterLayerDefinition( const QString &source = QString(), const double referenceScale = 0, const int dpi = 96 )
|
||||||
: source( QgsProperty::fromValue( source ) )
|
: source( QgsProperty::fromValue( source ) )
|
||||||
, referenceScale( referenceScale )
|
, referenceScale( referenceScale )
|
||||||
, dpi( dpi )
|
, dpi( dpi )
|
||||||
@ -227,7 +227,7 @@ class CORE_EXPORT QgsProcessingRasterLayerDefinition
|
|||||||
* The optional \a dpi argument can be used to specify the resolution a raster provider
|
* The optional \a dpi argument can be used to specify the resolution a raster provider
|
||||||
* (e.g., a WMS server) is using to generate the raster.
|
* (e.g., a WMS server) is using to generate the raster.
|
||||||
*/
|
*/
|
||||||
QgsProcessingRasterLayerDefinition( const QgsProperty &source, const long referenceScale = 0, const int dpi = 96 )
|
QgsProcessingRasterLayerDefinition( const QgsProperty &source, const double referenceScale = 0, const int dpi = 96 )
|
||||||
: source( source )
|
: source( source )
|
||||||
, referenceScale( referenceScale )
|
, referenceScale( referenceScale )
|
||||||
, dpi( dpi )
|
, dpi( dpi )
|
||||||
@ -241,7 +241,7 @@ class CORE_EXPORT QgsProcessingRasterLayerDefinition
|
|||||||
/**
|
/**
|
||||||
* If set to a value > 0, sets a scale at which a raster (e.g., a WMS) should be requested or rendered.
|
* If set to a value > 0, sets a scale at which a raster (e.g., a WMS) should be requested or rendered.
|
||||||
*/
|
*/
|
||||||
long referenceScale = 0;
|
double referenceScale = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates the resolution of the raster source (e.g., a WMS server). By default 96 DPI.
|
* Indicates the resolution of the raster source (e.g., a WMS server). By default 96 DPI.
|
||||||
|
@ -147,7 +147,7 @@ class GUI_EXPORT QgsProcessingMapLayerComboBox : public QWidget
|
|||||||
QString mFilterExpression;
|
QString mFilterExpression;
|
||||||
bool mIsOverridingDefaultGeometryCheck = false;
|
bool mIsOverridingDefaultGeometryCheck = false;
|
||||||
Qgis::InvalidGeometryCheck mGeometryCheck = Qgis::InvalidGeometryCheck::AbortOnInvalid;
|
Qgis::InvalidGeometryCheck mGeometryCheck = Qgis::InvalidGeometryCheck::AbortOnInvalid;
|
||||||
long mRasterReferenceScale = 0;
|
double mRasterReferenceScale = 0;
|
||||||
int mRasterDpi = 0;
|
int mRasterDpi = 0;
|
||||||
QPointer<QgsMapLayer> mPrevLayer;
|
QPointer<QgsMapLayer> mPrevLayer;
|
||||||
int mBlockChangedSignal = 0;
|
int mBlockChangedSignal = 0;
|
||||||
|
@ -32,9 +32,9 @@ QgsProcessingRasterSourceOptionsWidget::QgsProcessingRasterSourceOptionsWidget(
|
|||||||
connect( mDpiSpinBox, qOverload<int>( &QSpinBox::valueChanged ), this, &QgsPanelWidget::widgetChanged );
|
connect( mDpiSpinBox, qOverload<int>( &QSpinBox::valueChanged ), this, &QgsPanelWidget::widgetChanged );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsProcessingRasterSourceOptionsWidget::setReferenceScale( long scale )
|
void QgsProcessingRasterSourceOptionsWidget::setReferenceScale( double scale )
|
||||||
{
|
{
|
||||||
mReferenceScale->setScale( static_cast<double>( scale ) );
|
mReferenceScale->setScale( scale );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsProcessingRasterSourceOptionsWidget::setDpi( int dpi )
|
void QgsProcessingRasterSourceOptionsWidget::setDpi( int dpi )
|
||||||
@ -42,9 +42,9 @@ void QgsProcessingRasterSourceOptionsWidget::setDpi( int dpi )
|
|||||||
mDpiSpinBox->setValue( dpi );
|
mDpiSpinBox->setValue( dpi );
|
||||||
}
|
}
|
||||||
|
|
||||||
long QgsProcessingRasterSourceOptionsWidget::referenceScale() const
|
double QgsProcessingRasterSourceOptionsWidget::referenceScale() const
|
||||||
{
|
{
|
||||||
return static_cast< long >( mReferenceScale->scale() );
|
return mReferenceScale->scale();
|
||||||
}
|
}
|
||||||
|
|
||||||
int QgsProcessingRasterSourceOptionsWidget::dpi() const
|
int QgsProcessingRasterSourceOptionsWidget::dpi() const
|
||||||
|
@ -47,7 +47,7 @@ class GUI_EXPORT QgsProcessingRasterSourceOptionsWidget : public QgsPanelWidget,
|
|||||||
*
|
*
|
||||||
* \see referenceScale()
|
* \see referenceScale()
|
||||||
*/
|
*/
|
||||||
void setReferenceScale( long scale );
|
void setReferenceScale( double scale );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the resolution of the raster source (e.g., a WMS server).
|
* Sets the resolution of the raster source (e.g., a WMS server).
|
||||||
@ -63,7 +63,7 @@ class GUI_EXPORT QgsProcessingRasterSourceOptionsWidget : public QgsPanelWidget,
|
|||||||
*
|
*
|
||||||
* \see setReferenceScale()
|
* \see setReferenceScale()
|
||||||
*/
|
*/
|
||||||
long referenceScale() const;
|
double referenceScale() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolution of the raster source (e.g., a WMS server).
|
* Resolution of the raster source (e.g., a WMS server).
|
||||||
|
Loading…
x
Reference in New Issue
Block a user