You convert your contour to polylines
You get a list of grid points
For each polyline point you check which gridpoint is the closest → update the polyline point location to that gridpoint ( or simply use the list of closest gridpoints)
You pass the points to a cull duplicates
You rebuild the polyline from the culled list