Skip to content
Merged
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
34b2f4c
Add the option to truncate the existing osm tables
bchapuis Dec 18, 2024
ae33611
Add create sql script
bchapuis Dec 19, 2024
d4e5388
Improve osm naming convention in basemap
bchapuis Dec 30, 2024
9c1fbfa
Improve the queries in the create scripts
bchapuis Dec 30, 2024
f85d2a5
Improve the queries in the create scripts
bchapuis Dec 30, 2024
d2d6db7
Improve the queries in the create scripts
bchapuis Dec 30, 2024
dc90211
Improve the queries in the create scripts
bchapuis Dec 31, 2024
71f45df
Improve the refresh scripts
bchapuis Dec 31, 2024
bccc06c
Improve the refresh scripts
bchapuis Jan 1, 2025
4c77155
Improve the coherence of the tileset
bchapuis Jan 1, 2025
eb759ca
Improve the highway layer
bchapuis Jan 2, 2025
b8a6373
Improve the landuse layer
bchapuis Jan 5, 2025
0339712
Improve the natural layer
bchapuis Jan 5, 2025
4b66d19
Improve the highway layer
bchapuis Jan 5, 2025
d85a3aa
Improve the leisure layer
bchapuis Jan 5, 2025
5586150
Improve the highway layer
bchapuis Jan 5, 2025
df73698
Improve the amenity layer
bchapuis Jan 5, 2025
310684d
Filter the tags in the views
bchapuis Jan 5, 2025
8f4e509
Display turntable
bchapuis Jan 5, 2025
9bb33b9
Improve the aeroway layer
bchapuis Jan 6, 2025
f230bc9
Configure the spotless dbeaver sql formatter
bchapuis Jan 6, 2025
8f45f3e
Format the sql code
bchapuis Jan 6, 2025
e410c28
Add missing license headers
bchapuis Jan 6, 2025
f65c24c
Add cache directory to ignored files
bchapuis Jan 6, 2025
7c8eca8
Remove refresh scripts and fix tests
bchapuis Jan 6, 2025
dba2f89
Restore all the tags in views
bchapuis Jan 7, 2025
022bf73
Improve the route layer
bchapuis Jan 7, 2025
1e1e68b
Simplify the railway layer
bchapuis Jan 7, 2025
d6f9000
Simplify the waterway layer
bchapuis Jan 7, 2025
f28b5ee
Use views for linestrings and polygons
bchapuis Jan 7, 2025
b88028c
Improve the route layer
bchapuis Jan 7, 2025
45f5bda
Improve the railway layer
bchapuis Jan 7, 2025
1a777da
Use singular form for all osm table names
bchapuis Jan 7, 2025
b2fad92
Enable additional zoom levels due to loss of precision and display pa…
bchapuis Jan 8, 2025
74c3715
Add leisure track lines
bchapuis Jan 8, 2025
00d9af9
Improve the readme and fix minor style issues
bchapuis Jan 8, 2025
4ce7704
activate refresh steps
bchapuis Jan 8, 2025
d4f3f93
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