Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
302 changes: 164 additions & 138 deletions src/main/java/il/org/osm/israelhiking/PlanetSearchProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public List<OsmRelationInfo> preprocessOsmRelation(OsmElement.Relation relation)
setIconColorCategory(pointDocument, relation);

if (!"icon-waterfall".equals(pointDocument.poiIcon) &&
!"Biycle".equals(pointDocument.poiCategory) &&
!"Bicycle".equals(pointDocument.poiCategory) &&
!"Hiking".equals(pointDocument.poiCategory)) {
return null;
}
Expand Down Expand Up @@ -152,24 +152,29 @@ public void preprocessOsmWay(OsmElement.Way way) {

@Override
public void processFeature(SourceFeature sourceFeature, FeatureCollector features) {
if (sourceFeature.getSource() == "external") {
processExternalFeautre(sourceFeature, features);
return;
}
if (isBBoxFeature(sourceFeature, supportedLanguages)) {
insertBboxToElasticsearch(sourceFeature, supportedLanguages);
}
// ignore nodes and ways that should only be treated as polygons
if (sourceFeature.canBeLine()) {
processOsmRelationFeature(sourceFeature, features);
processMtbNameFeature(sourceFeature, features);
processWaterwayFeature(sourceFeature, features);
} else {
processOtherSourceFeature(sourceFeature, features);
try {
if (sourceFeature.getSource() == "external") {
processExternalFeautre(sourceFeature, features);
return;
}
if (isBBoxFeature(sourceFeature, supportedLanguages)) {
insertBboxToElasticsearch(sourceFeature, supportedLanguages);
}
// ignore nodes and ways that should only be treated as polygons
if (sourceFeature.canBeLine()) {
processOsmRelationFeature(sourceFeature, features);
processMtbNameFeature(sourceFeature, features);
processWaterwayFeature(sourceFeature, features);
processHighwayFeautre(sourceFeature, features);
} else {
processOtherSourceFeature(sourceFeature, features);
}
} catch (GeometryException e) {
// ignore bad geometries
}
}

private void processExternalFeautre(SourceFeature sourceFeature, FeatureCollector features) {
private void processExternalFeautre(SourceFeature sourceFeature, FeatureCollector features) throws GeometryException {
var pointDocument = new PointDocument();
pointDocument.poiIcon = sourceFeature.getString("poiIcon");
pointDocument.poiIconColor = sourceFeature.getString("poiIconColor");
Expand All @@ -184,16 +189,7 @@ private void processExternalFeautre(SourceFeature sourceFeature, FeatureCollecto
pointDocument.wikimedia_commons = sourceFeature.getString("wikimedia_commons");
Point point;
var docId = pointDocument.poiSource + "_" + sourceFeature.getString("identifier");
try {
point = (Point)sourceFeature.centroidIfConvex();
} catch (GeometryException e) {
try {
point = GeoUtils.point(sourceFeature.worldGeometry().getCoordinate());
} catch (GeometryException e2) {
// ignore bad geometries
return;
}
}
point = sourceFeature.canBeLine() ? GeoUtils.point(sourceFeature.worldGeometry().getCoordinate()) : (Point)sourceFeature.centroidIfConvex();
var lngLatPoint = GeoUtils.worldToLatLonCoords(point).getCoordinate();
pointDocument.location = new double[]{lngLatPoint.getX(), lngLatPoint.getY()};

Expand All @@ -206,7 +202,7 @@ private void processExternalFeautre(SourceFeature sourceFeature, FeatureCollecto
setFeaturePropertiesFromPointDocument(tileFeature, pointDocument);
}

private void processOsmRelationFeature(SourceFeature sourceFeature, FeatureCollector features) {
private void processOsmRelationFeature(SourceFeature sourceFeature, FeatureCollector features) throws GeometryException {
// get all the RouteRelationInfo instances we returned from preprocessOsmRelation that
// this way belongs to
for (var routeInfo : sourceFeature.relationInfo(RelationInfo.class)) {
Expand All @@ -221,36 +217,32 @@ private void processOsmRelationFeature(SourceFeature sourceFeature, FeatureColle
}
var mergedLines = RelationLineMergers.get(relation.id());
synchronized(mergedLines) {
try {
mergedLines.lineMerger.add(sourceFeature.line());
relation.memberIds.remove(sourceFeature.id());
mergedLines.lineMerger.add(sourceFeature.line());
relation.memberIds.remove(sourceFeature.id());

if (relation.firstMemberId == sourceFeature.id()) {
mergedLines.feature = sourceFeature;
}
if (relation.firstMemberId == sourceFeature.id()) {
mergedLines.feature = sourceFeature;
}

if (!relation.memberIds.isEmpty()) {
continue;
}
// All relation members were reached. Add a POI element for line relation
var point = getFirstPointOfLineRelation(mergedLines);
var lngLatPoint = GeoUtils.worldToLatLonCoords(point).getCoordinate();
relation.pointDocument.location = new double[]{lngLatPoint.getX(), lngLatPoint.getY()};

insertPointToElasticsearch(relation.pointDocument, "OSM_relation_" + relation.id());

var tileFeature = features.geometry(POINTS_LAYER_NAME, point)
.setZoomRange(10, 14)
.setId(relation.vectorTileFeatureId(config.featureSourceIdMultiplier()));
setFeaturePropertiesFromPointDocument(tileFeature, relation.pointDocument);
} catch (GeometryException e) {
throw new RuntimeException(e);
if (!relation.memberIds.isEmpty()) {
continue;
}
// All relation members were reached. Add a POI element for line relation
var point = getFirstPointOfLineRelation(mergedLines);
var lngLatPoint = GeoUtils.worldToLatLonCoords(point).getCoordinate();
relation.pointDocument.location = new double[]{lngLatPoint.getX(), lngLatPoint.getY()};

insertPointToElasticsearch(relation.pointDocument, "OSM_relation_" + relation.id());

var tileFeature = features.geometry(POINTS_LAYER_NAME, point)
.setZoomRange(10, 14)
.setId(relation.vectorTileFeatureId(config.featureSourceIdMultiplier()));
setFeaturePropertiesFromPointDocument(tileFeature, relation.pointDocument);
}
}
}

private void processMtbNameFeature(SourceFeature sourceFeature, FeatureCollector features) {
private void processMtbNameFeature(SourceFeature sourceFeature, FeatureCollector features) throws GeometryException {
if (!sourceFeature.hasTag("mtb:name")) {
return;
}
Expand All @@ -264,50 +256,46 @@ private void processMtbNameFeature(SourceFeature sourceFeature, FeatureCollector
}
var mergedLines = WaysLineMergers.get(minId);
synchronized(mergedLines) {
try {
mergedLines.lineMerger.add(sourceFeature.worldGeometry());
Singles.get(mtbName).ids.remove(sourceFeature.id());

mergedLines.lineMerger.add(sourceFeature.worldGeometry());
Singles.get(mtbName).ids.remove(sourceFeature.id());

if (minId == sourceFeature.id()) {
mergedLines.feature = sourceFeature;
}
if (!Singles.get(mtbName).ids.isEmpty()) {
return;
}
var feature = mergedLines.feature;
var point = GeoUtils.point(((Geometry)mergedLines.lineMerger.getMergedLineStrings().iterator().next()).getCoordinate());

var pointDocument = new PointDocument();
for (String language : supportedLanguages) {
CoalesceIntoMap(pointDocument.name, language, feature.getString("mtb:name:" + language), feature.getString("name:" + language), feature.getString("name"), feature.getString("mtb:name"));
CoalesceIntoMap(pointDocument.description, language, feature.getString("description:" + language), feature.getString("description"));
}
pointDocument.wikidata = feature.getString("wikidata");
pointDocument.image = feature.getString("image");
pointDocument.wikimedia_commons = feature.getString("wikimedia_commons");
pointDocument.poiCategory = "Bicycle";
pointDocument.poiIcon = "icon-bike";
pointDocument.poiIconColor = "gray";
pointDocument.poiSource = "OSM";
var lngLatPoint = GeoUtils.worldToLatLonCoords(point).getCoordinate();
pointDocument.location = new double[]{lngLatPoint.getX(), lngLatPoint.getY()};
if (minId == sourceFeature.id()) {
mergedLines.feature = sourceFeature;
}
if (!Singles.get(mtbName).ids.isEmpty()) {
return;
}
var feature = mergedLines.feature;
var point = GeoUtils.point(((Geometry)mergedLines.lineMerger.getMergedLineStrings().iterator().next()).getCoordinate());

insertPointToElasticsearch(pointDocument, "OSM_way_" + minId);
// This was the last way with the same mtb:name, so we can merge the lines and add the feature
// Add a POI element for a SingleTrack
var tileFeature = features.geometry(POINTS_LAYER_NAME, point)
.setZoomRange(10, 14)
// Override the feature id with the minimal id of the group
.setId(feature.vectorTileFeatureId(config.featureSourceIdMultiplier()));
setFeaturePropertiesFromPointDocument(tileFeature, pointDocument);
} catch (GeometryException e) {
throw new RuntimeException(e);
var pointDocument = new PointDocument();
for (String language : supportedLanguages) {
CoalesceIntoMap(pointDocument.name, language, feature.getString("mtb:name:" + language), feature.getString("name:" + language), feature.getString("name"), feature.getString("mtb:name"));
CoalesceIntoMap(pointDocument.description, language, feature.getString("description:" + language), feature.getString("description"));
}
pointDocument.wikidata = feature.getString("wikidata");
pointDocument.image = feature.getString("image");
pointDocument.wikimedia_commons = feature.getString("wikimedia_commons");
pointDocument.poiCategory = "Bicycle";
pointDocument.poiIcon = "icon-bike";
pointDocument.poiIconColor = "gray";
pointDocument.poiSource = "OSM";
var lngLatPoint = GeoUtils.worldToLatLonCoords(point).getCoordinate();
pointDocument.location = new double[]{lngLatPoint.getX(), lngLatPoint.getY()};

insertPointToElasticsearch(pointDocument, "OSM_way_" + minId);
// This was the last way with the same mtb:name, so we can merge the lines and add the feature
// Add a POI element for a SingleTrack
var tileFeature = features.geometry(POINTS_LAYER_NAME, point)
.setZoomRange(10, 14)
// Override the feature id with the minimal id of the group
.setId(feature.vectorTileFeatureId(config.featureSourceIdMultiplier()));
setFeaturePropertiesFromPointDocument(tileFeature, pointDocument);

}
}

private void processWaterwayFeature(SourceFeature sourceFeature, FeatureCollector features) {
private void processWaterwayFeature(SourceFeature sourceFeature, FeatureCollector features) throws GeometryException {
if (!sourceFeature.hasTag("waterway")) {
return;
}
Expand All @@ -321,53 +309,75 @@ private void processWaterwayFeature(SourceFeature sourceFeature, FeatureCollecto
}
var mergedLines = WaysLineMergers.get(minId);
synchronized(mergedLines) {
try {

mergedLines.lineMerger.add(sourceFeature.worldGeometry());
Waterways.get(name).ids.remove(sourceFeature.id());
mergedLines.lineMerger.add(sourceFeature.worldGeometry());
Waterways.get(name).ids.remove(sourceFeature.id());

if (minId == sourceFeature.id()) {
mergedLines.feature = sourceFeature;
}
if (!Waterways.get(name).ids.isEmpty()) {
return;
}
var feature = mergedLines.feature;
var point = GeoUtils.point(((Geometry)mergedLines.lineMerger.getMergedLineStrings().iterator().next()).getCoordinate());

var pointDocument = new PointDocument();
for (String language : supportedLanguages) {
CoalesceIntoMap(pointDocument.name, language, feature.getString("name:" + language), feature.getString("name"));
CoalesceIntoMap(pointDocument.description, language, feature.getString("description:" + language), feature.getString("description"));
}
pointDocument.wikidata = feature.getString("wikidata");
pointDocument.image = feature.getString("image");
pointDocument.wikimedia_commons = feature.getString("wikimedia_commons");
pointDocument.poiCategory = "Water";
pointDocument.poiIcon = "icon-waterfall";
pointDocument.poiIconColor = "blue";
pointDocument.poiSource = "OSM";
var lngLatPoint = GeoUtils.worldToLatLonCoords(point).getCoordinate();
pointDocument.location = new double[]{lngLatPoint.getX(), lngLatPoint.getY()};
if (minId == sourceFeature.id()) {
mergedLines.feature = sourceFeature;
}
if (!Waterways.get(name).ids.isEmpty()) {
return;
}
var feature = mergedLines.feature;
var point = GeoUtils.point(((Geometry)mergedLines.lineMerger.getMergedLineStrings().iterator().next()).getCoordinate());

insertPointToElasticsearch(pointDocument, "OSM_way_" + minId);
if (!isInterestingPoint(pointDocument)) {
// Skip adding features without any description or image to tiles
return;
}

var tileFeature = features.geometry(POINTS_LAYER_NAME, point)
.setZoomRange(10, 14)
// Override the feature id with the minimal id of the group
.setId(feature.vectorTileFeatureId(config.featureSourceIdMultiplier()));
setFeaturePropertiesFromPointDocument(tileFeature, pointDocument);
} catch (GeometryException e) {
throw new RuntimeException(e);
var pointDocument = new PointDocument();
for (String language : supportedLanguages) {
CoalesceIntoMap(pointDocument.name, language, feature.getString("name:" + language), feature.getString("name"));
CoalesceIntoMap(pointDocument.description, language, feature.getString("description:" + language), feature.getString("description"));
}
pointDocument.wikidata = feature.getString("wikidata");
pointDocument.image = feature.getString("image");
pointDocument.wikimedia_commons = feature.getString("wikimedia_commons");
pointDocument.poiCategory = "Water";
pointDocument.poiIcon = "icon-waterfall";
pointDocument.poiIconColor = "blue";
pointDocument.poiSource = "OSM";
var lngLatPoint = GeoUtils.worldToLatLonCoords(point).getCoordinate();
pointDocument.location = new double[]{lngLatPoint.getX(), lngLatPoint.getY()};

insertPointToElasticsearch(pointDocument, "OSM_way_" + minId);
if (!isInterestingPoint(pointDocument)) {
// Skip adding features without any description or image to tiles
return;
}

var tileFeature = features.geometry(POINTS_LAYER_NAME, point)
.setZoomRange(10, 14)
// Override the feature id with the minimal id of the group
.setId(feature.vectorTileFeatureId(config.featureSourceIdMultiplier()));
setFeaturePropertiesFromPointDocument(tileFeature, pointDocument);
}
}

private void processOtherSourceFeature(SourceFeature feature, FeatureCollector features) {
private void processHighwayFeautre(SourceFeature sourceFeature, FeatureCollector features) throws GeometryException {
if (!sourceFeature.hasTag("highway")) {
return;
}
var point = GeoUtils.point(sourceFeature.worldGeometry().getCoordinate());
var pointDocument = new PointDocument();
for (String language : supportedLanguages) {
CoalesceIntoMap(pointDocument.name, language, sourceFeature.getString("name:" + language), sourceFeature.getString("name"));
CoalesceIntoMap(pointDocument.description, language, sourceFeature.getString("description:" + language), sourceFeature.getString("description"));
}

pointDocument.wikidata = sourceFeature.getString("wikidata");
pointDocument.image = sourceFeature.getString("image");
pointDocument.wikimedia_commons = sourceFeature.getString("wikimedia_commons");
pointDocument.poiSource = "OSM";
var lngLatPoint = GeoUtils.worldToLatLonCoords(point).getCoordinate();
pointDocument.location = new double[]{lngLatPoint.getX(), lngLatPoint.getY()};
setIconColorCategory(pointDocument, sourceFeature);

if (pointDocument.poiIcon == "icon-search") {
return;
}

insertPointToElasticsearch(pointDocument, sourceFeatureToDocumentId(sourceFeature));
}

private void processOtherSourceFeature(SourceFeature feature, FeatureCollector features) throws GeometryException {
if (!feature.hasTag("name") &&
!feature.hasTag("wikidata") &&
!feature.hasTag("image") &&
Expand All @@ -380,16 +390,7 @@ private void processOtherSourceFeature(SourceFeature feature, FeatureCollector f
var docId = sourceFeatureToDocumentId(feature);
Point point;

try {
point = (Point)feature.centroidIfConvex();
} catch (GeometryException e) {
try {
point = GeoUtils.point(feature.worldGeometry().getCoordinate());
} catch (GeometryException e2) {
// ignore bad geometries
return;
}
}
point = (Point)feature.centroidIfConvex();

var pointDocument = new PointDocument();
for (String language : supportedLanguages) {
Expand Down Expand Up @@ -702,6 +703,31 @@ private void setIconColorCategory(PointDocument pointDocument, WithTags feature)
return;
}

if (feature.getString("highway") != null) {
switch (feature.getString("highway")) {
case "cycleway":
pointDocument.poiIconColor = "black";
pointDocument.poiCategory = "Bicycle";
pointDocument.poiIcon = "icon-bike";
return;
case "footway":
pointDocument.poiIconColor = "black";
pointDocument.poiCategory = "Hiking";
pointDocument.poiIcon = "icon-hike";
return;
case "path":
pointDocument.poiIconColor = "black";
pointDocument.poiCategory = "Hiking";
pointDocument.poiIcon = "icon-hike";
return;
case "track":
pointDocument.poiIconColor = "black";
pointDocument.poiCategory = "4x4";
pointDocument.poiIcon = "icon-four-by-four";
return;
}
}

if (feature.getString("ref:IL:inature") != null) {
pointDocument.poiIconColor = "#116C00";
pointDocument.poiIcon = "icon-inature";
Expand Down
Loading