Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the basemap schema and workflow #910

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
d217b4f
Add the option to truncate the existing osm tables
bchapuis Dec 18, 2024
a563406
Add create sql script
bchapuis Dec 19, 2024
fef7135
Improve osm naming convention in basemap
bchapuis Dec 30, 2024
e66b0ad
Improve the queries in the create scripts
bchapuis Dec 30, 2024
553e15e
Improve the queries in the create scripts
bchapuis Dec 30, 2024
8232be4
Improve the queries in the create scripts
bchapuis Dec 30, 2024
db68a84
Improve the queries in the create scripts
bchapuis Dec 31, 2024
b1c289e
Improve the refresh scripts
bchapuis Dec 31, 2024
3a49c5a
Improve the refresh scripts
bchapuis Jan 1, 2025
a573d28
Improve the coherence of the tileset
bchapuis Jan 1, 2025
6099fb8
Improve the highway layer
bchapuis Jan 2, 2025
03ba1ea
Improve the landuse layer
bchapuis Jan 5, 2025
4fa64e1
Improve the natural layer
bchapuis Jan 5, 2025
9037768
Improve the highway layer
bchapuis Jan 5, 2025
61ba616
Improve the leisure layer
bchapuis Jan 5, 2025
dd30468
Improve the highway layer
bchapuis Jan 5, 2025
ef2bf7c
Improve the amenity layer
bchapuis Jan 5, 2025
6030723
Filter the tags in the views
bchapuis Jan 5, 2025
f5b29ff
Display turntable
bchapuis Jan 5, 2025
d16ac23
Improve the aeroway layer
bchapuis Jan 6, 2025
5d12846
Configure the spotless dbeaver sql formatter
bchapuis Jan 6, 2025
07cbbe6
Format the sql code
bchapuis Jan 6, 2025
7e89e79
Add missing license headers
bchapuis Jan 6, 2025
b3ab2dd
Add cache directory to ignored files
bchapuis Jan 6, 2025
4dd5ef4
Remove refresh scripts and fix tests
bchapuis Jan 6, 2025
c4cb75a
Restore all the tags in views
bchapuis Jan 7, 2025
001eb72
Improve the route layer
bchapuis Jan 7, 2025
b253f8d
Simplify the railway layer
bchapuis Jan 7, 2025
1d639c6
Simplify the waterway layer
bchapuis Jan 7, 2025
58b1988
Use views for linestrings and polygons
bchapuis Jan 7, 2025
e30280d
Improve the route layer
bchapuis Jan 7, 2025
e701d0d
Improve the railway layer
bchapuis Jan 7, 2025
887461a
Use singular form for all osm table names
bchapuis Jan 7, 2025
998bd93
Enable additional zoom levels due to loss of precision and display pa…
bchapuis Jan 8, 2025
4eaa528
Add leisure track lines
bchapuis Jan 8, 2025
7b49d95
Improve the readme and fix minor style issues
bchapuis Jan 8, 2025
ce64358
activate refresh steps
bchapuis Jan 8, 2025
c290c76
Fix the scripts
bchapuis Jan 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ basemap/cache_*/
basemap/local.*
basemap/tiles.mbtiles
basemap/tiles/
basemap/cache/

# Examples
examples/ip-to-location/archives/
Expand Down
2 changes: 1 addition & 1 deletion .run/basemap-serve.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<configuration default="false" name="basemap-serve" type="Application" factoryName="Application">
<option name="MAIN_CLASS_NAME" value="org.apache.baremaps.cli.Baremaps" />
<module name="baremaps-cli" />
<option name="PROGRAM_PARAMETERS" value="map serve --tileset tileset.js --style style.js" />
<option name="PROGRAM_PARAMETERS" value="map serve --tileset tileset.js --style style.js --log-level DEBUG" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/basemap" />
<method v="2">
<option name="Make" enabled="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.apache.baremaps.cli.database;



