measure_ellipsoid.diff

Proposed patch - Alexander Bruy, 2010-11-22 09:08 AM

Download (15.1 KB)

View differences:

src/app/qgsmeasuredialog.h (working copy)
62 62

  
63 63
    //! Show the help for the dialog
64 64
    void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
65
  private slots:
66
    //! on change state projection enable
67
    void changeStateProjectionEnable();
65 68

  
66 69
  private:
67 70

  
src/app/qgsdisplayangle.h (working copy)
29 29
    /**Sets the measured angle value (in radians). The value is going to
30 30
      be converted to degrees / gon automatically if necessary*/
31 31
    void setValueInRadians( double value );
32

  
33
    bool projectionEnabled();
34

  
35
  signals:
36
    void changeStateProjectionEnable();
37
  
38
  private slots:
39
    void changeState();
40

  
32 41
};
33 42

  
34 43
#endif // QGSDISPLAYANGLE_H
src/app/qgsdisplayangle.cpp (working copy)
20 20
QgsDisplayAngle::QgsDisplayAngle( QWidget * parent, Qt::WindowFlags f ): QDialog( parent, f )
21 21
{
22 22
  setupUi( this );
23
  QSettings settings;
24
  int s = settings.value( "/qgis/measure/projection_enable", "2" ).toInt();
25
  if ( s == 2 )
26
    mcbProjectionEnabled->setCheckState( Qt::Checked );
27
  else
28
    mcbProjectionEnabled->setCheckState( Qt::Unchecked );
29

  
30
  connect( mcbProjectionEnabled, SIGNAL( stateChanged(int) ),
31
      this, SLOT( changeState() ) );
32
  connect( mcbProjectionEnabled, SIGNAL( stateChanged(int) ), 
33
      this, SIGNAL( changeStateProjectionEnable() ) );
23 34
}
24 35

  
25 36
QgsDisplayAngle::~QgsDisplayAngle()
......
27 38

  
28 39
}
29 40

  
41
bool QgsDisplayAngle::projectionEnabled()
42
{
43
  return mcbProjectionEnabled->isChecked();
44
}
45

  
30 46
void QgsDisplayAngle::setValueInRadians( double value )
31 47
{
32 48
  QSettings settings;
......
45 61
  }
46 62
}
47 63

  
64
void QgsDisplayAngle::changeState()
65
{
66
  QSettings settings;
67
  if ( mcbProjectionEnabled->isChecked() )
68
    settings.setValue( "/qgis/measure/projection_enable", 2);
69
  else
70
    settings.setValue( "/qgis/measure/projection_enable", 0);
71
}
src/app/qgsmeasuredialog.cpp (working copy)
52 52
  //mTable->setHeaderLabels(QStringList() << tr("Segments (in meters)") << tr("Total") << tr("Azimuth") );
53 53

  
54 54
  QSettings settings;
55
  int s = settings.value( "/qgis/measure/projection_enable", "2" ).toInt();
56
  if ( s == 2 )
57
    mcbProjectionEnabled->setCheckState( Qt::Checked );
58
  else
59
    mcbProjectionEnabled->setCheckState( Qt::Unchecked );
55 60

  
61
  connect( mcbProjectionEnabled, SIGNAL( stateChanged(int) ), 
62
      this, SLOT( changeStateProjectionEnable() ));
56 63

  
57 64
  updateUi();
58 65
}
......
91 98
  QSettings settings;
92 99
  int decimalPlaces = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt();
93 100

  
101
  // Create QgsDistance Area for customization ProjectionEnabled setting
102
  QgsDistanceArea myDa;  
103
  myDa.setSourceCrs( mTool->canvas()->mapRenderer()->destinationSrs().srsid() );
104
  myDa.setEllipsoid( mTool->canvas()->mapRenderer()->distanceArea()->ellipsoid() );
105
  myDa.setProjectionsEnabled( mcbProjectionEnabled->isChecked() );
106

  
94 107
  // show current distance/area while moving the point
95 108
  // by creating a temporary copy of point array
96
  // and adding moving point at the end
109
  // and adding moving point at the end  
97 110
  if ( mMeasureArea && mTool->points().size() > 1 )
98 111
  {
99 112
    QList<QgsPoint> tmpPoints = mTool->points();
100 113
    tmpPoints.append( point );
101
    double area = mTool->canvas()->mapRenderer()->distanceArea()->measurePolygon( tmpPoints );
114
    double area = myDa.measurePolygon( tmpPoints );
102 115
    editTotal->setText( formatArea( area, decimalPlaces ) );
103 116
  }
