Omaha #3975 added ability to import a damage path

Change-Id: Ib393ea42260e2698ff2e0b0e02937fdcdde408a6

Former-commit-id: 9e0e76b5a5a0ebf912c4855384cb82c2474875d5
This commit is contained in:
Nate Jensen 2015-02-12 11:57:37 -06:00
parent 2cec798991
commit 1858e84c98
2 changed files with 102 additions and 0 deletions

View file

@ -9,5 +9,11 @@
name="Export GeoJSON"
sortID="3">
</contextualMenu>
<contextualMenu
actionClass="com.raytheon.uf.viz.damagepath.ImportDamagePathAction"
capabilityClass="com.raytheon.uf.viz.damagepath.DamagePathLayer"
name="Import GeoJSON"
sortID="4">
</contextualMenu>
</extension>
</plugin>

View file

@ -0,0 +1,96 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.viz.damagepath;
import java.io.FileInputStream;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;
import com.raytheon.uf.common.json.JsonException;
import com.raytheon.uf.common.json.geo.GeoJsonUtil;
import com.raytheon.uf.common.json.geo.GeoJsonUtilSimpleImpl;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.viz.core.VizApp;
import com.raytheon.viz.ui.VizWorkbenchManager;
import com.raytheon.viz.ui.cmenu.AbstractRightClickAction;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.Polygon;
/**
* Action to import a damage path from a GeoJSON file specified by the user.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Feb 12, 2015 3975 njensen Initial creation
*
* </pre>
*
* @author njensen
* @version 1.0
*/
public class ImportDamagePathAction extends AbstractRightClickAction {
protected static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(ImportDamagePathAction.class);
public ImportDamagePathAction() {
super("Import GeoJSON");
}
@Override
public void run() {
VizApp.runSync(new Runnable() {
@Override
public void run() {
Shell shell = VizWorkbenchManager.getInstance()
.getCurrentWindow().getShell();
FileDialog fd = new FileDialog(shell, SWT.OPEN);
fd.setFilterExtensions(ExportDamagePathAction.EXTENSIONS);
String filename = fd.open();
if (filename != null) {
DamagePathLayer<?> layer = (DamagePathLayer<?>) getSelectedRsc();
try (FileInputStream fis = new FileInputStream(filename)) {
GeoJsonUtil json = new GeoJsonUtilSimpleImpl();
Geometry geom = json.deserializeGeom(fis);
if (geom instanceof Polygon) {
layer.setPolygon((Polygon) geom);
} else {
throw new JsonException("Damage path file "
+ filename + " must contain a Polygon!");
}
} catch (Exception e) {
statusHandler.error("Error importing damage path from "
+ filename, e);
}
}
}
});
}
}