@@ -176,6 +176,13 @@ void table_connection_t::start(bool append)
176176 table ().has_geom_column () ? flex_table_t ::table_type::interim
177177 : flex_table_t ::table_type::permanent,
178178 table ().full_name ()));
179+
180+ if (table ().has_geom_column () &&
181+ table ().geom_column ().needs_isvalid ()) {
182+ create_geom_check_trigger (m_db_connection.get (), table ().schema (),
183+ table ().name (),
184+ table ().geom_column ().name ());
185+ }
179186 }
180187
181188 prepare ();
@@ -195,6 +202,11 @@ void table_connection_t::stop(bool updateable, bool append)
195202 util::timer_t timer;
196203
197204 if (table ().has_geom_column ()) {
205+ if (table ().geom_column ().needs_isvalid ()) {
206+ drop_geom_check_trigger (m_db_connection.get (), table ().schema (),
207+ table ().name ());
208+ }
209+
198210 log_info (" Clustering table '{}' by geometry..." , table ().name ());
199211
200212 // Notices about invalid geometries are expected and can be ignored
@@ -207,14 +219,6 @@ void table_connection_t::stop(bool updateable, bool append)
207219 std::string sql = " INSERT INTO {} SELECT * FROM {}" _format (
208220 table ().full_tmp_name (), table ().full_name ());
209221
210- if (table ().geom_column ().srid () != 4326 ) {
211- // libosmium assures validity of geometries in 4326.
212- // Transformation to another projection could make the geometry
213- // invalid. Therefore add a filter to drop those.
214- sql += " WHERE ST_IsValid(\" {}\" )" _format (
215- table ().geom_column ().name ());
216- }
217-
218222 auto const postgis_version = get_postgis_version (*m_db_connection);
219223
220224 sql += " ORDER BY " ;
@@ -257,7 +261,8 @@ void table_connection_t::stop(bool updateable, bool append)
257261 if (updateable && table ().has_id_column ()) {
258262 create_id_index ();
259263
260- if (table ().has_geom_column () && table ().geom_column ().srid () != 4326 ) {
264+ if (table ().has_geom_column () &&
265+ table ().geom_column ().needs_isvalid ()) {
261266 create_geom_check_trigger (m_db_connection.get (), table ().schema (),
262267 table ().name (),
263268 table ().geom_column ().name ());
0 commit comments