Issue #1605 Improved finding closest area locations.

Former-commit-id: 9641b67da4 [formerly 9641b67da4 [formerly b8a43d95121a1876dc8136bd5758e9452167fad2]]
Former-commit-id: 1722713689
Former-commit-id: 459472a793
This commit is contained in:
Jonathan Sanchez 2013-02-14 11:12:23 -06:00
parent aecc5a69e9
commit 73110463b1
2 changed files with 32 additions and 6 deletions

View file

@ -29,14 +29,21 @@ import com.vividsolutions.jts.geom.prep.PreparedGeometry;
import com.vividsolutions.jts.geom.prep.PreparedGeometryFactory;
/**
*
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description ------------ ---------- -----------
* --------------------------
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Sep 25, 2012 #15425 Qinglu Lin Updated createClosestPoint().
* Feb 13, 2012 1605 jsanchez Calculated the point based on lat,lon values.
*
* @author jsanchez Sep 25, 2012 #15425 Qinglu Lin Updated createClosestPoint().
* </pre>
*
* @author jsanchez
* @version 1.0
*/
public class DbAreaSourceDataAdaptor extends AbstractDbSourceDataAdaptor {
@ -46,6 +53,10 @@ public class DbAreaSourceDataAdaptor extends AbstractDbSourceDataAdaptor {
private static final String cwaField = "cwa";
private static final String longitude = "lon";
private static final String latitude = "lat";
public DbAreaSourceDataAdaptor(PathcastConfiguration pathcastConfiguration,
UnitConverter distanceToMeters, Geometry searchArea,
String localizedSite) throws VizException {
@ -69,6 +80,8 @@ public class DbAreaSourceDataAdaptor extends AbstractDbSourceDataAdaptor {
ptFields.add(pointField);
ptFields.add(useDirectionField);
ptFields.add(suppressedDirectionsField);
ptFields.add(longitude);
ptFields.add(latitude);
List<String> fields = null;
if (sortBy != null && sortBy.length > 0) {
@ -96,7 +109,7 @@ public class DbAreaSourceDataAdaptor extends AbstractDbSourceDataAdaptor {
Map<String, Object> attributes = ptRslt.attributes;
String name = String.valueOf(attributes.get(pointField));
Coordinate point = ptRslt.geometry.getCoordinate();
Coordinate point = getPoint(attributes);
int population = getPopulation(ptFields, attributes);
int warngenlev = getWangenlev(ptFields, attributes);
List<String> partOfArea = getPartOfArea(ptFields, attributes,
@ -264,4 +277,17 @@ public class DbAreaSourceDataAdaptor extends AbstractDbSourceDataAdaptor {
return directions;
}
/**
* Returns a Coordinate based on the lat,lon values in the attributes.
*
* @param attributes
* @return
*/
private Coordinate getPoint(Map<String, Object> attributes) {
double lat = Double.valueOf(String.valueOf(attributes.get(latitude)));
double lon = Double.valueOf(String.valueOf(attributes.get(longitude)));
return new Coordinate(lon, lat);
}
}

View file

@ -39,6 +39,7 @@ import org.apache.commons.lang.ArrayUtils;
* Mar 3, 2011 jsanchez Initial creation
* Sep 25, 2012 15425 Qinglu Lin Implemented sorting on 'gid' in ascending order.
* Oct 17, 2012 jsanchez Refactored the enum sort to be more flexible.
* Feb 14, 2013 1605 jsanchez Updated the distance comparison for more accuracy.
*
* </pre>
*
@ -148,8 +149,7 @@ public class ClosestPointComparator implements Comparator<ClosestPoint> {
value = cp1.parentArea.compareTo(cp2.parentArea);
break;
case DISTANCE:
value = new Integer(cp1.roundedDistance)
.compareTo(cp2.roundedDistance);
value = new Double(cp1.distance).compareTo(cp2.distance);
break;
case GID:
value = new Integer(cp1.gid).compareTo(cp2.gid);