Skip to content

Commit 45ee00b

Browse files
Merge pull request #812 from cambridge-cares/808-add-pgrouting-dataset-type-to-stack-data-uploader
808 add pgrouting dataset type to stack data uploader
2 parents 88c1685 + d127eb0 commit 45ee00b

File tree

73 files changed

+28448
-35
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+28448
-35
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"database": "postgres",
3+
"workspace": "the_world_avatar",
4+
"datasetDirectory": "routing",
5+
"dataSubsets": [
6+
{
7+
"type": "OSMRouting",
8+
"skip": false,
9+
"schema": "public",
10+
"name": "routing"
11+
}
12+
]
13+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.osm files can be found on https://www.openstreetmap.org/ and a xml config file can be found on https://github.com/pgRouting/osm2pgrouting/blob/main/mapconfig.xml.

Deploy/stacks/dynamic/stack-clients/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: '3.8'
22
services:
33
stack-client:
4-
image: ghcr.io/cambridge-cares/stack-client${IMAGE_SUFFIX}:1.15.2
4+
image: ghcr.io/cambridge-cares/stack-client${IMAGE_SUFFIX}:1.16.0
55
secrets:
66
- blazegraph_password
77
- postgis_password

Deploy/stacks/dynamic/stack-clients/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<groupId>com.cmclinnovations</groupId>
99
<artifactId>stack-clients</artifactId>
10-
<version>1.15.2</version>
10+
<version>1.16.0</version>
1111

