Skip to content

Commit d9bab5b

Browse files
committed
Add external geojson, testing is still needed.
1 parent fec573e commit d9bab5b

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ hs_err_pid*
2424
replay_pid*
2525
target/
2626
data/
27+
dependency-reduced-pom.xml

src/main/java/il/org/osm/israelhiking/MainClass.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ static void run(Arguments args) throws Exception {
3636
planetiler.setProfile(profile)
3737
// override this default with osm_path="path/to/data.osm.pbf"
3838
.addOsmSource("osm", Path.of("data", "sources", area + ".osm.pbf"), "geofabrik:" + area)
39+
.addGeoJsonSource("external", Path.of("data", "sources", "external.geojson"))
3940
// override this default with mbtiles="path/to/output.mbtiles"
4041
.overwriteOutput(Path.of("data", PlanetSearchProfile.POINTS_LAYER_NAME + ".pmtiles"))
4142
.run();

src/main/java/il/org/osm/israelhiking/PlanetSearchProfile.java

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public List<OsmRelationInfo> preprocessOsmRelation(OsmElement.Relation relation)
109109
pointDocument.name.put(language, Coalesce(relation.getString("name:" + language), relation.getString("name")));
110110
pointDocument.description.put(language, Coalesce(relation.getString("description:" + language), relation.getString("description")));
111111
}
112+
pointDocument.poiSource = "OSM";
112113
pointDocument.wikidata = relation.getString("wikidata");
113114
pointDocument.image = relation.getString("image");
114115
pointDocument.wikimedia_commons = relation.getString("wikimedia_commons");
@@ -147,6 +148,10 @@ public void preprocessOsmWay(OsmElement.Way way) {
147148

148149
@Override
149150
public void processFeature(SourceFeature sourceFeature, FeatureCollector features) {
151+
if (sourceFeature.getSource() == "external") {
152+
processExternalFeautre(sourceFeature, features);
153+
return;
154+
}
150155
if (isBBoxFeature(sourceFeature, supportedLanguages)) {
151156
insertBboxToElasticsearch(sourceFeature, supportedLanguages);
152157
}
@@ -160,6 +165,43 @@ public void processFeature(SourceFeature sourceFeature, FeatureCollector feature
160165
}
161166
}
162167

168+
private void processExternalFeautre(SourceFeature sourceFeature, FeatureCollector features) {
169+
var pointDocument = new PointDocument();
170+
pointDocument.poiIcon = sourceFeature.getString("poiIcon");
171+
pointDocument.poiIconColor = sourceFeature.getString("poiIconColor");
172+
pointDocument.poiCategory = sourceFeature.getString("poiCategory");
173+
for (String language : supportedLanguages) {
174+
pointDocument.name.put(language, Coalesce(sourceFeature.getString("name:" + language), sourceFeature.getString("name")));
175+
pointDocument.description.put(language, Coalesce(sourceFeature.getString("description:" + language), sourceFeature.getString("description")));
176+
}
177+
pointDocument.poiSource = sourceFeature.getString("poiSource");
178+
pointDocument.wikidata = sourceFeature.getString("wikidata");
179+
pointDocument.image = sourceFeature.getString("image");
180+
pointDocument.wikimedia_commons = sourceFeature.getString("wikimedia_commons");
181+
Point point;
182+
var docId = pointDocument.poiSource + "_" + sourceFeature.getString("identifier");
183+
try {
184+
point = (Point)sourceFeature.centroidIfConvex();
185+
} catch (GeometryException e) {
186+
try {
187+
point = GeoUtils.point(sourceFeature.worldGeometry().getCoordinate());
188+
} catch (GeometryException e2) {
189+
LOGGER.warn("Failed to process external feature: {}", docId);
190+
return;
191+
}
192+
}
193+
var lngLatPoint = GeoUtils.worldToLatLonCoords(point).getCoordinate();
194+
pointDocument.location = new double[]{lngLatPoint.getX(), lngLatPoint.getY()};
195+
196+
insertPointToElasticsearch(pointDocument, docId);
197+
198+
var tileFeature = features.geometry("external", point)
199+
.setAttr("poiId", docId)
200+
.setZoomRange(10, 14)
201+
.setId(sourceFeature.id());
202+
setFeaturePropertiesFromPointDocument(tileFeature, pointDocument);
203+
}
204+
163205
private void processOsmRelationFeature(SourceFeature sourceFeature, FeatureCollector features) {
164206
// get all the RouteRelationInfo instances we returned from preprocessOsmRelation that
165207
// this way belongs to
@@ -243,6 +285,7 @@ private void processMtbNameFeature(SourceFeature sourceFeature, FeatureCollector
243285
pointDocument.poiCategory = "Bicycle";
244286
pointDocument.poiIcon = "icon-bike";
245287
pointDocument.poiIconColor = "gray";
288+
pointDocument.poiSource = "OSM";
246289
var lngLatPoint = GeoUtils.worldToLatLonCoords(point).getCoordinate();
247290
pointDocument.location = new double[]{lngLatPoint.getX(), lngLatPoint.getY()};
248291

@@ -299,6 +342,7 @@ private void processWaterwayFeature(SourceFeature sourceFeature, FeatureCollecto
299342
pointDocument.poiCategory = "Water";
300343
pointDocument.poiIcon = "icon-waterfall";
301344
pointDocument.poiIconColor = "blue";
345+
pointDocument.poiSource = "OSM";
302346
var lngLatPoint = GeoUtils.worldToLatLonCoords(point).getCoordinate();
303347
pointDocument.location = new double[]{lngLatPoint.getX(), lngLatPoint.getY()};
304348

@@ -351,6 +395,7 @@ private void processOtherSourceFeature(SourceFeature feature, FeatureCollector f
351395
pointDocument.wikidata = feature.getString("wikidata");
352396
pointDocument.image = feature.getString("image");
353397
pointDocument.wikimedia_commons = feature.getString("wikimedia_commons");
398+
pointDocument.poiSource = "OSM";
354399
var lngLatPoint = GeoUtils.worldToLatLonCoords(point).getCoordinate();
355400
pointDocument.location = new double[]{lngLatPoint.getX(), lngLatPoint.getY()};
356401

@@ -444,7 +489,8 @@ private void setFeaturePropertiesFromPointDocument(Feature tileFeature, PointDoc
444489
.setAttr("image", pointDocument.image)
445490
.setAttr("poiIcon", pointDocument.poiIcon)
446491
.setAttr("poiIconColor", pointDocument.poiIconColor)
447-
.setAttr("poiCategory", pointDocument.poiCategory);
492+
.setAttr("poiCategory", pointDocument.poiCategory)
493+
.setAttr("poiSource", pointDocument.poiSource);
448494
for (String lang : supportedLanguages) {
449495
tileFeature.setAttr("name:" + lang, pointDocument.name.get(lang));
450496
tileFeature.setAttr("description:" + lang, pointDocument.description.get(lang));

src/main/java/il/org/osm/israelhiking/PointDocument.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ class PointDocument {
1212
public String poiCategory;
1313
public String poiIcon;
1414
public String poiIconColor;
15+
public String poiSource;
1516
public double[] location;
1617
}

0 commit comments

Comments
 (0)