0

How can I code a script in python for the following problem? I have starting and ending coordinates of a straight line. I want to find coordinate of a point with a given distance from the starting point.

screenshot of input data in Excel

martineau
  • 119,623
  • 25
  • 170
  • 301
  • You can [linearly interpolate](https://en.wikipedia.org/wiki/Linear_interpolation) between the start point and the end point. This isn't accurate for long distances on the surface of the Earth, but may be close enough for relatively short ones. For more precision, you'll need to use the [Harersine formula](https://en.wikipedia.org/wiki/Haversine_formula) as shown in this [answer](https://stackoverflow.com/a/71704263/355230). – martineau Jul 18 '22 at 18:01

1 Answers1

0

May be this might help you. I had converted the coordinates into polar coordinates,

import pandas as pd
import re

df = pd.DataFrame({"Start_Northing": ["41°10'23"],"Start_Easting":["61°26'24"],"End_Northing":["41°10'42"],
     "End_Easting": ["61°27'00"]})

def dms2dd(s):
    degrees, minutes, seconds = re.split('[°\'"]+', s)
    dd = float(degrees) + float(minutes)/60 + float(seconds)/(60*60)
    return dd

for column in df.columns:
    df['New_'+ str(column)] = df[column].apply(dms2dd)
df['point Easting'] = df[["New_End_Northing", "New_End_Easting"]].apply(tuple, axis=1)
df["point Northing'"] = df[["New_Start_Northing", "New_Start_Easting"]].apply(tuple, axis=1)
df = df.drop(['New_Start_Northing','New_Start_Easting','New_End_Northing','New_End_Easting'],axis=1)
print(df.to_string())

The result is,

  Start_Northing Start_Easting End_Northing End_Easting               point Easting             point Northing'
0       41°10'23      61°26'24     41°10'42    61°27'00  (41.17833333333333, 61.45)  (41.17305555555555, 61.44)
Berlin Benilo
  • 472
  • 1
  • 12