I've been trying to use QGIS to calculate the length of polylines found in KML files, after having difficulty getting ArcGIS to work properly.

I used this process: https://www.qgistutorials.com/en/docs/3/calculating_line_lengths.html

Essentially doing:

  1. Starting default project in QGIS (using EPSG:4326)
  2. Using QuickMapServices to set a base map layer (say, google hybrid)
  3. Dragging and dropping the KML into QGIS. The placement of the KML aligns with the basemap, as well as the KML's placement in other programs like google earth.
  4. Either using the tutorial listed above (creating a geometry attributes layer via 'ellipsoidal' CRS) or using the field calculator to create a length attributes table.

Then using the lengths as I please.

However, there seems to be a difference in value between google earth pro and QGIS in some cases. In a test KML file I made in google earth pro, the length of a 15km line is almost exactly the same value (difference of about 10 metres) but with other files, the difference is almost double, despite the fact that they look exactly the same in KML

What could be causing this difference? Is it something to do with the KML files themselves (could the imported files be interpreting the lines as rectangles)? The process of importing and/or calculating? Something else?

EDIT: Ok, something is up - it seems that only ONE of the kml files i have been using previously are acting strangely. Not sure what's causing this specific one to have massive differences in distance, but the others I have used before all seem to mostly match the distances that QGIS report.

  • Is the difference dependent on latitude, by any chance? If something is being interpreted as being EPSG:3857 (Google "pseudo-Mercator"), local scale will be off by a factor of cos(latitude). Also, check what CRS your imported KML is in. – Houska Feb 10 at 1:38
  • @Houska The KML is imported as EPSG:4326. The QuickMapServices 'Google Hybrid' uses a CRS of EPSG:3857, but i use 'Ellipsoidal' instead of 'Project' or 'Layer' CRS to calculate the geometry attributes. I'm not sure how to check if difference is dependent on latitude, but the latitudes i'm using show a distance much smaller than it currently is. – jos Feb 10 at 1:54
  • @Houska KML files are always in EPSG:4326 (WGS84 Geographic) - it's in the specification. Ellipsoidal isn't a coordinate reference system, unless 'ellipsoidal' really means geodesic, what coordinate reference system are you using? If your lines fall way outside the bounds geometries can be severely distorted. Choosing a more local UTM, Lamberts or Albers projection should give more dependable results. – Michael Stimson Feb 10 at 1:57
  • I'm still very new to QGIS and GIS in general @MichaelStimson - how can I determine what CRS I'm using? It either seems to default to EPSG:4326 if I import the KML first or EPSG:3857 if I use the QuickMapServices option, but regardless of which CRS I use by default, the measurement remains the same. Ellipsoid is set to WGS84 as well. – jos Feb 10 at 2:01
  • You can change it in the canvas properties, however in that tutorial you can supply a projected coordinate reference system for your data if it has been projected, right click on the KML layer then save as, in the dialog you can opt to set the CRS (see gislounge.com/save-selection-new-file-using-qgis for pictures) change CRS to a local projected coordinate system. – Michael Stimson Feb 10 at 2:08

Turns out that the KML file I was using was made strangely - every line had an exact duplicate of itself hidden underneath it, which QGIS used in the geometric attributes to effectively double the length of each line.

The reason that the resulting geometric attributes weren't exactly doubled was because of the different datums mentioned by others; that, and perhaps a difference in how Google Earth/QGIS calculates distance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.