If you're working into the QGIS Python Console, do this:
Set the
ellipsoidalMode
toTrue
:distance.setEllipsoidalMode(True)
Set the ellipsoid over which QGIS will perform calculations, e.g., WGS84:
distance.setEllipsoid('WGS84')
Now you can measure the distance once again (which will give you ~322.48m.):
m = distance.measureLine(point1, point2)
If, on the contrary, you're working out of QGIS, i.e., in a PyQGIS standalone script, you need to setup the whole QGIS environment, which means that you need to initialize QGIS resources, among which are the reference systems used by QGIS. Just run the following code (adjust the prefixadjust the prefix if you're working on a different environment):
from qgis.core import QgsDistanceArea, QgsCoordinateReferenceSystem, QgsPoint, QgsApplication
from PyQt4.QtGui import QApplication
app = QApplication([])
QgsApplication.setPrefixPath("/usr", True) # Adjust it to your path
QgsApplication.initQgis()
point1 = QgsPoint(-46.443077,-67.51561)
point2 = QgsPoint(-46.4446,-67.512778)
#Create a measure object
distance = QgsDistanceArea()
crs = QgsCoordinateReferenceSystem()
crs.createFromSrsId(3452) # EPSG:4326
distance.setSourceCrs(crs)
distance.setEllipsoidalMode(True)
distance.setEllipsoid('WGS84')
m = distance.measureLine(point1, point2) # ~322.48m.