104 117
  else if ( !mMeasureArea && mTool->points().size() > 0 )
105 118
  {
106 119
    QgsPoint p1( mTool->points().last() ), p2( point );
107 120

  
108
    double d = mTool->canvas()->mapRenderer()->distanceArea()->measureLine( p1, p2 );
121
    double d = myDa.measureLine( p1, p2 );
109 122
    editTotal->setText( formatDistance( mTotal + d, decimalPlaces ) );
110 123
    QGis::UnitType myDisplayUnits;
111 124
    // Ignore units
......
120 133
  QSettings settings;
121 134
  int decimalPlaces = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt();
122 135

  
136
  // Create QgsDistance Area for customization ProjectionEnabled setting
137
  QgsDistanceArea myDa;  
138
  myDa.setSourceCrs( mTool->canvas()->mapRenderer()->destinationSrs().srsid() );
139
  myDa.setEllipsoid( mTool->canvas()->mapRenderer()->distanceArea()->ellipsoid() );
140
  myDa.setProjectionsEnabled( mcbProjectionEnabled->isChecked() );
141

  
123 142
  int numPoints = mTool->points().size();
124 143
  if ( mMeasureArea && numPoints > 2 )
125 144
  {
126
    double area = mTool->canvas()->mapRenderer()->distanceArea()->measurePolygon( mTool->points() );
145
    double area = myDa.measurePolygon( mTool->points() );
127 146
    editTotal->setText( formatArea( area, decimalPlaces ) );
128 147
  }
129 148
  else if ( !mMeasureArea && numPoints > 1 )
......
132 151

  
133 152
    QgsPoint p1 = mTool->points()[last], p2 = mTool->points()[last+1];
134 153

  
135
    double d = mTool->canvas()->mapRenderer()->distanceArea()->measureLine( p1, p2 );
154
    double d = myDa.measureLine( p1, p2 );
136 155

  
137 156
    mTotal += d;
138 157
    editTotal->setText( formatDistance( mTotal, decimalPlaces ) );
......
252 271
  QGis::UnitType myUnits = mTool->canvas()->mapUnits();
253 272
  if (( myUnits == QGis::Degrees || myUnits == QGis::Feet ) &&
254 273
      mTool->canvas()->mapRenderer()->distanceArea()->ellipsoid() != "NONE" &&
255
      mTool->canvas()->mapRenderer()->distanceArea()->hasCrsTransformEnabled() )
274
      mcbProjectionEnabled->isChecked() )
256 275
  {
257 276
    // Measuring on an ellipsoid returns meters, and so does using projections???
258 277
    myUnits = QGis::Meters;
259 278
    QgsDebugMsg( "We're measuring on an ellipsoid or using projections, the system is returning meters" );
260 279
  }
261

  
280
   
262 281
  // Get the units for display
263 282
  QSettings settings;
264 283
  QString myDisplayUnitsTxt = settings.value( "/qgis/measure/displayunits", "meters" ).toString();
265

  
284
  
266 285
  // Only convert between meters and feet
267 286
  if ( myUnits == QGis::Meters && myDisplayUnitsTxt == "feet" )
268 287
  {
......
289 308

  
290 309
  u = myUnits;
291 310
}
311

  
312
void QgsMeasureDialog::changeStateProjectionEnable()
313
{
314
  // store value
315
  QSettings settings;
316
  if ( mcbProjectionEnabled->isChecked() )
317
    settings.setValue( "/qgis/measure/projection_enable", 2);
318
  else
319
    settings.setValue( "/qgis/measure/projection_enable", 0);
320

  
321
  // clear interface
322
  mTable->clear();
323
  QTreeWidgetItem* item = new QTreeWidgetItem( QStringList( QString::number( 0, 'f', 1 ) ) );
324
  item->setTextAlignment( 0, Qt::AlignRight );
325
  mTable->addTopLevelItem( item );
326
  mTotal = 0;
327
  updateUi();
328

  
329
  int decimalPlaces = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt();
330
 
331
  // create DistanceArea
332
  QgsDistanceArea myDa;  
333
  myDa.setSourceCrs( mTool->canvas()->mapRenderer()->destinationSrs().srsid() );
334
  myDa.setEllipsoid( mTool->canvas()->mapRenderer()->distanceArea()->ellipsoid() );
335
  myDa.setProjectionsEnabled( mcbProjectionEnabled->isChecked() );
336
  
337
  if ( mMeasureArea )
338
  {
339
    double area = 0.0;
340
    if ( mTool->points().size() > 1 )
341
    {
342
      area = myDa.measurePolygon( mTool->points() );
343
    }
344
    editTotal->setText( formatArea( area, decimalPlaces ) );
345
  }else
346
  {
347
    QList<QgsPoint>::const_iterator it;
348
    bool b = true; // first point
349
  
350
    QgsPoint p1,p2;
351
     
352
    for (it=mTool->points().constBegin(); it != mTool->points().constEnd(); ++it)
353
    {
354
      p2 = *it;
355
      if ( !b )
356
      {
357
        double d  = myDa.measureLine( p1, p2 );
358
        mTotal += d;
359
        editTotal->setText( formatDistance( mTotal, decimalPlaces ) );
360
        QGis::UnitType myDisplayUnits;
361

  
362
        convertMeasurement( d, myDisplayUnits, false );
363

  
364
        QTreeWidgetItem *item = mTable->topLevelItem( mTable->topLevelItemCount() - 1 );
365
        item->setText( 0, QLocale::system().toString( d, 'f', decimalPlaces ) );
366
        item = new QTreeWidgetItem( QStringList( QLocale::system().toString( 0.0, 'f', decimalPlaces ) ) );
367
        item->setTextAlignment( 0, Qt::AlignRight );
368
        mTable->addTopLevelItem( item );
369
        mTable->scrollToItem( item );
370
      }
371
      p1 = p2;
372
      b = false;
373
    }
374
  }
375
}
src/app/qgsmaptoolmeasureangle.h (working copy)
59 59
    /**Deletes the rubber band and the dialog*/
