Integrating territorial spatial planning with the spatial autocorrelation of cultivated land quality indices can enhance the optimization of farmland preservation and food security. This study combines the “three lines” demarcation—basic farmland protection line, ecological protection line, and urban development boundary—with farmland spatial autocorrelation to propose an improved model for optimizing farmland layout. We employed a four-dimensional farmland quality evaluation system that includes the natural quality index, utilization management index, ecological environment index, and economic value index. Using Liuhe District as a case study, we applied the optimal combination weighting method for quality assessment and conducted spatial autocorrelation analysis to simulate the indices’ relationships at the plot scale. The results indicate that: (1) The natural quality index is high in the west and low in the east, while the other indices are high in the center and low at the margins. (2) Each quality index exhibits positive geographic autocorrelation, with Moran’s I values of 0.89, 0.67, 0.65, and 0.83, respectively. (3) The optimization scheme increased permanent basic farmland by 123.15 hm² and improved the quality grade by 1.45, classifying land into four primary categories focused on protection and development. The permanent basic farmland protection zone has the highest quality and non-agricultural construction should be prohibited on it. The urban development buffer zone, which has poor farmland quality and a locational advantage, is ideal for urban growth. The ecological environmental protection zone, despite its poor farmland quality, should be focused on conservation. The comprehensive adjustment zone should address land obstructions and facilitate a transition to permanent basic farmland.