@@ -23,6 +23,8 @@ public class NominatimConnector {
23
23
24
24
private static final String SELECT_COLS_PLACEX = "SELECT place_id, osm_type, osm_id, class, type, name, postcode, address, extratags, ST_Envelope(geometry) AS bbox, parent_place_id, linked_place_id, rank_address, rank_search, importance, country_code, centroid" ;
25
25
private static final String SELECT_COLS_ADDRESS = "SELECT p.name, p.class, p.type, p.rank_address" ;
26
+ private static final String SELECT_OSMLINE_OLD_STYLE = "SELECT place_id, osm_id, parent_place_id, startnumber, endnumber, interpolationtype, postcode, country_code, linegeo" ;
27
+ private static final String SELECT_OSMLINE_NEW_STYLE = "SELECT place_id, osm_id, parent_place_id, startnumber, endnumber, step, postcode, country_code, linegeo" ;
26
28
27
29
private final DBDataAdapter dbutils ;
28
30
private final JdbcTemplate template ;
@@ -33,8 +35,8 @@ public class NominatimConnector {
33
35
* This may be old-style interpolation (using interpolationtype) or
34
36
* new-style interpolation (using step).
35
37
*/
36
- private final RowMapper <NominatimResult > osmlineRowMapper ;
37
- private final String selectOsmlineSql ;
38
+ private final RowMapper <NominatimResult > osmlineToNominatimResult ;
39
+ private final boolean hasNewStyleInterpolation ;
38
40
39
41
40
42
/**
@@ -77,17 +79,14 @@ public NominatimConnector(String host, int port, String database, String usernam
77
79
78
80
doc .setCountry (countryNames .get (rs .getString ("country_code" )));
79
81
80
- NominatimResult result = new NominatimResult (doc );
81
- result .addHousenumbersFromAddress (address );
82
-
83
- return result ;
82
+ return NominatimResult .fromAddress (doc , address );
84
83
};
85
84
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 (dbutils . hasColumn ( template , "location_property_osmline" , "step" ) ) {
87
+ if (hasNewStyleInterpolation ) {
88
88
// new-style interpolations
89
- selectOsmlineSql = "SELECT place_id, osm_id, parent_place_id, startnumber, endnumber, step, postcode, country_code, linegeo" ;
90
- osmlineRowMapper = (rs , rownum ) -> {
89
+ osmlineToNominatimResult = (rs , rownum ) -> {
91
90
Geometry geometry = dbutils .extractGeometry (rs , "linegeo" );
92
91
93
92
PhotonDoc doc = new PhotonDoc (rs .getLong ("place_id" ), "W" , rs .getLong ("osm_id" ),
@@ -100,16 +99,13 @@ public NominatimConnector(String host, int port, String database, String usernam
100
99
101
100
doc .setCountry (countryNames .get (rs .getString ("country_code" )));
102
101
103
- NominatimResult result = new NominatimResult ( doc );
104
- result . addHouseNumbersFromInterpolation ( rs .getLong ("startnumber" ), rs .getLong ("endnumber" ),
102
+ return NominatimResult . fromInterpolation (
103
+ doc , rs .getLong ("startnumber" ), rs .getLong ("endnumber" ),
105
104
rs .getLong ("step" ), geometry );
106
-
107
- return result ;
108
105
};
109
106
} else {
110
107
// old-style interpolations
111
- selectOsmlineSql = "SELECT place_id, osm_id, parent_place_id, startnumber, endnumber, interpolationtype, postcode, country_code, linegeo" ;
112
- osmlineRowMapper = (rs , rownum ) -> {
108
+ osmlineToNominatimResult = (rs , rownum ) -> {
113
109
Geometry geometry = dbutils .extractGeometry (rs , "linegeo" );
114
110
115
111
PhotonDoc doc = new PhotonDoc (rs .getLong ("place_id" ), "W" , rs .getLong ("osm_id" ),
@@ -122,11 +118,9 @@ public NominatimConnector(String host, int port, String database, String usernam
122
118
123
119
doc .setCountry (countryNames .get (rs .getString ("country_code" )));
124
120
125
- NominatimResult result = new NominatimResult ( doc );
126
- result . addHouseNumbersFromInterpolation ( rs .getLong ("startnumber" ), rs .getLong ("endnumber" ),
121
+ return NominatimResult . fromInterpolation (
122
+ doc , rs .getLong ("startnumber" ), rs .getLong ("endnumber" ),
127
123
rs .getString ("interpolationtype" ), geometry );
128
-
129
- return result ;
130
124
};
131
125
}
132
126
}
@@ -165,9 +159,10 @@ public List<PhotonDoc> getByPlaceId(long placeId) {
165
159
}
166
160
167
161
public List <PhotonDoc > getInterpolationsByPlaceId (long placeId ) {
168
- List <NominatimResult > result = template .query (selectOsmlineSql
169
- + " FROM location_property_osmline WHERE place_id = ? and indexed_status = 0" ,
170
- osmlineRowMapper , placeId );
162
+ List <NominatimResult > result = template .query (
163
+ (hasNewStyleInterpolation ? SELECT_OSMLINE_NEW_STYLE : SELECT_OSMLINE_OLD_STYLE )
164
+ + " FROM location_property_osmline WHERE place_id = ? and indexed_status = 0" ,
165
+ osmlineToNominatimResult , placeId );
171
166
172
167
return result .isEmpty () ? null : result .get (0 ).getDocsWithHousenumber ();
173
168
}
@@ -248,16 +243,15 @@ public void readCountry(String countryCode, ImportThread importThread) {
248
243
249
244
doc .setCountry (cnames );
250
245
251
- NominatimResult result = new NominatimResult (doc );
252
- result .addHousenumbersFromAddress (address );
246
+ var result = NominatimResult .fromAddress (doc , address );
253
247
254
248
if (result .isUsefulForIndex ()) {
255
249
importThread .addDocument (result );
256
250
}
257
251
};
258
252
259
253
final RowCallbackHandler osmlineMapper = rs -> {
260
- NominatimResult docs = osmlineRowMapper .mapRow (rs , 0 );
254
+ NominatimResult docs = osmlineToNominatimResult .mapRow (rs , 0 );
261
255
assert (docs != null );
262
256
263
257
if (docs .isUsefulForIndex ()) {
@@ -270,16 +264,18 @@ public void readCountry(String countryCode, ImportThread importThread) {
270
264
" WHERE linked_place_id IS NULL AND centroid IS NOT NULL AND country_code is null" +
271
265
" ORDER BY geometry_sector, parent_place_id; " , placeMapper );
272
266
273
- template .query (selectOsmlineSql + " FROM location_property_osmline " +
274
- "WHERE startnumber is not null AND country_code is null " +
267
+ template .query ((hasNewStyleInterpolation ? SELECT_OSMLINE_NEW_STYLE : SELECT_OSMLINE_OLD_STYLE ) +
268
+ " FROM location_property_osmline" +
269
+ " WHERE startnumber is not null AND country_code is null" +
275
270
" ORDER BY geometry_sector, parent_place_id; " , osmlineMapper );
276
271
} else {
277
272
template .query (SELECT_COLS_PLACEX + " FROM placex " +
278
273
" WHERE linked_place_id IS NULL AND centroid IS NOT NULL AND country_code = ?" +
279
274
" ORDER BY geometry_sector, parent_place_id; " , placeMapper , countryCode );
280
275
281
- template .query (selectOsmlineSql + " FROM location_property_osmline " +
282
- "WHERE startnumber is not null AND country_code = ?" +
276
+ template .query ((hasNewStyleInterpolation ? SELECT_OSMLINE_NEW_STYLE : SELECT_OSMLINE_OLD_STYLE ) +
277
+ " FROM location_property_osmline" +
278
+ " WHERE startnumber is not null AND country_code = ?" +
283
279
" ORDER BY geometry_sector, parent_place_id; " , osmlineMapper , countryCode );
284
280
285
281
}
0 commit comments