60 60
    void stopMeasuring();
61 61

  
62
    /** recalculate angle if projection state changed*/
63
    void changeStateProjectionEnable();
64

  
62 65
};
63 66

  
64 67
#endif // QGSMAPTOOLMEASUREANGLE_H
src/app/qgsmaptoolmeasureangle.cpp (working copy)
49 49
    QgsDistanceArea* distArea = mCanvas->mapRenderer()->distanceArea();
50 50
    if ( distArea )
51 51
    {
52
      double azimutOne = distArea->bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 0 ) );
53
      double azimutTwo = distArea->bearing( mAnglePoints.at( 1 ), point );
52
      //show angle in dialog
53
      if ( !mResultDisplay )
54
      {
55
        mResultDisplay = new QgsDisplayAngle( mCanvas->topLevelWidget() );
56
        QObject::connect( mResultDisplay, SIGNAL( rejected() ), this, SLOT( stopMeasuring() ) );
57
        QObject::connect( mResultDisplay, SIGNAL( changeStateProjectionEnable() ), 
58
            this, SLOT( changeStateProjectionEnable() ) );
59
        mResultDisplay->move( e->pos() - QPoint( 100, 100 ) );
60
      }
61
      mResultDisplay->show();   
62
      
63
      QgsDistanceArea myDa;
64
      myDa.setSourceCrs( mCanvas->mapRenderer()->destinationSrs().srsid() );
65
      myDa.setEllipsoid( distArea->ellipsoid() );
66
      myDa.setProjectionsEnabled( mResultDisplay->projectionEnabled() );
67

  
68
      //angle calculation
69
      double azimutOne = myDa.bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 0 ) );
70
      double azimutTwo = myDa.bearing( mAnglePoints.at( 1 ), point );
54 71
      double resultAngle = azimutTwo - azimutOne;
55 72
      QgsDebugMsg( QString::number( qAbs( resultAngle ) ) );
56 73
      QgsDebugMsg( QString::number( M_PI ) );
......
66 83
        }
67 84
      }
68 85

  
69
      //show angle in dialog
70
      if ( !mResultDisplay )
71
      {
72
        mResultDisplay = new QgsDisplayAngle( mCanvas->topLevelWidget() );
73
        QObject::connect( mResultDisplay, SIGNAL( rejected() ), this, SLOT( stopMeasuring() ) );
74
        mResultDisplay->move( e->pos() - QPoint( 100, 100 ) );
75
      }
76
      mResultDisplay->show();
77 86
      mResultDisplay->setValueInRadians( resultAngle );
78 87
    }
79 88
  }
......
145 154
  }
146 155
}
147 156

  
157
void QgsMapToolMeasureAngle::changeStateProjectionEnable()
158
{
159
  if ( mAnglePoints.size() != 3 )
160
    return;
161
  if ( !mResultDisplay )
162
    return;
163
  
164
  QgsDistanceArea myDa;
165
  myDa.setSourceCrs( mCanvas->mapRenderer()->destinationSrs().srsid() );
166
  myDa.setEllipsoid( mCanvas->mapRenderer()->distanceArea()->ellipsoid() );
167
  myDa.setProjectionsEnabled( mResultDisplay->projectionEnabled() );
148 168

  
169
  //angle calculation
170
  double azimutOne = myDa.bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 0 ) );
