Last active
June 13, 2020 10:39
-
-
Save mpuig/4502507 to your computer and use it in GitHub Desktop.
How to calculate the (real) distance of a linestring object, in km (or any other distance unit)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.contrib.gis.geos import Point | |
| from django.contrib.gis.geos import LineString | |
| from models import Track | |
| # [...] | |
| points = [] | |
| for lat,lon in coords: | |
| pnt = Point(float(lon), float(lat)) | |
| points.append(pnt) | |
| track.geom = Linestring(points) | |
| track.save() | |
| track.length = Track.objects.length().get(id=track.id).length.km | |
| track.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment