Merge "Issue #1091 Added localMaps.py capability" into development

Former-commit-id: c1defed68e [formerly 05bf20edb5d43f2a78af0ce8a7c595226ca4cd43]
Former-commit-id: 998b7fc209
This commit is contained in:
Nate Jensen 2012-09-19 17:45:26 -05:00 committed by Gerrit Code Review
commit d0fa730f08
30 changed files with 1266 additions and 1752 deletions

View file

@ -86,6 +86,7 @@ import com.vividsolutions.jts.io.WKBReader;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Feb 19, 2009 randerso Initial creation
* Sep 18, 2012 #1019 randerso improved error handling
*
* </pre>
*
@ -526,8 +527,8 @@ public class DbMapResource extends
queryJob = new MapQueryJob();
// Prepopulate fields
getLabelFields();
getGeometryType();
getLabelFields();
getLevels();
}
@ -842,8 +843,8 @@ public class DbMapResource extends
resourceData.getTable(), resourceData.getGeomField())
.getGeometryType();
} catch (Throwable e) {
statusHandler.handle(Priority.PROBLEM,
"Error querying geometry type", e);
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(),
e);
}
}

View file

@ -39,7 +39,8 @@ import com.vividsolutions.jts.geom.Envelope;
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Dec 9, 2011 bsteffen Initial creation
* Dec 9, 2011 bsteffen Initial creation
* Sep 18, 2012 #1019 randerso cleaned up geometry type query
*
* </pre>
*
@ -143,10 +144,16 @@ public class DefaultDbMapQuery implements DbMapQuery {
query.append(schema);
query.append("' AND f_table_name='");
query.append(table);
query.append("' LIMIT 1;");
query.append("' AND f_geometry_column='");
query.append(this.geomField);
query.append("';");
List<Object[]> results = DirectDbQuery.executeQuery(query.toString(),
MAPS, QueryLanguage.SQL);
if (results.isEmpty()) {
throw new VizException("Maps database table \"" + table
+ "\" is missing or invalid");
}
return (String) results.get(0)[0];
}

View file

@ -22,12 +22,11 @@
# You must include the following line
from Maps import *
# Example of adding a new map background. This one is called "WYCounties"
# on the GFE maps menu, uses the uscounty shapefile, is filtered to include
# Example of adding a group of edit areas. This one is called "WYCounties"
# on the GFE Edit Areas menu, uses the County table, is filtered to include
# just the Wyoming counties. Edit areas are automatically generated"
# and named WY_countyName.
WYcounties = ShapeFile(MAPDIR)
WYcounties.filename(CountyMapName)
WYcounties = ShapeTable('County')
WYcounties.filter(lambda x : x['STATE'] == "WY")
WYcounties.name = 'WYCounties'
WYcounties.editAreaName = ['STATE','COUNTYNAME']

View file

@ -22,18 +22,15 @@
# You must include the following line
from Maps import *
# Example of adding a new map background. This one is called "WYCounties"
# on the GFE maps menu, uses the uscounty shapefile, is filtered to include
# Example of adding a group of edit areas. This one is called "WYCounties"
# on the GFE Edit Areas menu, uses the County table, is filtered to include
# just the Wyoming counties. Edit areas are automatically generated"
# and named WY_countyName. The clip region is expanded from the default
# by 2 degrees in the north and east directions
WYcounties = ShapeFile(MAPDIR)
WYcounties.filename(CountyMapName)
# and named WY_countyName.
WYcounties = ShapeTable('County')
WYcounties.filter(lambda x : x['STATE'] == "WY")
WYcounties.name = 'WYCounties'
WYcounties.editAreaName = ['STATE','COUNTYNAME']
WYcounties.groupName = 'WYCounties'
WYcounties.expandDomain = (2, 2, 0, 0)
maps.append(WYcounties)

View file

@ -151,7 +151,7 @@ public class TestHazardUtils extends TestCase {
* if eval() throws a JepException.
*/
public void assertEval(String pythonExpr) throws JepException, Exception {
assertTrue(pythonExpr, testScript.eval(pythonExpr));
assertTrue(pythonExpr, testScript.evaluate(pythonExpr));
}
/**
@ -184,8 +184,8 @@ public class TestHazardUtils extends TestCase {
sb.append(msg).append(": ");
}
fail(String.format("%sExpected match for '%s', result was '%s'", sb
.toString(), pattern, result));
fail(String.format("%sExpected match for '%s', result was '%s'",
sb.toString(), pattern, result));
}
}
@ -229,7 +229,7 @@ public class TestHazardUtils extends TestCase {
// the data manager and parm manager is in the constructor.
boolean evalResult;
evalResult = testScript
.eval("hazardUtils = MockHazardUtils.MockHazardUtils(dataManager, None)");
.evaluate("hazardUtils = MockHazardUtils.MockHazardUtils(dataManager, None)");
// If eval somehow failed without throwing a JepException, fail.
assertTrue(evalResult);
@ -479,8 +479,8 @@ public class TestHazardUtils extends TestCase {
argmap);
if (obj instanceof String) {
String str = (String) obj;
str = str.substring(0, Math.min(str.length(), PYTHON_TR_STR
.length()));
str = str.substring(0,
Math.min(str.length(), PYTHON_TR_STR.length()));
assertEquals("Return should be Python TimeRanges",
PYTHON_TR_STR, str);
} else {
@ -498,8 +498,8 @@ public class TestHazardUtils extends TestCase {
argmap);
if (obj instanceof String) {
String str = (String) obj;
str = str.substring(0, Math.min(str.length(), JAVA_TR_STR
.length()));
str = str.substring(0,
Math.min(str.length(), JAVA_TR_STR.length()));
assertEquals("Return should be Java TimeRanges", JAVA_TR_STR,
str);
} else {
@ -610,13 +610,12 @@ public class TestHazardUtils extends TestCase {
assertNull("_removeOldGrids should return null", str);
//
//
argmap.clear();
str = (String) testScript.execute("getvalue", "log", argmap);
assertTrue(
"output log:" + str,
str
.matches("parm\\(hazXYZ\\):deleteTR\\(<PyJobject object at 0x[0-9a-fA-F]+>\\)\\s"));
str.matches("parm\\(hazXYZ\\):deleteTR\\(<PyJobject object at 0x[0-9a-fA-F]+>\\)\\s"));
} catch (JepException e) {
throw new Exception(e);
@ -708,8 +707,8 @@ public class TestHazardUtils extends TestCase {
// Since JepException is a catch-all, make sure it contains the
// right value in its message.
if (!je.getMessage().contains("Cannot split grid for")) {
fail(String.format("Bad exception message: %s", je
.getMessage()));
fail(String.format("Bad exception message: %s",
je.getMessage()));
}
}
} catch (JepException e) {

View file

@ -113,7 +113,7 @@ public class TestSmartScript extends TestCase {
// Create a SmartScript instance for use by the tests.
boolean evalResult;
evalResult = testScript
.eval("smartScript = SmartScript.SmartScript(dataManager)");
.evaluate("smartScript = SmartScript.SmartScript(dataManager)");
// If eval somehow failed without throwing a JepException, fail.
assertTrue(evalResult);
@ -163,10 +163,11 @@ public class TestSmartScript extends TestCase {
argmap.put("::numericGrid", "discreteGrid");
Object obj = null;
try {
if (!testScript.eval("tcTuple = (1000, 1200, 600)")) {
if (!testScript.evaluate("tcTuple = (1000, 1200, 600)")) {
throw new Exception("eval(\"tcTuple... failed.");
}
if (!testScript.eval("dkList = ['One', ('Singular', 'Sensation')]")) {
if (!testScript
.evaluate("dkList = ['One', ('Singular', 'Sensation')]")) {
throw new Exception("eval(\"dklist = ... failed.");
}
obj = testScript.execute("createGrid", "smartScript", argmap);
@ -200,7 +201,7 @@ public class TestSmartScript extends TestCase {
Integer outInt = null;
try {
testScript.eval("keyList = []");
testScript.evaluate("keyList = []");
argmap.put("::keys", "keyList");
argmap.put("uglyStr", key1);
outInt = (Integer) testScript.execute("getIndex", "smartScript",

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry exported="true" kind="lib" path="gt-postgis-2.6.4.jar" sourcepath="gt-postgis-2.6.4-sources.zip"/>
<classpathentry exported="true" kind="lib" path="common-2.2.1.jar"/>
<classpathentry exported="true" kind="lib" path="jdom-1.0.jar"/>
<classpathentry exported="true" kind="lib" path="commons-beanutils-1.7.0.jar"/>
@ -21,10 +22,11 @@
<classpathentry exported="true" kind="lib" path="gt-graph-2.6.4.jar" sourcepath="gt-graph-2.6.4-sources.jar"/>
<classpathentry exported="true" kind="lib" path="gt-gtopo30-2.6.4.jar" sourcepath="gt-gtopo30-2.6.4-sources.jar"/>
<classpathentry exported="true" kind="lib" path="gt-image-2.6.4.jar" sourcepath="gt-image-2.6.4-sources.jar"/>
<classpathentry exported="true" kind="lib" path="gt-main-2.6.4.jar" sourcepath="geotools-2.6.4-sources.zip"/>
<classpathentry exported="true" kind="lib" path="gt-main-2.6.4.jar" sourcepath="gt-main-2.6.4-sources.jar"/>
<classpathentry exported="true" kind="lib" path="gt-metadata-2.6.4.jar" sourcepath="gt-metadata-2.6.4-sources.jar"/>
<classpathentry exported="true" kind="lib" path="gt-referencing-2.6.4.jar" sourcepath="gt-referencing-2.6.4-sources.jar"/>
<classpathentry exported="true" kind="lib" path="gt-referencing3D-2.6.4.jar" sourcepath="gt-referencing3D-2.6.4-sources-.jar"/>
<classpathentry exported="true" kind="lib" path="gt-shapefile-2.6.4.jar" sourcepath="gt-shapefile-2.6.4-sources.zip"/>
<classpathentry kind="output" path="bin"/>
<referencedentry exported="true" kind="lib" path="gt-jdbc-2.6.4.jar" sourcepath="gt-jdbc-2.6.4-sources.zip"/>
</classpath>

View file

@ -20,6 +20,7 @@ Bundle-ClassPath: geoapi-2.3-M1.jar,
gt-referencing-2.6.4.jar,
gt-referencing3D-2.6.4.jar,
gt-shapefile-2.6.4.jar,
gt-postgis-2.6.4.jar,
jts-1.10.jar,
commons-beanutils-1.7.0.jar,
commons-codec-1.2.jar,
@ -80,6 +81,7 @@ Export-Package: com.vividsolutions.jts,
org.geotools.coverage.processing.operation,
org.geotools.data,
org.geotools.data.crs,
org.geotools.data.postgis,
org.geotools.data.shapefile,
org.geotools.data.shapefile.dbf,
org.geotools.data.shapefile.indexed,
@ -127,4 +129,5 @@ Bundle-ActivationPolicy: lazy
Require-Bundle: javax.vecmath;bundle-version="1.3.1",
javax.measure;bundle-version="1.0.0",
org.apache.commons.logging,
org.apache.log4j
org.apache.log4j,
org.postgres;bundle-version="1.0.0"

View file

@ -23,4 +23,7 @@ bin.includes = META-INF/,\
commons-lang-2.3.jar,\
commons-pool-1.5.3.jar,\
common-2.2.1.jar,\
jdom-1.0.jar
jdom-1.0.jar,\
gt-postgis-2.6.4.jar,\
gt-jdbc-2.6.4.jar,\
gt-jdbc-postgis-2.6.4.jar

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,335 @@
##
# 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.
##
# NOTE: THIS FILE SHOULD NOT BE USER_MODIFIED. INSTEAD, REFER TO THE
# DOCUMENTATION ON HOW ENTRIES IN THIS FILE MAY BE OVERRIDDEN. REFER TO
# LOCALMAPS DOCUMENTATION.
# Maps.py - map background definitions for ifpServer
from ShapeTable import ShapeTable
import siteConfig, LogStream, JUtil
BASELINE = getattr(siteConfig, 'BASELINE', 0)
# Following lines extract the CWA (WFO name) from siteConfig
CWA = siteConfig.GFESUITE_SITEID
# Each map is identified by a Python variable. The ShapeTable
# is first identified as the data source. The map is then filtered in
# differing ways, or not at all if desired. The name of the map
# is specified. The edit area name and edit area group
# are specified, if it is desired to automatically generate edit areas
# from the map.
#
# NOTE: In AWIPS 2 map backgrounds are created using map bundles.
# Maps.py is only used for generating edit areas.
#
#MapNameVariable = ShapeTable('the name of the map table')
#MapNameVariable.filter( -- - - - - filter string - - - - - - )
#MapNameVariable.name = 'the display name of the map'
#MapNameVariable.editAreaName = 'attribute in ShapeTable to be used to name
# 'editArea'
#MapNameVariable.groupName = 'name of the edit area group'
#
# -------------------------------------------------------------
# Functions for determining name of edit areas
# -------------------------------------------------------------
# FIPS codes
def fips(atts):
#make sure fips attribute exists and of proper length
#make sure state attribute exists and of proper length
if atts.has_key('fips') and len(atts['fips']) == 5 and \
atts.has_key('state') and len(atts['state']) == 2:
fips = atts['fips'][-3:] #last 3 digits from fips code
s = atts['state'] + "C" + fips #assemble COC013
return s
else:
return "" #for no fips in ShapeTable
# Public Zones
def cwazones(atts):
if atts.has_key('zone') and len(atts['zone']) == 3 and \
atts.has_key('state') and len(atts['state']) == 2:
return atts['state'] + "Z" + atts['zone'] #assemble COZ023
else:
return "" #bad attributes
# Fire Wx Zones
def fwxzones(atts):
if atts.has_key('zone') and len(atts['zone']) == 3 and \
atts.has_key('state') and len(atts['state']) == 2:
return atts['state'] + "Z" + atts['zone'] #assemble COZ023
else:
return ""
# Marine Zones
def marineZ(atts):
if atts.has_key('id') and len(atts['id']) == 6:
return atts['id']
else:
return ""
# Offshore Marine Zones
def offshoreZ(atts):
if atts.has_key('id') and len(atts['id']) == 6:
return atts['id']
else:
return ""
#---------------------------------------------------------------------
# Map Background Filters
#---------------------------------------------------------------------
# filter for public zones.
def publicZoneFilter(atts):
if not atts.has_key('cwa'):
return 0
# this CWA (all but AFC site)
if atts['cwa'] == CWA:
return 1
# AFC data - separate out AER/ALU data
elif atts['cwa'] == 'AFC':
id = cwazones(atts)
if CWA == 'AER':
return id in ['AKZ101', 'AKZ111', 'AKZ121', 'AKZ125', 'AKZ131',
'AKZ135', 'AKZ141', 'AKZ145', 'AKZ171']
elif CWA == 'ALU':
return id in ['AKZ151', 'AKZ155', 'AKZ161', 'AKZ181',
'AKZ185', 'AKZ187', 'AKZ191', 'AKZ195']
elif CWA == 'AICE':
return 1
return 0
# filter for fire weather zones.
def firewxZoneFilter(atts):
if not atts.has_key('cwa'):
return 0
# this CWA (all but AFC site)
if atts['cwa'] == CWA:
return 1
# AFC data - separate out AER/ALU data
elif atts['cwa'] == 'AFC':
id = fwxzones(atts)
if CWA == 'AER':
return id in ['AKZ101', 'AKZ111', 'AKZ121', 'AKZ125', 'AKZ131',
'AKZ135', 'AKZ141', 'AKZ145', 'AKZ171']
elif CWA == 'ALU':
return id in ['AKZ151', 'AKZ155', 'AKZ161', 'AKZ181',
'AKZ185', 'AKZ187', 'AKZ191', 'AKZ195']
elif CWA == 'AICE':
return 1
return 0
# filter for marine zones.
def marineZoneFilter(atts):
if not atts.has_key('wfo'):
return 0
# this CWA (all but AFC site)
if atts['wfo'] == CWA:
return 1
# AFC data - separate out AER/ALU data
elif atts['wfo'] == 'AFC':
id = marineZ(atts)
if CWA == 'AER':
return id in ['PKZ120', 'PKZ121', 'PKZ125', 'PKZ126', 'PKZ127',
'PKZ128', 'PKZ129', 'PKZ130', 'PKZ132', 'PKZ136', 'PKZ137',
'PKZ138', 'PKZ140', 'PKZ141']
elif CWA == 'ALU':
return id in ['PKZ150', 'PKZ155', 'PKZ160', 'PKZ165', 'PKZ170',
'PKZ171', 'PKZ172', 'PKZ175', 'PKZ176', 'PKZ179', 'PKZ180',
'PKZ185']
elif CWA == 'AICE':
return 1
return 0
# filter for offshore marine zones.
def offshoreZoneFilter(atts):
if not atts.has_key('wfo'):
return 0
# this CWA (all but AFC site)
if atts['wfo'] == CWA:
return 1
# AFC data - separate out AER/ALU data
elif atts['wfo'] == 'AFC':
id = offshoreZ(atts)
if CWA == 'AER':
return id in ['PKZ350']
elif CWA == 'ALU':
return id in ['PKZ410']
elif CWA == 'AICE':
return 1
return 0
#---------------------------------------------------------------------
# Map Background Definitions
#---------------------------------------------------------------------
# CWA Counties
CWAcounties = ShapeTable('County')
CWAcounties.filter(lambda x : x['cwa'][0:3] == CWA or x['cwa'][3:6] == CWA)
CWAcounties.name = 'Counties_' + CWA
CWAcounties.editAreaName = ['state','countyname']
CWAcounties.groupName = 'Counties'
# FIPS for my counties - only include first WFO indicated in CWA field
FIPS = ShapeTable('County')
FIPS.name = 'FIPS_' + CWA
FIPS.filter(lambda x : x['cwa'][0:3] == CWA)
FIPS.editAreaName = fips
FIPS.groupName = 'FIPS_' + CWA
# Unfiltered Counties
Counties = ShapeTable('County')
Counties.name = 'Counties'
Counties.editAreaName = fips
Counties.groupName = 'FIPS'
# CWA Zones
CWAzones = ShapeTable('Zone')
CWAzones.filter(publicZoneFilter)
CWAzones.name = 'Zones_' + CWA
CWAzones.editAreaName = cwazones
CWAzones.groupName = 'Zones_' + CWA
# Unfiltered Zones
Zones = ShapeTable('Zone')
Zones.name = 'Zones'
Zones.editAreaName = cwazones
Zones.groupName = 'Zones'
# Fire Wx Zones
FWCWAzones = ShapeTable('FireWxZones')
FWCWAzones.filter(firewxZoneFilter)
FWCWAzones.name = 'FireWxZones_' + CWA
FWCWAzones.editAreaName = fwxzones
FWCWAzones.groupName = 'FireWxZones_' + CWA
# Unfiltered Fire Wx Zones
FWZones = ShapeTable('FireWxZones')
FWZones.name = 'FireWxZones'
FWZones.editAreaName = fwxzones
FWZones.groupName = 'FireWxZones'
# CWAs for all
cwas = ShapeTable('CWA')
cwas.name = 'CWA_all'
cwas.editAreaName = 'wfo'
cwas.groupName = 'WFOs'
# ISC areas for all
isc = ShapeTable('ISC')
isc.name = 'ISC_all'
isc.editAreaName = ['ISC','wfo']
isc.groupName = 'ISC'
# Fire Wx AOR for all
fwaor = ShapeTable('FireWxAOR')
fwaor.name = 'FireWxAOR'
fwaor.editAreaName = ['FireWxAOR', 'cwa']
fwaor.groupName = 'FireWxAOR'
# Marine Zones for CWA
CWAmzones = ShapeTable('MarineZones')
CWAmzones.filter(marineZoneFilter)
CWAmzones.name = 'Marine_Zones_' + CWA
CWAmzones.editAreaName = marineZ
CWAmzones.groupName = 'MZones_' + CWA
# Marine Zones (unfiltered)
Mzones = ShapeTable('MarineZones')
Mzones.name = "Marine_Zones"
Mzones.editAreaName = marineZ
Mzones.groupName = 'MZones'
# States (unfiltered)
States = ShapeTable('States')
States.name = "States"
States.editAreaName = 'name'
States.groupName = 'States'
# RFC maps
rfc = ShapeTable('RFC')
rfc.name = "RFC"
rfc.editAreaName = ['ISC','site_id']
rfc.groupName = 'ISC'
# Offshore Marine Zones - unfiltered
offshore = ShapeTable('Offshore')
offshore.name = "Offshore_Marine_Zones"
offshore.editAreaName = offshoreZ
offshore.groupName = 'OffShoreMZones'
# Offshore Marine Zones - filtered by CWA
offshoreCWA = ShapeTable('Offshore')
offshoreCWA.filter(offshoreZoneFilter)
offshoreCWA.name = "Offshore_Marine_Zones_" + CWA
offshoreCWA.editAreaName = offshoreZ
offshoreCWA.groupName = 'OffShoreMZones_' + CWA
# this is a complete listing of all maps
maps = [ CWAcounties, FIPS, Counties, CWAzones, Zones, FWCWAzones, FWZones,
cwas, isc, fwaor, CWAmzones, Mzones, States, rfc, offshore, offshoreCWA ]
# import the local maps file
if not BASELINE:
try:
from localMaps import *
except ImportError:
pass
def getMaps():
from java.util import ArrayList
jmaps = ArrayList(len(maps))
for m in maps:
j = m.toJavaObj()
jmaps.add(j)
for k,v in globals().iteritems():
if v is m:
j.setInstanceName(k)
break
return jmaps
def runFilter(instance, info):
info = JUtil.javaObjToPyVal(info)
return bool(globals()[instance].doFilter(info))
def runNamer(instance, info):
info = JUtil.javaObjToPyVal(info)
return str(globals()[instance].getEAName(info))

View file

@ -0,0 +1,451 @@
/**
* 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.edex.plugin.gfe.reference;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Properties;
import org.geotools.data.DataStore;
import org.geotools.data.DefaultQuery;
import org.geotools.data.FeatureSource;
import org.geotools.data.postgis.PostgisDataStoreFactory;
import org.geotools.factory.CommonFactoryFinder;
import org.geotools.factory.GeoTools;
import org.geotools.feature.FeatureCollection;
import org.hibernate.engine.SessionFactoryImplementor;
import org.opengis.feature.IllegalAttributeException;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.feature.type.AttributeDescriptor;
import org.opengis.filter.Filter;
import org.opengis.filter.FilterFactory2;
import org.opengis.geometry.BoundingBox;
import com.raytheon.uf.common.dataquery.db.QueryResult;
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.edex.core.EDEXUtil;
import com.raytheon.uf.edex.database.tasks.SqlQueryTask;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.LineString;
import com.vividsolutions.jts.geom.MultiLineString;
import com.vividsolutions.jts.geom.MultiPoint;
import com.vividsolutions.jts.geom.MultiPolygon;
import com.vividsolutions.jts.geom.Point;
import com.vividsolutions.jts.geom.Polygon;
/**
* Class to allow reading (and optionally filtering) of an PostGIS table
*
* <pre>
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Sep 18, 2012 #1091 randerso Initial creation
*
* </pre>
*
* @author randerso
* @version 1.0
*/
public class DbShapeSource {
private static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(DbShapeSource.class);
public static enum ShapeType {
NONE, POINT, POLYLINE, POLYGON
}
private static final String DB_NAME = "maps";
private static final String SCHEMA_NAME = "mapdata";
private static DataStore _dataStore;
private static int refCount = 0;
private boolean filtered = false;
private String displayName;
private boolean hasEditAreaName = false;
private String groupName;
private String instanceName;
private String tableName;
private List<String> attributeNames;
private FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection;
private Iterator<SimpleFeature> featureIterator;
private String shapeField;
private ShapeType type;
private Geometry boundingGeom;
private BoundingBox boundingBox;
private DefaultQuery query;
private String typeName;
private SimpleFeatureType schema;
/**
* Create a DbShapeSource
*
* @param tableName
* the name of the database table.
* @throws IOException
*/
public DbShapeSource(String tableName) throws IOException {
this.tableName = tableName;
this.typeName = this.tableName.toLowerCase();
refCount++;
}
@Override
protected void finalize() throws Throwable {
refCount--;
if (refCount == 0) {
if (_dataStore != null) {
_dataStore.dispose();
_dataStore = null;
}
}
super.finalize();
}
private synchronized DataStore getDataStore() throws IOException {
if (_dataStore == null) {
SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) EDEXUtil
.getESBComponent("mapsSessionFactory");
Properties props = sessionFactory.getProperties();
String host = props.getProperty("db.addr");
String port = props.getProperty("db.port");
String user = props.getProperty("connection.username");
String passwd = props.getProperty("connection.password");
PostgisDataStoreFactory factory = new PostgisDataStoreFactory();
Map<String, Object> params = new HashMap<String, Object>();
params.put("host", host);
params.put("port", port);
params.put("database", DB_NAME);
params.put("schema", SCHEMA_NAME);
params.put("user", user);
params.put("passwd", passwd);
params.put("dbtype", "postgis");
params.put("wkb enabled", true);
_dataStore = factory.createDataStore(params);
}
return _dataStore;
}
/**
* @throws IOException
*
*/
public void open() throws IOException {
DataStore dataStore = getDataStore();
schema = dataStore.getSchema(typeName);
shapeField = schema.getGeometryDescriptor().getLocalName();
featureCollection = null;
featureIterator = null;
query = new DefaultQuery();
query.setTypeName(typeName);
List<String> propNames = new ArrayList<String>(getAttributeNames());
propNames.add(shapeField);
query.setPropertyNames(propNames);
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(GeoTools
.getDefaultHints());
Filter filter = null;
if (boundingGeom != null) {
filter = ff.intersects(ff.property(shapeField),
ff.literal(boundingGeom));
}
if (boundingBox != null) {
filter = ff.bbox(ff.property(shapeField), boundingBox);
}
if (filter != null) {
query.setFilter(filter);
}
FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = dataStore
.getFeatureSource(typeName);
featureCollection = featureSource.getFeatures(query);
featureIterator = featureCollection.iterator();
}
/**
* Returns the database table name
*
* @return
*/
public String getTableName() {
return this.tableName;
}
/**
* @throws IOException
*
*/
public void close() throws IOException {
if (featureIterator != null) {
featureCollection.close(featureIterator);
featureIterator = null;
featureCollection = null;
}
}
public boolean hasNext() throws IOException {
if (featureIterator == null) {
throw new IOException("DataStore is not open");
}
return featureIterator.hasNext();
}
public SimpleFeature next() throws NoSuchElementException, IOException,
IllegalAttributeException {
if (featureIterator == null) {
throw new IOException("DataStore is not open");
}
return featureIterator.next();
}
public synchronized ShapeType getShapeType() throws IOException {
if (this.type == null) {
boolean closeIt = false;
if (schema == null) {
open();
closeIt = true;
}
Class<?> geometryType = schema.getGeometryDescriptor().getType()
.getBinding();
if (geometryType == Point.class || geometryType == MultiPoint.class) {
this.type = ShapeType.POINT;
} else if (geometryType == LineString.class
|| geometryType == MultiLineString.class) {
this.type = ShapeType.POLYLINE;
} else if (geometryType == Polygon.class
|| geometryType == MultiPolygon.class) {
this.type = ShapeType.POLYGON;
} else {
this.type = ShapeType.NONE;
}
if (closeIt) {
close();
}
}
return this.type;
}
public synchronized List<String> getAttributeNames() throws IOException {
if (attributeNames == null) {
List<AttributeDescriptor> attrDesc = schema
.getAttributeDescriptors();
if (attrDesc == null || attrDesc.size() == 0) {
return null;
}
attributeNames = new ArrayList<String>(attrDesc.size());
for (AttributeDescriptor at : attrDesc) {
Class<?> atType = at.getType().getBinding();
if (!Geometry.class.isAssignableFrom(atType)) {
attributeNames.add(at.getLocalName());
}
}
}
return attributeNames;
}
/**
* @param i
* @return
* @throws IOException
*/
public Map<String, Object> getAttributes(SimpleFeature f)
throws IOException {
Map<String, Object> retVal = new HashMap<String, Object>();
for (String at : getAttributeNames()) {
Object attr = f.getAttribute(at);
if (attr != null) {
retVal.put(at, attr);
}
}
return retVal;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return this.getDisplayName();
}
/**
* @return the filter
*/
public boolean isFiltered() {
return this.filtered;
}
/**
* @param filter
* the filter to set
*/
public void setFiltered(boolean filtered) {
this.filtered = filtered;
}
public void setBoundingGeometry(Geometry geom) {
this.boundingGeom = geom;
}
public void setBoundingBox(BoundingBox bbox) {
this.boundingBox = bbox;
}
/**
* @return
* @throws IOException
*/
public int getFeatureCount() throws IOException {
if (this.featureCollection == null) {
throw new IOException(
"DataStore must be open when calling getFeatureCount");
}
return this.featureCollection.size();
}
public String getDisplayName() {
return displayName;
}
public void setDisplayName(String name) {
this.displayName = name;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public boolean hasEditAreaName() {
return this.hasEditAreaName;
}
public void setHasEditAreaName(boolean hasEditAreaName) {
this.hasEditAreaName = hasEditAreaName;
}
public String getInstanceName() {
return instanceName;
}
public void setInstanceName(String instanceName) {
this.instanceName = instanceName;
}
public static void main(String[] args) {
long t0 = System.currentTimeMillis();
DbShapeSource dbShape = null;
try {
dbShape = new DbShapeSource("States");
dbShape.open();
System.out.println("Open Took " + (System.currentTimeMillis() - t0)
+ " ms");
System.out.println(dbShape.getShapeType());
while (dbShape.hasNext()) {
SimpleFeature feature = dbShape.next();
Map<String, Object> attributes = dbShape.getAttributes(feature);
List<String> keys = new ArrayList<String>(attributes.keySet());
Collections.sort(keys);
for (String key : keys) {
Object attribute = attributes.get(key);
System.out.println(key + ": " + attribute);
}
System.out.println();
}
} catch (IOException e) {
statusHandler.error(
"IOException reading " + dbShape.getTableName(), e);
} finally {
try {
if (dbShape != null) {
dbShape.close();
}
} catch (IOException e) {
statusHandler.error(
"IOException closing " + dbShape.getTableName(), e);
}
}
System.out.println("Took " + (System.currentTimeMillis() - t0) + " ms");
}
public Date getLastUpdated() {
Date retVal = new Date();
String sqlQuery = "SELECT import_time FROM " + SCHEMA_NAME
+ ".map_version WHERE table_name = '" + this.typeName + "';";
try {
SqlQueryTask task = new SqlQueryTask(sqlQuery, DB_NAME);
QueryResult result = task.execute();
retVal = (Date) result.getRowColumnValue(0, 0);
} catch (Exception e) {
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e);
}
return retVal;
}
}

View file

@ -1,275 +0,0 @@
/**
* 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.edex.plugin.gfe.reference;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.geotools.geometry.jts.JTS;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.metadata.spatial.PixelOrientation;
import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.TransformException;
import com.raytheon.edex.plugin.gfe.config.IFPServerConfig;
import com.raytheon.edex.plugin.gfe.config.IFPServerConfigManager;
import com.raytheon.edex.plugin.gfe.exception.GfeConfigurationException;
import com.raytheon.edex.plugin.gfe.reference.ShapeFile.IEditAreaNamer;
import com.raytheon.edex.plugin.gfe.reference.ShapeFile.IMapBackgroundFilter;
import com.raytheon.uf.common.dataplugin.gfe.db.objects.GridLocation;
import com.raytheon.uf.common.geospatial.MapUtil;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Polygon;
import com.vividsolutions.jts.geom.prep.PreparedGeometry;
import com.vividsolutions.jts.geom.prep.PreparedGeometryFactory;
/**
* Load edit area information for a site from shape files. This is a limited
* version of the processing that takes place in MapManager, created so that
* ConfigureTextProductsHandler can rebuild the combinations files, area
* dictionary file, and city location file.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* May 4, 2011 wldougher Initial creation
*
* </pre>
*
* @author wldougher
* @version 1.0
*/
public class EditAreaLoader {
private transient Log log = LogFactory.getLog(getClass());
/**
* Load the shapefiles for site and use them to generate editAreaMap and
* editAreaAttrs. The output collections are not cleared, so results may
* accumulate if the same collections are used in multiple calls.
*
* @param site
* @param editAreaMap
* The edit area map (output).
* @param editAreaAttrs
* The edit area attributes (output)
* @throws IOException
* When one or more shape files cannot be read
*/
public void load(String site, Map<String, List<String>> editAreaMap,
Map<String, Map<String, String>> editAreaAttrs)
throws GfeConfigurationException, IOException {
if (editAreaMap == null) {
throw new IllegalArgumentException("editAreaMap is null");
}
if (editAreaAttrs == null) {
throw new IllegalArgumentException("editAreaAttrs is null");
}
// Get the site's bounding geometry
IFPServerConfig config = getServerConfig(site);
GridLocation gloc = config.dbDomain();
Coordinate c0 = new Coordinate(0, 0);
Coordinate c1 = new Coordinate(gloc.getNx() - 1, 0);
Coordinate c2 = new Coordinate(gloc.getNx() - 1, gloc.getNy() - 1);
Coordinate c3 = new Coordinate(0, gloc.getNy() - 1);
GeometryFactory gf = new GeometryFactory();
Polygon p = gf.createPolygon(
gf.createLinearRing(new Coordinate[] { c0, c1, c2, c3, c0 }),
null);
PreparedGeometry boundingGeometry = PreparedGeometryFactory.prepare(p);
// transform: shape file geometry to boundingGeometry CRS
MathTransform transform = MapUtil.getTransformFromLatLon(
PixelOrientation.CENTER, gloc);
ShapeFile[] shapeFiles = Maps.getMaps(site, Maps.GetMode.UNCONDITIONAL);
for (ShapeFile shapeFile : shapeFiles) {
List<String> created = new ArrayList<String>();
if (shapeFile.getEditAreaName() == null) {
continue;
}
log.debug("creating: " + shapeFile.getDisplayName());
try {
shapeFile.open();
IMapBackgroundFilter filter = shapeFile
.getMapBackgroundFilter();
while (shapeFile.hasNext()) {
SimpleFeature f = shapeFile.next();
Map<String, String> info = shapeFile.getAttributes(f);
if (filter != null && !filter.filter(info)) {
continue;
}
String editAreaName;
// functions return a string
if (shapeFile.getEditAreaName() instanceof IEditAreaNamer) {
editAreaName = ((IEditAreaNamer) shapeFile
.getEditAreaName()).getEditAreaName(info);
// non-functions allow only a string
} else {
editAreaName = defaultEditAreaNaming(info,
shapeFile.getEditAreaName());
}
// validate edit area name
String ean = validateEAN(editAreaName);
if (ean.length() == 0) {
continue;
}
Geometry mp = (Geometry) f.getDefaultGeometry();
Geometry mpGrid;
try {
mpGrid = JTS.transform(mp, transform);
} catch (TransformException e) {
log.warn("Error transforming geometry for edit area "
+ ean + " : skipped", e);
continue;
}
if (!boundingGeometry.intersects(mpGrid)) {
continue;
}
Map<String, String> savedInfo = editAreaAttrs.get(ean);
if (savedInfo == null) {
created.add(ean);
editAreaAttrs.put(ean, info);
}
}
} finally {
shapeFile.close();
}
editAreaMap.put(shapeFile.getDisplayName(), created);
}
}
/**
* Get the server configuration for site. This is just a wrapper around the
* static method of the same name in IFPServerConfig.
*
* @param site
* The site whose server configuration is to be found
* @return The server configuration for the site.
*/
protected IFPServerConfig getServerConfig(String site)
throws GfeConfigurationException {
return IFPServerConfigManager.getServerConfig(site);
}
/**
* Validate edit area name. Changes the name as needed to ensure a valid
* python name.
* <p>
* Copied from MapManager
*
* @param editAreaName
* @return
*/
protected String validateEAN(String ean) {
String s = ean;
// strip out white space and puncuation (except _)
for (int i = s.length() - 1; i >= 0; i--) {
if (!Character.isLetterOrDigit(s.charAt(i)) && s.charAt(i) != '_') {
s = s.substring(0, i) + s.substring(i + 1);
}
}
// ensure 1st character is not a number. If a number, preprend.
if (s.length() > 0 && Character.isDigit(s.charAt(0))) {
s = "ea" + s;
}
return s;
}
/**
* Generate an edit area name from a collection of attributes and an edit
* area name definition. If the edit area name definition is not a String or
* an array of Strings, an empty String is returned.
* <p>
* Copied from MapManager
*
* @param info
* A Map of shape file attribute names to values
* @param eanDefinition
* The Object returned from a call to getEditAreaName() on a
* ShapeFile instance, but NOT an IEditAreaNamer instance.
* @return An edit area name constructed from the input parameters. The name
* may not be a valid Python name.
* @see validateEAN(String)
*/
protected String defaultEditAreaNaming(Map<String, String> info,
Object eanDefinition) {
// simple case, the edit area name definition is the attribute key
if (eanDefinition instanceof String) {
String ean = (String) eanDefinition;
if (info.containsKey(ean)) {
return info.get(ean);
} else {
return ean;
}
} else if (eanDefinition instanceof String[]) {
String s = "";
for (String e : (String[]) eanDefinition) {
// valid attribute
if (info.containsKey(e)) {
if (s.length() == 0) {
s = info.get(e);
} else {
s = s + "_" + info.get(e);
}
// not valid attribute, so use definition directly
} else {
if (s.length() == 0) {
s = e;
} else {
s = s + "_" + e;
}
}
}
return s;
} else {
return "";
}
}
}

View file

@ -1,166 +0,0 @@
/**
* 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.edex.plugin.gfe.reference;
import com.raytheon.edex.plugin.gfe.reference.ShapeFile.ShapeType;
/**
* TODO Add Description
*
* <pre>
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 17, 2008 randerso Initial creation
*
* </pre>
*
* @author randerso
* @version 1.0
*/
public class MapID {
private ShapeType _mapType;
private String _shapefileName;
private String _name;
/**
* Default constructor for MapID.
*
*/
public MapID() {
this._mapType = ShapeType.NONE;
}
/**
* Constructor for MapID class taking a map name, a map type, and a
*
* @param name
* @param mapType
* @param shapefileName
*/
public MapID(final String name, final ShapeType mapType,
final String shapefileName) {
this._name = name;
this._mapType = mapType;
this._shapefileName = shapefileName;
}
public String mapTypeAsString() {
return this._mapType.toString();
}
public String filename() {
return "MAPS_" + this._name;
}
/**
* @return the _mapType
*/
public ShapeType getMapType() {
return _mapType;
}
/**
* @return the _shapefileName
*/
public String getShapefileName() {
return _shapefileName;
}
/**
* @return the _name
*/
public String getName() {
return _name;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
String o = "(" + getName() + "," + mapTypeAsString() + ","
+ getShapefileName() + ")";
return o;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (_mapType == null ? 0 : _mapType.hashCode());
result = prime * result + (_name == null ? 0 : _name.hashCode());
result = prime * result
+ (_shapefileName == null ? 0 : _shapefileName.hashCode());
return result;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final MapID other = (MapID) obj;
if (_mapType == null) {
if (other._mapType != null) {
return false;
}
} else if (!_mapType.equals(other._mapType)) {
return false;
}
if (_name == null) {
if (other._name != null) {
return false;
}
} else if (!_name.equals(other._name)) {
return false;
}
if (_shapefileName == null) {
if (other._shapefileName != null) {
return false;
}
} else if (!_shapefileName.equals(other._shapefileName)) {
return false;
}
return true;
}
}

View file

