Skip to content

Commit 30449fe

Browse files
committed
make OsmlineRowMapper a full class
1 parent a24c2c3 commit 30449fe

File tree

2 files changed

+32
-36
lines changed

2 files changed

+32
-36
lines changed

src/main/java/de/komoot/photon/nominatim/NominatimConnector.java

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import de.komoot.photon.PhotonDoc;
44
import de.komoot.photon.nominatim.model.AddressRow;
55
import de.komoot.photon.nominatim.model.AddressType;
6+
import de.komoot.photon.nominatim.model.OsmlineRowMapper;
67
import de.komoot.photon.nominatim.model.PlaceRowMapper;
78
import org.apache.commons.dbcp2.BasicDataSource;
89
import org.locationtech.jts.geom.Geometry;
@@ -82,47 +83,28 @@ public NominatimConnector(String host, int port, String database, String usernam
8283
return NominatimResult.fromAddress(doc, address);
8384
};
8485

85-
hasNewStyleInterpolation = dbutils.hasColumn(template, "location_property_osmline", "step");
8686
// Setup handling of interpolation table. There are two different formats depending on the Nominatim version.
87-
if (hasNewStyleInterpolation) {
88-
// new-style interpolations
89-
osmlineToNominatimResult = (rs, rownum) -> {
90-
Geometry geometry = dbutils.extractGeometry(rs, "linegeo");
91-
92-
PhotonDoc doc = new PhotonDoc(rs.getLong("place_id"), "W", rs.getLong("osm_id"),
93-
"place", "house_number")
94-
.parentPlaceId(rs.getLong("parent_place_id"))
95-
.countryCode(rs.getString("country_code"))
96-
.postcode(rs.getString("postcode"));
87+
// new-style interpolations
88+
hasNewStyleInterpolation = dbutils.hasColumn(template, "location_property_osmline", "step");
89+
final OsmlineRowMapper osmlineRowMapper = new OsmlineRowMapper();
90+
osmlineToNominatimResult = (rs, rownum) -> {
91+
PhotonDoc doc = osmlineRowMapper.mapRow(rs, rownum);
9792

98-
completePlace(doc);
93+
completePlace(doc);
94+
doc.setCountry(countryNames.get(rs.getString("country_code")));
9995

100-
doc.setCountry(countryNames.get(rs.getString("country_code")));
96+
Geometry geometry = dbutils.extractGeometry(rs, "linegeo");
10197

98+
if (hasNewStyleInterpolation) {
10299
return NominatimResult.fromInterpolation(
103100
doc, rs.getLong("startnumber"), rs.getLong("endnumber"),
104101
rs.getLong("step"), geometry);
105-
};
106-
} else {
107-
// old-style interpolations
108-
osmlineToNominatimResult = (rs, rownum) -> {
109-
Geometry geometry = dbutils.extractGeometry(rs, "linegeo");
110-
111-
PhotonDoc doc = new PhotonDoc(rs.getLong("place_id"), "W", rs.getLong("osm_id"),
112-
"place", "house_number")
113-
.parentPlaceId(rs.getLong("parent_place_id"))
114-
.countryCode(rs.getString("country_code"))
115-
.postcode(rs.getString("postcode"));
116-
117-
completePlace(doc);
118-
119-
doc.setCountry(countryNames.get(rs.getString("country_code")));
102+
}
120103

121-
return NominatimResult.fromInterpolation(
122-
doc, rs.getLong("startnumber"), rs.getLong("endnumber"),
123-
rs.getString("interpolationtype"), geometry);
124-
};
125-
}
104+
return NominatimResult.fromInterpolation(
105+
doc, rs.getLong("startnumber"), rs.getLong("endnumber"),
106+
rs.getString("interpolationtype"), geometry);
107+
};
126108
}
127109

128110

@@ -250,9 +232,24 @@ public void readCountry(String countryCode, ImportThread importThread) {
250232
}
251233
};
252234

235+
final OsmlineRowMapper osmlineRowMapper = new OsmlineRowMapper();
253236
final RowCallbackHandler osmlineMapper = rs -> {
254-
NominatimResult docs = osmlineToNominatimResult.mapRow(rs, 0);
255-
assert (docs != null);
237+
final PhotonDoc doc = osmlineRowMapper.mapRow(rs, 0);
238+
239+
completePlace(doc);
240+
doc.setCountry(cnames);
241+
242+
final Geometry geometry = dbutils.extractGeometry(rs, "linegeo");
243+
final NominatimResult docs;
244+
if (hasNewStyleInterpolation) {
245+
docs = NominatimResult.fromInterpolation(
246+
doc, rs.getLong("startnumber"), rs.getLong("endnumber"),
247+
rs.getLong("step"), geometry);
248+
} else {
249+
docs = NominatimResult.fromInterpolation(
250+
doc, rs.getLong("startnumber"), rs.getLong("endnumber"),
251+
rs.getString("interpolationtype"), geometry);
252+
}
256253

257254
if (docs.isUsefulForIndex()) {
258255
importThread.addDocument(docs);

src/main/java/de/komoot/photon/nominatim/NominatimResult.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import org.locationtech.jts.geom.GeometryFactory;
66
import org.locationtech.jts.geom.Point;
77
import org.locationtech.jts.linearref.LengthIndexedLine;
8-
import org.slf4j.Logger;
98

109
import java.util.*;
1110
import java.util.regex.Pattern;

0 commit comments

Comments
 (0)