Assessing the risk of epidemics is crucial for safeguarding public health. Current research on epidemic risk assessment mostly relies on administrative divisions, which fail to capture the spatial differences in risk within these divisions. Taking Shanghai as a case study, this research employs geocoding techniques to spatialize the distribution of cases within administrative regions. It combines this information with geospatial big data that exhibits a strong correlation with population exposure rates as risk factors. Using GIS technology, the data is spatialized, and a relationship between risk factors and the distribution of new cases is established through geographic detectors and geographically weighted regression models. This approach enables the assessment of epidemic infection risks in different regions within administrative divisions based on the spatiotemporal variation of case distribution. The results demonstrate that the assessment method developed in this study effectively reflects the infection risks in different areas within administrative divisions. The risk index generated by the model exhibits a strong Spearman correlation coefficient (p = 0.869, p < 0.001) and a high coefficient of determination (R2 = 0.938, p < 0.001) when compared to the actual distribution of new cases. This confirms the accuracy of assessing infection risks across different spatial areas. The methodology proposed in this study can be applied for epidemic risk assessment during public health emergencies and assist in formulating effective prevention and control policies.