PurposeDemolishing abandoned buildings has been found to reduce nearby firearm violence. However, these effects might vary within cities and across time scales. We aimed to identify potential moderators of the effects of demolitions on firearm violence using a novel approach that combined machine learning and aerial imagery.MethodsOutcomes were annual counts of fatal and non-fatal shootings in Rochester, New York, from 2000 to 2020. Treatment was demolitions conducted from 2009 to 2019. Units of analysis were 152×152 m grid squares. We used a difference-in-differences approach to test effects: (A) the year after each demolition and (B) as demolitions accumulated over time. As moderators, we used a built environment typology generated by extracting information from aerial imagery using convolutional neural networks, a deep learning approach, combined with k-means clustering. We stratified our main models by built environment cluster to test for moderation.ResultsOne demolition was associated with a 14% shootings reduction (incident rate ratio (IRR)=0.86, 95% CI 0.83 to 0.90, p<0.001) the following year. Demolitions were also associated with a long-term, 2% reduction in shootings per year for each cumulative demolition (IRR=0.98, 95% CI 0.95 to 1.00, p=0.02). In the stratified models, densely built areas with higher street connectivity displayed following-year effects, but not long-term effects. Areas with lower density and larger parcels displayed long-term effects but not following-year effects.ConclusionsThe built environment might influence the magnitude and duration of the effects of demolitions on firearm violence. Policymakers may consider complementary programmes to help sustain these effects in high-density areas.