Skip to content

Commit 39afdbc

Browse files
committedSep 21, 2016
dxf export: support reprojection
1 parent 1d09d7a commit 39afdbc

File tree

11 files changed

+199
-123
lines changed

11 files changed

+199
-123
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5068,13 +5068,15 @@ void QgisApp::dxfExport()
50685068
dxfExport.setSymbologyScaleDenominator( d.symbologyScale() );
50695069
dxfExport.setSymbologyExport( d.symbologyMode() );
50705070
dxfExport.setLayerTitleAsName( d.layerTitleAsName() );
5071+
dxfExport.setDestinationCrs( d.crs() );
50715072
if ( mapCanvas() )
50725073
{
50735074
dxfExport.setMapUnits( mapCanvas()->mapUnits() );
50745075
//extent
50755076
if ( d.exportMapExtent() )
50765077
{
5077-
dxfExport.setExtent( mapCanvas()->extent() );
5078+
QgsCoordinateTransform t( mapCanvas()->mapSettings().destinationCrs(), QgsCoordinateReferenceSystem( d.crs(), QgsCoordinateReferenceSystem::InternalCrsId ) );
5079+
dxfExport.setExtent( t.transformBoundingBox( mapCanvas()->extent() ) );
50785080
}
50795081
}
50805082

‎src/app/qgsdxfexportdialog.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include "qgslayertreemapcanvasbridge.h"
2929
#include "qgsvisibilitypresetcollection.h"
3030
#include "qgsmapcanvas.h"
31+
#include "qgsgenericprojectionselector.h"
32+
#include "qgscrscache.h"
3133

3234
#include <QFileDialog>
3335
#include <QPushButton>
@@ -453,10 +455,21 @@ QgsDxfExportDialog::QgsDxfExportDialog( QWidget *parent, Qt::WindowFlags f )
453455
QStringList ids = QgsProject::instance()->visibilityPresetCollection()->presets();
454456
ids.prepend( "" );
455457
mVisibilityPresets->addItems( ids );
456-
mVisibilityPresets->setCurrentIndex( mVisibilityPresets->findText( QgsProject::instance()->readEntry( "dxf", "/lastVisibilityPreset", "" ) ) );
458+
mVisibilityPresets->setCurrentIndex( mVisibilityPresets->findText( QgsProject::instance()->readEntry( "dxf", "/lastVisibliltyPreset", "" ) ) );
457459

458460
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
459461
restoreGeometry( s.value( "/Windows/DxfExport/geometry" ).toByteArray() );
462+
463+
mCRS = QgsProject::instance()->readEntry( "dxf", "/lastDxfCrs",
464+
s.value( "qgis/lastDxfCrs", QString::number( QgisApp::instance()->mapCanvas()->mapSettings().destinationCrs().srsid() ) ).toString()
465+
).toLong();
466+
467+
QgsCoordinateReferenceSystem crs = QgsCRSCache::instance()->crsBySrsId( mCRS );
468+
mCrsSelector->setCrs( crs );
469+
mCrsSelector->setLayerCrs( crs );
470+
mCrsSelector->dialog()->setMessage( tr( "Select the coordinate reference system for the dxf file. "
471+
"The data points will be transformed from the layer coordinate reference system." ) );
472+
460473
mEncoding->addItems( QgsDxfExport::encodings() );
461474
mEncoding->setCurrentIndex( mEncoding->findText( QgsProject::instance()->readEntry( "dxf", "/lastDxfEncoding", s.value( "qgis/lastDxfEncoding", "CP1252" ).toString() ) ) );
462475
}
@@ -600,17 +613,29 @@ void QgsDxfExportDialog::saveSettings()
600613
s.setValue( "qgis/lastDxfMapRectangle", mMapExtentCheckBox->isChecked() );
601614
s.setValue( "qgis/lastDxfLayerTitleAsName", mLayerTitleAsName->isChecked() );
602615
s.setValue( "qgis/lastDxfEncoding", mEncoding->currentText() );
616+
s.setValue( "qgis/lastDxfCrs", QString::number( mCRS ) );
603617

