/** * Creates a direct {@link ICRS} instance from the given {@link CRSCodeType} not just a {@link CRSRef}, if no * {@link ICRS} was found an {@link UnknownCRSException} will be thrown. All configured {@link CRSStore}s will be * considered and the first match returned. * * @param codeType * the {@link CodeType} of the CRS to return * @return a direct {@link ICRS} instance with the given {@link CodeType} not just a {@link CRSRef} * @throws UnknownCRSException * if a {@link ICRS} with the name is not known */ public synchronized static ICRS lookup( CRSCodeType codeType ) throws UnknownCRSException { return lookup( null, codeType ); }
/** * returns true if the the passed SRS is available in deegree * * @param srs * @return <code>true</code> if the the passed SRS is available in deegree */ private boolean isAvailable( String srs ) { ICRS crs = null; try { crs = CRSManager.lookup( srs ); } catch ( UnknownCRSException e ) { return false; } return crs != null; }
/** * Creates a direct {@link ICRS} instance from the given name not just a {@link CRSRef}, if no {@link ICRS} was * found an {@link UnknownCRSException} will be thrown. All configured {@link CRSStore}s will be considered and the * first match returned. * * @param name * of the crs, e.g. EPSG:4326 * @return a direct {@link ICRS} instance corresponding to the given name not just a {@link CRSRef}, using all * configured {@link CRSStore}s. * @throws UnknownCRSException * if a {@link ICRS} with the name is not known */ public synchronized static ICRS lookup( String name ) throws UnknownCRSException { return lookup( name, false ); }
/** * Creates a direct {@link ICRS} instance from the given name using not just a {@link CRSRef} the given storeID, if * no {@link ICRS} was found in the given store an {@link UnknownCRSException} will be thrown. * * @param storeId * identifier of the {@link CRSStore} looking for the {@link ICRS} with the given name, may be * <code>null</code> if in all {@link CRSStore}s should be searched * @param name * of the crs, e.g. EPSG:31466 * @return a direct {@link ICRS} instance not just a {@link CRSRef} corresponding to the given name from the * {@link CRSStore} with the given id * @throws UnknownCRSException * if a {@link ICRS} with the name is not known */ public synchronized static ICRS lookup( String storeId, String name ) throws UnknownCRSException { return lookup( storeId, name, false ); }
/** * Creates a direct {@link ICRS} instance from the given name not just a {@link CRSRef}, if no {@link ICRS} was * found an {@link UnknownCRSException} will be thrown. All configured {@link CRSStore}s will be considered and the * first match returned. * * @param name * of the crs, e.g. EPSG:4326 * @param forceXY * true if the axis order of the coordinate system should be x/y (EAST/NORTH; WEST/SOUTH); false id the * defined axis order should be used * @return a direct {@link ICRS} instance corresponding to the given name not just a {@link CRSRef}, using all * configured {@link CRSStore}s. * @throws UnknownCRSException * if a {@link ICRS} with the name is not known */ public synchronized static ICRS lookup( String name, boolean forceXY ) throws UnknownCRSException { return lookup( null, name, forceXY ); }
@Override public Object getObject( String uri, String baseURL ) { ICRS crs = null; try { crs = lookup( uri, forceXY ); } catch ( UnknownCRSException e ) { LOG.debug( "Could not find CRS with uri " + uri + "; return null." ); } return crs; } }, uri, null, forceXY );
private ICRS parseCRS( XMLStreamReader in ) throws UnknownCRSException, XMLStreamException { String crs = XMLStreamUtils.getRequiredText( in, new QName( SLDNS, "CRS" ), true ); return CRSManager.lookup( crs ); }
public static void checkCrs( String path, HttpServletResponse resp ) throws IOException { Pair<DeegreeWorkspace, String> p = getWorkspaceAndPath( path ); try { CRSManager.lookup( p.second ); IOUtils.write( "true", resp.getOutputStream() ); } catch ( UnknownCRSException e ) { IOUtils.write( "false", resp.getOutputStream() ); } }
private ICRS deriveCrs( String srid ) { LOG.debug( "Deriving CRS from database SRID ('" + srid + "')." ); try { return lookup( "EPSG:" + srid, true ); } catch ( UnknownCRSException e ) { LOG.error( "Deriving CRS from database SRID ('" + srid + "') failed. Use StorageCRS option to configure CRS explicitly." ); } try { LOG.warn( "Defaulting to EPSG:4326." ); return lookup( "EPSG:4326", true ); } catch ( UnknownCRSException e ) { throw new RuntimeException( e.getMessage(), e ); } } }
/** * @param crs * @return an instantiated crs.(created from provider) */ private ICRS getCRS( String crs ) { ICRS result = null; try { result = CRSManager.lookup( crs ); } catch ( UnknownCRSException e ) { if ( LOG.isDebugEnabled() ) { LOG.debug( e.getMessage(), e ); } } return result; }
/** * Creates a new Transformer object, with the given id as the target CRS. * * @param targetCRS * an identifier to which all incoming coordinates shall be transformed. * @throws UnknownCRSException * if the given crs name could not be mapped to a valid (configured) crs. * @throws IllegalArgumentException * if the given parameter is null. */ protected Transformer( String targetCRS ) throws UnknownCRSException, IllegalArgumentException { if ( targetCRS == null ) { throw new IllegalArgumentException( Messages.getMessage( "CRS_PARAMETER_NOT_NULL", "Transformer(String)", "targetCRS" ) ); } this.targetCRS = CRSManager.lookup( targetCRS ); // this.tCRS = new ICoordinateSystemReference( targetCRS ); }
/** * transforms the coordinates of a deegree geometry to the target coordinate reference system. * * @param geo * to be transformed * @param sourceCRS * the source CRS for the geometry. overwrites the CRS of the geometry. * @return the same geometry in a different crs. * @throws TransformationException * if the transformation between the source and target crs cannot be created. * @throws IllegalArgumentException * if the coordinates system of the geometry is <code>null</code> * @throws UnknownCRSException * if the given CRS is not found */ public Geometry transform( Geometry geo, String sourceCRS ) throws TransformationException, IllegalArgumentException, UnknownCRSException { return transform( geo, CRSManager.lookup( sourceCRS ), false, null ); }
private void getCRSFromFile( File prj ) { BufferedReader in = null; try { in = new BufferedReader( new FileReader( prj ) ); String c = in.readLine().trim(); try { crs = CRSManager.lookup( c ); LOG.debug( ".prj contained EPSG code '{}'", crs.getAlias() ); } catch ( UnknownCRSException e2 ) { LOG.warn( "Could not parse the .prj projection file for {}, reason: {}.", shpName, e2.getLocalizedMessage() ); LOG.warn( "The file also does not contain a valid EPSG code, assuming CRS:84 (WGS84 with x/y axis order)." ); LOG.trace( "Stack trace of failed WKT parsing:", e2 ); crs = CRSManager.lookup( "CRS:84" ); } } catch ( IOException e1 ) { LOG.debug( "Stack trace:", e1 ); LOG.warn( "The shape datastore for '{}' could not be initialized, because no CRS was defined.", shpName ); available = false; } catch ( Exception e1 ) { LOG.warn( "The shape datastore for '{}' could not be initialized, because no CRS was defined.", shpName ); LOG.trace( "Stack trace:", e1 ); available = false; } finally { IOUtils.closeQuietly( in ); } }
/** * Creates a transformation chain, which can be used to transform incoming coordinates (in the given source CRS) * into this Transformer's targetCRS. * * @param sourceCRS * in which the coordinates are defined. * @return the Transformation chain. * @throws TransformationException * if no transformation chain could be created. * @throws IllegalArgumentException * if the given ICoordinateSystem is <code>null</code> * @throws UnknownCRSException * if the given crs name could not be mapped to a valid (configured) crs. * */ protected Transformation createCRSTransformation( String sourceCRS ) throws TransformationException, IllegalArgumentException, UnknownCRSException { if ( sourceCRS == null ) { throw new IllegalArgumentException( Messages.getMessage( "CRS_PARAMETER_NOT_NULL", "createCRSTransformation( ICoordinateSystem )", "sourceCRS" ) ); } return CRSManager.getTransformation( null, CRSManager.lookup( sourceCRS ), targetCRS ); }
private static ICRS getCRS( IIOMetadata metaData ) { GeoTiffIIOMetadataAdapter geoTIFFMetaData = new GeoTiffIIOMetadataAdapter( metaData ); try { int modelType = Integer.valueOf( geoTIFFMetaData.getGeoKey( GeoTiffIIOMetadataAdapter.GTModelTypeGeoKey ) ); String epsgCode = null; if ( modelType == GeoTiffIIOMetadataAdapter.ModelTypeProjected ) { epsgCode = geoTIFFMetaData.getGeoKey( GeoTiffIIOMetadataAdapter.ProjectedCSTypeGeoKey ); } else if ( modelType == GeoTiffIIOMetadataAdapter.ModelTypeGeographic ) { epsgCode = geoTIFFMetaData.getGeoKey( GeoTiffIIOMetadataAdapter.GeographicTypeGeoKey ); } if ( epsgCode != null && epsgCode.length() != 0 ) { try { return CRSManager.lookup( "EPSG:" + epsgCode ); } catch ( UnknownCRSException e ) { LOG.error( "No coordinate system found for EPSG:" + epsgCode ); } } } catch ( UnsupportedOperationException ex ) { LOG.debug( "couldn't read crs information in GeoTIFF" ); } return null; }
private Envelope parseBoundingBox( XMLStreamReader in ) throws UnknownCRSException, OWSException, XMLStreamException { String crsValue = XMLStreamUtils.getAttributeValue( in, "crs" ); ICRS crs = CRSManager.lookup( crsValue ); QName lowerCorner = new QName( OWS_NS, "LowerCorner" ); skipToRequiredElement( in, lowerCorner ); double[] min = parseCorner( in, lowerCorner ); QName upperCorner = new QName( OWS_NS, "UpperCorner" ); skipToRequiredElement( in, upperCorner ); double[] max = parseCorner( in, upperCorner ); return GEOMETRY_FACTORY.createEnvelope( min, max, crs ); }
public static Envelope getEnvelopeAndCrs( IIOMetadata metaData, int width, int height, ICRS crs ) { GeoTiffIIOMetadataAdapter geoTIFFMetaData = new GeoTiffIIOMetadataAdapter( metaData ); try { if ( crs == null ) { int modelType = Integer.valueOf( geoTIFFMetaData.getGeoKey( GeoTiffIIOMetadataAdapter.GTModelTypeGeoKey ) ); String epsgCode = null; if ( modelType == GeoTiffIIOMetadataAdapter.ModelTypeProjected ) { epsgCode = geoTIFFMetaData.getGeoKey( GeoTiffIIOMetadataAdapter.ProjectedCSTypeGeoKey ); } else if ( modelType == GeoTiffIIOMetadataAdapter.ModelTypeGeographic ) { epsgCode = geoTIFFMetaData.getGeoKey( GeoTiffIIOMetadataAdapter.GeographicTypeGeoKey ); } if ( epsgCode != null && epsgCode.length() != 0 ) { try { crs = CRSManager.lookup( "EPSG:" + epsgCode ); } catch ( UnknownCRSException e ) { LOG.error( "No coordinate system found for EPSG:" + epsgCode ); } } } if ( crs == null ) { throw new ResourceInitException( "No CRS information could be read from GeoTIFF, " + "and none was configured. Please configure a" + " CRS or add one to the GeoTIFF." ); } return getEnvelope( metaData, width, height, crs ); } catch ( UnsupportedOperationException ex ) { LOG.debug( "couldn't read crs information in GeoTIFF" ); } return null; }
private ICRS determineDefaultCrs( Insert insert, List<ICRS> queryCRS ) throws OWSException { String srsName = insert.getSrsName(); if ( srsName != null ) { try { ICRS defaultCrs = CRSManager.lookup( insert.getSrsName() ); if ( !isCrsSupported( defaultCrs, queryCRS ) ) { String msg = "The value of the srsName parameter is not one of the SRS values the server claims to support in its capabilities document."; throw new OWSException( msg, INVALID_PARAMETER_VALUE, "srsName" ); } return defaultCrs; } catch ( UnknownCRSException e ) { String msg = "Cannot perform insert. Specified srsName '" + srsName + "' is not supported by this WFS."; throw new OWSException( msg, INVALID_PARAMETER_VALUE, "srsName" ); } } return null; }
private static void exportLonLatEnvelope( XMLStreamWriter writer, Envelope envelope ) throws XMLStreamException { try { ICRS wgs84 = CRSManager.lookup( "EPSG:4326" ); GeometryTransformer transformer = new GeometryTransformer( wgs84 ); Envelope lonLatEnv = (Envelope) transformer.transform( envelope ); writer.writeStartElement( WCS_100_NS, "lonLatEnvelope" ); // @srsName urn:ogc:def:crs:OGC:1.3:CRS84 writer.writeAttribute( "srsName", "urn:ogc:def:crs:OGC:1.3:CRS84" ); exportGMLPos( writer, lonLatEnv.getMin().get0(), lonLatEnv.getMin().get1() ); exportGMLPos( writer, lonLatEnv.getMax().get0(), lonLatEnv.getMax().get1() ); writer.writeEndElement(); // lonLatEnvelope } catch ( UnknownCRSException e ) { e.printStackTrace(); return; } catch ( TransformationException e ) { e.printStackTrace(); return; } }
ICRS crs = null; if ( configuredCrs != null ) { crs = CRSManager.lookup( configuredCrs );