use of org.opengis.referencing.FactoryException in project hale by halestudio.
the class WKTPreferencesCRSFactory method getDescriptionText.
/**
* @see AuthorityFactory#getDescriptionText(String)
*/
@Override
public InternationalString getDescriptionText(String code) throws FactoryException {
if (code == null) {
return null;
}
if (code.startsWith("EPSG:")) {
// $NON-NLS-1$
code = code.substring(5);
}
code = code.trim();
String wkt = node.get(code, null);
if (wkt == null) {
// $NON-NLS-1$ //$NON-NLS-2$
throw new FactoryException("Unknown EPSG code: '" + code + "'");
}
wkt = wkt.trim();
int start = wkt.indexOf('"');
int end = wkt.indexOf('"', start + 1);
return new org.geotools.util.SimpleInternationalString(wkt.substring(start + 1, end));
}
use of org.opengis.referencing.FactoryException in project hale by halestudio.
the class AdvCrsAuthorityFactory method getDescriptionText.
@Override
public InternationalString getDescriptionText(String code) throws FactoryException {
if (code == null) {
return null;
}
if (code.startsWith(AUTHORITY_PREFIX)) {
code = code.substring(AUTHORITY_PREFIX.length());
}
code = code.trim();
String epsgCode = mappings.get(code);
if (epsgCode == null) {
// $NON-NLS-1$ //$NON-NLS-2$
throw new FactoryException("Unknown AdV code: '" + code + "'");
}
String wkt = CRS.decode(epsgCode).toWKT();
int start = wkt.indexOf('"');
int end = wkt.indexOf('"', start + 1);
return new org.geotools.util.SimpleInternationalString(wkt.substring(start + 1, end));
}
use of org.opengis.referencing.FactoryException in project hale by halestudio.
the class AdvCrsAuthorityFactory method createCoordinateReferenceSystem.
/**
* @see CRSAuthorityFactory#createCoordinateReferenceSystem(String)
*/
@Override
public synchronized CoordinateReferenceSystem createCoordinateReferenceSystem(String code) throws FactoryException {
if (code == null) {
return null;
}
if (!code.startsWith(AUTHORITY_PREFIX)) {
throw new // $NON-NLS-1$
NoSuchAuthorityCodeException(// $NON-NLS-1$
"This factory only understands AdV codes", AUTHORITY, code);
}
final String advCode = code.substring(AUTHORITY_PREFIX.length()).trim();
if (cache.containsKey(advCode)) {
CoordinateReferenceSystem value = cache.get(advCode);
if (value != null) {
// CRS was already created
return value;
}
}
String epsgCode = getEpsgCode(advCode);
if (epsgCode == null) {
// $NON-NLS-1$
throw new NoSuchAuthorityCodeException("Unknown AdV code", AUTHORITY, code);
}
try {
CoordinateReferenceSystem crs = CRS.decode(epsgCode, false);
cache.put(advCode, crs);
return crs;
} catch (FactoryException fex) {
throw fex;
}
}
use of org.opengis.referencing.FactoryException in project coastal-hazards by USGS-CIDA.
the class CRSUtils method transformFeatureCollection.
/**
* Returns a SimpleFeatureCollection with transformed default geometry
*
* @param featureCollection source feature collection (features may be
* modified)
* @param sourceCrs original coordinate reference system
* @param targetCrs new coordinate reference system
* @return new SimpleFeatureCollection
*/
public static SimpleFeatureCollection transformFeatureCollection(FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection, CoordinateReferenceSystem sourceCrs, CoordinateReferenceSystem targetCrs) {
List<SimpleFeature> sfList = new LinkedList<SimpleFeature>();
MathTransform transform = null;
try {
transform = CRS.findMathTransform(sourceCrs, targetCrs, true);
} catch (FactoryException ex) {
// do something better than this
return null;
}
FeatureIterator<SimpleFeature> features = null;
try {
features = featureCollection.features();
SimpleFeature feature = null;
while (features.hasNext()) {
feature = features.next();
Geometry geometry = (Geometry) feature.getDefaultGeometry();
Geometry utmGeometry = null;
try {
utmGeometry = JTS.transform(geometry, transform);
} catch (TransformException ex) {
// TODO handle exceptions
LOGGER.warn("Unhandled exception in transformFeatureCollection", ex);
}
feature.setDefaultGeometry(utmGeometry);
sfList.add(feature);
}
} finally {
if (null != features) {
features.close();
}
}
return DataUtilities.collection(sfList);
}
use of org.opengis.referencing.FactoryException in project coastal-hazards by USGS-CIDA.
the class LayerResource method createRasterLayer.
@POST
@Path("/raster")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_PLAIN)
@RolesAllowed({ CoastalHazardsTokenBasedSecurityFilter.CCH_ADMIN_ROLE })
public Response createRasterLayer(@Context HttpServletRequest req, @FormDataParam("metadata") String metadata, @FormDataParam("file") InputStream zipFileStream, @FormDataParam("file") FormDataContentDisposition fileDisposition) {
List<Service> services = new ArrayList<>();
try {
log.info("Raster layer upload - about to parseRequest");
String newId = IdGenerator.generate();
String metadataId;
if (metadata == null || metadata.isEmpty()) {
throw new ServerErrorException("Metadata file is missing or empty.", Status.INTERNAL_SERVER_ERROR);
}
try {
log.info("Raster layer create - about to doCSWInsertFromString");
metadataId = MetadataUtil.doCSWInsertFromString(metadata);
} catch (IOException | ParserConfigurationException | SAXException ex) {
throw new ServerErrorException("Error inserting metadata to the CSW server.", Status.INTERNAL_SERVER_ERROR, ex);
}
log.info("Raster layer create - about to makeCSWServiceForUrl with metadataId: " + metadataId);
services.add(MetadataUtil.makeCSWServiceForUrl(MetadataUtil.getMetadataByIdUrl(metadataId)));
Bbox bbox = MetadataUtil.getBoundingBoxFromFgdcMetadata(metadata);
log.info("Starting CRS Identifier Lookup");
long startTime = System.nanoTime();
String EPSGcode = CRS.lookupIdentifier(MetadataUtil.getCrsFromFgdcMetadata(metadata), true);
long endTime = System.nanoTime();
// divide by 1000000 to get milliseconds
long duration = (endTime - startTime) / 1000000;
log.info("Finished CRS Identifier Lookup. Took " + duration + "ms.");
if (bbox == null || EPSGcode == null) {
throw new ServerErrorException("Unable to identify bbox or epsg code from metadata.", Status.INTERNAL_SERVER_ERROR);
}
log.info("Raster layer create - about to addRasterLayer to geoserver with an id of: " + newId);
log.info("Raster layer create - about to addRasterLayer to geoserver with a bbox: " + bbox.getBbox());
log.info("Raster layer create - about to addRasterLayer to geoserver with an EPSG of: " + EPSGcode);
Service rasterService = GeoserverUtil.addRasterLayer(geoserverEndpoint, zipFileStream, newId, bbox, EPSGcode);
if (null == rasterService) {
throw new ServerErrorException("Unable to create a store and/or layer in GeoServer.", Status.INTERNAL_SERVER_ERROR);
} else {
services.add(rasterService);
}
if (!services.isEmpty()) {
Layer layer = new Layer();
layer.setId(newId);
layer.setServices(services);
layer.setBbox(bbox);
try (LayerManager manager = new LayerManager()) {
manager.save(layer);
}
return Response.created(layerURI(layer)).build();
} else {
throw new ServerErrorException("Unable to create layer", Status.INTERNAL_SERVER_ERROR);
}
} catch (JAXBException | FactoryException | IOException ex) {
throw new ServerErrorException("Error parsing upload request", Status.INTERNAL_SERVER_ERROR, ex);
}
}
Aggregations