604618
QgsProject::instance()->writeEntry( "dxf", "/lastDxfSymbologyMode", mSymbologyModeComboBox->currentIndex() );
605619
QgsProject::instance()->writeEntry( "dxf", "/lastSymbologyExportScale", mScaleWidget->scale() );
606620
QgsProject::instance()->writeEntry( "dxf", "/lastDxfLayerTitleAsName", mLayerTitleAsName->isChecked() );
607621
QgsProject::instance()->writeEntry( "dxf", "/lastDxfMapRectangle", mMapExtentCheckBox->isChecked() );
608622
QgsProject::instance()->writeEntry( "dxf", "/lastDxfEncoding", mEncoding->currentText() );
609623
QgsProject::instance()->writeEntry( "dxf", "/lastVisibilityPreset", mVisibilityPresets->currentText() );
624+
QgsProject::instance()->writeEntry( "dxf", "/lastDxfCrs", QString::number( mCRS ) );
610625
}
611626

612627

613628
QString QgsDxfExportDialog::encoding() const
614629
{
615630
return mEncoding->currentText();
616631
}
632+
633+
void QgsDxfExportDialog::on_mCrsSelector_crsChanged( const QgsCoordinateReferenceSystem &crs )
634+
{
635+
mCRS = crs.srsid();
636+
}
637+
638+
long QgsDxfExportDialog::crs() const
639+
{
640+
return mCRS;
641+
}

‎src/app/qgsdxfexportdialog.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class QgsDxfExportDialog : public QDialog, private Ui::QgsDxfExportDialogBase
8888
bool exportMapExtent() const;
8989
bool layerTitleAsName() const;
9090
QString encoding() const;
91+
long crs() const;
9192

9293
public slots:
9394
/** Change the selection of layers in the list */
@@ -99,11 +100,14 @@ class QgsDxfExportDialog : public QDialog, private Ui::QgsDxfExportDialogBase
99100
void setOkEnabled();
100101
void saveSettings();
101102
void on_mVisibilityPresets_currentIndexChanged( int index );
103+
void on_mCrsSelector_crsChanged( const QgsCoordinateReferenceSystem &crs );
102104

103105
private:
104106
void cleanGroup( QgsLayerTreeNode *node );
105107
QgsLayerTreeGroup *mLayerTreeGroup;
106108
FieldSelectorDelegate *mFieldSelectorDelegate;
109+
110+
long mCRS;
107111
};
108112

109113
#endif // QGSDXFEXPORTDIALOG_H

‎src/core/dxf/qgsdxfexport.cpp

Lines changed: 96 additions & 83 deletions
Large diffs are not rendered by default.

‎src/core/dxf/qgsdxfexport.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "qgsgeometry.h"
2222
#include "qgssymbolv2.h"
23+
#include "qgsmapsettings.h"
2324

2425
#include <QColor>
2526
#include <QList>
@@ -95,6 +96,16 @@ class CORE_EXPORT QgsDxfExport
9596
*/
9697
QGis::UnitType mapUnits() const { return mMapUnits; }
9798