1212
<name>Stack Clients</name>
1313
<url>https://theworldavatar.io</url>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.cmclinnovations.stack.clients.core;
2+
3+
import java.util.Arrays;
4+
import java.util.List;
5+
6+
import com.fasterxml.jackson.annotation.JsonCreator;
7+
8+
public class Option {
9+
private List<String> optionList;
10+
11+
@JsonCreator
12+
public Option(String option) {
13+
this.optionList = Arrays.asList(option);
14+
}
15+
16+
@JsonCreator
17+
public Option(List<String> option) {
18+
this.optionList = option;
19+
}
20+
21+
public List<String> getOptionList() {
22+
return optionList;
23+
}
24+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.cmclinnovations.stack.clients.core;
2+
3+
import java.util.ArrayList;
4+
import java.util.HashMap;
5+
import java.util.List;
6+
import java.util.Map;
7+
8+
import com.fasterxml.jackson.annotation.JsonProperty;
9+
10+
public class Options {
11+
@JsonProperty("options")
12+
private final Map<String, Option> argOptions = new HashMap<>();
13+
private final List<String> flags = new ArrayList<>();
14+
15+
public Options() {
16+
}
17+
18+
public List<String> getOptionsList() {
19+
List<String> optionsList = new ArrayList<>();
20+
optionsList.addAll(flags);
21+
argOptions.forEach((key, value) -> {
22+
optionsList.add(key);
23+
optionsList.addAll(value.getOptionList());
24+
});
25+
return optionsList;
26+
}
27+
28+
public Map<String, Option> getArgOptions() {
29+
return argOptions;
30+
}
31+
32+
public List<String> getFlags() {
33+
return flags;
34+
}
35+
}

Deploy/stacks/dynamic/stack-clients/src/main/java/com/cmclinnovations/stack/clients/core/datasets/DataSubset.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
@JsonSubTypes({
1212
@Type(value = Tabular.class, names = { "Tabular", "tabular" }),
1313
@Type(value = Vector.class, names = { "Vector", "vector" }),
14+
@Type(value = OSMRouting.class, names = { "OSMRouting", "osmRouting", "OsmRouting", "osmrouting" }),
1415
@Type(value = Raster.class, names = { "Raster", "raster" }),
1516
@Type(value = RDF.class, names = { "Triples", "triples", "RDF", "rdf", "Quads", "quads" }),
1617
@Type(value = TBoxCSV.class, names = { "TBoxCSV", "TboxCSV", "tboxcsv" }),

Deploy/stacks/dynamic/stack-clients/src/main/java/com/cmclinnovations/stack/clients/core/datasets/GeoServerDataSubset.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ public boolean usesGeoServer() {
1010
@Override
1111
void loadInternal(Dataset parent) {
1212
super.loadInternal(parent);
13-
createLayer(parent.getWorkspaceName(), parent.getDatabase());
13+
createLayers(parent.getWorkspaceName(), parent.getDatabase());
1414
}
1515

16-
public abstract void createLayer(String workspaceName, String database);
16+
public abstract void createLayers(String workspaceName, String database);
1717

1818
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.cmclinnovations.stack.clients.core.datasets;
2+
3+
import java.nio.file.Path;
4+
5+
import com.cmclinnovations.stack.clients.core.Options;
6+
import com.cmclinnovations.stack.clients.geoserver.GeoServerClient;
7+
import com.cmclinnovations.stack.clients.geoserver.GeoServerVectorSettings;
8+
import com.cmclinnovations.stack.clients.postgis.PGRoutingClient;
9+
import com.fasterxml.jackson.annotation.JsonProperty;
10+
11+
import it.geosolutions.geoserver.rest.encoder.metadata.virtualtable.GSVirtualTableEncoder;
12+
13+
public class OSMRouting extends GeoServerDataSubset {
14+
@JsonProperty
15+
protected Options osm2PGRoutingOptions = new Options();
16+
17+
@JsonProperty
18+
protected GeoServerVectorSettings waysGeoServerSettings = new GeoServerVectorSettings();
19+
@JsonProperty
20+
protected GeoServerVectorSettings verticesGeoServerSettings = new GeoServerVectorSettings();
21+
@JsonProperty
22+
protected GeoServerVectorSettings poiGeoServerSettings = new GeoServerVectorSettings();
23+
24+
@Override
25+
public void loadData(Path dirPath, String database, String baseIRI) {
26+
PGRoutingClient.getInstance().uploadRoutingDataDirectoryToPostGIS(database, dirPath.toString(),
27+
getTablePrefix(), osm2PGRoutingOptions, false);
28+
}
29+
30+
@Override
31+
public void createLayers(String workspaceName, String database) {
32+
createLayer(workspaceName, database, prefixTableName("ways"), waysGeoServerSettings);
33+
createLayer(workspaceName, database, prefixTableName("ways_vertices_pgr"), verticesGeoServerSettings);
34+
createLayer(workspaceName, database, prefixTableName("pointsofinterest"), poiGeoServerSettings);
35+
}
36+
37+
private void createLayer(String workspaceName, String database, String layerName,
38+
GeoServerVectorSettings geoServerVectorSettings) {
39+
GSVirtualTableEncoder virtualTable = geoServerVectorSettings.getVirtualTable();
40+
if (null != virtualTable) {
41+
virtualTable.setSql(handleFileValues(virtualTable.getSql()));
42+
}
43+
44+
GeoServerClient.getInstance()
45+
.createPostGISLayer(workspaceName, database, layerName, geoServerVectorSettings);
46+
}
47+
48+
private String prefixTableName(String tableName) {
49+
return getTablePrefix() + tableName;
50+
}
51+
52+
private String getTablePrefix() {
53+
return getName() + "_";
54+
}
55+
}

Deploy/stacks/dynamic/stack-clients/src/main/java/com/cmclinnovations/stack/clients/core/datasets/Raster.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public void loadData(Path dirPath, String database, String baseIRI) {
2525
}
2626

2727
@Override
28-
public void createLayer(String workspaceName, String database) {
28+
public void createLayers(String workspaceName, String database) {
2929
GeoServerClient.getInstance()
3030
.createGeoTiffLayer(workspaceName, getName(), database, PostGISClient.DEFAULT_SCHEMA_NAME,
3131
geoServerSettings);

0 commit comments

Comments
 (0)