Omaha #3741 - Updated procedures for calculation of a center for zone and station.

Former-commit-id: 6343f04511 [formerly a34a8901f83457fa21fc99a0f2ff0df956487b62]
Former-commit-id: a873fe7b5c
This commit is contained in:
Slav Korolev 2014-11-03 14:34:01 -05:00
parent 3445c780cf
commit ec877476d9
4 changed files with 206 additions and 192 deletions

View file

@ -34,7 +34,6 @@ import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import com.raytheon.uf.common.monitor.config.FSSObsMonitorConfigurationManager;
import com.raytheon.uf.common.monitor.data.CommonConfig.AppName;
import com.raytheon.uf.common.monitor.xml.AreaIdXML;
import com.raytheon.uf.common.monitor.xml.AreaIdXML.ZoneType;
@ -53,6 +52,7 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
* Nov 20, 2012 1297 skorolev Changes for non-blocking dialog.
* Apr 23, 2014 3054 skorolev Fixed issues with removing a new zone from list.
* Apr 28, 2014 3086 skorolev Removed local getAreaConfigMgr method.
* Nov 10, 2014 3741 skorolev Fixed configXML issue.
*
* </pre>
*
@ -97,8 +97,6 @@ public class EditNewZoneDlg extends CaveSWTDialog {
/** Deleted zone */
private String delZone;
private FSSObsMonitorConfigurationManager areaConfigMgr;
/**
* Constructor.
*
@ -113,7 +111,6 @@ public class EditNewZoneDlg extends CaveSWTDialog {
super(parent, SWT.DIALOG_TRIM, CAVE.DO_NOT_BLOCK);
setText(appName.toString() + ": Edit a Newly Added Zone");
this.macDlg = macDlg;
areaConfigMgr = macDlg.getInstance();
}
/*
@ -313,7 +310,7 @@ public class EditNewZoneDlg extends CaveSWTDialog {
* Populate list of added zones.
*/
private void populate() {
java.util.List<String> newList = areaConfigMgr.getAddedZones();
java.util.List<String> newList = macDlg.configMgr.getAddedZones();
zoneList.setItems(newList.toArray(new String[newList.size()]));
}
@ -322,7 +319,7 @@ public class EditNewZoneDlg extends CaveSWTDialog {
*/
private void handleZoneSelection() {
String zone = zoneList.getItem(zoneList.getSelectionIndex());
AreaIdXML areaXml = areaConfigMgr.getAreaXml(zone);
AreaIdXML areaXml = macDlg.configMgr.getAreaXml(zone);
// DR #7343: a null areaXml causes an "Unhandled event loop exception"
if (areaXml != null) {
idTF.setText(areaXml.getAreaId());
@ -355,7 +352,7 @@ public class EditNewZoneDlg extends CaveSWTDialog {
}
String area = zoneList.getItem(zoneList.getSelectionIndex());
zoneList.remove(zoneList.getSelectionIndex());
areaConfigMgr.removeArea(area);
macDlg.configMgr.removeArea(area);
idTF.setText("");
latTF.setText("");
lonTF.setText("");
@ -393,8 +390,8 @@ public class EditNewZoneDlg extends CaveSWTDialog {
type = ZoneType.MARITIME;
}
// Replace previously added zone
areaConfigMgr.removeArea(area);
areaConfigMgr.removeAddedArea(area);
macDlg.configMgr.removeArea(area);
macDlg.configMgr.removeAddedArea(area);
macDlg.configMgr.addArea(area, lat, lon, type);
populate();
// Return cursor to the top of the list.

View file

@ -42,11 +42,16 @@ import org.eclipse.swt.widgets.Layout;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import com.raytheon.uf.common.geospatial.SpatialException;
import com.raytheon.uf.common.monitor.MonitorAreaUtils;
import com.raytheon.uf.common.monitor.config.FSSObsMonitorConfigurationManager;
import com.raytheon.uf.common.monitor.data.CommonConfig;
import com.raytheon.uf.common.monitor.data.CommonConfig.AppName;
import com.raytheon.uf.common.monitor.data.ObConst;
import com.raytheon.uf.common.monitor.xml.AreaIdXML;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.viz.core.IDisplayPane;
import com.raytheon.uf.viz.core.IDisplayPaneContainer;
import com.raytheon.uf.viz.core.drawables.IDescriptor;
@ -58,7 +63,6 @@ import com.raytheon.uf.viz.monitor.config.CommonTableConfig.GraphType;
import com.raytheon.uf.viz.monitor.config.CommonTableConfig.ObsHistType;
import com.raytheon.uf.viz.monitor.data.ObHourReports;
import com.raytheon.uf.viz.monitor.data.ObMultiHrsReports;
import com.raytheon.uf.viz.monitor.data.ObStnHourReports;
import com.raytheon.uf.viz.monitor.data.ObTrendDataSet;
import com.raytheon.uf.viz.monitor.data.TableData;
import com.raytheon.uf.viz.monitor.data.TableUtil;
@ -70,6 +74,8 @@ import com.raytheon.uf.viz.monitor.util.ObUtil;
import com.raytheon.viz.ui.EditorUtil;
import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
import com.raytheon.viz.ui.dialogs.ICloseCallback;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.io.ParseException;
/**
* Abstract Zone table dialog that is the foundation for all Zone dialogs.
@ -90,6 +96,7 @@ import com.raytheon.viz.ui.dialogs.ICloseCallback;
* May 15, 2014 3086 skorolev Replaced MonitorConfigurationManager with FSSObsMonitorConfigurationManager.
* Sep 15, 2014 3220 skorolev Added refreshZoneTableData method.
* Oct 17, 2014 3220 skorolev Added condition into launchTrendPlot to avoid NPE.
* Nov 03, 2014 3741 skorolev Updated zoom procedures.
*
* </pre>
*
@ -99,6 +106,8 @@ import com.raytheon.viz.ui.dialogs.ICloseCallback;
public abstract class ZoneTableDlg extends CaveSWTDialog implements
IMonitorListener, IMonitorControlListener, IStationTableAction,
IZoneTableAction {
private final static IUFStatusHandler statusHandler = UFStatus
.getHandler(ZoneTableDlg.class);
/** Array listening monitors **/
protected List<IMonitor> controlListeners = new ArrayList<IMonitor>();
@ -725,16 +734,6 @@ public abstract class ZoneTableDlg extends CaveSWTDialog implements
public void launchObHistoryTable(int rowIndex) {
String station = stnTblData.getTableRows().get(rowIndex)
.getTableCellData(0).getCellText();
ObStnHourReports report = obData.getObHourReports()
.getObZoneHourReports(selectedZone)
.getObStnHourReports(station);
if (report.getStationCenter() != null) {
lat = report.getStationCenter()[1];
lon = report.getStationCenter()[0];
} else {
lat = 0.0;
lon = 0.0;
}
// Set dialog index
String dialogID = appName.name() + station;
ObsHistType histType = null;
@ -792,10 +791,16 @@ public abstract class ZoneTableDlg extends CaveSWTDialog implements
* @throws Exception
*/
private void zoomToZone(String zone) throws Exception {
double[] zoneCenter = MonitorAreaUtils.getZoneCenter(zone);
if (zoneCenter != null) {
zoomAndRecenter(zoneCenter, ZONE_ZOOM_LEVEL);
Coordinate zoneCenter = MonitorAreaUtils.getZoneCenter(zone);
if (zoneCenter == null) { // Test a newly added zone.
AreaIdXML zoneXML = configMgr.getAreaXml(zone);
if (zoneXML != null // Coordinates do not the null values.
&& (zoneXML.getCLon() != null || zoneXML.getCLat() != null)) {
zoneCenter = new Coordinate(zoneXML.getCLon(),
zoneXML.getCLat());
}
}
zoomAndRecenter(zoneCenter, ZONE_ZOOM_LEVEL);
}
/*
@ -809,12 +814,14 @@ public abstract class ZoneTableDlg extends CaveSWTDialog implements
public void zoomToStation(int rowIndex) {
String selectedStation = stnTblData.getTableRows().get(rowIndex)
.getTableCellData(0).getCellText();
ObStnHourReports reports = obData.getObHourReports()
.getObZoneHourReports(selectedZone)
.getObStnHourReports(selectedStation);
double[] stnCenter = reports.getStationCenter();
if (stnCenter != null) {
zoomAndRecenter(stnCenter, STATION_ZOOM_LEVEL);
try {
Coordinate stnCenter = MonitorAreaUtils
.getStationCenter(selectedStation);
if (stnCenter != null) {
zoomAndRecenter(stnCenter, STATION_ZOOM_LEVEL);
}
} catch (SpatialException | ParseException e) {
statusHandler.handle(Priority.ERROR, e.getLocalizedMessage(), e);
}
}
@ -824,7 +831,10 @@ public abstract class ZoneTableDlg extends CaveSWTDialog implements
* @param center
* @param zoom
*/
private void zoomAndRecenter(double[] center, float zoom) {
private void zoomAndRecenter(Coordinate center, float zoom) {
if (center == null) {// No zoom.
return;
}
IDisplayPaneContainer container = EditorUtil.getActiveVizContainer();
if (container != null) {
IDescriptor descriptor = container.getActiveDisplayPane()
@ -838,7 +848,8 @@ public abstract class ZoneTableDlg extends CaveSWTDialog implements
float zoomLevel = zoom / mapWidth;
for (IDisplayPane pane : container.getDisplayPanes()) {
pane.getRenderableDisplay().getExtent().reset();
pane.getRenderableDisplay().recenter(center);
pane.getRenderableDisplay().recenter(
new double[] { center.x, center.y });
pane.getRenderableDisplay().zoom(zoomLevel);
pane.refresh();
}

View file

@ -10,7 +10,13 @@ import com.raytheon.uf.common.monitor.config.FSSObsMonitorConfigurationManager;
import com.raytheon.uf.common.monitor.scan.ScanUtils;
import com.raytheon.uf.common.monitor.xml.StationIdXML;
import com.raytheon.uf.common.site.SiteMap;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.Point;
import com.vividsolutions.jts.io.ParseException;
import com.vividsolutions.jts.io.WKBReader;
import com.vividsolutions.jts.io.WKTWriter;
@ -27,7 +33,8 @@ import com.vividsolutions.jts.io.WKTWriter;
* Apr 29, 2011 DR#8986 zhao Read in "counties", not "forecast zones",
* Feb 22, 2012 14413 zhao modified getAdjacentZones to add "C" or "Z"
* Apr 30, 2014 3086 skorolev Replaced MonitorConfigurationManager with FSSObsMonitorConfigurationManager
* Oct 17, 2014 2757 skorolev Corrected SQL in the getAdjacentZones to avoid duplicates.
* Oct 17, 2014 2757 skorolev Corrected SQL in the getAdjacentZones to avoid duplicates.
* Nov 03, 2014 3741 skorolev Updated getZoneCenter and added getStationCenter methods.
*
* </pre>
*
@ -36,6 +43,9 @@ import com.vividsolutions.jts.io.WKTWriter;
*/
public class MonitorAreaUtils {
private final static IUFStatusHandler statusHandler = UFStatus
.getHandler(MonitorAreaUtils.class);
public static final String COUNTY_TABLE = "mapdata.county";
public static final String FORECAST_ZONE_TABLE = "mapdata.zone";
@ -75,8 +85,9 @@ public class MonitorAreaUtils {
counties.add(state + "C" + fips.substring(2));
}
}
} catch (Exception e) {
e.printStackTrace();
} catch (SpatialException e) {
statusHandler.handle(Priority.ERROR, "Error to get the counties.",
e);
}
return counties;
}
@ -108,8 +119,9 @@ public class MonitorAreaUtils {
zones.add(state + "Z" + zone);
}
}
} catch (Exception e) {
e.printStackTrace();
} catch (SpatialException e) {
statusHandler.handle(Priority.ERROR,
"Error to get forecast zones.", e);
}
return zones;
}
@ -148,8 +160,9 @@ public class MonitorAreaUtils {
}
}
} catch (Exception e) {
e.printStackTrace();
} catch (SpatialException e) {
statusHandler.handle(Priority.ERROR, "Error to get marine zones.",
e);
}
return zones;
@ -161,10 +174,10 @@ public class MonitorAreaUtils {
* : zone ID (either a county zone or a maritime zone)
* @return a list of stations (with station ID and station type) associated
* with the zone
* @throws Exception
* @throws ParseException
*/
public static List<StationIdXML> getZoneReportingStationXMLs(String zone)
throws Exception {
throws ParseException {
List<StationIdXML> stations = new ArrayList<StationIdXML>();
@ -200,11 +213,9 @@ public class MonitorAreaUtils {
}
}
}
} catch (Exception e) {
System.err.println("============== zone = " + zone);
e.printStackTrace();
throw new Exception(
"Unable to query for Zone envelope and stations list", e);
} catch (SpatialException e) {
statusHandler.handle(Priority.ERROR,
"Error retrieving station XMLs for zone " + zone, e);
}
return stations;
}
@ -235,10 +246,10 @@ public class MonitorAreaUtils {
*
* @param zone
* @return
* @throws VizException
* @throws ParseException
*/
public static List<String> getZoneReportingStations(String zone)
throws Exception {
throws ParseException {
List<String> stations = new ArrayList<String>();
try {
@ -281,11 +292,9 @@ public class MonitorAreaUtils {
}
}
} catch (Exception e) {
System.err.println("============== zone = " + zone);
e.printStackTrace();
throw new Exception(
"Unable to query for Zone envelope and stations list", e);
} catch (SpatialException e) {
statusHandler.handle(Priority.ERROR,
"Error retrieving stations for zone " + zone, e);
}
return stations;
}
@ -295,9 +304,11 @@ public class MonitorAreaUtils {
*
* @param zone
* @return the text string of the polygon describing the area coverage
* @throws Exception
* @throws SpatialException
* @throws ParseException
*/
private static String getZoneEnvelope(String zone) throws Exception {
private static String getZoneEnvelope(String zone) throws SpatialException,
ParseException {
WKBReader wkbReader = new WKBReader();
Geometry geo = null;
@ -348,14 +359,18 @@ public class MonitorAreaUtils {
ISpatialQuery sq = SpatialQueryFactory.create();
Object[] results = sq.dbRequest(sql, MAPS_DB);
if (results.length > 0) {
if (results[0] instanceof Object[]) {
Object obj[] = (Object[]) results[0];
geo = readGeometry(obj[0], wkbReader);
} else {
geo = readGeometry(results[0], wkbReader);
try {
if (results[0] instanceof Object[]) {
Object obj[] = (Object[]) results[0];
geo = readGeometry(obj[0], wkbReader);
} else {
geo = readGeometry(results[0], wkbReader);
}
} catch (Exception e) {
statusHandler.handle(Priority.PROBLEM,
"Error to read geometry for zone " + zone, e);
}
}
return getPolygonText(geo);
}
@ -365,15 +380,12 @@ public class MonitorAreaUtils {
* @param obj
* @param wkbReader
* @return
* @throws ParseException
*/
public static Geometry readGeometry(Object obj, WKBReader wkbReader) {
public static Geometry readGeometry(Object obj, WKBReader wkbReader)
throws ParseException {
Geometry geometry = null;
try {
geometry = wkbReader.read((byte[]) obj);
} catch (Exception e) {
e.printStackTrace();
}
geometry = wkbReader.read((byte[]) obj);
return geometry.buffer(0);
}
@ -384,7 +396,6 @@ public class MonitorAreaUtils {
* @return
*/
public static String getPolygonText(Geometry geometry) {
WKTWriter wktWriter = new WKTWriter();
return wktWriter.writeFormatted(geometry);
}
@ -394,17 +405,19 @@ public class MonitorAreaUtils {
*
* @param cwaList
* @return
* @throws SpatialException
*/
public static List<String> getAdjacentZones(String[] cwaList) {
public static List<String> getAdjacentZones(String[] cwaList)
throws SpatialException {
List<String> zones = new ArrayList<String>();
String sqlCounty = "select distinct state, fips from "
String sqlCounty = "select distinct state, fips from "
+ FSSObsMonitorConfigurationManager.COUNTY_TABLE
+ " where cwa in (''";
String sqlForecastZone = "select distinct state, zone from "
String sqlForecastZone = "select distinct state, zone from "
+ FSSObsMonitorConfigurationManager.FORECAST_ZONE_TABLE
+ " where cwa in (''";
String sqlMaritimeZone = "select distinct id from "
String sqlMaritimeZone = "select distinct id from "
+ FSSObsMonitorConfigurationManager.MARINE_ZONE_TABLE
+ " where wfo in (''";
for (int i = 0; i < cwaList.length; i++) {
@ -423,65 +436,57 @@ public class MonitorAreaUtils {
ISpatialQuery sq = null;
try {
sq = SpatialQueryFactory.create();
Object[] resultsCounty = sq.dbRequest(sqlCounty, "maps");
Object[] resultsForecastZone = sq
.dbRequest(sqlForecastZone, "maps");
Object[] resultsMaritimeZone = sq
.dbRequest(sqlMaritimeZone, "maps");
sq = SpatialQueryFactory.create();
Object[] resultsCounty = sq.dbRequest(sqlCounty, "maps");
Object[] resultsForecastZone = sq.dbRequest(sqlForecastZone, "maps");
Object[] resultsMaritimeZone = sq.dbRequest(sqlMaritimeZone, "maps");
if (SpatialQueryFactory.getType().equals("CAVE")) {
if (resultsCounty.length > 0) {
for (int i = 0; i < resultsCounty.length; i++) {
Object[] oa = (Object[]) resultsCounty[i];
String state = (String) oa[0];
String fips = (String) oa[1];
zones.add(state + "C" + fips.substring(2));
}
}
if (resultsForecastZone.length > 0) {
for (int i = 0; i < resultsForecastZone.length; i++) {
Object[] oa = (Object[]) resultsForecastZone[i];
String state = (String) oa[0];
String zone = (String) oa[1];
zones.add(state + "Z" + zone);
}
}
if (resultsMaritimeZone.length > 0) {
for (int i = 0; i < resultsMaritimeZone.length; i++) {
Object[] oa = (Object[]) resultsMaritimeZone[i];
zones.add((String) oa[0]);
}
}
} else {
if (resultsCounty.length > 0) {
for (int i = 0; i < resultsCounty.length; i++) {
Object[] oa = (Object[]) resultsCounty[i];
String czn = oa[0].toString() + "C"
+ oa[1].toString().substring(2);
zones.add(czn);
}
}
if (resultsForecastZone.length > 0) {
for (int i = 0; i < resultsForecastZone.length; i++) {
Object[] oa = (Object[]) resultsForecastZone[i];
String fcz = oa[0].toString() + "Z" + oa[1].toString();
zones.add(fcz);
}
}
if (resultsMaritimeZone.length > 0) {
for (int i = 0; i < resultsMaritimeZone.length; i++) {
String mzn = resultsMaritimeZone[i].toString();
zones.add(mzn);
}
if (SpatialQueryFactory.getType().equals("CAVE")) {
if (resultsCounty.length > 0) {
for (int i = 0; i < resultsCounty.length; i++) {
Object[] oa = (Object[]) resultsCounty[i];
String state = (String) oa[0];
String fips = (String) oa[1];
zones.add(state + "C" + fips.substring(2));
}
}
if (resultsForecastZone.length > 0) {
for (int i = 0; i < resultsForecastZone.length; i++) {
Object[] oa = (Object[]) resultsForecastZone[i];
String state = (String) oa[0];
String zone = (String) oa[1];
zones.add(state + "Z" + zone);
}
}
if (resultsMaritimeZone.length > 0) {
for (int i = 0; i < resultsMaritimeZone.length; i++) {
Object[] oa = (Object[]) resultsMaritimeZone[i];
zones.add((String) oa[0]);
}
}
} else {
if (resultsCounty.length > 0) {
for (int i = 0; i < resultsCounty.length; i++) {
Object[] oa = (Object[]) resultsCounty[i];
String czn = oa[0].toString() + "C"
+ oa[1].toString().substring(2);
zones.add(czn);
}
}
if (resultsForecastZone.length > 0) {
for (int i = 0; i < resultsForecastZone.length; i++) {
Object[] oa = (Object[]) resultsForecastZone[i];
String fcz = oa[0].toString() + "Z" + oa[1].toString();
zones.add(fcz);
}
}
if (resultsMaritimeZone.length > 0) {
for (int i = 0; i < resultsMaritimeZone.length; i++) {
String mzn = resultsMaritimeZone[i].toString();
zones.add(mzn);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return zones;
}
@ -490,9 +495,9 @@ public class MonitorAreaUtils {
*
* @param zone
* @return
* @throws Exception
* @throws SpatialException
*/
public static Geometry getZoneGeometry(String zone) throws Exception {
public static Geometry getZoneGeometry(String zone) throws SpatialException {
WKBReader wkbReader = new WKBReader();
Geometry geo = null;
@ -504,7 +509,7 @@ public class MonitorAreaUtils {
ISpatialQuery sq = null;
if (isMarineZone(zone)) {
sql = "select AsBinary("
+ ScanUtils.getStandardResolutionLevel("marineZones")
+ ScanUtils.getStandardResolutionLevel("marinezones")
+ ") from " + MARINE_ZONE_TABLE + " where id = '" + zone
+ "'";
} else if (zone.charAt(2) == 'Z') { // "forecast zone"
@ -525,14 +530,18 @@ public class MonitorAreaUtils {
sq = SpatialQueryFactory.create();
Object[] results = sq.dbRequest(sql, MAPS_DB);
if (results.length > 0) {
if (results[0] instanceof Object[]) {
Object obj[] = (Object[]) results[0];
geo = readGeometry(obj[0], wkbReader);
} else {
geo = readGeometry(results[0], wkbReader);
try {
if (results[0] instanceof Object[]) {
Object obj[] = (Object[]) results[0];
geo = readGeometry(obj[0], wkbReader);
} else {
geo = readGeometry(results[0], wkbReader);
}
} catch (ParseException e) {
statusHandler.handle(Priority.PROBLEM,
"Error to read geometry for zone " + zone, e);
}
}
return geo;
}
@ -547,14 +556,11 @@ public class MonitorAreaUtils {
String sql = "select distinct id from " + MARINE_ZONE_TABLE
+ " where id = '" + zone + "'";
ISpatialQuery sq = null;
// List<Object[]> results = DirectDbQuery.executeQuery(sql, MAPS_DB,
// QueryLanguage.SQL);
sq = SpatialQueryFactory.create();
Object[] results = sq.dbRequest(sql, MAPS_DB);
if ((results.length > 0) && results[0].equals(zone)) {
return true;
}
return false;
}
@ -563,48 +569,44 @@ public class MonitorAreaUtils {
*
* @param zone
* @return
* @throws Exception
* @throws SpatialException
*/
public static double[] getZoneCenter(String zone) throws Exception {
double[] zoneCenter = null;
/**
* DR#9905: "county" for a CONUS site; "forecast zone" for an OCONUS
* site
*/
String sql = "";
ISpatialQuery sq = null;
if (isMarineZone(zone)) { // "marine zone"
sql = "select distinct lat, lon from " + MARINE_ZONE_TABLE
+ " where id = '" + zone + "'";
} else if (zone.charAt(2) == 'Z') { // "forecast zone"
String state_zone = zone.substring(0, 2) + zone.substring(3);
sql = "select lat, lon from " + FORECAST_ZONE_TABLE
+ " where state_zone = '" + state_zone + "'";
} else { // "county"
String state = zone.substring(0, 2);
String fipsLike = "%" + zone.substring(3);
sql = "select lat, lon from " + COUNTY_TABLE + " where state = '"
+ state + "' and fips like '" + fipsLike + "'";
}
sq = SpatialQueryFactory.create();
Object[] results = sq.dbRequest(sql, MAPS_DB);
Double lat = null;
Double lon = null;
if (results.length != 0) {
if (results[0] instanceof Object[]) {
Object[] res = (Object[]) results[0];
lat = ((Number) res[0]).doubleValue();
lon = ((Number) res[1]).doubleValue();
public static Coordinate getZoneCenter(String zone) throws SpatialException {
Coordinate zoneCenter = null;
Geometry geom = getZoneGeometry(zone);
if (geom != null) {
Point ctrd = geom.getCentroid();
if (ctrd != null) {
zoneCenter = ctrd.getCoordinate();
} else {
lat = ((Number) results[0]).doubleValue();
lon = ((Number) results[1]).doubleValue();
statusHandler.handle(Priority.PROBLEM,
"Problem to get the coordinates for zone " + zone);
}
zoneCenter = new double[] { lon, lat };
}
return zoneCenter;
}
/**
* Get station coordinates.
*
* @param stationid
* @return
* @throws SpatialException
* @throws ParseException
*/
public static Coordinate getStationCenter(String stationid)
throws SpatialException, ParseException {
Coordinate stnCenter = null;
ISpatialQuery sq = null;
String sql = "select AsBinary(the_geom) from common_obs_spatial where stationid = '"
+ stationid + "'";
sq = SpatialQueryFactory.create();
Object results[] = sq.dbRequest(sql, "metadata");
if (results.length > 0) {
WKBReader wkbReader = new WKBReader();
Geometry stationGeo = wkbReader.read((byte[]) results[0]);
stnCenter = stationGeo.getCoordinate();
}
return stnCenter;
}
}

View file

@ -31,13 +31,16 @@ import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
import com.raytheon.uf.common.localization.PathManagerFactory;
import com.raytheon.uf.common.monitor.MonitorAreaUtils;
import com.raytheon.uf.common.monitor.scan.ScanUtils;
import com.raytheon.uf.common.serialization.SerializationException;
import com.raytheon.uf.common.serialization.SingleTypeJAXBManager;
import com.raytheon.uf.common.site.xml.AdjacentWfoXML;
import com.raytheon.uf.common.site.xml.CwaXML;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.common.util.StringUtil;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.io.ParseException;
import com.vividsolutions.jts.io.WKBReader;
/**
@ -52,6 +55,7 @@ import com.vividsolutions.jts.io.WKBReader;
* Jul 24, 2013 2219 mpduff Improve error handling.
* Oct 02, 2013 2361 njensen Use JAXBManager for XML
* May 23, 2014 3086 skorolev Cleaned code.
* Nov 11, 2014 3741 skorolev Corrected Exceptions.
*
* </pre>
*
@ -102,20 +106,14 @@ public class AdjacentWfoMgr {
* Read the XML adjacent data for the current XML file name.
*/
private void readAdjXml() {
adjXML = null;
IPathManager pm = PathManagerFactory.getPathManager();
String path = pm.getFile(
pm.getContext(LocalizationType.COMMON_STATIC,
LocalizationLevel.BASE), fileName).getAbsolutePath();
statusHandler.debug("**** path = " + path);
try {
adjXML = null;
IPathManager pm = PathManagerFactory.getPathManager();
String path = pm.getFile(
pm.getContext(LocalizationType.COMMON_STATIC,
LocalizationLevel.BASE), fileName)
.getAbsolutePath();
statusHandler.debug("**** path = " + path);
adjXML = jaxb.unmarshalFromXmlFile(path);
ArrayList<CwaXML> list = adjXML.getAreaIds();
for (CwaXML cx : list) {
if (cx.getId().equals(currentSite)) {
@ -126,8 +124,12 @@ public class AdjacentWfoMgr {
.toArray(new String[idList.size()]));
}
}
} catch (Exception e) {
statusHandler.error("Error setting up adjacent WFO data", e);
} catch (SerializationException e) {
statusHandler.handle(Priority.PROBLEM,
"Unable to serialize adjacent XML", e);
} catch (SpatialException e) {
statusHandler.handle(Priority.PROBLEM,
"Error to read adjacent XML", e);
}
}
@ -210,7 +212,7 @@ public class AdjacentWfoMgr {
for (String site : areaList) {
sb.append(StringUtil.NEWLINE).append(site);
}
UFStatus.getHandler(AdjacentWfoMgr.class).warn(sb.toString());
statusHandler.handle(Priority.WARN, sb.toString());
}
return adjAreaGeometry;
@ -255,8 +257,10 @@ public class AdjacentWfoMgr {
} catch (SpatialException e) {
UFStatus.getHandler(AdjacentWfoMgr.class).error(
"Error getting CWA Geometry", e);
} catch (ParseException e) {
statusHandler.handle(Priority.PROBLEM,
"Failed to parse the geometry.", e);
}
return geo;
}