99+
/**
100+
* Set destination CRS
101+
*/
102+
void setDestinationCrs( long crs );
103+
104+
/**
105+
* Set destination CRS
106+
*/
107+
long destinationCrs();
108+
98109
/**
99110
* Set symbology export mode
100111
* @param e the mode
@@ -418,9 +429,7 @@ class CORE_EXPORT QgsDxfExport
418429
void writeSymbolLayerLinetype( const QgsSymbolLayerV2 *symbolLayer );
419430
void writeLinetype( const QString &styleName, const QVector<qreal> &pattern, QgsSymbolV2::OutputUnit u );
420431

421-
QgsRectangle dxfExtent() const;
422-
423-
void addFeature( QgsSymbolV2RenderContext &ctx, const QString &layer, const QgsSymbolLayerV2 *symbolLayer, const QgsSymbolV2 *symbol );
432+
void addFeature( QgsSymbolV2RenderContext &ctx, const QgsCoordinateTransform *ct, const QString &layer, const QgsSymbolLayerV2 *symbolLayer, const QgsSymbolV2 *symbol );
424433

425434
//returns dxf palette index from symbol layer color
426435
static QColor colorFromSymbolLayer( const QgsSymbolLayerV2 *symbolLayer, QgsSymbolV2RenderContext &ctx );
@@ -448,6 +457,9 @@ class CORE_EXPORT QgsDxfExport
448457

449458
//! DXF layer name for each label feature
450459
QMap< QString, QMap<QgsFeatureId, QString> > mDxfLayerNames;
460+
long mCrs;
461+
QgsMapSettings mMapSettings;
462+
double mFactor;
451463
};
452464

453465
#endif // QGSDXFEXPORT_H

‎src/core/pal/layer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "geomfunction.h"
3636
#include "util.h"
3737
#include "qgslabelingenginev2.h"
38+
3839
#include <cmath>
3940
#include <vector>
4041

‎src/core/pal/util.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
#include "labelposition.h"
3434
#include "feature.h"
3535
#include "geomfunction.h"
36+
37+
#include <qgslogger.h>
3638
#include <cfloat>
3739

3840
#ifndef M_PI
@@ -105,11 +107,13 @@ QLinkedList<const GEOSGeometry *>* pal::Util::unmulti( const GEOSGeometry *the_g
105107
int nGeom;
106108
int i;
107109

110+
GEOSContextHandle_t geosctxt = geosContext();
111+
108112
while ( !queue->isEmpty() )
109113
{
110114
geom = queue->takeFirst();
111-
GEOSContextHandle_t geosctxt = geosContext();
112-
switch ( GEOSGeomTypeId_r( geosctxt, geom ) )
115+
int type = GEOSGeomTypeId_r( geosctxt, geom );
116+
switch ( type )
113117
{
114118
case GEOS_MULTIPOINT:
115119
case GEOS_MULTILINESTRING:
@@ -126,6 +130,7 @@ QLinkedList<const GEOSGeometry *>* pal::Util::unmulti( const GEOSGeometry *the_g
126130
final_queue->append( geom );
127131
break;
128132
default:
133+
QgsDebugMsg( QString( "unexpected geometry type:%1" ).arg( type ) );
129134
delete final_queue;
130135
delete queue;
131136
return nullptr;

‎src/core/qgsmaprenderercustompainterjob.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void QgsMapRendererCustomPainterJob::cancel()
139139
for ( LayerRenderJobs::iterator it = mLayerJobs.begin(); it != mLayerJobs.end(); ++it )
140140
{
141141
it->context.setRenderingStopped( true );
142-
if ( it->renderer->feedback() )
142+
if ( it->renderer && it->renderer->feedback() )
143143
it->renderer->feedback()->cancel();
144144
}
145145

‎src/plugins/coordinate_capture/coordinatecapturemaptool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
CoordinateCaptureMapTool::CoordinateCaptureMapTool( QgsMapCanvas* thepCanvas )
3030
: QgsMapTool( thepCanvas )
31+
, mpRubberBand( nullptr )
3132
{
3233
// set cursor
3334
QPixmap myCursor = QPixmap(( const char ** ) capture_point_cursor );
@@ -40,7 +41,6 @@ CoordinateCaptureMapTool::CoordinateCaptureMapTool( QgsMapCanvas* thepCanvas )
4041

4142
CoordinateCaptureMapTool::~CoordinateCaptureMapTool()
4243
{
43-
delete mpRubberBand;
4444
}
4545

4646
void CoordinateCaptureMapTool::canvasMoveEvent( QgsMapMouseEvent * thepEvent )

‎src/plugins/roadgraph/shortestpathwidget.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,6 @@ RgShortestPathWidget::RgShortestPathWidget( QWidget* theParent, RoadGraphPlugin
174174
} //RgShortestPathWidget::RgShortestPathWidget()
175175
RgShortestPathWidget::~RgShortestPathWidget()
176176
{
177-
delete mFrontPointMapTool;
178-
delete mBackPointMapTool;
179-
180-
delete mrbFrontPoint;
181-
delete mrbBackPoint;
182-
delete mrbPath;
183177
} //RgShortestPathWidget::~RgShortestPathWidget()
184178

185179
void RgShortestPathWidget::mapCanvasExtentsChanged()

‎src/ui/qgsdxfexportdialogbase.ui

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,21 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>402</width>
10-
<height>534</height>
9+
<width>1049</width>
10+
<height>680</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
1414
<string>DXF export</string>
1515
</property>
1616
<layout class="QGridLayout" name="gridLayout_2">
17-
<item row="2" column="1" colspan="2">
18-
<widget class="QgsScaleWidget" name="mScaleWidget" native="true">
19-
<property name="showCurrentScaleButton" stdset="0">
20-
<bool>true</bool>
21-
</property>
22-
</widget>
23-
</item>
24-
<item row="3" column="1" colspan="2">
25-
<widget class="QComboBox" name="mEncoding"/>
26-
</item>
2717
<item row="0" column="2">
2818
<widget class="QToolButton" name="mFileSelectionButton">
2919
<property name="text">
3020
<string>...</string>
3121
</property>
3222
</widget>
3323
</item>
34-
<item row="5" column="0" colspan="3">
35-
<widget class="QgsLayerTreeView" name="mTreeView">
36-
<property name="selectionMode">
37-
<enum>QAbstractItemView::ExtendedSelection</enum>
38-
</property>
39-
<attribute name="headerDefaultSectionSize">
40-
<number>0</number>
41-
</attribute>
42-
</widget>
43-
</item>
4424
<item row="0" column="0">
4525
<widget class="QLabel" name="mSaveAsLabel">
4626
<property name="text">
@@ -82,6 +62,26 @@
8262
</widget>
8363
</item>
8464
<item row="7" column="0" colspan="3">
65+
<widget class="QgsLayerTreeView" name="mTreeView">
66+
<property name="selectionMode">
67+
<enum>QAbstractItemView::ExtendedSelection</enum>
68+
</property>
69+
<attribute name="headerDefaultSectionSize">
70+
<number>0</number>
71+
</attribute>
72+
</widget>
73+
</item>
74+
<item row="2" column="1" colspan="2">
75+
<widget class="QgsScaleWidget" name="mScaleWidget">
76+
<property name="showCurrentScaleButton">
77+
<bool>true</bool>
78+
</property>
79+
</widget>
80+
</item>
81+
<item row="3" column="1" colspan="2">
82+
<widget class="QComboBox" name="mEncoding"/>
83+
</item>
84+
<item row="9" column="0" colspan="3">
8585
<layout class="QGridLayout" name="gridLayout_3">
8686
<item row="0" column="0">
8787
<widget class="QPushButton" name="mSelectAllButton">
@@ -115,14 +115,14 @@
115115
<item row="0" column="1">
116116
<widget class="QLineEdit" name="mFileLineEdit"/>
117117
</item>
118-
<item row="9" column="0" colspan="3">
118+
<item row="11" column="0" colspan="3">
119119
<widget class="QCheckBox" name="mMapExtentCheckBox">
120120
<property name="text">
121121
<string>Export features intersecting the current map extent</string>
122122
</property>
123123
</widget>
124124
</item>
125-
<item row="10" column="0" colspan="3">
125+
<item row="12" column="0" colspan="3">
126126
<widget class="QDialogButtonBox" name="buttonBox">
127127
<property name="orientation">
128128
<enum>Qt::Horizontal</enum>
@@ -149,16 +149,36 @@
149149
</property>
150150
</widget>
151151
</item>
152-
<item row="8" column="0" colspan="3">
152+
<item row="10" column="0" colspan="3">
153153
<widget class="QCheckBox" name="mLayerTitleAsName">
154154
<property name="text">
155155
<string>Use layer title as name if set</string>
156156
</property>
157157
</widget>
158158
</item>
159+
<item row="5" column="0">
160+
<widget class="QLabel" name="label_3">
161+
<property name="text">
162+
<string>CRS</string>
163+
</property>
164+
</widget>
165+
</item>
166+
<item row="5" column="1" colspan="2">
167+
<widget class="QgsProjectionSelectionWidget" name="mCrsSelector">
168+
<property name="focusPolicy">
169+
<enum>Qt::StrongFocus</enum>
170+
</property>
171+
</widget>
172+
</item>
159173
</layout>
160174
</widget>
161175
<customwidgets>
176+
<customwidget>
177+
<class>QgsProjectionSelectionWidget</class>
178+
<extends>QWidget</extends>
179+
<header>qgsprojectionselectionwidget.h</header>
180+
<container>1</container>
181+
</customwidget>
162182
<customwidget>
163183
<class>QgsScaleWidget</class>
164184
<extends>QWidget</extends>

0 commit comments

Comments
 (0)
Please sign in to comment.