  We use the Gaia DR2 catalog to improve the astrometric accuracy of about 1.7
billion objects in Pan-STARRS1 Data Release 2 (PS1 DR2). We also obtain proper
motions for these PS1 objects. The cross match between Gaia and PS1 reveals
residuals that are correlated on a scale of about 1 arcmin. We apply a
spatially adaptive correction algorithm for all PS1 objects having more than
two detections to reduce these residuals and align the object positions to
Gaia. For point-like PS1 objects that cross match to Gaia, the algorithm
reduces PS1/Gaia residuals by 33% in position (median value of 13.5 mas reduced
to 9.0 mas) and by 24% in proper motion (median value of 6.3 mas/yr reduced to
4.8 mas/yr). The residuals for the corrected positions are smallest for objects
with the most point-like morphologies and with intermediate magnitudes of about
17 mag. The residual errors in declination are systematically larger than those
in right ascension; the declination errors increase with zenith angle in
proportion to the air mass of the observations. Declination positional
residuals at a given declination generally vary with color and are consistent
with the effects of differential atmospheric refraction. In principle, these
residuals could be reduced further by taking into account object color.
