// Select all nodes inside the box into the node temp table.
LOG.finer("Selecting all nodes inside bounding box.");
rowCount = jdbcTemplate.update(
"CREATE TEMPORARY TABLE bbox_nodes ON COMMIT DROP AS"
+ " SELECT * FROM nodes WHERE (geom && ?)",
new PGgeometry(bboxPolygon));
LOG.finer("Adding a primary key to the temporary nodes table.");
jdbcTemplate.update("ALTER TABLE ONLY bbox_nodes ADD CONSTRAINT pk_bbox_nodes PRIMARY KEY (id)");
LOG.finer("Updating query analyzer statistics on the temporary nodes table.");
jdbcTemplate.update("ANALYZE bbox_nodes");
// Select all ways inside the bounding box into the way temp table.
if (capabilityChecker.isWayLinestringSupported()) {
LOG.finer("Selecting all ways inside bounding box using way linestring geometry.");
// We have full way geometry available so select ways
// overlapping the requested bounding box.
rowCount = jdbcTemplate.update(
"CREATE TEMPORARY TABLE bbox_ways ON COMMIT DROP AS"
+ " SELECT * FROM ways WHERE (linestring && ?)",
new PGgeometry(bboxPolygon));
} else if (capabilityChecker.isWayBboxSupported()) {
LOG.finer("Selecting all ways inside bounding box using dynamically built"
+ " way linestring with way bbox indexing.");
// The inner query selects the way id and node coordinates for
// all ways constrained by the way bounding box which is
// indexed.
// The middle query converts the way node coordinates into
// linestrings.
// The outer query constrains the query to the linestrings
// inside the bounding box. These aren't indexed but the inner
// query way bbox constraint will minimise the unnecessary data.
rowCount = jdbcTemplate.update(
"CREATE TEMPORARY TABLE bbox_ways ON COMMIT DROP AS"
+ " SELECT w.* FROM ("
+ "SELECT c.id AS id, First(c.version) AS version, First(c.user_id) AS user_id,"
+ " First(c.tstamp) AS tstamp, First(c.changeset_id) AS changeset_id, First(c.tags) AS tags,"
+ " First(c.nodes) AS nodes, ST_MakeLine(c.geom) AS way_line FROM ("
+ "SELECT w.*, n.geom AS geom FROM nodes n"
+ " INNER JOIN way_nodes wn ON n.id = wn.node_id"
+ " INNER JOIN ways w ON wn.way_id = w.id"
+ " WHERE (w.bbox && ?) ORDER BY wn.way_id, wn.sequence_id"
+ ") c "
+ "GROUP BY c.id"
+ ") w "
+ "WHERE (w.way_line && ?)",
new PGgeometry(bboxPolygon),
new PGgeometry(bboxPolygon)
);
} else {
LOG.finer("Selecting all way ids inside bounding box using already selected nodes.");
// No way bbox support is available so select ways containing