Skip to content
Permalink
Browse files
[FEATURE]: add base mechanisms for OGR feature style export
  • Loading branch information
mhugent committed Dec 7, 2012
1 parent cb7d1ec commit b0b9098fdc2b084177afb15e4d48da9bab75d6a9
@@ -24,6 +24,8 @@
#include "qgsmessagelog.h"
#include "qgscoordinatereferencesystem.h"
#include "qgsvectorfilewriter.h"
#include "qgsrendererv2.h"
#include "qgssymbolv2.h"

#include <QFile>
#include <QSettings>
@@ -430,7 +432,7 @@ QString QgsVectorFileWriter::errorMessage()
return mErrorMessage;
}

bool QgsVectorFileWriter::addFeature( QgsFeature& feature )
bool QgsVectorFileWriter::addFeature( QgsFeature& feature, QgsFeatureRendererV2* renderer )
{
// create the feature
OGRFeatureH poFeature = OGR_F_Create( OGR_L_GetLayerDefn( mLayer ) );
@@ -564,6 +566,30 @@ bool QgsVectorFileWriter::addFeature( QgsFeature& feature )
}
}

//add OGR feature style type
if ( mExportFeatureStyle && renderer )
{
//concatenate ogr styles of all symbols
QgsSymbolV2List symbols = renderer->symbolsForFeature( feature );
QString styleString;
QString currentStyle;

QgsSymbolV2List::const_iterator symbolIt = symbols.constBegin();
for ( ; symbolIt != symbols.constEnd(); ++symbolIt )
{
currentStyle = ( *symbolIt )->ogrFeatureStyle();
if ( currentStyle.isEmpty() )
{
continue;
}
if ( symbolIt != symbols.constBegin() )
{
styleString.append( ";" );
}
styleString.append( currentStyle );
}
}

// put the created feature to layer
if ( OGR_L_CreateFeature( mLayer, poFeature ) != OGRERR_NONE )
{
@@ -132,7 +132,7 @@ class CORE_EXPORT QgsVectorFileWriter
QString errorMessage();

/** add feature to the currently opened shapefile */
bool addFeature( QgsFeature& feature );
bool addFeature( QgsFeature& feature, QgsFeatureRendererV2* renderer = 0 );

//! @note not available in python bindings
QMap<int, int> attrIdxToOgrIdx() { return mAttrIdxToOgrIdx; }
@@ -168,6 +168,9 @@ class CORE_EXPORT QgsVectorFileWriter
/** map attribute indizes to OGR field indexes */
QMap<int, int> mAttrIdxToOgrIdx;

/** flag if OGR feature type style should be exported*/
bool mExportFeatureStyle;

private:
static bool driverMetadata( QString driverName, QString &longName, QString &trLongName, QString &glob, QString &ext );
};
@@ -54,6 +54,8 @@ class CORE_EXPORT QgsSymbolLayerV2
virtual void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const
{ Q_UNUSED( props ); element.appendChild( doc.createComment( QString( "SymbolLayerV2 %1 not implemented yet" ).arg( layerType() ) ) ); }

virtual QString ogrFeatureStyle() const { return QString(); }

virtual QgsStringMap properties() const = 0;

virtual void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size ) = 0;
@@ -314,6 +314,26 @@ void QgsSymbolV2::toSld( QDomDocument &doc, QDomElement &element, QgsStringMap p
}
}

QString QgsSymbolV2::ogrFeatureStyle() const
{
QString styleString;
QString currentStyleString;
for ( QgsSymbolLayerV2List::const_iterator it = mLayers.constBegin(); it != mLayers.constEnd(); ++it )
{
currentStyleString = ( *it )->ogrFeatureStyle();
if ( currentStyleString.isEmpty() )
{
continue;
}

if ( it != mLayers.constBegin() )
{
styleString.append( ";" );
}
styleString.append( currentStyleString );
}
}

QgsSymbolLayerV2List QgsSymbolV2::cloneLayers() const
{
QgsSymbolLayerV2List lst;
@@ -113,6 +113,9 @@ class CORE_EXPORT QgsSymbolV2

void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;

/**Returns the OGR feature style string for the symbol*/
QString ogrFeatureStyle() const;

OutputUnit outputUnit() const { return mOutputUnit; }
void setOutputUnit( OutputUnit u ) { mOutputUnit = u; }

0 comments on commit b0b9098

Please sign in to comment.