Skip to content

Commit

Permalink
Merge branch 'master' into CategorizedRendererUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
ccrook committed Sep 20, 2014
2 parents abd9e3c + 808464f commit 47f7db5
Show file tree
Hide file tree
Showing 18 changed files with 195 additions and 101 deletions.
5 changes: 5 additions & 0 deletions python/core/qgscolorscheme.sip
Expand Up @@ -143,6 +143,11 @@ class QgsUserColorScheme : QgsGplColorScheme
*/
void setName( const QString name );

/**Erases the associated gpl palette file from the users "palettes" folder
* @returns true if erase was successful
*/
bool erase();

protected:

virtual QString gplFilePath();
Expand Down
2 changes: 2 additions & 0 deletions python/core/symbology-ng/qgssymbolv2.sip
Expand Up @@ -85,6 +85,8 @@ class QgsSymbolV2
//! @note customContext parameter added in 2.6
void drawPreviewIcon( QPainter* painter, QSize size, QgsRenderContext* customContext = 0 );

QImage asImage( QSize size, QgsRenderContext* customContext = 0 );

QImage bigSymbolPreviewImage();

QString dump() const;
Expand Down
Expand Up @@ -92,6 +92,9 @@ def processAlgorithm(self, progress):
else:
pointCount = int(round(f[fieldName] * da.measure(fGeom)))

if strategy == 0 and pointCount == 0:
continue

index = QgsSpatialIndex()
points = dict()

Expand Down
6 changes: 3 additions & 3 deletions python/plugins/processing/algs/qgis/ZonalStatistics.py
Expand Up @@ -137,8 +137,8 @@ def processAlgorithm(self, progress):
columnPrefix + 'unique', 21, 6)
(idxRange, fields) = vector.findOrCreateField(layer, fields,
columnPrefix + 'range', 21, 6)
(idxCV, fields) = vector.findOrCreateField(layer, fields, columnPrefix
+ 'cv', 21, 6)
(idxVar, fields) = vector.findOrCreateField(layer, fields, columnPrefix
+ 'var', 21, 6)

# idxMedian, fields = ftools_utils.findOrCreateField(layer, fields,
# columnPrefix + "median", 21, 6)
Expand Down Expand Up @@ -222,7 +222,7 @@ def processAlgorithm(self, progress):
attrs.insert(idxStd, float(masked.std()))
attrs.insert(idxUnique, numpy.unique(masked.compressed()).size)
attrs.insert(idxRange, float(masked.max()) - float(masked.min()))
attrs.insert(idxCV, float(masked.var()))
attrs.insert(idxVar, float(masked.var()))
# attrs.insert(idxMedian, float(masked.median()))

outFeat.setAttributes(attrs)
Expand Down
23 changes: 10 additions & 13 deletions python/plugins/processing/algs/qgis/ftools/PointDistance.py
Expand Up @@ -113,7 +113,7 @@ def linearMatrix(self, inLayer, inField, targetLayer, targetField,
index = vector.spatialindex(targetLayer)

inIdx = inLayer.fieldNameIndex(inField)
outIdx = targetLayer.fieldNameIndex(inField)
outIdx = targetLayer.fieldNameIndex(targetField)

outFeat = QgsFeature()
inGeom = QgsGeometry()
Expand All @@ -125,7 +125,7 @@ def linearMatrix(self, inLayer, inField, targetLayer, targetField,
total = 100.0 / float(len(features))
for inFeat in features:
inGeom = inFeat.geometry()
inID = inFeat.attributes()[inIdx]
inID = unicode(inFeat.attributes()[inIdx])
featList = index.nearestNeighbor(inGeom.asPoint(), nPoints)
distList = []
vari = 0.0
Expand All @@ -137,17 +137,16 @@ def linearMatrix(self, inLayer, inField, targetLayer, targetField,
dist = distArea.measureLine(inGeom.asPoint(),
outGeom.asPoint())
if matType == 0:
self.writer.addRecord([unicode(inID), unicode(outID),
unicode(dist)])
self.writer.addRecord([inID,unicode(outID),unicode(dist)])
else:
distList.append(float(dist))

if matType == 2:
if matType != 0:
mean = sum(distList) / len(distList)
for i in distList:
vari += (i - mean) * (i - mean)
vari = math.sqrt(vari / len(distList))
self.writer.addRecord([unicode(inID), unicode(mean),
self.writer.addRecord([inID, unicode(mean),
unicode(vari), unicode(min(distList)),
unicode(max(distList))])

Expand All @@ -173,18 +172,16 @@ def regularMatrix(self, inLayer, inField, targetLayer, targetField,

for inFeat in features:
inGeom = inFeat.geometry()
inID = inFeat.attributes()[inIdx]
inID = unicode(inFeat.attributes()[inIdx])
featList = index.nearestNeighbor(inGeom.asPoint(), nPoints)
if first:
featList = index.nearestNeighbor(inGeom.asPoint(), nPoints)
first = False
data = ['ID']
for i in featList:
request = QgsFeatureRequest().setFilterFid(i)
outFeat = targetLayer.getFeatures(request).next()
data.append(unicode(outFeat.attributes[outIdx]))
for i in range(len(featList)):
data.append('DIST_{0}'.format(i+1))
self.writer.addRecord(data)

data = [unicode(inID)]
data = [inID]
for i in featList:
request = QgsFeatureRequest().setFilterFid(i)
outFeat = targetLayer.getFeatures(request).next()
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/script/ScriptAlgorithm.py
Expand Up @@ -263,7 +263,7 @@ def processAlgorithm(self, progress):
ns[out.name] = out.value

script += self.script
exec script in ns
exec(script) in ns
for out in self.outputs:
out.setValue(ns[out.name])

Expand Down
73 changes: 3 additions & 70 deletions python/plugins/processing/tools/raster.py
Expand Up @@ -52,80 +52,13 @@ def scanraster(layer, progress):


def mapToPixel(mX, mY, geoTransform):
"""Convert map coordinates to pixel coordinates.
@param mX Input map X coordinate (double)
@param mY Input map Y coordinate (double)
@param geoTransform Input geotransform (six doubles)
@return pX, pY Output coordinates (two doubles)
"""

if geoTransform[2] + geoTransform[4] == 0:
pX = (mX - geoTransform[0]) / geoTransform[1]
pY = (mY - geoTransform[3]) / geoTransform[5]
else:
(pX, pY) = applyGeoTransform(mX, mY, invertGeoTransform(geoTransform))
(pX, pY) = gdal.ApplyGeoTransform(
gdal.InvGeoTransform(geoTransform)[1], mX, mY)
return (int(pX), int(pY))


def pixelToMap(pX, pY, geoTransform):
"""Convert pixel coordinates to map coordinates.
@param pX Input pixel X coordinate (double)
@param pY Input pixel Y coordinate (double)
@param geoTransform Input geotransform (six doubles)
@return mX, mY Output coordinates (two doubles)
"""

(mX, mY) = applyGeoTransform(pX + 0.5, pY + 0.5, geoTransform)
return (mX, mY)


def applyGeoTransform(inX, inY, geoTransform):
"""Apply a geotransform to coordinates.
@param inX Input coordinate (double)
@param inY Input coordinate (double)
@param geoTransform Input geotransform (six doubles)
@return outX, outY Output coordinates (two doubles)
"""

outX = geoTransform[0] + inX * geoTransform[1] + inY * geoTransform[2]
outY = geoTransform[3] + inX * geoTransform[4] + inY * geoTransform[5]
return (outX, outY)


def invertGeoTransform(geoTransform):
"""Invert standard 3x2 set of geotransform coefficients.
@param geoTransform Input GeoTransform (six doubles - unaltered)
@return outGeoTransform Output GeoTransform (six doubles - updated)
on success, None if the equation is uninvertable
"""

# We assume a 3rd row that is [1 0 0]
# Compute determinate
det = geoTransform[1] * geoTransform[5] - geoTransform[2] * geoTransform[4]

if abs(det) < 0.000000000000001:
return

invDet = 1.0 / det

# Compute adjoint and divide by determinate
outGeoTransform = [0, 0, 0, 0, 0, 0]
outGeoTransform[1] = geoTransform[5] * invDet
outGeoTransform[4] = -geoTransform[4] * invDet

outGeoTransform[2] = -geoTransform[2] * invDet
outGeoTransform[5] = geoTransform[1] * invDet

outGeoTransform[0] = (geoTransform[2] * geoTransform[3] - geoTransform[0]
* geoTransform[5]) * invDet
outGeoTransform[3] = (-geoTransform[1] * geoTransform[3] + geoTransform[0]
* geoTransform[4]) * invDet

return outGeoTransform
return gdal.ApplyGeoTransform(geoTransform, pX + 0.5, pY + 0.5)


class RasterWriter:
Expand Down
1 change: 1 addition & 0 deletions src/browser/CMakeLists.txt
Expand Up @@ -61,6 +61,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../gui/attributetable
${CMAKE_CURRENT_BINARY_DIR}/../ui
${CMAKE_CURRENT_BINARY_DIR}
${GEOS_INCLUDE_DIR}
${GDAL_INCLUDE_DIR} # remove once raster layer is cleaned up
)

Expand Down
33 changes: 33 additions & 0 deletions src/core/composer/qgsatlascomposition.cpp
Expand Up @@ -47,6 +47,9 @@ QgsAtlasComposition::QgsAtlasComposition( QgsComposition* composition ) :
QgsExpression::setSpecialColumn( "$atlasfeatureid", QVariant(( int )0 ) );
QgsExpression::setSpecialColumn( "$atlasfeature", QVariant::fromValue( QgsFeature() ) );
QgsExpression::setSpecialColumn( "$atlasgeometry", QVariant::fromValue( QgsGeometry() ) );

//listen out for layer removal
connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( removeLayers( QStringList ) ) );
}

QgsAtlasComposition::~QgsAtlasComposition()
Expand All @@ -55,13 +58,43 @@ QgsAtlasComposition::~QgsAtlasComposition()

void QgsAtlasComposition::setEnabled( bool enabled )
{
if ( enabled == mEnabled )
{
return;
}

mEnabled = enabled;
mComposition->setAtlasMode( QgsComposition::AtlasOff );
emit toggled( enabled );
emit parameterChanged();
}

void QgsAtlasComposition::removeLayers( QStringList layers )
{
if ( !mCoverageLayer )
{
return;
}

foreach ( QString layerId, layers )
{
if ( layerId == mCoverageLayer->id() )
{
//current coverage layer removed
mCoverageLayer = 0;
setEnabled( false );
return;
}
}
}

void QgsAtlasComposition::setCoverageLayer( QgsVectorLayer* layer )
{
if ( layer == mCoverageLayer )
{
return;
}

mCoverageLayer = layer;

// update the number of features
Expand Down
4 changes: 4 additions & 0 deletions src/core/composer/qgsatlascomposition.h
Expand Up @@ -23,6 +23,7 @@
#include <QString>
#include <QDomElement>
#include <QDomDocument>
#include <QStringList>

class QgsComposerMap;
class QgsComposition;
Expand Down Expand Up @@ -305,6 +306,9 @@ class CORE_EXPORT QgsAtlasComposition : public QObject
public:
typedef QMap< QgsFeatureId, QVariant > SorterKeys;

private slots:
void removeLayers( QStringList layers );

private:
// value of field that is used for ordering of features
SorterKeys mFeatureKeys;
Expand Down
12 changes: 12 additions & 0 deletions src/core/qgscolorscheme.cpp
Expand Up @@ -338,6 +338,18 @@ QgsColorScheme *QgsUserColorScheme::clone() const
return new QgsUserColorScheme( mFilename );
}

bool QgsUserColorScheme::erase()
{
QString filePath = gplFilePath();
if ( filePath.isEmpty() )
{
return false;
}

//try to erase gpl file
return QFile::remove( filePath );
}

QString QgsUserColorScheme::gplFilePath()
{
QString palettesDir = QgsApplication::qgisSettingsDirPath() + "/palettes";
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgscolorscheme.h
Expand Up @@ -155,6 +155,11 @@ class CORE_EXPORT QgsUserColorScheme : public QgsGplColorScheme
*/
void setName( const QString name ) { mName = name; }

/**Erases the associated gpl palette file from the users "palettes" folder
* @returns true if erase was successful
*/
bool erase();

protected:

QString mName;
Expand Down
13 changes: 13 additions & 0 deletions src/core/symbology-ng/qgssymbolv2.cpp
Expand Up @@ -308,6 +308,19 @@ void QgsSymbolV2::drawPreviewIcon( QPainter* painter, QSize size, QgsRenderConte
}
}

QImage QgsSymbolV2::asImage( QSize size, QgsRenderContext* customContext )
{
QImage image( size , QImage::Format_ARGB32_Premultiplied );
image.fill( 0 );

QPainter p( &image );
p.setRenderHint( QPainter::Antialiasing );

drawPreviewIcon( &p, size, customContext );

return image;
}


QImage QgsSymbolV2::bigSymbolPreviewImage()
{
Expand Down
2 changes: 2 additions & 0 deletions src/core/symbology-ng/qgssymbolv2.h
Expand Up @@ -110,6 +110,8 @@ class CORE_EXPORT QgsSymbolV2
//! @note customContext parameter added in 2.6
void drawPreviewIcon( QPainter* painter, QSize size, QgsRenderContext* customContext = 0 );

QImage asImage( QSize size, QgsRenderContext* customContext = 0 );

QImage bigSymbolPreviewImage();

QString dump() const;
Expand Down

1 comment on commit 47f7db5

@gioman
Copy link
Contributor

@gioman gioman commented on 47f7db5 Oct 5, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I found this issue http://hub.qgis.org/issues/11329 with the new legend format option in QGIS master, cheers.

Please sign in to comment.