Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
naming
Source Link
Vince
  • 20.3k
  • 16
  • 48
  • 65

I have a list of coordinates, knowing that I am working using EPSG:4326 and using Python I would like to calculate the length in kilometres of the polyline defined by these coordinates.

Coords = [(0.0, 50.787944),
 (0.0, 50.787944),
 (-0.20159865271498856, 50.824569950535725),
 (-0.40044683717220364, 50.803694),
 (-0.599761967889834, 50.78975316549538)]

I've tried with geopandasGeoPandas and shapely but reading the documentation I can't find an easy way to do it. Is there any function that allows me to calculate the length in kilometre knowing Coords and the reference system used?

I have a list of coordinates, knowing that I am working using EPSG:4326 and using Python I would like to calculate the length in kilometres of the polyline defined by these coordinates.

Coords = [(0.0, 50.787944),
 (0.0, 50.787944),
 (-0.20159865271498856, 50.824569950535725),
 (-0.40044683717220364, 50.803694),
 (-0.599761967889834, 50.78975316549538)]

I've tried with geopandas and shapely but reading the documentation I can't find an easy way to do it. Is there any function that allows me to calculate the length in kilometre knowing Coords and the reference system used?

I have a list of coordinates, knowing that I am working using EPSG:4326 and using Python I would like to calculate the length in kilometres of the polyline defined by these coordinates.

Coords = [(0.0, 50.787944),
 (0.0, 50.787944),
 (-0.20159865271498856, 50.824569950535725),
 (-0.40044683717220364, 50.803694),
 (-0.599761967889834, 50.78975316549538)]

I've tried with GeoPandas and shapely but reading the documentation I can't find an easy way to do it. Is there any function that allows me to calculate the length in kilometre knowing Coords and the reference system used?

I don't think is a good idea to duplicate the content, the code provided was a possible answer maybe note the best but surely fully functional.
Source Link
G M
  • 2.1k
  • 2
  • 21
  • 31

I have a list of coordinates, knowing that I am working using EPSG:4326 and using Python I would like to calculate the length in kilometres of the polyline defined by these coordinates.

Coords = [(0.0, 50.787944),
 (0.0, 50.787944),
 (-0.20159865271498856, 50.824569950535725),
 (-0.40044683717220364, 50.803694),
 (-0.599761967889834, 50.78975316549538)]

I've tried with geopandas and shapely but reading the documentation I can't find an easy way to do it. Is there any function that allows me to calculate the length in kilometre knowing Coords and the reference system used?

Eventually, I have understood the steps to follow I had to convert the EPSG:4326 which has degrees as for units to a coordinate system in meters as EPSG:32618. So eventually I have end up following the instructions in the shapely documentation for transformations.

Coords = [(0.0, 50.787944),
 (0.0, 50.787944),
 (-0.20159865271498856, 50.824569950535725),
 (-0.40044683717220364, 50.803694),
 (-0.599761967889834, 50.78975316549538)] 
 
polyline = LineString(Coords)

After converting the list of coordinates to a shapely LineString I used pyproj for computing the transformation. I had initially a attributeError : module 'pyproj' has no attribute 'CRS' because I was using an old version.

import pyproj

from shapely.geometry import Point
from shapely.ops import transform


wgs84 = pyproj.CRS('EPSG:4326')
utm = pyproj.CRS('EPSG:32618')
utm_polyline = transform(project, wgs84_pt)
length_km = utm_polyline.length/1000

If using pyproj < 2.1:

from functools import partial
import pyproj

from shapely.ops import transform


wgs84 = pyproj.Proj(init='epsg:4326')
utm = pyproj.Proj(init='epsg:32618')

project = partial(
    pyproj.transform,
    wgs84,
    utm)

utm_polyline = transform(project, polyline)
length_km = utm_polyline.length/1000

I have a list of coordinates, knowing that I am working using EPSG:4326 and using Python I would like to calculate the length in kilometres of the polyline defined by these coordinates.

Coords = [(0.0, 50.787944),
 (0.0, 50.787944),
 (-0.20159865271498856, 50.824569950535725),
 (-0.40044683717220364, 50.803694),
 (-0.599761967889834, 50.78975316549538)]

I've tried with geopandas and shapely but reading the documentation I can't find an easy way to do it. Is there any function that allows me to calculate the length in kilometre knowing Coords and the reference system used?

Eventually, I have understood the steps to follow I had to convert the EPSG:4326 which has degrees as for units to a coordinate system in meters as EPSG:32618. So eventually I have end up following the instructions in the shapely documentation for transformations.

Coords = [(0.0, 50.787944),
 (0.0, 50.787944),
 (-0.20159865271498856, 50.824569950535725),
 (-0.40044683717220364, 50.803694),
 (-0.599761967889834, 50.78975316549538)] 
 
polyline = LineString(Coords)

After converting the list of coordinates to a shapely LineString I used pyproj for computing the transformation. I had initially a attributeError : module 'pyproj' has no attribute 'CRS' because I was using an old version.

import pyproj

from shapely.geometry import Point
from shapely.ops import transform


wgs84 = pyproj.CRS('EPSG:4326')
utm = pyproj.CRS('EPSG:32618')
utm_polyline = transform(project, wgs84_pt)
length_km = utm_polyline.length/1000

If using pyproj < 2.1:

from functools import partial
import pyproj

from shapely.ops import transform


