Spatially selective measurement of temperature or pH