171
  double azimutTwo = myDa.bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 2 ) );
172
  double resultAngle = azimutTwo - azimutOne;
173
  QgsDebugMsg( QString::number( fabs( resultAngle ) ) );
174
  QgsDebugMsg( QString::number( M_PI ) );
175
  if ( fabs( resultAngle ) > M_PI )
176
  {
177
    if ( resultAngle < 0 )
178
    {
179
      resultAngle = M_PI + ( resultAngle + M_PI );
180
    }
181
    else
182
    {
183
      resultAngle = -M_PI + ( resultAngle - M_PI );
184
    }
185
  }
186
  mResultDisplay->setValueInRadians( resultAngle );
149 187

  
188
}
189

  
src/ui/qgsmeasurebase.ui (working copy)
31 31
   <property name="spacing">
32 32
    <number>6</number>
33 33
   </property>
34
   <item row="1" column="2">
34
   <item row="2" column="2">
35 35
    <widget class="QLineEdit" name="editTotal">
36 36
     <property name="font">
37 37
      <font>
......
47 47
     </property>
48 48
    </widget>
49 49
   </item>
50
   <item row="1" column="1">
50
   <item row="2" column="1">
51 51
    <spacer>
52 52
     <property name="orientation">
53 53
      <enum>Qt::Horizontal</enum>
......
63 63
     </property>
64 64
    </spacer>
65 65
   </item>
66
   <item row="1" column="0">
66
   <item row="2" column="0">
67 67
    <widget class="QLabel" name="textLabel2">
68 68
     <property name="text">
69 69
      <string>Total</string>
......
73 73
     </property>
74 74
    </widget>
75 75
   </item>
76
   <item row="0" column="0" colspan="3">
76
   <item row="1" column="0" colspan="3">
77 77
    <widget class="QTreeWidget" name="mTable">
78 78
     <property name="editTriggers">
79 79
      <set>QAbstractItemView::NoEditTriggers</set>
......
91 91
     </column>
92 92
    </widget>
93 93
   </item>
94
   <item row="2" column="2">
94
   <item row="3" column="2">
95 95
    <widget class="QDialogButtonBox" name="buttonBox">
96 96
     <property name="standardButtons">
97 97
      <set>QDialogButtonBox::Close|QDialogButtonBox::Help</set>
98 98
     </property>
99 99
    </widget>
100 100
   </item>
101
   <item row="0" column="0" colspan="3">
102
    <widget class="QCheckBox" name="mcbProjectionEnabled">
103
     <property name="text">
104
      <string>Ellipsoidal (WGS84)</string>
105
     </property>
106
    </widget>
107
   </item>
101 108
  </layout>
102 109
 </widget>
103 110
 <layoutdefault spacing="6" margin="11"/>
src/ui/qgsdisplayanglebase.ui (working copy)
6 6
   <rect>
7 7
    <x>0</x>
8 8
    <y>0</y>
9
    <width>276</width>
10
    <height>78</height>
9
    <width>293</width>
10
    <height>105</height>
11 11
   </rect>
12 12
  </property>
13 13
  <property name="windowTitle">
14 14
   <string>Angle</string>
15 15
  </property>
16 16
  <layout class="QGridLayout" name="gridLayout">
17
   <item row="0" column="0" colspan="2">
17
   <item row="1" column="0" colspan="2">
18 18
    <widget class="QLineEdit" name="mAngleLineEdit">
19 19
     <property name="readOnly">
20 20
      <bool>true</bool>
21 21
     </property>
22 22
    </widget>
23 23
   </item>
24
   <item row="1" column="0">
24
   <item row="2" column="0">
25 25
    <spacer name="horizontalSpacer">
26 26
     <property name="orientation">
27 27
      <enum>Qt::Horizontal</enum>
......
34 34
     </property>
35 35
    </spacer>
36 36
   </item>
37
   <item row="1" column="1">
37
   <item row="2" column="1">
38 38
    <widget class="QDialogButtonBox" name="buttonBox">
39 39
     <property name="orientation">
40 40
      <enum>Qt::Horizontal</enum>
......
44 44
     </property>
45 45
    </widget>
46 46
   </item>
47
   <item row="0" column="0">
48
    <widget class="QCheckBox" name="mcbProjectionEnabled">
49
     <property name="text">
50
      <string>Ellipsoidal (WGS84)</string>
51
     </property>
52
    </widget>
53
   </item>
47 54
  </layout>
48 55
 </widget>
49 56
 <resources/>