A method for planning and optimizing a path of a machinery moving in an area, comprises the steps of: taking coordinates of an area-contour, an operating width of the moving machinery, a distance between the area-contour and a perimetric path within the area-contour as parameters, eroding (mathematical morphological operation) the area by the distance to an interior of the area, thereby obtaining a smaller area delineated by a contour, selecting a lane orientation within the eroded area contour, and partitioning the eroded area into adjacent interior lanes, intersecting the interior lanes with the eroded area contour, thereby generating a lane grid and a corresponding connected undirected transition graph, performing a mathematical algorithm for determining an optimized sequence of position coordinates on the lane grid, wherein a complete area covering path is generated. This method enables a cost-efficient optimized path of machinery through agricultural fields.