-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
40 lines (34 loc) · 1.42 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import numpy as np
import pandas as pd
from shapely.geometry import Polygon
import matplotlib
matplotlib.use('Qt5Agg')
def preProcessObs(dfObstaclesRaw):
# Preprocess dfObstacles
dfObstacles = dfObstaclesRaw.rename({dfObstaclesRaw.columns[0]: 'NumPoints',
dfObstaclesRaw.columns[1]: 'X',
dfObstaclesRaw.columns[2]: 'Y',
dfObstaclesRaw.columns[3]: 'Z',
dfObstaclesRaw.columns[4]: 'obsType'}, axis=1)
dfObstacles = dfObstacles.sort_values(by=['obsType'])
return dfObstacles
# A Function to form a map from the obstacles data
def point2Obs(dfObstacles, pointMultiplier=4):
# Set the polygons DF
dfPoly = pd.DataFrame()
dfPoly.insert(len(dfPoly.columns), column='Name', value=np.unique(dfObstacles.obsType))
polyList = []
xx = []
yy = []
for obs in dfPoly['Name']:
dfObs = dfObstacles[dfObstacles.obsType == obs]
pointList = []
for point in range(len(dfObs)):
pointList.append((dfObs.iloc[point].X, dfObs.iloc[point].Y))
polyUpgraded = Polygon(pointList).convex_hull
x, y = polyUpgraded.exterior.coords.xy
xx = xx + x.tolist()
yy = yy + y.tolist()
polyList.append(polyUpgraded)
dfPoly.insert(len(dfPoly.columns), column='Polygon', value=polyList)
return dfPoly