The continuous worsening of urban thermal environments poses a severe threat to human health and is among the main problems associated with urban climate change and sustainable development. This issue is particularly severe in high-density built-up areas. Existing studies on the thermal environments (temperature data extracted from satellite remote sensing images) are mainly focused on urban canopy areas (airspace below the average height of trees or buildings) rather than the near surface region (at pedestrian height). However, the main outdoor activity space of urban residents is the area near surface region. Hence, this study aims to investigate the influence of urban form (i.e., building density, height, and openness) on thermal environment near the surface region. The high-density built-up areas of a typical megacity (i.e., Nanjing) in China were selected, and the thermal environments of 26 typical blocks were simulated using ENVI-met software. Temperature field measurements were carried out for simulation validation. On this basis, a classified and comparative study was conducted by selecting the key spatial form elements that affect thermal environments. The results showed that in actual high-density built-up areas, single urban form parameter does not determine the thermal environments near the urban surface but mainly affected by the use (function) of space. For this study, the overall thermal environment of a street block is optimal when the building density is between 40% and 50% and the average building height is between 8 and 17 stories. Nonetheless, the urban form can be improved to optimize the overall effects on building functions and thermal environments. Furthermore, function-specific urban form optimization strategies were proposed to optimize thermal environments according to specific functional needs.