Class GeoTools
String constants in
 this class.
 There are many aspects to the configuration of GeoTools:
- Default Settings: Are handled as the Hints returned by 
getDefaultHints(), the default values can be provided in application code, or specified using system properties. - Integration JNDI: Telling the GeoTools library about the facilities of an application, or application container
       takes several forms. This class provides the 
init(InitialContext)method allowing to tell GeoTools about the JNDI context to use. - Integration Plugins: If hosting GeoTools in a alternate plugin system such as Spring or OSGi, application may
       needs to hunt down the 
FactoryFinders and register additional "Factory Iterators" for GeoTools to search using theaddFactoryIteratorProvider(org.geotools.util.factory.FactoryIteratorProvider)method. 
- Since:
 - 2.4
 - Author:
 - Jody Garnett, Martin Desruisseaux
 
- 
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe system property key for the default value to be assigned to theCRS_AUTHORITY_EXTRA_DIRECTORYhint.static final StringThe system property key for the default value to be assigned to theHints.DATE_TIME_FORMAT_HANDLINGhint.Default JNDI name validator, allows lookups only on names without a scheme, or using thejavascheme.static final StringThe system property key for the default value to be assigned to theHints.ENCODE_EWKThint.static final StringThe system property key for the default value to be assigned to the {@link Hints# ENTITY_RESOLVER} hint.static final StringThe system property key for the default value to be assigned to theEPSG_DATA_SOURCEhint.static final StringThe system property key for the default value to be assigned to theFORCE_LONGITUDE_FIRST_AXIS_ORDERhint.static final StringThe system property key for the default value to be assigned to the {@link Hints# FORCE_SRS_STYLE} hint.static final StringThe system property key for the default value to be assigned to theHints.HTTP_CLIENThint.static final StringThe system property key for the default value to be assigned to theHints.HTTP_LOGGINGhint.static final StringThe system property key for the default value to be assigned to theHints.LOCAL_DATE_TIME_HANDLINGhint.static final StringThe system property key for the default value to be assigned to the {@link Hints# RESAMPLE_TOLERANCE} hint. - 
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddChangeListener(ChangeListener listener) Adds the specified listener to the list of objects to inform when system-wide configuration changed.static voidaddClassLoader(ClassLoader classLoader) Adds a class loader to be included in the list of class loaders that are used to locate GeoTools plug-ins.static HintsaddDefaultHints(Hints hints) Used to combine provided hints with global GeoTools defaults.static voidAdds an alternative way to search for factory implementations.static voidClears the initial context (closes it if not null)static voidInforms every listeners that system-wide configuration changed.static StringDeprecated.static StringDeprecated.With no replacement, GeoTools now uses JNDI lookups as instructed in {@link * #jndiLookup(String)}, but does not put any object in the contex, the downstream * application should do it if necessary instead.static StringReturns summary information about GeoTools and the current environment.static PropertiesReturns the raw properties object containing all properties about this GeoTools build.static StringReports back the vcs revision at which the version of GeoTools was built.static StringReports back the timestamp at which the version of GeoTools of built.static HintsReturns the default set of hints used for the various utility classes.static EntityResolvergetEntityResolver(Hints hints) Returns the default entity resolver, used to configureSAXParser.static StringReturns summary information about the GeoTools version and the host environment.static StringReturns the names of the GeoTools jars on the classpath.static InitialContextDeprecated.Please usejndiLookup(String)instead, or provide anInitialContextto theinit(InitialContext)method and use it directly.static ManifestgetManifest(Class<?> type) Lookup the MANIFEST.MF for the provided class.static VersionReports back the version of GeoTools being used.static VersiongetVersion(Class<?> type) Lookup version for provided class.static voidinit()Initializes GeoTools for use.static voidinit(InitialContext initialContext) Provides GeoTools with the JNDI context for resource lookup.static voidInitializes GeoTools for use.static booleanChecks if JNDI is available, either because it was initialized, or because it was possible to create one.static ObjectjndiLookup(String name) Looks up an object from the JNDIInitialContext.static voidReports the GeoTools version number to the standard output stream.static voidremoveChangeListener(ChangeListener listener) Removes the specified listener from the list of objects to inform when system-wide configuration changed.static voidRemoves a provider that was previously added.static voidsetJNDINameValidator(Predicate<String> validator) Sets up a function that will be called to validate the JNDI lookups.static voidsetLoggerFactory(LoggerFactory<?> factory) Sets the global logger factory. 
- 
Field Details
- 
CRS_AUTHORITY_EXTRA_DIRECTORY
The system property key for the default value to be assigned to theCRS_AUTHORITY_EXTRA_DIRECTORYhint. - 
EPSG_DATA_SOURCE
The system property key for the default value to be assigned to theEPSG_DATA_SOURCEhint. - 
FORCE_LONGITUDE_FIRST_AXIS_ORDER
The system property key for the default value to be assigned to theFORCE_LONGITUDE_FIRST_AXIS_ORDERhint.This setting can provide a transition path for projects expecting a (longitude, latitude) axis order on a system-wide level. Application developpers can set the default value as below:
Note that this system property applies mostly to the default EPSG factory. Most other factories (System.setProperty(FORCE_LONGITUDE_FIRST_AXIS_ORDER, "true");
"CRS","AUTO", etc.) don't need this property since they use (longitude, latitude) axis order by design. - 
FORCE_SRS_STYLE
The system property key for the default value to be assigned to the {@link Hints# FORCE_SRS_STYLE} hint.GML Encoding in geotools forces http://www.opengis.net/gml/srs/epsg.xml# syntax on CRS that are East\North oriented or have no orientation (such as 1D CRS). This property prevents this behaviour.
System.setProperty(FORCE_SRS_STYLE, "true");
 - 
ENTITY_RESOLVER
The system property key for the default value to be assigned to the {@link Hints# ENTITY_RESOLVER} hint.This setting specifies the XML Entity resolver to be used when configuring a SAXParser
 - 
RESAMPLE_TOLERANCE
The system property key for the default value to be assigned to the {@link Hints# RESAMPLE_TOLERANCE} hint.This setting specifies the tolerance used when linearizing warp transformation into piecewise linear ones, by default it is 0.333 pixels
 - 
LOCAL_DATE_TIME_HANDLING
The system property key for the default value to be assigned to theHints.LOCAL_DATE_TIME_HANDLINGhint.This setting specifies if dates shall be treated as local dates ignoring time zones.
- Since:
 - 15.0
 - See Also:
 
 - 
DATE_TIME_FORMAT_HANDLING
The system property key for the default value to be assigned to theHints.DATE_TIME_FORMAT_HANDLINGhint.This setting specifies if GML 2 temporal data shall be formatted using same approach as GML 3+.
- Since:
 - 21.0
 - See Also:
 
 - 
ENCODE_WKT
The system property key for the default value to be assigned to theHints.ENCODE_EWKThint.This setting specifies if geometries with
CoordinateReferenceSystemin the user data shall be encoded as EWKT or not.- Since:
 - 19.0
 - See Also:
 
 - 
HTTP_CLIENT
The system property key for the default value to be assigned to theHints.HTTP_CLIENThint.This setting specifies whether we wan't to use a special http client
- Since:
 - 25.0
 - See Also:
 
 - 
HTTP_LOGGING
The system property key for the default value to be assigned to theHints.HTTP_LOGGINGhint.This setting specifies whether we want to log all http requests.
- Since:
 - 25.0
 - See Also:
 
 - 
DEFAULT_JNDI_VALIDATOR
Default JNDI name validator, allows lookups only on names without a scheme, or using thejavascheme. 
 - 
 - 
Method Details
- 
getAboutInfo
Returns summary information about GeoTools and the current environment. Calls getEnvironmentInfo() followed by getGeoToolsJarInfo() and concatenates their results.- Returns:
 - requested information as a string
 
 - 
getEnvironmentInfo
Returns summary information about the GeoTools version and the host environment.- Returns:
 - information as a String
 
 - 
getGeoToolsJarInfo
Returns the names of the GeoTools jars on the classpath.- Returns:
 - list of jars as a formatted string
 
 - 
getBuildRevision
Reports back the vcs revision at which the version of GeoTools was built.- Returns:
 - The svn revision.
 
 - 
getBuildTimestamp
Reports back the timestamp at which the version of GeoTools of built.- Returns:
 - The build timestamp.
 
 - 
getBuildProperties
Returns the raw properties object containing all properties about this GeoTools build.Example from the 14.3 release:
- version=14.3
 - build.revision=2298d56000bef6f526b521a480316ea544c74571
 - build.branch=rel_14.3
 - build.timestamp=21-Mar-2016 21:30
 
 - 
getVersion
Reports back the version of GeoTools being used.- Returns:
 - The current GeoTools version.
 
 - 
getVersion
Lookup version for provided class.Version number is determined by either:
- Use of jar naming convention, matching jars such as jts-1.13.jar
 - Use of MANIFEST.MF (to check Implementation-Version, Project-Version)
 - To assist
 
- Returns:
 - Version (or null if unavailable)
 
 - 
getManifest
Lookup the MANIFEST.MF for the provided class.This can be used to quickly verify packaging information.
- Returns:
 - MANIFEST.MF contents, please note contents may be empty when running from IDE
 
 - 
setLoggerFactory
Sets the global logger factory.This method is the same as calling
Logging.setLoggerFactory(factory)to configure bothLogging.ALLlogger creation.GeoTools provides logback, log4j, reload4j, and commons-logging factories. This method exists to allow you supply your own implementation (when using a GeoTools library in an exotic environment like Eclipse, OC4J or your application).
If
nullis used, the Java logging formatter for console output is replaced by a monoline formatter.- Parameters:
 factory- The logger factory to use, or null for native java util logging.- Since:
 - 2.4
 - See Also:
 
 - 
init
Initializes GeoTools for use. This convenience method performs various tasks (more may be added in the future), including setting up the Java logging framework in one of the following states:- If Logback is available, then messages in 
org.geotoolsandorg.eclipse.imagennamespace sent to logger are redirected to SL4J API used by logback. - Otherwise if Log4J is available, then messages in
       
org.geotoolsandorg.eclipse.imagennamespace sent to Java logger are redirected to Log4J API. - Otherwise if Reload4J is available, then messages in
       
org.geotoolsandorg.eclipse.imagennamespace sent to Java logger are redirected to Log4J 1 API used by Reload4J. - finally if Commons-logging is available, then
       messages in 
org.geotoolsandorg.eclipse.imagennamespaces sent to the Java logger are redirected to Commons-logging. - Otherwise, the Java logging formatter for console output is replaced by a monoline formatter.
 
In addition, the default hints are initialized to the specified
hints.Invoking this method is not required for the GeoTools library to function. It is just a convenience method for overwriting select Java and GeoTools default settings. Supplying these defaults is not desirable in all settings, such as writing test cases.
Example of typical invocation in a GeoServer environment:
Hints hints = new Hints(); hints.put(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE); hints.put(Hints.FORCE_AXIS_ORDER_HONORING, "http"); GeoTools.init(hints);- Parameters:
 hints- The hints to use.- See Also:
 - 
Logging.setLoggerFactory(String)Logging.forceMonolineConsoleOutput()Hints.putSystemDefault(java.awt.RenderingHints)getDefaultHints()
 
 - If Logback is available, then messages in 
 - 
init
public static void init()Initializes GeoTools for use. This convenience method performs various tasks (more may be added in the future)Primary task is setting up the Java logging framework with a logging factory (if it has not been done already):
- If Logging.ALL has already been configured no further work is required.
 - Otherwise if Logback is available, then messages in
       
org.geotoolsandorg.eclipse.imagennamespace sent to logger are redirected to SL4J API used by logback. - Otherwise if Log4J is available, then messages in
       
org.geotoolsandorg.eclipse.imagennamespace sent to Java logger are redirected to Log4J API. - Otherwise if Reload4J is available, then messages in
       
org.geotoolsandorg.eclipse.imagennamespace sent to Java logger are redirected to Log4J 1 API used by Reload4J. - Otherwise if Commons-logging is available, then
       messages in 
org.geotoolsandorg.eclipse.imagennamespaces sent to the Java logger are redirected to Commons-logging. - Otherwise, the Java logging formatter for console output is replaced by a monoline formatter.
 
Invoking this method is not required fpr the GeoTools library to function. It is just a convenience method for overwriting select Java and GeoTools default settings. Supplying these defaults is not always desirable, for example when quickly writing test cases.
- See Also:
 - 
Logging.setLoggerFactory(String)Logging.forceMonolineConsoleOutput()Hints.putSystemDefault(java.awt.RenderingHints)getDefaultHints()
 
 - 
init
Provides GeoTools with the JNDI context for resource lookup.- Parameters:
 initialContext- The initial context to use for JNDI lookup- Since:
 - 2.4
 - See Also:
 
 - 
getDefaultHints
Returns the default set of hints used for the various utility classes. This default set is determined by:- The  available. Some property keys are enumerated in the
       
GeoToolsclass. - Any hints added by call to the 
Hints.putSystemDefault(java.awt.RenderingHints)orinit(org.geotools.util.factory.Hints)method. 
Long term plan: We would like to transition the utility classes to being injected with their required factories, either by taking Hints as part of their constructor, or otherwise. Making this change would be a three step process 1) create instance methods for each static final class method 2) create an singleton instance of the class 3) change each static final class method into a call to the singleton. With this in place we could then encourage client code to make use of utility class instances before eventually retiring the static final methods.
- Returns:
 - A copy of the default hints. It is safe to add to it.
 
 - The  available. Some property keys are enumerated in the
       
 - 
addDefaultHints
Used to combine provided hints with global GeoTools defaults. - 
getEntityResolver
Returns the default entity resolver, used to configureSAXParser.- Parameters:
 hints- An optional set of hints, ornullif none, seeHints.ENTITY_RESOLVER.- Returns:
 - An entity resolver (never 
null) 
 - 
getInitialContext
Deprecated.Please usejndiLookup(String)instead, or provide anInitialContextto theinit(InitialContext)method and use it directly.Returns the default initial context.- Returns:
 - The initial context (never 
null). - Throws:
 NamingException- if the initial context can't be created.
 - 
isJNDIAvailable
public static boolean isJNDIAvailable()Checks if JNDI is available, either because it was initialized, or because it was possible to create one. - 
setJNDINameValidator
Sets up a function that will be called to validate the JNDI lookups. If not set, the DEFAULT_JNDI_VALIDATOR is used. The function may want to log the reason why a given name was denied lookup.- Parameters:
 validator- A function returning true if the lookups are meant to be performed, false otherwise.
 - 
jndiLookup
Looks up an object from the JNDIInitialContext. By default, it only allows lookups with no scheme, or inside thejavascheme. One can set up a custom name validation routine using- Parameters:
 name-- Returns:
 - Throws:
 NamingException
 - 
clearInitialContext
Clears the initial context (closes it if not null)- Throws:
 NamingException- Since:
 - 15.0
 
 - 
fixName
Deprecated.With no replacement, GeoTools now uses JNDI lookups as instructed injndiLookup(String), but does not put any object in the contex, the downstream application should do it if necessary instead.Converts a GeoTools name to the syntax used by the GeoTools JNDI context. Names may be constructed in a variety of ways depending on the implementation ofInitialContext. GeoTools uses"jdbc:EPSG"internally, but many implementaitons use the form"jdbc/EPSG". Calling this method before use will set the name right.- Parameters:
 name- Name of the form"jdbc:EPSG", ornull.- Returns:
 - Name fixed up with 
Context.composeName(String,String), ornullif the given name was null. - Since:
 - 2.4
 
 - 
fixName
Deprecated.With no replacement, GeoTools now uses JNDI lookups as instructed in {@link * #jndiLookup(String)}, but does not put any object in the contex, the downstream * application should do it if necessary instead.Converts a GeoTools name to the syntax used by the specified JNDI context. This method is similar tofixName(String), but uses the specified context instead of the GeoTools one.- Parameters:
 context- The context to use, ornullif none.name- Name of the form"jdbc:EPSG", ornull.- Returns:
 - Name fixed up with 
Context.composeName(String,String), ornullif the given name was null. - Since:
 - 2.4
 
 - 
addFactoryIteratorProvider
Adds an alternative way to search for factory implementations.FactoryRegistryhas a default mechanism bundled in it, which uses the content of allMETA-INF/servicesdirectories found on the classpath. ThisaddFactoryIteratorProvidermethod allows to specify additional discovery algorithms. It may be useful in the context of some frameworks that use the constructor injection pattern, like the Spring framework.- Parameters:
 provider- A new provider for factory iterators.
 - 
removeFactoryIteratorProvider
Removes a provider that was previously added. Note that factories already obtained from the specified provider will not be deregistered by this method.- Parameters:
 provider- The provider to remove.
 - 
addChangeListener
Adds the specified listener to the list of objects to inform when system-wide configuration changed.- Parameters:
 listener- The listener to add.
 - 
removeChangeListener
Removes the specified listener from the list of objects to inform when system-wide configuration changed.- Parameters:
 listener- The listener to remove.
 - 
fireConfigurationChanged
public static void fireConfigurationChanged()Informs every listeners that system-wide configuration changed. - 
addClassLoader
Adds a class loader to be included in the list of class loaders that are used to locate GeoTools plug-ins.Client code that calls this method may also need to call
FactoryRegistry.scanForPlugins()on any existing registry to force it to clear its cache and use the added class loader to locate plugins.- Parameters:
 classLoader- The class loader.
 - 
main
Reports the GeoTools version number to the standard output stream.- Parameters:
 args- Command line arguments.
 
 - 
 
jndiLookup(String), but does not put any object in the contex, the downstream application should do it if necessary instead.