Two-dimensional (2D) magnetic interactions, a single dx2-y2 band, and strong orbital splitting between dx2-y2 and d3z2-r2 orbitals are essential characteristics of cuprate superconductors. However, infinite-layer nickelates with small rare-earth ion display three-dimensional (3D) magnetic correlations, itinerant Ni d3z2-r2 band at the Fermi level, and weak orbital splitting between two eg orbitals, strikingly different from those of cuprate, which might be detrimental for superconducting properties. Here, through first-principles calculations, we predict that epitaxial strain in infinite-layer nickelates RNiO2 could fulfill the deliberate switching from 3D to 2D electronic and magnetic transitions. A general strain-orbital-spin relationship is proposed, and the strain controlled relative position of the localized Ni dx2-y2 band and itinerant Ni d3z2-r2 band are revealed to be the key ingredient that governs the Fermi surface and strength of the interlayer magnetic interactions. For RNiO2 with smaller rare-earth ion like DyNiO2, we propose that the desired cuprate-like electronic structure and 2D magnetic dimensionality could be successfully realized by compressive strain through tuning the energy level of Ni dx2-y2 and d3z2-r2 bands. We further develop a finite-temperature lattice wannier model and a Heisenberg spin model, which establish a complete temperature- and strain-dependent structural and magnetic phase diagram of epitaxial DyNiO2 thin films. Our work opens new perspective for the modulation of lattice, orbital, and spin states in infinite-layer nickelates and provides rich structural, electronic, and magnetic flexibility for the control of the superconducting-related properties.