103 |
return result; |
return result; |
104 |
} |
} |
105 |
|
|
106 |
//the "hack" with max 1.5 degrees latitude and 2.5 degrees longitude is only valid since we only service danish trains |
//the "hack" with max 0.5 degrees latitude and 0.9 degrees longitude is only valid since we only service danish trains, |
107 |
// in denmark 1.5dg latitude ~ 165km, 2.5dg longitude ~ 155km |
// in denmark 0.5dg latitude ~ 55km, 0.9dg longitude ~ 57km |
108 |
|
|
109 |
// the ultra fast method (and only slightly inaccurate as long as we only cover a limited geographically area) |
// the ultra fast method (and only slightly inaccurate as long as we only cover a limited geographically area) |
110 |
// is using an aproximation of the length of 1 latitude degree and 1 longitude degree and just use pythagoras to |
// is using an aproximation of the length of 1 latitude degree and 1 longitude degree and just use pythagoras to |
113 |
|
|
114 |
public List<StationBean> getByLocationWorker(double latitude, double longitude, boolean geolimit) throws SQLException { |
public List<StationBean> getByLocationWorker(double latitude, double longitude, boolean geolimit) throws SQLException { |
115 |
|
|
116 |
String limitExpression = geolimit == true ? "AND abs(latitude-?)<1.5 AND abs(longitude-?)<2.5 " : ""; |
String limitExpression = geolimit == true ? "AND abs(latitude-?)<0.5 AND abs(longitude-?)<0.9 " : ""; |
117 |
|
|
118 |
String SQL = "SELECT id,name,latitude,longitude,stationcode_fjrn,stationcode_stog, stationcode_metro, address, " + |
String SQL = "SELECT id,name,latitude,longitude,stationcode_fjrn,stationcode_stog, stationcode_metro, address, " + |
119 |
"earth_distance( earth_coord, ll_to_earth(?,?))::int AS calcdist " + |
"earth_distance( earth_coord, ll_to_earth(?,?))::int AS calcdist " + |
121 |
"WHERE enabled = true " + limitExpression + |
"WHERE enabled = true " + limitExpression + |
122 |
"ORDER BY calcdist ASC " + |
"ORDER BY calcdist ASC " + |
123 |
"LIMIT " + LOCATION_LIMIT; |
"LIMIT " + LOCATION_LIMIT; |
124 |
|
|
125 |
|
|
126 |
|
|
127 |
List<StationBean> result; |
List<StationBean> result; |
128 |
Connection conn = null; |
Connection conn = null; |
139 |
} |
} |
140 |
res = stmt.executeQuery(); |
res = stmt.executeQuery(); |
141 |
result = convertResultset(res); |
result = convertResultset(res); |
142 |
|
|
143 |
} finally { |
} finally { |
144 |
if (res != null) |
if (res != null) |
145 |
res.close(); |
res.close(); |
214 |
return station; |
return station; |
215 |
} |
} |
216 |
|
|
217 |
public int getBySpecificName(String name) throws SQLException { |
public int getIdByName(String name) throws SQLException { |
218 |
String SQL = "SELECT id,name,latitude,longitude,stationcode_fjrn,stationcode_stog, stationcode_metro, address, 0.0 " + |
String SQL = "SELECT id,name,latitude,longitude,stationcode_fjrn,stationcode_stog, stationcode_metro, address, 0.0 " + |
219 |
"FROM trainstations " + |
"FROM trainstations " + |
220 |
"WHERE name = ? AND enabled = true " + |
"WHERE name = ? AND enabled = true " + |