Spin reorientation in the vicinity of the edge of ultrathin magnetic films and nanowires