@@ -204,6 +204,39 @@ class Analyser_Osmosis(Analyser):
204
204
CREATE INDEX idx_multipolygons_poly_proj ON {0}.multipolygons USING gist(poly_proj);
205
205
CREATE INDEX idx_multipolygons_tags ON {0}.multipolygons USING gist (tags);
206
206
ANALYZE {0}.multipolygons;
207
+ """
208
+
209
+ sql_create_polygons = """
210
+ CREATE UNLOGGED TABLE {0}.polygons AS
211
+ SELECT
212
+ 'R' AS type,
213
+ id,
214
+ tags,
215
+ poly,
216
+ poly_proj
217
+ FROM
218
+ {0}.multipolygons
219
+ WHERE
220
+ is_valid
221
+ UNION ALL
222
+ SELECT
223
+ 'W' AS type,
224
+ id,
225
+ tags,
226
+ ST_MakePolygon(linestring) AS poly,
227
+ ST_MakePolygon(ST_Transform(linestring, {1})) AS poly_proj
228
+ FROM
229
+ ways
230
+ WHERE
231
+ tags != ''::hstore AND
232
+ is_polygon AND
233
+ ST_IsValid(ST_MakePolygon(ST_Transform(linestring, {1})))
234
+ ;
235
+
236
+ CREATE INDEX idx_polygons ON {0}.polygons USING gist(poly);
237
+ CREATE INDEX idx_polygons_proj ON {0}.polygons USING gist(poly_proj);
238
+ CREATE INDEX idx_polygons_tags ON {0}.polygons USING gist(tags);
239
+ ANALYZE {0}.polygons;
207
240
"""
208
241
209
242
sql_create_buildings = """
@@ -368,6 +401,15 @@ def requires_tables_build(self, tables):
368
401
elif table == 'touched_multipolygons' :
369
402
self .requires_tables_build (['multipolygons' ])
370
403
self .create_view_touched ('multipolygons' , 'R' )
404
+ elif table == 'polygons' :
405
+ self .requires_tables_build (["multipolygons" ])
406
+ self .giscurs .execute (self .sql_create_polygons .format (self .config .db_schema .split (',' )[0 ], self .config .options .get ("proj" )))
407
+ elif table == 'touched_polygons' :
408
+ self .requires_tables_build (["polygons" ])
409
+ self .create_view_touched ('polygons' , ['W' , 'R' ])
410
+ elif table == 'not_touched_polygons' :
411
+ self .requires_tables_build (["polygons" ])
412
+ self .create_view_not_touched ('polygons' , ['W' , 'R' ])
371
413
elif table == 'buildings' :
372
414
self .giscurs .execute (self .sql_create_buildings .format (self .config .db_schema .split (',' )[0 ], self .config .options .get ("proj" )))
373
415
elif table == 'touched_buildings' :
@@ -497,10 +539,11 @@ def create_view_touched(self, table, type, id = 'id'):
497
539
FROM
498
540
{0}
499
541
JOIN transitive_touched ON
500
- transitive_touched.data_type = '{1}' AND
501
- {0}.{2 } = transitive_touched.id
542
+ transitive_touched.data_type = ANY(%s) AND
543
+ {0}.{1 } = transitive_touched.id
502
544
"""
503
- self .giscurs .execute (sql .format (table , type , id ))
545
+ type = type if isinstance (type , (list , tuple )) else [type ]
546
+ self .giscurs .execute (sql .format (table , id ), (type , ))
504
547
505
548
def create_view_not_touched (self , table , type , id = 'id' ):
506
549
"""
@@ -513,12 +556,13 @@ def create_view_not_touched(self, table, type, id = 'id'):
513
556
FROM
514
557
{0}
515
558
LEFT JOIN transitive_touched ON
516
- transitive_touched.data_type = '{1}' AND
517
- {0}.{2 } = transitive_touched.id
559
+ transitive_touched.data_type = ANY(%s) AND
560
+ {0}.{1 } = transitive_touched.id
518
561
WHERE
519
562
transitive_touched.id IS NULL
520
563
"""
521
- self .giscurs .execute (sql .format (table , type , id ))
564
+ type = type if isinstance (type , (list , tuple )) else [type ]
565
+ self .giscurs .execute (sql .format (table , id ), (type , ))
522
566
523
567
def run00 (self , sql , callback = None ):
524
568
if self .explain_sql :
0 commit comments