@@ -116,34 +116,51 @@ func (s *Server) BillsShapefilesHandler() http.HandlerFunc {
116116 WHERE 1=1
117117 -- Dynamic bill filters will be added here
118118 ),
119+ unique_parishes AS (
120+ SELECT DISTINCT ON (civ_par, start_yr, ST_AsText(geom_01))
121+ id,
122+ par,
123+ civ_par,
124+ dbn_par,
125+ omeka_par,
126+ subunit,
127+ city_cnty,
128+ start_yr,
129+ sp_total,
130+ sp_per,
131+ geom_01
132+ FROM bom.parishes_shp
133+ WHERE 1=1
134+ -- Dynamic parish filters will be added here
135+ ),
119136 parish_data AS (
120- SELECT
121- parishes_shp .id,
122- parishes_shp .par,
123- parishes_shp .civ_par,
124- parishes_shp .dbn_par,
125- parishes_shp .omeka_par,
126- parishes_shp .subunit,
127- parishes_shp .city_cnty,
128- parishes_shp .start_yr,
129- parishes_shp .sp_total,
130- parishes_shp .sp_per,
137+ SELECT
138+ unique_parishes .id,
139+ unique_parishes .par,
140+ unique_parishes .civ_par,
141+ unique_parishes .dbn_par,
142+ unique_parishes .omeka_par,
143+ unique_parishes .subunit,
144+ unique_parishes .city_cnty,
145+ unique_parishes .start_yr,
146+ unique_parishes .sp_total,
147+ unique_parishes .sp_per,
131148 COALESCE(SUM(CASE WHEN fb.count_type = 'buried' THEN fb.count ELSE 0 END), 0) as total_buried,
132149 COALESCE(SUM(CASE WHEN fb.count_type = 'plague' THEN fb.count ELSE 0 END), 0) as total_plague,
133150 COUNT(fb.parish_id) as bill_count,
134- parishes_shp .geom_01
135- FROM
136- bom.parishes_shp
151+ unique_parishes .geom_01
152+ FROM
153+ unique_parishes
137154 LEFT JOIN
138- bom.parishes p ON p.canonical_name = parishes_shp .civ_par
155+ bom.parishes p ON LOWER(REPLACE(REPLACE( p.canonical_name, '-', ' '), '.', '')) = LOWER(REPLACE(REPLACE(unique_parishes .civ_par, '-', ' '), '.', ''))
139156 LEFT JOIN
140157 filtered_bills fb ON fb.parish_id = p.id
141158 WHERE 1=1
142159 -- Dynamic parish filters will be added here
143160 GROUP BY
144- parishes_shp .id, parishes_shp .par, parishes_shp .civ_par, parishes_shp .dbn_par,
145- parishes_shp .omeka_par, parishes_shp .subunit, parishes_shp .city_cnty,
146- parishes_shp .start_yr, parishes_shp .sp_total, parishes_shp .sp_per, parishes_shp .geom_01
161+ unique_parishes .id, unique_parishes .par, unique_parishes .civ_par, unique_parishes .dbn_par,
162+ unique_parishes .omeka_par, unique_parishes .subunit, unique_parishes .city_cnty,
163+ unique_parishes .start_yr, unique_parishes .sp_total, unique_parishes .sp_per, unique_parishes .geom_01
147164 )
148165 SELECT json_build_object(
149166 'type', 'FeatureCollection',
@@ -230,10 +247,11 @@ func buildSeparateFilters(year, startYear, endYear, subunit, cityCounty, billTyp
230247 var parishFilters []string
231248
232249 // Add filters based on provided parameters
250+ // Note: Year filters only apply to bills, not parish geometries
251+ // Parish geometries are filtered by other attributes (subunit, city_cnty, parish ID)
233252 if year != "" {
234253 if yearInt , err := strconv .Atoi (year ); err == nil {
235254 billFilters = append (billFilters , fmt .Sprintf ("AND b.year = %d" , yearInt ))
236- parishFilters = append (parishFilters , fmt .Sprintf ("AND parishes_shp.start_yr = %d" , yearInt ))
237255 }
238256 } else {
239257 // Use start-year and end-year if provided
0 commit comments