|
3 | 3 | import de.komoot.photon.PhotonDoc;
|
4 | 4 | import de.komoot.photon.nominatim.model.AddressRow;
|
5 | 5 | import de.komoot.photon.nominatim.model.AddressType;
|
| 6 | +import de.komoot.photon.nominatim.model.OsmlineRowMapper; |
6 | 7 | import de.komoot.photon.nominatim.model.PlaceRowMapper;
|
7 | 8 | import org.apache.commons.dbcp2.BasicDataSource;
|
8 | 9 | import org.locationtech.jts.geom.Geometry;
|
@@ -82,47 +83,28 @@ public NominatimConnector(String host, int port, String database, String usernam
|
82 | 83 | return NominatimResult.fromAddress(doc, address);
|
83 | 84 | };
|
84 | 85 |
|
85 |
| - hasNewStyleInterpolation = dbutils.hasColumn(template, "location_property_osmline", "step"); |
86 | 86 | // 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); |
97 | 92 |
|
98 |
| - completePlace(doc); |
| 93 | + completePlace(doc); |
| 94 | + doc.setCountry(countryNames.get(rs.getString("country_code"))); |
99 | 95 |
|
100 |
| - doc.setCountry(countryNames.get(rs.getString("country_code"))); |
| 96 | + Geometry geometry = dbutils.extractGeometry(rs, "linegeo"); |
101 | 97 |
|
| 98 | + if (hasNewStyleInterpolation) { |
102 | 99 | return NominatimResult.fromInterpolation(
|
103 | 100 | doc, rs.getLong("startnumber"), rs.getLong("endnumber"),
|
104 | 101 | 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 | + } |
120 | 103 |
|
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 | + }; |
126 | 108 | }
|
127 | 109 |
|
128 | 110 |
|
@@ -250,9 +232,24 @@ public void readCountry(String countryCode, ImportThread importThread) {
|
250 | 232 | }
|
251 | 233 | };
|
252 | 234 |
|
| 235 | + final OsmlineRowMapper osmlineRowMapper = new OsmlineRowMapper(); |
253 | 236 | 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 | + } |
256 | 253 |
|
257 | 254 | if (docs.isUsefulForIndex()) {
|
258 | 255 | importThread.addDocument(docs);
|
|
0 commit comments