I am working on datasets that provides me the GPS Coordinates (Latitudes and Longitudes) of the path covered by a tractor (in .csv format). I want to separate the field and path from the data (refer to the images below).
Sample Dataset: https://drive.google.com/open?id=1rVNbkuJuPmcGUzQI9NhKwYJPgcEeypq3
Plot of my Data
Plot Explained
Here is the code for reading the csv and plotting it,
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
path = r"data_stackoverflow.csv" #importing Data
df = pd.read_csv(path) #Read .csv to a pandas dataframe
latitude = df.Latitude.tolist() #convert the column Latitude to list, latitude
longitude = df.Longitude.tolist() #convert the column Longitude to list, longitude
coordinates=list(zip(latitude, longitude))
arr = np.array(coordinates) #numpy array of all points
x=arr[:,[0]]
y=arr[:,[1]]
plt.title("GPS Data Visualized")
plt.xlabel("Latitude")
plt.ylabel("Longitude")
plt.plot(x,y)
plt.scatter(x,y)
My Question
How do I separate the path from the field? Is there any specific algorithm to do so?
I have tried implementing DBSCAN on the dataset but the result is not always accurate.
What should my result be
I want a dataframe as a result that must gives me field data points only.
The plot of my result should look somewhat like this (field only),
Sample Result
I think we can consider points belonging to the path to a field as outliers.
Demo:
from sklearn.ensemble import IsolationForest
out = IsolationForest(n_estimators=200, contamination="auto", behaviour="new")
df["x"] = out.fit_predict(df[["Latitude", "Longitude"]])
mask = df["x"] == 1
fig, (ax1, ax2) = plt.subplots(2, 1, sharex=True, sharey=True, figsize=(10, 10))
ax1.plot(df["Longitude"], df["Latitude"], linewidth=1)
ax2.plot(df.loc[mask, "Longitude"], df.loc[mask, "Latitude"], linewidth=1)

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With