  To understand the history and formation mechanisms of galaxies it is crucial
to determine their current multidimensional structure. Here we focus on stellar
population properties, such as metallicity and [$\alpha$/Fe] enhancement. We
devise a new technique to recover the distribution of these parameters using
spatially resolved, line-of-sight averaged data. Our chemodynamical method is
based on the made-to-measure (M2M) framework and results in an $N$-body model
for the abundance distribution. We test our method on a mock data set and find
that the radial and azimuthal profiles are well-recovered, however only the
overall shape of the vertical profile matches the true profile. We apply our
procedure to spatially resolved maps of mean [Z/H] and [$\alpha$/Fe] for the
Andromeda Galaxy, using an earlier barred dynamical model of M31. We find that
the metallicity is enhanced along the bar, with possible maxima at the ansae.
In the edge-on view the [Z/H] distribution has an X shape due to the
boxy/peanut bulge; the average vertical metallicity gradient is equal to
$-0.133\pm0.006$ dex/kpc. We identify a metallicity-enhanced ring around the
bar, which also has relatively lower [$\alpha$/Fe]. The highest [$\alpha$/Fe]
is found in the centre, due to the classical bulge. Away from the centre, the
$\alpha$-overabundance in the bar region increases with height, which could be
an indication of a thick disc. We argue that the galaxy assembly resulted in a
sharp peak of metallicity in the central few hundred parsecs and a more gentle
negative gradient in the remaining disc, but no [$\alpha$/Fe] gradient. The
formation of the bar lead to the re-arrangement of the [Z/H] distribution,
causing a flat gradient along the bar. Subsequent star formation close to the
bar ends may have produced the metallicity enhancements at the ansae and the
[Z/H] enhanced lower-$\alpha$ ring.
