How to get appropriate CRS for a position specified in lat/lon coordinates?

You can calculate the UTM zone of each town center from the longitude, starting at zone 1 from -180°E to -174°E. zone=ROUND((183+longitude)/6;0) should calculate that in one step.

The EPSG code is 32600+zone for positive latitudes and 32700+zone for negatives.

Together in one formula:

EPSG=32700-ROUND((45+latitude)/90;0)*100+ROUND((183+longitude)/6;0)

Alternatively, create a custom CRS on the town center:

+proj=tmerc +lat_0=(latitude) +lon_0=(longitude) +k=1 +x_0=0 +y_0=0 +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs