use of gov.usgs.cida.coastalhazards.metadata.CRSParameters in project coastal-hazards by USGS-CIDA.
the class MetadataUtil method getCrsFromFgdcMetadata.
public static CoordinateReferenceSystem getCrsFromFgdcMetadata(String inMetadata) throws FactoryException, JAXBException, UnsupportedEncodingException {
// create the WKT to instantiate a CRS object from org.geotools.referencing
CRSParameters crsParms = new CRSParameters();
Metadata metadata = null;
try {
JAXBContext jaxbContext = JAXBContext.newInstance(Metadata.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
metadata = (Metadata) jaxbUnmarshaller.unmarshal(new ByteArrayInputStream(inMetadata.getBytes("UTF-8")));
} catch (JAXBException e) {
// schema used https: www.fgdc.gov/schemas/metadata/fgdc-std-001-1998-sect01.xsd
log.error("Unable to parse xml file. Has the schema changed? https:www.fgdc.gov/schemas/metadata/fgdc-std-001-1998-sect01.xsd :" + e.getMessage());
throw e;
}
Horizsys horizsys = metadata.getSpref().getHorizsys();
String ellips = horizsys.getGeodetic().getEllips();
String horizdn = horizsys.getGeodetic().getHorizdn();
double denflat = horizsys.getGeodetic().getDenflat();
double semiaxis = horizsys.getGeodetic().getSemiaxis();
String mapprojn = horizsys.getPlanar().getMapproj().getMapprojn();
double feast = horizsys.getPlanar().getMapproj().getMapprojp().getFeast();
double fnorth = horizsys.getPlanar().getMapproj().getMapprojp().getFnorth();
double latprjo = horizsys.getPlanar().getMapproj().getMapprojp().getLatprjo();
double longcm = horizsys.getPlanar().getMapproj().getMapprojp().getLongcm();
double stdparll = horizsys.getPlanar().getMapproj().getMapprojp().getStdparll();
// these defaults were derived from the first 3 raster files meta-data CR, AE, PAE
// Hoping that these can be optional or located in future metadata in which case
// an if check should be performed and the value replaced if it doesn't match the default
String defaultGcs = "GCS_North_American_1983";
String defaultPrimeM = "Greenwich\",0.0]";
String defaultUnit = "Degree\",0.0174532925199433]]";
String defaultProjection = "Albers";
String defaultLengthUnit = "Meter";
double defaultLengthValue = 1.0;
crsParms.setEllips(ellips);
crsParms.setHorizdn(horizdn);
crsParms.setDenflat(denflat);
crsParms.setSemiaxis(semiaxis);
crsParms.setMapprojn(mapprojn);
crsParms.setFeast(feast);
crsParms.setFnorth(fnorth);
crsParms.setLatprjo(latprjo);
crsParms.setLongcm(longcm);
crsParms.setStdparll(stdparll);
crsParms.setGcs(defaultGcs);
crsParms.setPrimeM(defaultPrimeM);
crsParms.setUnit(defaultUnit);
crsParms.setProjection(defaultProjection);
crsParms.setLengthUnit(defaultLengthUnit);
crsParms.setLengthValue(defaultLengthValue);
// same as FactoryFinder.getCRSFactory(null).createFromWKT(wkt);
return CRS.parseWKT(buildWkt(crsParms));
}
use of gov.usgs.cida.coastalhazards.metadata.CRSParameters in project coastal-hazards by USGS-CIDA.
the class MetadataUtilTest method testWktBuilder.
@Test
public void testWktBuilder() throws FactoryException {
String expString = getStringFromWKTBuilder();
CRSParameters parms = new CRSParameters();
parms.setDenflat(298.257222101);
parms.setEllips("GRS 1980");
parms.setFeast(0.0);
parms.setFnorth(0.0);
parms.setGcs("GCS_North_American_1983");
parms.setHorizdn("North American Datum 1983");
parms.setLatprjo(23.0);
parms.setLengthUnit("Meter");
parms.setLengthValue(1.0);
parms.setLongcm(-96.0);
parms.setMapprojn("Albers Conical Equal Area");
parms.setPrimeM("Greenwich\",0.0]");
parms.setProjection("Albers");
parms.setSemiaxis(6378137.0);
parms.setStdparll(45.5);
parms.setUnit("Degree\",0.0174532925199433]]");
String built = buildWkt(parms);
System.out.println("String builtVia wkt parm dto: " + built);
assertEquals(expString, built);
}
Aggregations