wgs84 = pyproj.Proj(init='epsg:4326')
utm = pyproj.Proj(init='epsg:32618')

project = partial(
    pyproj.transform,
    wgs84,
    utm)

utm_polyline = transform(project, polyline)
length_km = utm_polyline.length/1000

I have a list of coordinates, knowing that I am working using EPSG:4326 and using Python I would like to calculate the length in kilometres of the polyline defined by these coordinates.

Coords = [(0.0, 50.787944),
 (0.0, 50.787944),
 (-0.20159865271498856, 50.824569950535725),
 (-0.40044683717220364, 50.803694),
 (-0.599761967889834, 50.78975316549538)]

I've tried with geopandas and shapely but reading the documentation I can't find an easy way to do it. Is there any function that allows me to calculate the length in kilometre knowing Coords and the reference system used?

Tiny adjustments
Source Link
Taras
  • 34k
  • 4
  • 73
  • 148

I have a list of coordinates, knowing that I am working using EPSG:4326 and using Python I would like to calculate the length in kilometres of the polyline defined by these coordinates.

Coords = [(0.0, 50.787944),
 (0.0, 50.787944),
 (-0.20159865271498856, 50.824569950535725),
 (-0.40044683717220364, 50.803694),
 (-0.599761967889834, 50.78975316549538)]

I've tried with geopandas and shapely but reading the documentation I can't find an easy way to do it. Is there any function that allows me to calculate the length in kilometre knowing Coords and the reference system used?

Eventually, I have understood the steps to follow I had to convert the EPSG:4326 which has degrees as for units to a coordinate system in meters as EPSG:32618. So eventually I have end up following the instructions in the shapely documentation for transformations.

Coords = [(0.0, 50.787944),
 (0.0, 50.787944),
 (-0.20159865271498856, 50.824569950535725),
 (-0.40044683717220364, 50.803694),
 (-0.599761967889834, 50.78975316549538)] 
 
polyline = LineString(Coords)

After converting the list of coordinates to a shapely LineString I used pyproj for computing the transformation. I had initially a attributeError : module 'pyproj' has no attribute 'CRS' because I was using an old version.

import pyproj

from shapely.geometry import Point
from shapely.ops import transform


wgs84 = pyproj.CRS('EPSG:4326')
utm = pyproj.CRS('EPSG:32618')
utm_polyline = transform(project, wgs84_pt)
length_km = utm_polyline.length/1000

If using pyproj < 2.1:

from functools import partial
import pyproj

from shapely.ops import transform


wgs84 = pyproj.Proj(init='epsg:4326')
utm = pyproj.Proj(init='epsg:32618')

project = partial(
    pyproj.transform,
    wgs84,
    utm)

utm_polyline = transform(project, polyline)
length_km = utm_polyline.length/1000

I have a list of coordinates, knowing that I am working using EPSG:4326 and using Python I would like to calculate the length in kilometres of the polyline defined by these coordinates.

Coords = [(0.0, 50.787944),
 (0.0, 50.787944),
 (-0.20159865271498856, 50.824569950535725),
 (-0.40044683717220364, 50.803694),
 (-0.599761967889834, 50.78975316549538)]

I've tried with geopandas and shapely but reading the documentation I can't find an easy way to do it. Is there any function that allows me to calculate the length in kilometre knowing Coords and the reference system used?

I have a list of coordinates, knowing that I am working using EPSG:4326 and using Python I would like to calculate the length in kilometres of the polyline defined by these coordinates.

Coords = [(0.0, 50.787944),
 (0.0, 50.787944),
 (-0.20159865271498856, 50.824569950535725),
 (-0.40044683717220364, 50.803694),
 (-0.599761967889834, 50.78975316549538)]

I've tried with geopandas and shapely but reading the documentation I can't find an easy way to do it. Is there any function that allows me to calculate the length in kilometre knowing Coords and the reference system used?

Eventually, I have understood the steps to follow I had to convert the EPSG:4326 which has degrees as for units to a coordinate system in meters as EPSG:32618. So eventually I have end up following the instructions in the shapely documentation for transformations.

Coords = [(0.0, 50.787944),
 (0.0, 50.787944),
 (-0.20159865271498856, 50.824569950535725),
 (-0.40044683717220364, 50.803694),
 (-0.599761967889834, 50.78975316549538)] 
 
polyline = LineString(Coords)

After converting the list of coordinates to a shapely LineString I used pyproj for computing the transformation. I had initially a attributeError : module 'pyproj' has no attribute 'CRS' because I was using an old version.

import pyproj

from shapely.geometry import Point
from shapely.ops import transform


wgs84 = pyproj.CRS('EPSG:4326')
utm = pyproj.CRS('EPSG:32618')
utm_polyline = transform(project, wgs84_pt)
length_km = utm_polyline.length/1000

If using pyproj < 2.1:

from functools import partial
import pyproj

from shapely.ops import transform


wgs84 = pyproj.Proj(init='epsg:4326')
utm = pyproj.Proj(init='epsg:32618')

project = partial(
    pyproj.transform,
    wgs84,
    utm)

utm_polyline = transform(project, polyline)
length_km = utm_polyline.length/1000
Title changed, Content structured, Two tags added
Source Link
Taras
  • 34k
  • 4
  • 73
  • 148
Loading
Source Link
G M
  • 2.1k
  • 2
  • 21
  • 31
Loading