import java.nio.file.Path;
import java.util.concurrent.Callable;
import org.apache.baremaps.cli.Options;
Expand Down Expand Up @@ -55,6 +54,7 @@ public Integer call() throws Exception {
file.toAbsolutePath(),
database,
srid,
true,
true).execute(new WorkflowContext());
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class ImportOsmPbf implements Task {
private Object database;
private Integer databaseSrid;
private Boolean replaceExisting;
private Boolean truncateTables;

/**
* Constructs a {@code ImportOsmPbf}.
Expand All @@ -61,11 +62,12 @@ public ImportOsmPbf() {
* @param replaceExisting whether to replace the existing tables
*/
public ImportOsmPbf(Path file, Object database,
Integer databaseSrid, Boolean replaceExisting) {
Integer databaseSrid, Boolean replaceExisting, Boolean truncateTables) {
this.file = file;
this.database = database;
this.databaseSrid = databaseSrid;
this.replaceExisting = replaceExisting;
this.truncateTables = truncateTables;
}

/**
Expand All @@ -82,8 +84,8 @@ public void execute(WorkflowContext context) throws Exception {
var wayRepository = new WayRepository(datasource);
var relationRepository = new RelationRepository(datasource);

// Drop the existing tables
if (TRUE.equals(replaceExisting)) {
// Drop the existing tables
headerRepository.drop();
nodeRepository.drop();
wayRepository.drop();
Expand All @@ -96,6 +98,14 @@ public void execute(WorkflowContext context) throws Exception {
relationRepository.create();
}

// Truncate the existing tables
if (TRUE.equals(truncateTables)) {
headerRepository.truncate();
nodeRepository.truncate();
wayRepository.truncate();
relationRepository.truncate();
}

var coordinateMap = context.getCoordinateMap();
var referenceMap = context.getReferenceMap();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void test() throws IOException {
new Step("import", List.of("download"),
List.of(new ImportOsmPbf(Paths.get("liechtenstein-latest.osm.pbf"),
"jdbc:postgresql://localhost:5432/baremaps?&user=baremaps&password=baremaps",
3857, true)))));
3857, true, true)))));
var json = mapper.writeValueAsString(workflow1);
assertTrue(json.contains(DownloadUrl.class.getSimpleName()));
assertTrue(json.contains(ImportOsmPbf.class.getSimpleName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void execute() {
new Step("import-osmpbf", List.of("fetch-osmpbf"),
List.of(new ImportOsmPbf(Paths.get("downloads/liechtenstein.osm.pbf"),
jdbcUrl(),
3857, true))),
3857, true, true))),
new Step("fetch-shapefile", List.of(), List.of(new DownloadUrl(
"https://osmdata.openstreetmap.de/download/simplified-water-polygons-split-3857.zip",
Paths.get("downloads/simplified-water-polygons-split-3857.zip"), false))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class CoordinateMap extends PostgresMap<Long, Coordinate> {
* Constructs a {@link CoordinateMap}.
*/
public CoordinateMap(DataSource dataSource) {
this(dataSource, "public", "osm_nodes");
this(dataSource, "public", "osm_node");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public HeaderRepository(DataSource dataSource) {
this(
dataSource,
"public",
"osm_headers",
"osm_header",
"replication_sequence_number",
"replication_timestamp",
"replication_url",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public NodeRepository(DataSource dataSource) {
this(
dataSource,
"public",
"osm_nodes",
"osm_node",
"id",
"version",
"uid",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class ReferenceMap extends PostgresMap<Long, List<Long>> {
* Constructs a {@code PostgresReferenceMap}.
*/
public ReferenceMap(DataSource dataSource) {
this(dataSource, "public", "osm_ways");
this(dataSource, "public", "osm_way");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public RelationRepository(DataSource dataSource) {
this(
dataSource,
"public",
"osm_relations",
"osm_relation",
"id",
"version",
"uid",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class WayRepository implements Repository<Long, Way> {
public WayRepository(DataSource dataSource) {
this(dataSource,
"public",
"osm_ways",
"osm_way",
"id",
"version",
"uid",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,20 @@ public void add(String name, DataTable table) {

var schema = new DataSchemaImpl(name, properties);

// Drop the table if it exists
var dropQuery = dropTable(schema);
logger.debug(dropQuery);
try (var dropStatement = connection.prepareStatement(dropQuery)) {
dropStatement.execute();
}

// Create the table
var createQuery = createTable(schema);
logger.debug(createQuery);
try (var createStatement = connection.prepareStatement(createQuery)) {
createStatement.execute();
}

// Truncate the table
var truncateQuery = truncateTable(schema);
logger.debug(truncateQuery);
try (var truncateStatement = connection.prepareStatement(truncateQuery)) {
truncateStatement.execute();
}

// Copy the data
var pgConnection = connection.unwrap(PGConnection.class);
var copyQuery = copy(schema);
Expand Down Expand Up @@ -206,6 +206,16 @@ protected String dropTable(DataSchema schema) {
return String.format("DROP TABLE IF EXISTS \"%s\" CASCADE", schema.name());
}

/**
* Generate a truncate table query.
*
* @param schema the schema
* @return the query
*/
protected String truncateTable(DataSchema schema) {
return String.format("TRUNCATE TABLE \"%s\" CASCADE", schema.name());
}

/**
* Generate a create table query.
*
Expand All @@ -214,7 +224,7 @@ protected String dropTable(DataSchema schema) {
*/
protected String createTable(DataSchema schema) {
StringBuilder builder = new StringBuilder();
builder.append("CREATE TABLE \"");
builder.append("CREATE TABLE IF NOT EXISTS \"");
builder.append(schema.name());
builder.append("\" (");
builder.append(schema.columns().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ void resetDatabase() throws SQLException, IOException {
PostgresUtils.executeResource(connection, "queries/osm_drop_tables.sql");
PostgresUtils.executeResource(connection, "queries/osm_drop_tables.sql");
PostgresUtils.executeResource(connection, "queries/osm_create_tables.sql");
assertTrue(tableExists("osm_headers"));
assertTrue(tableExists("osm_nodes"));
assertTrue(tableExists("osm_ways"));
assertTrue(tableExists("osm_relations"));
assertTrue(tableExists("osm_header"));
assertTrue(tableExists("osm_node"));
assertTrue(tableExists("osm_way"));
assertTrue(tableExists("osm_relation"));
}
}

Expand Down
7 changes: 2 additions & 5 deletions baremaps-postgres/src/test/resources/queries/hello-world.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,5 @@
-- See the License for the specific language governing permissions and
-- limitations under the License.

DO $$
BEGIN
PERFORM 'Hello, World!';
END
$$;
DO $$ BEGIN PERFORM 'Hello, World!';
END $$;
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
CREATE EXTENSION IF NOT EXISTS hstore;
CREATE EXTENSION IF NOT EXISTS postgis;
CREATE
EXTENSION IF NOT EXISTS hstore;

CREATE
EXTENSION IF NOT EXISTS postgis;
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,12 @@
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
CREATE INDEX CONCURRENTLY IF NOT EXISTS osm_ways_gin ON osm_ways USING gin (nodes);
CREATE INDEX CONCURRENTLY IF NOT EXISTS osm_relations_gin ON osm_relations USING gin (member_refs);
CREATE
INDEX IF NOT EXISTS osm_way_gin ON
osm_way
USING gin(nodes);

CREATE
INDEX IF NOT EXISTS osm_relation_gin ON
osm_relation
USING gin(member_refs);
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
CREATE INDEX CONCURRENTLY IF NOT EXISTS osm_nodes_gix ON osm_nodes USING GIST (geom);
CREATE INDEX CONCURRENTLY IF NOT EXISTS osm_ways_gix ON osm_ways USING GIST (geom);
CREATE INDEX CONCURRENTLY IF NOT EXISTS osm_relations_gix ON osm_relations USING GIST (geom);
CREATE
INDEX IF NOT EXISTS osm_node_gix ON
osm_node
USING GIST(geom);

CREATE
INDEX IF NOT EXISTS osm_way_gix ON
osm_way
USING GIST(geom);

CREATE
INDEX IF NOT EXISTS osm_relation_gix ON
osm_relation
USING GIST(geom);
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
CREATE INDEX CONCURRENTLY IF NOT EXISTS osm_nodes_gix ON osm_nodes USING SPGIST (geom);
CREATE INDEX CONCURRENTLY IF NOT EXISTS osm_ways_gix ON osm_ways USING SPGIST (geom);
CREATE INDEX CONCURRENTLY IF NOT EXISTS osm_relations_gix ON osm_relations USING SPGIST (geom);
CREATE
INDEX IF NOT EXISTS osm_node_gix ON
osm_node
USING SPGIST(geom);

CREATE
INDEX IF NOT EXISTS osm_way_gix ON
osm_way
USING SPGIST(geom);

CREATE
INDEX IF NOT EXISTS osm_relation_gix ON
osm_relation
USING SPGIST(geom);
Loading
Loading