@ -38,22 +38,22 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import jep.JepException;
import org.geotools.geometry.jts.JTS;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.geometry.BoundingBox;
import org.opengis.metadata.spatial.PixelOrientation;
import org.opengis.referencing.operation.MathTransform;
import com.raytheon.edex.plugin.gfe.config.IFPServerConfig;
import com.raytheon.edex.plugin.gfe.reference.ShapeFile.IEditAreaNamer;
import com.raytheon.edex.plugin.gfe.reference.ShapeFile.IMapBackgroundFilter;
import com.raytheon.edex.plugin.gfe.reference.ShapeFile.ShapeType;
import com.raytheon.edex.plugin.gfe.reference.DbShapeSource.ShapeType;
import com.raytheon.edex.plugin.gfe.textproducts.AreaDictionaryMaker;
import com.raytheon.edex.plugin.gfe.textproducts.CombinationsFileMaker;
import com.raytheon.edex.plugin.gfe.textproducts.Configurator;
import com.raytheon.uf.common.dataplugin.gfe.db.objects.GridLocation;
import com.raytheon.uf.common.dataplugin.gfe.grid.Grid2DBit;
import com.raytheon.uf.common.dataplugin.gfe.python.GfePyIncludeUtil;
import com.raytheon.uf.common.dataplugin.gfe.reference.ReferenceData;
import com.raytheon.uf.common.dataplugin.gfe.reference.ReferenceData.CoordinateType;
import com.raytheon.uf.common.dataplugin.gfe.reference.ReferenceID;
@ -62,12 +62,17 @@ import com.raytheon.uf.common.dataplugin.gfe.sample.SampleId;
import com.raytheon.uf.common.geospatial.MapUtil;
import com.raytheon.uf.common.localization.IPathManager;
import com.raytheon.uf.common.localization.LocalizationContext;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
import com.raytheon.uf.common.localization.PathManagerFactory;
import com.raytheon.uf.common.message.WsId;
import com.raytheon.uf.common.python.PyUtil;
import com.raytheon.uf.common.python.PythonEval;
import com.raytheon.uf.common.serialization.SerializationUtil;
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.FileUtil;
import com.raytheon.uf.edex.database.cluster.ClusterLockUtils;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
@ -90,7 +95,7 @@ import com.vividsolutions.jts.simplify.TopologyPreservingSimplifier;
* Apr 10, 2008 #1075 randerso Initial creation
* Jun 25, 2008 #1210 randerso Modified to get directories from UtilityContext
* Oct 13, 2008 #1607 njensen Added genCombinationsFiles()
*
* Sep 18, 2012 #1091 randerso Changed to use Maps.py and localMaps.py
*
* </pre>
*
@ -98,7 +103,8 @@ import com.vividsolutions.jts.simplify.TopologyPreservingSimplifier;
* @version 1.0
*/
public class MapManager {
private static final Log theLogger = LogFactory.getLog(MapManager.class);
private static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(MapManager.class);
private static final String EDIT_AREAS_DIR = FileUtil.join("gfe",
"editAreas");
@ -109,211 +115,135 @@ public class MapManager {
private static final String SAMPLE_SETS_DIR = FileUtil.join("gfe",
"sampleSets");
protected static final String EDIT_AREA_GEN_TASK = "GfeEditAreaGeneration";
private IFPServerConfig _config;
private List<String> _mapErrors;
private List<MapID> _ids;
private Map<String, ArrayList<String>> editAreaMap = new HashMap<String, ArrayList<String>>();
private Map<String, Map<String, String>> editAreaAttrs = new HashMap<String, Map<String, String>>();
private Map<String, Map<String, Object>> editAreaAttrs = new HashMap<String, Map<String, Object>>();
private List<String> iscMarkersID = new ArrayList<String>();
private List<Coordinate> iscMarkers = new ArrayList<Coordinate>();
private String commonStaticConfigDir;
private final String commonStaticConfigDir;
private String edexStaticSiteDir;
private final String edexStaticBaseDir;
private final String edexStaticConfigDir;
private final String edexStaticSiteDir;
private static final double EA_EQ_TOLERANCE = 0.0005;
private PythonEval pyScript;
public MapManager(IFPServerConfig serverConfig) {
this(serverConfig, null);
}
@SuppressWarnings("unchecked")
public MapManager(IFPServerConfig serverConfig, String dir) {
_config = serverConfig;
try {
_config = serverConfig;
String siteId = _config.getSiteID().get(0);
IPathManager pathMgr = PathManagerFactory.getPathManager();
LocalizationContext edexStaticSite = pathMgr.getContextForSite(
LocalizationType.EDEX_STATIC, siteId);
this.edexStaticSiteDir = pathMgr.getFile(edexStaticSite, ".")
.getAbsolutePath();
String siteId = _config.getSiteID().get(0);
IPathManager pathMgr = PathManagerFactory.getPathManager();
LocalizationContext edexStaticBase = pathMgr.getContext(
LocalizationType.EDEX_STATIC, LocalizationLevel.BASE);
this.edexStaticBaseDir = pathMgr.getFile(edexStaticBase, ".")
.getAbsolutePath();
LocalizationContext edexStaticConfig = pathMgr.getContext(
LocalizationType.EDEX_STATIC, LocalizationLevel.CONFIGURED);
this.edexStaticConfigDir = pathMgr.getFile(edexStaticConfig, ".")
.getAbsolutePath();
LocalizationContext edexStaticSite = pathMgr.getContextForSite(
LocalizationType.EDEX_STATIC, siteId);
this.edexStaticSiteDir = pathMgr.getFile(edexStaticSite, ".")
.getAbsolutePath();
if (dir != null) {
this.commonStaticConfigDir = dir;
} else {
LocalizationContext commonStaticConfig = pathMgr.getContext(
LocalizationContext.LocalizationType.COMMON_STATIC,
LocalizationContext.LocalizationLevel.CONFIGURED);
commonStaticConfig.setContextName(siteId);
if (dir != null) {
this.commonStaticConfigDir = dir;
} else {
LocalizationContext commonStaticConfig = pathMgr.getContext(
LocalizationContext.LocalizationType.COMMON_STATIC,
LocalizationContext.LocalizationLevel.CONFIGURED);
commonStaticConfig.setContextName(siteId);
this.commonStaticConfigDir = pathMgr.getFile(commonStaticConfig,
".").getAbsolutePath();
this.commonStaticConfigDir = pathMgr.getFile(
commonStaticConfig, ".").getAbsolutePath();
}
_mapErrors = new ArrayList<String>();
long t0 = System.currentTimeMillis();
statusHandler.info("MapManager " + _config.getSiteID().get(0)
+ " started.");
String includePath = PyUtil.buildJepIncludePath(true,
GfePyIncludeUtil.getGfeConfigIncludePath(siteId),
FileUtil.join(edexStaticBaseDir, "gfe"),
GfePyIncludeUtil.getCommonPythonIncludePath());
List<DbShapeSource> maps = null;
pyScript = null;
try {
pyScript = new PythonEval(includePath,
MapManager.class.getClassLoader());
pyScript.eval("from Maps import *");
Object results = pyScript.execute("getMaps", null);
maps = (List<DbShapeSource>) results;
} catch (JepException e) {
statusHandler.error("Error getting maps", e);
}
boolean needUpdate = true;
needUpdate = updateNeeded(maps,
FileUtil.join(this.commonStaticConfigDir, EDIT_AREAS_DIR));
statusHandler.info("getMaps took: "
+ (System.currentTimeMillis() - t0) + " ms");
if (needUpdate) {
statusHandler.info("Number of maps to process: " + maps.size());
// edit area generation phase,
// if any edit areas are out of date, then redo all
genEditArea(maps);
} else {
statusHandler.info("All edit areas are up to date.");
}
// configure the text products
Configurator configurator = new Configurator(_config.getSiteID()
.get(0));
statusHandler.info("Configuring text products....");
configurator.execute();
if (needUpdate) {
// need the attributes from the edit area step to be able to do
// this right
String site = _config.getSiteID().get(0);
new CombinationsFileMaker().genCombinationsFiles(site,
editAreaMap);
new AreaDictionaryMaker()
.genAreaDictionary(site, editAreaAttrs);
}
statusHandler.info("MapManager ready.");
long t1 = System.currentTimeMillis();
statusHandler.info("MapCreation time: " + (t1 - t0) + " ms");
} finally {
if (pyScript != null) {
pyScript.dispose();
}
}
_mapErrors = new ArrayList<String>();
_ids = new ArrayList<MapID>();
long t0 = System.currentTimeMillis();
theLogger
.info("MapManager " + _config.getSiteID().get(0) + " started.");
// try{
// Module mapMod("Maps");
ShapeFile[] maps = Maps.getMaps(_config.getSiteID().get(0),
Maps.GetMode.UNCONDITIONAL);
boolean anyCached;
// anyCached = maps != null;
anyCached = cacheNeeded(maps,
FileUtil.join(this.commonStaticConfigDir, EDIT_AREAS_DIR));
theLogger.info("getMaps took: " + (System.currentTimeMillis() - t0)
+ " ms");
// map == null tells us the shape files have not changed, skip this
if (anyCached) {
theLogger.info("Number of maps to process: " + maps.length);
// edit area generation phase, if any maps are outdated, then redo
// all
genEditArea(maps);
ClusterLockUtils.lock(EDIT_AREA_GEN_TASK, _config.getSiteID()
.get(0), 0, false);
} else {
theLogger.info("All edit areas are up to date.");
}
// adding valid maps to list
// addValidMaps(maps);
// configure the text products
Configurator configurator = new Configurator(_config.getSiteID().get(0));
theLogger.info("Configuring text products....");
configurator.execute();
if (anyCached) {
// need the attributes from the edit area step to be able to do this
// right
String site = _config.getSiteID().get(0);
new CombinationsFileMaker().genCombinationsFiles(site, editAreaMap);
new AreaDictionaryMaker().genAreaDictionary(site, editAreaAttrs);
}
// configure products (formatter templates)
// try
// {
// Module txtConfigMod("configureTextProducts");
// String mode = "CREATE";
// txtConfigMod.getAttr("configureTextProducts").call(
// _config.baseDir().stringPtr(),
// _config.siteID()[0].stringPtr(),
// mode.stringPtr(), _altA2Afile.stringPtr());
// }
// catch (Error &e)
// {
// std::ostringstream o;
// o + "Error in configuring text products: " + e + std::endl
// + std::ends;
// e.clear();
// String error =
// "********* TEXT PRODUCT CONFIGURATION ERROR *********\n";
// error += o.str().c_str();
// theLogger.error(error);
// _mapErrors.append(error);
// }
//
//
// // configure products (dictionaries and combos)
// try
// {
// Dictionary attD;
// for (int i = 0; i < _ids.length(); i++)
// attD.add(_ids[i].name().stringPtr(),
// getAttributes(_ids[i]));
// Module txtConfigMod("createComboAreaDict");
// txtConfigMod.getAttr("configureTextComboAreaDict").call(attD,
// _config.baseDir().stringPtr(),
// _config.siteID()[0].stringPtr());
// }
// catch (Error &e)
// {
// std::ostringstream o;
// o + "Error in configuring combinations/areaDictionary: "
// + e + std::endl + std::ends;
// e.clear();
// String error =
// "********* COMBINATIONS/AREADICTIONARY CONFIGURATION ERROR
// *********\n";
// error += o.str().c_str();
// theLogger.error(error);
// _mapErrors.append(error);
// }
//
// // determine unused shapefiles
// theLogger.debug("Unused Shapefiles: " + unusedShapefiles(basename)
// );
//
// mapMod.unload();
// }
// catch (Error &e)
// {
// theLogger.error("Error in Maps.py, localMaps.py, MapFiles.py, "
// + "or localMapFiles.py file: ", e);
// e.clear();
// }
theLogger.info("MapManager ready.");
long t1 = System.currentTimeMillis();
theLogger.info("MapCreation time: " + (t1 - t0) + " ms");
}
/**
* @param maps
*/
@SuppressWarnings("unused")
private void addValidMaps(ShapeFile[] maps) {
// PathMgr pm(_config.dbBaseDirectory(), "MAPS");
// String directory(pm.writePath(AccessLevel::baseName(), ""));
for (int i = 0; i < maps.length; i++) {
try {
// if cache file has no records, then don't add to list
// String cacheName = directory + maps[i].getName();
// ShapeFile shapeFile = new ShapeFile(cacheName);
ShapeFile shapeFile = maps[i];
shapeFile.open();
int nrecs = shapeFile.getFeatureCount();
theLogger.debug("RECORDS for: " + maps[i].getDisplayName()
+ " " + nrecs);
shapeFile.close();
if (nrecs > 0) {
_ids.add(new MapID(maps[i].getDisplayName(), maps[i]
.getShapeType(), maps[i].getFile()
.getAbsolutePath()));
} else {
theLogger.debug("Map [" + maps[i].getDisplayName()
+ "] contains no records.");
}
} catch (Exception e) {
String error = "********* MAP BACKGROUND GENERATION ERROR - Cached Shapefile *********\n"
+ "Error in generating map #"
+ i
+ " Name: "
+ maps[i].getDisplayName()
+ " Basename: "
+ maps[i].getFile();
theLogger.error(error, e);
_mapErrors.add(error);
}
}
}
/**
* Searches the parent directory of a provided list of shape files to
* determine whether or not they contain a file that is newer than any files
@ -327,34 +257,47 @@ public class MapManager {
* @return True, if any file in the parent folder of any of the shape files
* is newer than anything in the specified directory. Else, false.
*/
@SuppressWarnings("unused")
private boolean cacheNeeded(ShapeFile[] maps, final String directory) {
private boolean updateNeeded(List<DbShapeSource> maps,
final String directory) {
// calc newest file inside maps.directory()
long newestShapeFile = Long.MIN_VALUE;
for (ShapeFile map : maps) {
File shapePath = map.getFile().getParentFile().getAbsoluteFile();
File[] shapeFiles = shapePath.listFiles(new FileFilter() {
@Override
public boolean accept(File file) {
return file.isFile();
}
});
if (shapeFiles != null) {
for (File file : shapeFiles) {
newestShapeFile = Math.max(newestShapeFile,
file.lastModified());
}
}
long newestSource = Long.MIN_VALUE;
for (DbShapeSource map : maps) {
newestSource = Math.max(newestSource, map.getLastUpdated()
.getTime());
}
// also check for siteConfig or localConfig changes
String configDir = FileUtil.join(edexStaticSiteDir, "config", "gfe");
File file = new File(configDir, "siteConfig.py");
newestShapeFile = Math.max(newestShapeFile, file.lastModified());
file = new File(configDir, "localConfig.py");
// Determine time of last modification of Maps.py, serverConfig,
// localConfig, localMaps, and siteConfig.
String baseConfigDir = FileUtil
.join(edexStaticBaseDir, "config", "gfe");
String siteConfigDir = FileUtil
.join(edexStaticSiteDir, "config", "gfe");
File file = new File(baseConfigDir, "Maps.py");
newestSource = Math.max(newestSource, file.lastModified());
file = new File(baseConfigDir, "serverConfig.py");
newestSource = Math.max(newestSource, file.lastModified());
file = new File(siteConfigDir, "siteConfig.py");
newestSource = Math.max(newestSource, file.lastModified());
file = new File(siteConfigDir, "localConfig.py");
if (file.exists()) {
newestShapeFile = Math.max(newestShapeFile, file.lastModified());
newestSource = Math.max(newestSource, file.lastModified());
}
// special case check for localMaps going away
// if the tag file exists, then localMaps was previously used
file = new File(siteConfigDir, "localMaps.py");
File localMapsTag = new File(FileUtil.join(this.edexStaticConfigDir,
"config", "gfe", "usingLocalMaps"));
if (file.exists()) {
newestSource = Math.max(newestSource, file.lastModified());
localMapsTag.mkdirs();
} else if (localMapsTag.exists()) {
localMapsTag.delete();
newestSource = System.currentTimeMillis();
}
// calc oldest file in directory
@ -382,27 +325,22 @@ public class MapManager {
oldestEditArea = editAreaFiles[0].lastModified();
}
// FIXME use last execution time instead
// ClusterTask task = ClusterLockUtils.lookupLock(
// MapManager.EDIT_AREA_GEN_TASK, cwa);
// oldestEditArea = task.getLastExecution();
}
return (newestShapeFile > oldestEditArea);
return (newestSource > oldestEditArea);
}
private void genEditArea(ShapeFile[] maps) {
private void genEditArea(List<DbShapeSource> maps) {
long t0 = System.currentTimeMillis();
theLogger.info("Edit Area generation phase");
statusHandler.info("Edit Area generation phase");
@SuppressWarnings("unused")
WsId fakeBase = null;
try {
fakeBase = new WsId(InetAddress.getLocalHost(), "BASE", "ifpServer");
} catch (UnknownHostException e1) {
theLogger.error("Unable to get IP address for localhost");
statusHandler.error("Unable to get IP address for localhost");
}
// _refMgr->deleteAllReferenceData(fakeBase);
@ -432,9 +370,19 @@ public class MapManager {
}
}
for (int i = 0; i < maps.length; i++) {
ShapeFile m = maps[i];
int i = 0;
BoundingBox bounds = null;
try {
bounds = MapUtil.getBoundingEnvelope(this._config.dbDomain());
} catch (Exception e1) {
statusHandler
.handle(Priority.PROBLEM, e1.getLocalizedMessage(), e1);
}
for (DbShapeSource m : maps) {
m.setBoundingBox(bounds);
try {
m.open();
if (m.getShapeType() != ShapeType.POLYGON) {
continue;
}
@ -447,15 +395,23 @@ public class MapManager {
+ " Name: "
+ m.getDisplayName()
+ " Basename: "
+ m.getFile();
theLogger.error(error, e);
+ m.getTableName();
statusHandler.error(error, e);
_mapErrors.add(error);
} finally {
try {
m.close();
} catch (IOException e) {
statusHandler.handle(Priority.PROBLEM,
e.getLocalizedMessage(), e);
}
}
i++;
}
writeISCMarker();
long t1 = System.currentTimeMillis();
theLogger.info("EditArea generation time: " + (t1 - t0) + " ms");
statusHandler.info("EditArea generation time: " + (t1 - t0) + " ms");
}
/**
@ -505,12 +461,13 @@ public class MapManager {
SerializationUtil.jaxbMarshalToXmlFile(sd,
path.getAbsolutePath());
} catch (Exception e) {
theLogger.error("Error writing ISC Markers to file "
+ path.getAbsolutePath(), e);
statusHandler.error(
"Error writing ISC Markers to file "
+ path.getAbsolutePath(), e);
}
}
} else {
theLogger.error("Unable to write to " + sampleDir);
statusHandler.error("Unable to write to " + sampleDir);
}
}
}
@ -523,15 +480,14 @@ public class MapManager {
* @param m
* @param string
*/
private void makeReferenceData(ShapeFile mapDef) {
private void makeReferenceData(DbShapeSource mapDef) {
// we skip over entries that don't have an editAreaName
// this will throw an exception, if editAreaName not defined.
Object ean = mapDef.getEditAreaName();
if (ean == null) {
if (!mapDef.hasEditAreaName()) {
return;
}
theLogger.debug("creating: " + mapDef.getDisplayName());
statusHandler.debug("creating: " + mapDef.getDisplayName());
List<ReferenceData> data = createReferenceData(mapDef);
if (data.size() == 0) {
return;
@ -559,7 +515,7 @@ public class MapManager {
if (n.length() == 7 && n.startsWith("ISC_")) {
String cwa = n.substring(4, 7);
if (cwa.equals(thisSite)) {
theLogger
statusHandler
.debug("creating: ISC_Tool_Area and ISC_Send_Area"
+ " from "
+ data.get(i).getId().getName());
@ -589,7 +545,7 @@ public class MapManager {
if (knownSites.contains(cwa)) {
if (!anySites) {
anySites = true;
theLogger.debug("creating: ISC_Marker_Set");
statusHandler.debug("creating: ISC_Marker_Set");
}
createISCMarker(cwa, data.get(i));
}
@ -625,9 +581,8 @@ public class MapManager {
other = (ReferenceData) SerializationUtil
.jaxbUnmarshalFromXmlFile(path);
} catch (Exception e) {
theLogger.error(
"Error reading edit area file "
+ path.getAbsolutePath(), e);
statusHandler.error("Error reading edit area file "
+ path.getAbsolutePath(), e);
}
Geometry refG = ref.getPolygons(CoordinateType.LATLON);
@ -635,7 +590,7 @@ public class MapManager {
refG.normalize();
othG.normalize();
if (!refG.equalsExact(othG, EA_EQ_TOLERANCE)) {
theLogger.warn("Ignoring " + ref.getId().getName()
statusHandler.warn("Ignoring " + ref.getId().getName()
+ " due to previous definition.");
}
} else {
@ -644,13 +599,13 @@ public class MapManager {
SerializationUtil.jaxbMarshalToXmlFile(ref,
path.getAbsolutePath());
} catch (Exception e) {
theLogger.error("Error writing edit area to file "
statusHandler.error("Error writing edit area to file "
+ path.getAbsolutePath(), e);
}
}
}
} else {
theLogger.error("Unable to write to " + areaDir);
statusHandler.error("Unable to write to " + areaDir);
}
}
@ -701,7 +656,8 @@ public class MapManager {
iscMarkers.add(centerLatLon);
iscMarkersID.add(wfo);
} catch (Exception e) {
theLogger.error("Error generating ISC markers for wfo:" + wfo, e);
statusHandler.error("Error generating ISC markers for wfo:" + wfo,
e);
}
}
@ -744,7 +700,8 @@ public class MapManager {
out.write('\n');
}
} catch (IOException e) {
theLogger.error("Error saving edit area group: " + groupName);
statusHandler.error("Error saving edit area group: "
+ groupName);
} finally {
if (out != null) {
try {
@ -755,7 +712,7 @@ public class MapManager {
}
}
} else {
theLogger.error("Unable to write to " + groupDir);
statusHandler.error("Unable to write to " + groupDir);
}
}
@ -777,9 +734,8 @@ public class MapManager {
list.add(area);
}
} catch (Exception e) {
theLogger.error(
"Error reading group file: "
+ groupFile.getAbsolutePath(), e);
statusHandler.error("Error reading group file: "
+ groupFile.getAbsolutePath(), e);
} finally {
if (in != null) {
try {
@ -836,66 +792,26 @@ public class MapManager {
return swath;
}
private String defaultEditAreaNaming(Map<String, String> info,
Object eanDefinition) {
// simple case, the edit area name definition is the attribute key
if (eanDefinition instanceof String) {
String ean = (String) eanDefinition;
if (info.containsKey(ean)) {
return info.get(ean);
} else {
return ean;
}
} else if (eanDefinition instanceof String[]) {
String s = "";
for (String e : (String[]) eanDefinition) {
// valid attribute
if (info.containsKey(e)) {
if (s.length() == 0) {
s = info.get(e);
} else {
s = s + "_" + info.get(e);
}
// not valid attribute, so use definition directly
} else {
if (s.length() == 0) {
s = e;
} else {
s = s + "_" + e;
}
}
}
return s;
} else {
return "";
}
}
/**
* Returns a sequence of ReferenceData objects for the supplied shapefile
* basename. Determines the naming of the edit areas by using the supplied
* Returns a sequence of ReferenceData objects for the supplied shape
* source. Determines the naming of the edit areas by using the supplied
* mapconfig object's attributes.
*
* @param name
* @param mapDef
* @return
*/
private List<ReferenceData> createReferenceData(ShapeFile mapDef) {
private List<ReferenceData> createReferenceData(DbShapeSource mapDef) {
// ServerResponse sr;
List<ReferenceData> data = new ArrayList<ReferenceData>();
// Module dean("DefaultEditAreaNaming");
ArrayList<String> created = new ArrayList<String>();
GeometryFactory gf = new GeometryFactory();
DbShapeSource shapeSource = mapDef;
try {
// PathMgr pm(_config.dbBaseDirectory(), "MAPS");
// String directory = pm.writePath(AccessLevel.baseName(), "");
ShapeFile shapeFile = mapDef;
IMapBackgroundFilter filter = shapeFile.getMapBackgroundFilter();
GridLocation gloc = _config.dbDomain();
MathTransform transform = MapUtil.getTransformFromLatLon(
@ -910,27 +826,17 @@ public class MapManager {
PreparedGeometry boundingGeometry = PreparedGeometryFactory
.prepare(p);
shapeFile.open();
Map<String, ReferenceData> tempData = new HashMap<String, ReferenceData>();
while (shapeFile.hasNext()) {
SimpleFeature f = shapeFile.next();
Map<String, String> info = shapeFile.getAttributes(f);
while (shapeSource.hasNext()) {
SimpleFeature f = shapeSource.next();
Map<String, Object> info = shapeSource.getAttributes(f);
if (filter != null && !filter.filter(info)) {
if (mapDef.isFiltered()
&& !runFilter(mapDef.getInstanceName(), info)) {
continue;
}
String editAreaName;
// functions return a string
if (mapDef.getEditAreaName() instanceof IEditAreaNamer) {
editAreaName = ((IEditAreaNamer) mapDef.getEditAreaName())
.getEditAreaName(info);
// non-functions allow only a string
} else {
editAreaName = defaultEditAreaNaming(info,
mapDef.getEditAreaName());
}
String editAreaName = runNamer(mapDef.getInstanceName(), info);
ReferenceData tmp;
// validate edit area name, add edit area to the dictionary
@ -940,6 +846,10 @@ public class MapManager {
}
Geometry mp = (Geometry) f.getDefaultGeometry();
if (mp == null) {
continue;
}
Geometry mpGrid = JTS.transform(mp, transform);
if (!boundingGeometry.intersects(mpGrid)) {
continue;
@ -963,12 +873,12 @@ public class MapManager {
polygons = gf
.createMultiPolygon(new Polygon[] { (Polygon) mp });
} else {
theLogger.info("Creating empty polygon");
statusHandler.info("Creating empty polygon");
polygons = gf.createMultiPolygon(new Polygon[] {});
}
if (!polygons.isValid()) {
String error = shapeFile.getFile()
String error = shapeSource.getTableName()
+ " contains invalid polygons.";
for (int i = 0; i < polygons.getNumGeometries(); i++) {
Geometry g = polygons.getGeometryN(i);
@ -976,15 +886,13 @@ public class MapManager {
error += "\n" + g;
}
}
theLogger.error(error);
statusHandler.error(error);
}
tempData.put(ean, new ReferenceData(_config.dbDomain(),
new ReferenceID(ean), polygons, CoordinateType.LATLON));
}
shapeFile.close();
// transfer dictionary values to Seq values
data.addAll(tempData.values());
tempData.clear();
@ -992,15 +900,47 @@ public class MapManager {
String error = "********* EDIT AREA GENERATION ERROR - Create Reference Data *********\n"
+ "Error in generating edit areas from maps for map "
+ mapDef.getDisplayName();
theLogger.error(error, e);
statusHandler.error(error, e);
_mapErrors.add(error);
}
theLogger.debug("EAs: " + created);
statusHandler.debug("EAs: " + created);
editAreaMap.put(mapDef.getDisplayName(), created);
return data;
}
private String runNamer(String instance, Map<String, Object> info) {
String editAreaName = "";
Map<String, Object> args = new HashMap<String, Object>();
args.put("instance", instance);
args.put("info", info);
try {
editAreaName = (String) pyScript.execute("runNamer", args);
} catch (Throwable e) {
statusHandler.handle(Priority.PROBLEM,
"Exception getting editAreaName for " + instance, e);
}
return editAreaName;
}
private boolean runFilter(String instance, Map<String, Object> info) {
boolean result = false;
Map<String, Object> args = new HashMap<String, Object>();
args.put("instance", instance);
args.put("info", info);
try {
result = (Boolean) pyScript.execute("runFilter", args);
} catch (Throwable e) {
statusHandler.handle(Priority.PROBLEM, "Exception filtering "
+ instance, e);
}
return result;
}
/**
* Validate edit area name. Changes the name as needed to ensure a valid
* python name.

View file

@ -1,520 +0,0 @@
/**
* 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.edex.plugin.gfe.reference;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.geotools.factory.CommonFactoryFinder;
import org.geotools.factory.GeoTools;
import org.opengis.filter.Filter;
import org.opengis.filter.FilterFactory2;
import com.raytheon.edex.plugin.gfe.reference.ShapeFile.IEditAreaNamer;
import com.raytheon.edex.plugin.gfe.reference.ShapeFile.IMapBackgroundFilter;
import com.raytheon.uf.common.localization.IPathManager;
import com.raytheon.uf.common.localization.LocalizationContext;
import com.raytheon.uf.common.localization.PathManagerFactory;
import com.raytheon.uf.common.util.FileUtil;
import com.raytheon.uf.edex.database.cluster.ClusterLockUtils;
import com.raytheon.uf.edex.database.cluster.ClusterTask;
/**
* Defines what edit areas are to be generated based on shapefiles
*
* <pre>
* SOFTWARE HISTORY
* Date Ticket// Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 10, 2008 randerso Initial creation
* Jun 25, 2008 #1210 randerso Modified to get directories from UtilityContext
* Jul 10, 2009 #2590 njensen Added support for multiple sites
*
* </pre>
*
* @author randerso
* @version 1.0
*/
public class Maps {
public static enum GetMode {
FILES_CHANGED, UNCONDITIONAL
}
private static final List<String> ALU_OFFSHORE_ZONES = Arrays
.asList(new String[] { "PKZ410" });
private static final List<String> AER_OFFSHORE_ZONES = Arrays
.asList(new String[] { "PKZ350" });
private static final List<String> ALU_MARINE_ZONES = Arrays
.asList(new String[] { "PKZ150", "PKZ155", "PKZ160", "PKZ165",
"PKZ170", "PKZ171", "PKZ172", "PKZ175", "PKZ176", "PKZ179",
"PKZ180", "PKZ185" });
private static final List<String> AER_MARINE_ZONES = Arrays
.asList(new String[] { "PKZ120", "PKZ121", "PKZ125", "PKZ126",
"PKZ127", "PKZ128", "PKZ129", "PKZ130", "PKZ132", "PKZ136",
"PKZ137", "PKZ138", "PKZ140", "PKZ141" });
private static final List<String> ALU_ZONES = Arrays.asList(new String[] {
"AKZ151", "AKZ155", "AKZ161", "AKZ181", "AKZ185", "AKZ187",
"AKZ191", "AKZ195" });
private static final List<String> AER_ZONES = Arrays.asList(new String[] {
"AKZ101", "AKZ111", "AKZ121", "AKZ125", "AKZ131", "AKZ135",
"AKZ141", "AKZ145", "AKZ171" });
private static final Log theLogger = LogFactory.getLog(Maps.class);
// -------------------------------------------------------------
// Functions for determining name of edit areas
// -------------------------------------------------------------
// FIPS codes
private static class fips implements IEditAreaNamer {
@Override
public String getEditAreaName(Map<String, String> atts) {
// make sure FIPS attribute exists and of proper length
// make sure STATE attribute exists and of proper length
String fips = atts.get("FIPS");
String state = atts.get("STATE");
if (fips != null && fips.length() == 5 && state != null
&& state.length() == 2) {
// last 3 digits from FIPS code
;
String s = state + "C" + fips.substring(fips.length() - 3); // assemble
// COC013
return s;
} else {
return ""; // for no FIPS in shapefile
}
}
}
// Public Zones
private static class cwazones implements IEditAreaNamer {
@Override
public String getEditAreaName(Map<String, String> atts) {
String zone = atts.get("ZONE");
String state = atts.get("STATE");
if (zone != null && zone.length() == 3 && state != null
&& state.length() == 2) {
return state + "Z" + zone; // assemble COZ023
} else {
return ""; // bad attributes
}
}
}
// Fire Wx Zones
private static class fwxzones implements IEditAreaNamer {
@Override
public String getEditAreaName(Map<String, String> atts) {
String zone = atts.get("ZONE");
String state = atts.get("STATE");
if (zone != null && zone.length() == 3 && state != null
&& state.length() == 2) {
return state + "Z" + zone; // assemble COZ023
} else {
return "";
}
}
}
// Marine Zones
private static class marineZ implements IEditAreaNamer {
@Override
public String getEditAreaName(Map<String, String> atts) {
String id = atts.get("ID");
if (id != null && id.length() == 6) {
return id;
} else {
return "";
}
}
}
// Offshore Marine Zones
private static class offshoreZ implements IEditAreaNamer {
@Override
public String getEditAreaName(Map<String, String> atts) {
String id = atts.get("ID");
if (id != null && id.length() == 6) {
return id;
} else {
return "";
}
}
}
// ---------------------------------------------------------------------
// Map Background Filters
// ---------------------------------------------------------------------
// filter for public zones.
private static class publicZoneFilter implements IMapBackgroundFilter {
private cwazones cwazones = new cwazones();
private String cwaStr;
protected publicZoneFilter(String cwa) {
cwaStr = cwa;
}
@Override
public boolean filter(Map<String, String> atts) {
// this CWA (all but AFC site)
if (cwaStr.equals(atts.get("CWA"))) {
return true;
// AFC data - separate out AER/ALU data
} else if ("AFC".equals(atts.get("CWA"))) {
String id = cwazones.getEditAreaName(atts);
if ("AER".equals(cwaStr)) {
return AER_ZONES.contains(id);
} else if ("ALU".equals(cwaStr)) {
return ALU_ZONES.contains(id);
} else if ("AICE".equals(cwaStr)) {
return true;
}
}
return false;
}
}
// filter for fire weather zones.
private static class firewxZoneFilter implements IMapBackgroundFilter {
private fwxzones fwxzones = new fwxzones();
private String cwaStr;
protected firewxZoneFilter(String cwa) {
cwaStr = cwa;
}
@Override
public boolean filter(Map<String, String> atts) {
// this CWA (all but AFC site)
if (cwaStr.equals(atts.get("CWA"))) {
return true;
// AFC data - separate out AER/ALU data
} else if ("AFC".equals(atts.get("CWA"))) {
String id = fwxzones.getEditAreaName(atts);
if ("AER".equals(cwaStr)) {
return AER_ZONES.contains(id);
} else if ("ALU".equals(cwaStr)) {
return ALU_ZONES.contains(id);
} else if ("AICE".equals(cwaStr)) {
return true;
}
}
return false;
}
}
// filter for marine zones.
private static class marineZoneFilter implements IMapBackgroundFilter {
private marineZ marineZ = new marineZ();
private String cwaStr;
protected marineZoneFilter(String cwa) {
cwaStr = cwa;
}
@Override
public boolean filter(Map<String, String> atts) {
// this CWA (all but AFC site)
if (cwaStr.equals(atts.get("WFO"))) {
return true;
// AFC data - separate out AER/ALU data
} else if ("AFC".equals(atts.get("WFO"))) {
String id = marineZ.getEditAreaName(atts);
if ("AER".equals(cwaStr)) {
return AER_MARINE_ZONES.contains(id);
} else if ("ALU".equals(cwaStr)) {
return ALU_MARINE_ZONES.contains(id);
} else if ("AICE".equals(cwaStr)) {
return true;
}
}
return false;
}
}
// filter for offshore marine zones.
private static class offshoreZoneFilter implements IMapBackgroundFilter {
private offshoreZ offshoreZ = new offshoreZ();
private String cwaStr;
protected offshoreZoneFilter(String cwa) {
cwaStr = cwa;
}
@Override
public boolean filter(Map<String, String> atts) {
// this CWA (all but AFC site)
if (cwaStr.equals(atts.get("WFO"))) {
return true;
// AFC data - separate out AER/ALU data
} else if ("AFC".equals(atts.get("WFO"))) {
String id = offshoreZ.getEditAreaName(atts);
if ("AER".equals(cwaStr)) {
return AER_OFFSHORE_ZONES.contains(id);
} else if ("ALU".equals(cwaStr)) {
return ALU_OFFSHORE_ZONES.contains(id);
} else if ("AICE".equals(cwaStr)) {
return true;
}
}
return false;
}
}
// ---------------------------------------------------------------------
// Map Background Definitions
// ---------------------------------------------------------------------
public static ShapeFile[] getMaps(String cwaStr, GetMode mode) {
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(GeoTools
.getDefaultHints());
String shapeFileDir = "";
IPathManager pathMgr = PathManagerFactory.getPathManager();
LocalizationContext edexStaticBase = pathMgr.getContext(
LocalizationContext.LocalizationType.EDEX_STATIC,
LocalizationContext.LocalizationLevel.BASE);
try {
shapeFileDir = pathMgr.getFile(edexStaticBase, "shapefiles")
.getCanonicalPath() + File.separator;
} catch (IOException e) {
theLogger.error(e);
}
ShapeFile[] maps = null;
if (GetMode.UNCONDITIONAL == mode
|| filesHaveChanges(cwaStr, shapeFileDir)) {
// CWA Counties
String p1 = cwaStr + "*";
String p2 = "???" + p1;
Filter countyFilter = ff.or(ff.like(ff.property("CWA"), p1),
ff.like(ff.property("CWA"), p2));
ShapeFile CWAcounties = new ShapeFile(shapeFileDir + "County");
CWAcounties.setAttributeFilter(countyFilter);
CWAcounties.setDisplayName("Counties_" + cwaStr);
CWAcounties.setEditAreaName(new String[] { "STATE", "COUNTYNAME" });
CWAcounties.setGroupName("Counties");
// FIPS for my counties - only include first WFO indicated in CWA
// field
Filter fipsFilter = ff.like(ff.property("CWA"), p1);
ShapeFile FIPS = new ShapeFile(shapeFileDir + "County");
FIPS.setDisplayName("FIPS_" + cwaStr);
FIPS.setAttributeFilter(fipsFilter);
FIPS.setEditAreaName(new fips());
FIPS.setGroupName("FIPS_" + cwaStr);
// Unfiltered Counties
ShapeFile Counties = new ShapeFile(shapeFileDir + "County");
Counties.setDisplayName("Counties");
Counties.setEditAreaName(new fips());
Counties.setGroupName("FIPS");
// CWA Zones
ShapeFile CWAzones = new ShapeFile(shapeFileDir + "Zone");
CWAzones.setMapBackgroundFilter(new publicZoneFilter(cwaStr));
CWAzones.setDisplayName("Zones_" + cwaStr);
CWAzones.setEditAreaName(new cwazones());
CWAzones.setGroupName("Zones_" + cwaStr);
// Unfiltered Zones
ShapeFile Zones = new ShapeFile(shapeFileDir + "Zone");
Zones.setDisplayName("Zones");
Zones.setEditAreaName(new cwazones());
Zones.setGroupName("Zones");
// Fire Wx Zones
ShapeFile FWCWAzones = new ShapeFile(shapeFileDir + "FireWxZones");
FWCWAzones.setMapBackgroundFilter(new firewxZoneFilter(cwaStr));
FWCWAzones.setDisplayName("FireWxZones_" + cwaStr);
FWCWAzones.setEditAreaName(new fwxzones());
FWCWAzones.setGroupName("FireWxZones_" + cwaStr);
// Unfiltered Fire Wx Zones
ShapeFile FWZones = new ShapeFile(shapeFileDir + "FireWxZones");
FWZones.setDisplayName("FireWxZones");
FWZones.setEditAreaName(new fwxzones());
FWZones.setGroupName("FireWxZones");
// CWA for just this CWA
Filter cwaFilter = ff
.equals(ff.property("CWA"), ff.literal(cwaStr));
ShapeFile cwa = new ShapeFile(shapeFileDir + "CWA");
cwa.setAttributeFilter(cwaFilter);
cwa.setDisplayName("CWA");
// CWAs for all
ShapeFile cwas = new ShapeFile(shapeFileDir + "CWA");
cwas.setDisplayName("CWA_all");
cwas.setEditAreaName("WFO");
cwas.setGroupName("WFOs");
// ISC areas for all
ShapeFile isc = new ShapeFile(shapeFileDir + "ISC");
isc.setDisplayName("ISC_all");
isc.setEditAreaName(new String[] { "ISC", "WFO" });
isc.setGroupName("ISC");
// Fire Wx AOR for all
ShapeFile fwaor = new ShapeFile(shapeFileDir + "FireWxAOR");
fwaor.setDisplayName("FireWxAOR");
fwaor.setEditAreaName(new String[] { "FireWxAOR", "CWA" });
fwaor.setGroupName("FireWxAOR");
// Marine Zones for CWA
ShapeFile CWAmzones = new ShapeFile(shapeFileDir + "MarineZones");
CWAmzones.setMapBackgroundFilter(new marineZoneFilter(cwaStr));
CWAmzones.setDisplayName("Marine_Zones_" + cwaStr);
CWAmzones.setEditAreaName(new marineZ());
CWAmzones.setGroupName("MZones_" + cwaStr);
// Marine Zones (unfiltered)
ShapeFile Mzones = new ShapeFile(shapeFileDir + "MarineZones");
Mzones.setDisplayName("Marine_Zones");
Mzones.setEditAreaName(new marineZ());
Mzones.setGroupName("MZones");
// States (unfiltered)
ShapeFile States = new ShapeFile(shapeFileDir + "States");
States.setDisplayName("States");
States.setEditAreaName("NAME");
States.setGroupName("States");
// River Basins - unfiltered
ShapeFile Basins = new ShapeFile(shapeFileDir + "Basins");
Basins.setDisplayName("Basins");
// RFC maps
ShapeFile rfc = new ShapeFile(shapeFileDir + "RFC");
rfc.setDisplayName("RFC");
rfc.setEditAreaName(new String[] { "ISC", "SITE_ID" });
rfc.setGroupName("ISC");
// Lakes - unfiltered
ShapeFile lakes = new ShapeFile(shapeFileDir + "Lake");
lakes.setDisplayName("Lakes");
// Offshore Marine Zones - unfiltered
ShapeFile offshore = new ShapeFile(shapeFileDir + "Offshore");
offshore.setDisplayName("Offshore_Marine_Zones");
offshore.setEditAreaName(new offshoreZ());
offshore.setGroupName("OffShoreMZones");
// Offshore Marine Zones - filtered by CWA
ShapeFile offshoreCWA = new ShapeFile(shapeFileDir + "Offshore");
offshoreCWA.setMapBackgroundFilter(new offshoreZoneFilter(cwaStr));
offshoreCWA.setDisplayName("Offshore_Marine_Zones_" + cwaStr);
offshoreCWA.setEditAreaName(new offshoreZ());
offshoreCWA.setGroupName("OffShoreMZones_" + cwaStr);
// High Sea Marine Zones - unfiltered
ShapeFile hsmz = new ShapeFile(shapeFileDir + "HighSea");
hsmz.setDisplayName("High_Sea_Marine_Zones");
// High Sea Marine Zones - filtered by CWA
Filter wfoFilter = ff
.equals(ff.property("WFO"), ff.literal(cwaStr));
ShapeFile CWAhsmz = new ShapeFile(shapeFileDir + "HighSea");
CWAhsmz.setAttributeFilter(wfoFilter);
CWAhsmz.setDisplayName("High_Sea_Marine_Zones_" + cwaStr);
// Interstates
Filter interstateFilter = ff.equals(ff.property("ADMN_CLASS"),
ff.literal("Interstate"));
ShapeFile interstates = new ShapeFile(shapeFileDir + "Interstate");
interstates.setAttributeFilter(interstateFilter);
interstates.setDisplayName("Interstates");
// Low-resolution highways
ShapeFile highways = new ShapeFile(shapeFileDir + "Highway");
highways.setDisplayName("Interstates_and_US_Highways");
// Cities, filtered
Filter populationFilter = ff.greater(ff.property("POP_1990"),
ff.literal(50000f));
ShapeFile cities = new ShapeFile(shapeFileDir + "City");
cities.setAttributeFilter(populationFilter);
cities.setDisplayName("Cities");
ShapeFile canada = new ShapeFile(shapeFileDir + "Canada");
canada.setDisplayName("Canada");
Filter countryFilter = ff.equals(ff.property("GMI_CNTRY"),
ff.literal("USA"));
ShapeFile world = new ShapeFile(shapeFileDir + "World");
world.setDisplayName("Countries");
world.setAttributeFilter(countryFilter);
ShapeFile railroads = new ShapeFile(shapeFileDir + "Railroad");
railroads.setDisplayName("RailRoads");
ShapeFile airports = new ShapeFile(shapeFileDir + "FAA"
+ File.separator + "Airport");
airports.setDisplayName("Airports");
maps = new ShapeFile[] { CWAcounties, Counties, FIPS, CWAzones,
Zones, cwa, cwas, CWAmzones, Mzones, States, Basins, rfc,
lakes, hsmz, CWAhsmz, interstates, highways, cities,
FWZones, FWCWAzones, isc, canada, world, railroads,
offshore, offshoreCWA, fwaor, airports };
}
return maps;
}
private static boolean filesHaveChanges(String cwa, String shapeFileDir) {
boolean filesHaveChanges = false;
File dir = new File(shapeFileDir);
if (dir.exists() && dir.isDirectory()) {
ClusterTask task = ClusterLockUtils.lookupLock(
MapManager.EDIT_AREA_GEN_TASK, cwa);
filesHaveChanges = FileUtil.hasBeenModifiedSince(dir,
task.getLastExecution(), true);
}
return filesHaveChanges;
}
}

View file

@ -1,415 +0,0 @@
/**
* 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.edex.plugin.gfe.reference;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import org.geotools.data.DefaultQuery;
import org.geotools.data.DefaultTransaction;
import org.geotools.data.FeatureSource;
import org.geotools.data.shapefile.indexed.IndexType;
import org.geotools.data.shapefile.indexed.IndexedShapefileDataStore;
import org.geotools.factory.CommonFactoryFinder;
import org.geotools.factory.GeoTools;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.FeatureIterator;
import org.opengis.feature.IllegalAttributeException;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.feature.type.AttributeDescriptor;
import org.opengis.filter.Filter;
import org.opengis.filter.FilterFactory2;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.LineString;
import com.vividsolutions.jts.geom.MultiLineString;
import com.vividsolutions.jts.geom.MultiPoint;
import com.vividsolutions.jts.geom.MultiPolygon;
import com.vividsolutions.jts.geom.Point;
import com.vividsolutions.jts.geom.Polygon;
/**
* Class to allow reading (and optionally filtering) of an ESRI shape file
*
* <pre>
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 11, 2008 #1075 randerso Initial creation
*
* </pre>
*
* @author randerso
* @version 1.0
*/
public class ShapeFile {
// move to MapDef
public interface IMapBackgroundFilter {
public boolean filter(Map<String, String> atts);
}
// move to EditAreaDef
public interface IEditAreaNamer {
public String getEditAreaName(Map<String, String> atts);
}
private IMapBackgroundFilter filter; // move to MapDef
private String displayName; // move to MapDef
private Object editAreaName; // move to EditAreaDef
private String groupName; // move to EditAreaDef
public static enum ShapeType {
NONE, POINT, POLYLINE, POLYGON
};
private File location;
private Filter attributeFilter;
private IndexedShapefileDataStore dataStore;
private String[] shapefileAttributes;
private FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection;
private FeatureIterator<SimpleFeature> featureIterator;
private DefaultTransaction trx;
private String shapeField;
private ShapeType type;
private Geometry boundingGeom;
private DefaultQuery query;
/**
* Create a shape file
*
* @param location
* the pathname of a file or directory containing the shape file.
* If a directory is supplied, it is assumed it contains a single
* shape file and the first *.shp file located will be used.
*/
public ShapeFile(String path) {
this(new File(path));
}
/**
* Create a shape file
*
* @param location
* the file or directory containing the shape file. If a
* directory is supplied, it is assumed it contains a single
* shape file and the first *.shp file located will be used.
*/
public ShapeFile(File location) {
this.location = location;
}
/**
* @throws IOException
*
*/
public void open() throws IOException {
File file = getFile();
dataStore = new IndexedShapefileDataStore(file.toURI().toURL(), null,
true, true, IndexType.QIX);
shapeField = dataStore.getSchema().getGeometryDescriptor()
.getLocalName();
featureCollection = null;
featureIterator = null;
String[] types = dataStore.getTypeNames();
query = new DefaultQuery();
query.setTypeName(types[0]);
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(GeoTools
.getDefaultHints());
Filter filter = null;
if (boundingGeom != null) {
filter = ff.intersects(ff.property(shapeField), ff
.literal(boundingGeom));
}
if (attributeFilter != null) {
if (filter == null) {
filter = attributeFilter;
} else {
filter = ff.and(attributeFilter, filter);
}
}
if (filter != null) {
query.setFilter(filter);
}
FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = dataStore
.getFeatureSource();
featureCollection = featureSource.getFeatures(query);
featureIterator = featureCollection.features();
}
/**
* Returns the path of the .shp file
*
* @return
*/
public File getFile() {
File file = this.location;
if (file.exists() && file.isDirectory()) {
for (File path : file.listFiles()) {
if (path.getName().endsWith(".shp")) {
return path;
}
}
}
return file;
}
/**
* @throws IOException
*
*/
public void close() throws IOException {
if (trx != null) {
trx.close();
trx = null;
}
if (featureIterator != null) {
featureIterator.close();
featureIterator = null;
featureCollection = null;
}
if (dataStore != null) {
dataStore.dispose();
dataStore = null;
}
}
public boolean hasNext() throws IOException {
if (featureIterator == null) {
throw new IOException("ShapeFile is not open");
}
return featureIterator.hasNext();
}
public SimpleFeature next() throws NoSuchElementException, IOException,
IllegalAttributeException {
if (featureIterator == null) {
throw new IOException("ShapeFile is not open");
}
return featureIterator.next();
}
public synchronized ShapeType getShapeType() throws IOException {
if (this.type == null) {
boolean closeIt = false;
if (dataStore == null) {
open();
closeIt = true;
}
Class<?> geometryType = dataStore.getSchema()
.getGeometryDescriptor().getType().getBinding();
if (geometryType == Point.class || geometryType == MultiPoint.class) {
this.type = ShapeType.POINT;
} else if (geometryType == LineString.class
|| geometryType == MultiLineString.class) {
this.type = ShapeType.POLYLINE;
} else if (geometryType == Polygon.class
|| geometryType == MultiPolygon.class) {
this.type = ShapeType.POLYGON;
} else {
this.type = ShapeType.NONE;
}
if (closeIt) {
close();
}
}
return this.type;
}
public synchronized String[] getAttributeNames() throws IOException {
if (shapefileAttributes == null) {
List<AttributeDescriptor> at = dataStore.getSchema()
.getAttributeDescriptors();
if (at == null || at.size() == 0) {
return null;
}
shapefileAttributes = new String[at.size() - 1];
int j = 0;
for (int i = 0; i < at.size(); i++) {
if (!at.get(i).getLocalName().equals(shapeField)) {
shapefileAttributes[j] = at.get(i).getLocalName();
j++;
}
}
}
return shapefileAttributes;
}
/**
* @param i
* @return
* @throws IOException
*/
public Map<String, String> getAttributes(SimpleFeature f)
throws IOException {
Map<String, String> retVal = new HashMap<String, String>();
for (String at : getAttributeNames()) {
retVal.put(at, f.getAttribute(at).toString());
}
return retVal;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return this.getFile().getName();
}
/**
* @return the filter
*/
public IMapBackgroundFilter getMapBackgroundFilter() {
return filter;
}
/**
* @param filter
* the filter to set
*/
public void setMapBackgroundFilter(IMapBackgroundFilter filter) {
this.filter = filter;
}
public void setBoundingGeometry(Geometry geom) {
this.boundingGeom = geom;
}
/**
* @return the attributeFilter
*/
public Filter getAttributeFilter() {
return attributeFilter;
}
/**
* @param attributeFilter
* the attributeFilter to set
*/
public void setAttributeFilter(Filter attributeFilter) {
this.attributeFilter = attributeFilter;
}
/**
* @return
* @throws IOException
*/
public int getFeatureCount() throws IOException {
if (this.featureCollection == null) {
throw new IOException(
"Shapefile must be open when calling getFeatureCount");
}
return this.featureCollection.size();
}
public String getDisplayName() {
return displayName;
}
public void setDisplayName(String name) {
this.displayName = name;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public Object getEditAreaName() {
return editAreaName;
}
public void setEditAreaName(Object editAreaName) {
this.editAreaName = editAreaName;
}
public static void main(String[] args) {
ShapeFile shapeFile = new ShapeFile(new File(
"/home/randerso/shapefiles/States"));
try {
shapeFile.open();
System.out.println(shapeFile.getShapeType());
while (shapeFile.hasNext()) {
SimpleFeature feature = shapeFile.next();
for (Object attribute : feature.getAttributes()) {
if (!(attribute instanceof Geometry)) {
System.out.println(attribute);
}
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if (shapeFile != null) {
shapeFile.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}

View file

@ -73,7 +73,7 @@ public class AreaDictionaryMaker {
* A Map from edit area names to shape file attributes
*/
public void genAreaDictionary(String site,
Map<String, Map<String, String>> editAreaAttrs) {
Map<String, Map<String, Object>> editAreaAttrs) {
theLogger.info("Area Dictionary generation phase");
if (site == null) {

View file

@ -19,14 +19,9 @@
**/
package com.raytheon.edex.plugin.gfe.textproducts;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.raytheon.edex.plugin.gfe.reference.EditAreaLoader;
import com.raytheon.uf.common.dataplugin.gfe.request.ConfigureTextProductsRequest;
import com.raytheon.uf.common.serialization.comm.IRequestHandler;
@ -39,8 +34,10 @@ import com.raytheon.uf.common.serialization.comm.IRequestHandler;
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Mar 9, 2011 wldougher Initial creation
* May 4, 2011 wldougher Add script file creation
* Mar 9, 2011 wldougher Initial creation
* May 4, 2011 wldougher Add script file creation
* Sep 18, 2011 #1091 randerso Removed combo file and area dictionary creation
* since they were not in A1
*
* </pre>
*
@ -86,11 +83,6 @@ public class ConfigureTextProductsHandler implements
configurator.execute();
log.info(String.format("configureTextProducts ran for site %s", site));
Map<String, List<String>> editAreaMap = new HashMap<String, List<String>>();
Map<String, Map<String, String>> editAreaAttrs = new HashMap<String, Map<String, String>>();
new EditAreaLoader().load(site, editAreaMap, editAreaAttrs);
combinationsFileMaker.genCombinationsFiles(site, editAreaMap);
areaDictionaryMaker.genAreaDictionary(site, editAreaAttrs);
return null;
}
}

View file

@ -0,0 +1,66 @@
#!/usr/bin/env python
##
# 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.
##
import string
# DefaultEditAreaNaming
# this function defines the default edit area naming convention
# for use in Maps.py/LocalMaps.py and the MapManager
# could be a string, which is the edit area name (attribute)
# could be a list, which is the edit area name set of attributes
# "ZONE"
def defaultEditAreaNaming(info, eanDefinition):
# simple case, the edit area name definition is the attribute key
if type(eanDefinition) == str:
if info.has_key(eanDefinition):
return info[eanDefinition]
else:
return eanDefinition
elif type(eanDefinition) == list:
s = ''
for e in eanDefinition:
# valid attribute
if info.has_key(e):
if len(s) == 0:
s = info[e]
else:
s = s + "_" + info[e]
# not valid attribute, so use definition directly
else:
if len(s) == 0:
s = e
else:
s = s + "_" + e
return s
else:
return ''
def getEditAreaName(info, nameAttr):
if callable(nameAttr):
return nameAttr(info)
return defaultEditAreaNaming(info, nameAttr)

View file

@ -0,0 +1,77 @@
##
# 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.
##
import JUtil
import DefaultEditAreaNaming
from com.raytheon.edex.plugin.gfe.reference import DbShapeSource
#
# Python wrapper class for PostGIS table with interface like A1 ShapeFile.py
#
#
# SOFTWARE HISTORY
#
# Date Ticket# Engineer Description
# ------------ ---------- ----------- --------------------------
# 09/04/12 #9441 randerso Initial Creation.
#
#
#
class ShapeTable(JUtil.JavaWrapperClass):
def __init__(self, identifier):
self.identifier = identifier
self.name = None
self.editAreaName = None
self.groupName = None
self.javaObj = DbShapeSource(identifier)
pass
def filename(self, filen):
raise NotImplementedError, "This method is obsolete. See comments in Maps.py"
def filter(self, fn):
if callable(fn):
self._func = fn
self.javaObj.setFiltered(True)
else:
raise TypeError(self.__class__+".filter() requires a function")
def doFilter(self, atts):
return self._func(atts)
def getEAName(self, atts):
if self.editAreaName is not None:
return DefaultEditAreaNaming.getEditAreaName(atts, self.editAreaName)
return ""
def toJavaObj(self):
self.javaObj.setDisplayName(self.name)
self.javaObj.setGroupName(self.groupName)
if self.editAreaName is not None:
self.javaObj.setHasEditAreaName(True);
return self.javaObj
def __repr__(self):
if self.name is not None:
return self.name
else:
return self.identifier

View file

@ -38,7 +38,8 @@ import com.raytheon.uf.common.util.FileUtil;
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Oct 9, 2008 njensen Initial creation
* Oct 9, 2008 njensen Initial creation
* Sep 18, 2012 #1091 randerso added base directory to getGfeConfigIncludePath
* </pre>
*
* @author njensen
@ -391,8 +392,12 @@ public class GfePyIncludeUtil {
}
public static String getGfeConfigIncludePath(String siteId) {
return getPath(PATH_MANAGER.getContextForSite(
String baseConfigDir = getPath(PATH_MANAGER.getContext(
LocalizationType.EDEX_STATIC, LocalizationLevel.BASE),
GFE_CONFIG);
String siteConfigDir = getPath(PATH_MANAGER.getContextForSite(
LocalizationType.EDEX_STATIC, siteId), GFE_CONFIG);
return PyUtil.buildJepIncludePath(siteConfigDir, baseConfigDir);
}
public static String getVCModulesIncludePath() {

View file

@ -84,8 +84,6 @@ import com.vividsolutions.jts.geom.Polygon;
* as creating a grid coverage from an image, or from a data grid, and
* reprojecting a coverage into another projection/coordinate system.
*
* @author chammack
*
* <pre>
*
* SOFTWARE HISTORY
@ -95,8 +93,11 @@ import com.vividsolutions.jts.geom.Polygon;
* 05/16/2012 14993 D. Friedman Add oversampling option to
* reprojectGeometry.
* 06/19/2012 14988 D. Friedman Make oversampling more like AWIPS 1
* 09/18/2012 #1091 randerso corrected getBoundingEnvelope
*
* </pre>
*
* @author chammack
*/
@SuppressWarnings("unchecked")
public class MapUtil {
@ -354,14 +355,16 @@ public class MapUtil {
* @param addBorder
* expand envelope to include a 1 grid cell border after
* reprojection
* @param oversampleFactor oversample factor for new grid
* @param oversampleFactor
* oversample factor for new grid
* @return the reprojected grid geometry
* @throws FactoryException
* , TransformException
*/
public static GeneralGridGeometry reprojectGeometry(
GeneralGridGeometry sourceGeometry, Envelope targetEnvelope,
boolean addBorder, int oversampleFactor) throws FactoryException, TransformException {
boolean addBorder, int oversampleFactor) throws FactoryException,
TransformException {
CoordinateReferenceSystem targetCRS = targetEnvelope
.getCoordinateReferenceSystem();
ReferencedEnvelope targetREnv = null;
@ -387,7 +390,6 @@ public class MapUtil {
ReferencedEnvelope newEnv = new ReferencedEnvelope(JTS.getEnvelope2D(
newTargetREnv.intersection(newSourceEnv), LATLON_PROJECTION),
LATLON_PROJECTION);
ReferencedEnvelope newEnvInSourceProjection = newEnv.transform(sourceCRS, false, 500);
newEnv = newEnv.transform(targetCRS, false, 500);
// Calculate nx and ny, start with the number of original grid
// points in the intersection and then adjust to the new aspect
@ -401,10 +403,9 @@ public class MapUtil {
int ny = (int) (nx * aspectRatio);
if (oversampleFactor > 1) {
int inCount = sourceGeometry.getGridRange().getSpan(0) *
sourceGeometry.getGridRange().getSpan(1);
double outCount = inCount * newEnv.getArea() /
sourceEnv.getArea();
int inCount = sourceGeometry.getGridRange().getSpan(0)
* sourceGeometry.getGridRange().getSpan(1);
double outCount = inCount * newEnv.getArea() / sourceEnv.getArea();
outCount *= 4;
nx = (int) Math.sqrt(outCount / aspectRatio);
ny = (int) (nx * aspectRatio);
@ -950,6 +951,13 @@ public class MapUtil {
return latLon;
}
public static void gridCoordinateToNative(Coordinate[] coords,
PixelOrientation orientation, ISpatialObject spatialObject) {
transformCoordinates(getTransformToNative(orientation, spatialObject),
coords);
}
/**
* Returns the rotation from true north (in degrees) of the specified point
* (in latLon). A positive number indicates that north is to the right of
@ -1039,7 +1047,7 @@ public class MapUtil {
* @throws TransformException
* @throws FactoryException
*/
public static com.vividsolutions.jts.geom.Envelope getBoundingEnvelope(
public static ReferencedEnvelope getBoundingEnvelope(
ISpatialObject spatialObject) throws TransformException,
FactoryException {
@ -1048,12 +1056,12 @@ public class MapUtil {
Coordinate[] coords = new Coordinate[] { new Coordinate(0, ny - 1),
new Coordinate(nx, -1) };
gridCoordinateToLatLon(coords, PixelOrientation.LOWER_LEFT,
gridCoordinateToNative(coords, PixelOrientation.LOWER_LEFT,
spatialObject);
ReferencedEnvelope env = new ReferencedEnvelope(coords[0].x,
coords[1].x, coords[0].y, coords[1].y,
MapUtil.LATLON_PROJECTION);
coords[1].x, coords[0].y, coords[1].y, spatialObject.getCrs());
ReferencedEnvelope boundingEnv;
boundingEnv = env.transform(MapUtil.LATLON_PROJECTION, true);

View file

@ -30,7 +30,10 @@ import jep.JepException;
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Oct 5, 2011 njensen Initial creation
* Oct 5, 2011 njensen Initial creation
* Sep 19, 2012 #1091 randerso Changed to extend PythonScript to
* allow access to both eval and execute
* methods
*
* </pre>
*
@ -38,7 +41,7 @@ import jep.JepException;
* @version 1.0
*/
public class PythonEval extends PythonInterpreter {
public class PythonEval extends PythonScript {
public PythonEval(String anIncludePath, ClassLoader aClassLoader)
throws JepException {

View file

@ -99,6 +99,7 @@ public class PythonMapScript extends PythonScript {
* @throws JepException
* if Jep chokes on the scripted code.
*/
@Override
public Object execute(String methodName, String instanceName,
Map<String, Object> argmap) throws JepException {
@ -149,7 +150,7 @@ public class PythonMapScript extends PythonScript {
* @throws JepException
* if Jepp chokes on the expression.
*/
public boolean eval(String pythonExpr) throws JepException {
public boolean evaluate(String pythonExpr) throws JepException {
return jep.eval(pythonExpr);
}
}