org.geotools.util.factory.GeoTools类的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(11.6k)|赞(0)|评价(0)|浏览(383)

本文整理了Java中org.geotools.util.factory.GeoTools类的一些代码示例,展示了GeoTools类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GeoTools类的具体详情如下:
包路径:org.geotools.util.factory.GeoTools
类名称:GeoTools

GeoTools介绍

[英]Static methods relative to the global GeoTools configuration. GeoTools can be configured in a system-wide basis through System#getProperties, some of them are declared as 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 the #addFactoryIteratorProvidermethod.
    [中]相对于全局GeoTools配置的静态方法。GeoTools可以通过system#getProperties在系统范围内进行配置,其中一些在此类中声明为字符串常量。
    GeoTools的配置有许多方面:
    *默认设置:作为#GetDefaultHitts()返回的提示处理,默认值可以在应用程序代码中提供,也可以使用系统属性指定。
    *集成JNDI:告诉GeoTools库有关应用程序或应用程序容器的功能有多种形式。此类提供了#init(InitialContext)方法,允许GeoTools了解要使用的JNDI上下文。
    *集成插件:如果在替代插件系统(如Spring或OSGi)中托管GeoTools,则应用程序可能需要查找FactoryFinder,并为GeoTools注册额外的“Factory迭代器”,以便使用#AddFactoryInteratorProviderMethod进行搜索。

代码示例

代码示例来源:origin: geoserver/geoserver

  1. /** Builds the default coverage contained in the current store */
  2. public CoverageInfo buildCoverage(String coverageName) throws Exception {
  3. if (store == null || !(store instanceof CoverageStoreInfo)) {
  4. throw new IllegalStateException("Coverage store not set.");
  5. }
  6. CoverageStoreInfo csinfo = (CoverageStoreInfo) store;
  7. GridCoverage2DReader reader =
  8. (GridCoverage2DReader)
  9. catalog.getResourcePool()
  10. .getGridCoverageReader(csinfo, GeoTools.getDefaultHints());
  11. if (reader == null)
  12. throw new Exception(
  13. "Unable to acquire a reader for this coverage with format: "
  14. + csinfo.getFormat().getName());
  15. return buildCoverage(reader, coverageName, null);
  16. }

代码示例来源:origin: geotools/geotools

  1. /** Make sure a JNDI context is available */
  2. public boolean isAvailable() {
  3. try {
  4. GeoTools.getInitialContext(GeoTools.getDefaultHints());
  5. return true;
  6. } catch (Exception e) {
  7. return false;
  8. }
  9. }
  10. }

代码示例来源:origin: geotools/geotools

  1. /**
  2. * Provides GeoTools with the JNDI context for resource lookup.
  3. *
  4. * @param applicationContext The initial context to use.
  5. * @see #getInitialContext
  6. * @since 2.4
  7. */
  8. public static void init(final InitialContext applicationContext) {
  9. synchronized (GeoTools.class) {
  10. context = applicationContext;
  11. }
  12. fireConfigurationChanged();
  13. }

代码示例来源:origin: geoserver/geoserver

  1. GeoTools.init((Hints) null);
  2. final Hints defHints = GeoTools.getDefaultHints();

代码示例来源:origin: geotools/geotools

  1. public String newRequestHandle(WFSOperationType operation) {
  2. StringBuilder handle =
  3. new StringBuilder("GeoTools ")
  4. .append(GeoTools.getVersion())
  5. .append("(")
  6. .append(GeoTools.getBuildRevision())
  7. .append(") WFS ")
  8. .append(getVersion())
  9. .append(" DataStore @");
  10. try {
  11. handle.append(InetAddress.getLocalHost().getHostName());
  12. } catch (Exception ignore) {
  13. handle.append("<uknown host>");
  14. }
  15. AtomicLong reqHandleSeq = requestHandleSequences.get(operation);
  16. handle.append('#').append(reqHandleSeq.incrementAndGet());
  17. return handle.toString();
  18. }

代码示例来源:origin: geotools/geotools

  1. /**
  2. * Reports the GeoTools {@linkplain #getVersion version} number to the {@linkplain System#out
  3. * standard output stream}.
  4. *
  5. * @param args Command line arguments.
  6. */
  7. public static void main(String[] args) {
  8. final Arguments arguments = new Arguments(args);
  9. args = arguments.getRemainingArguments(0);
  10. arguments.out.print("GeoTools version ");
  11. arguments.out.println(getVersion());
  12. final Hints hints = getDefaultHints();
  13. if (hints != null && !hints.isEmpty()) {
  14. arguments.out.println(hints);
  15. }
  16. }
  17. }

代码示例来源:origin: geotools/geotools

  1. /**
  2. * Returns the default entity resolver, used to configure {@link SAXParser}.
  3. *
  4. * @param hints An optional set of hints, or {@code null} if none, see {@link
  5. * Hints#ENTITY_RESOLVER}.
  6. * @return An entity resolver (never {@code null})
  7. */
  8. public static EntityResolver getEntityResolver(Hints hints) {
  9. if (hints == null) {
  10. hints = getDefaultHints();
  11. }
  12. if (hints.containsKey(Hints.ENTITY_RESOLVER)) {
  13. Object hint = hints.get(Hints.ENTITY_RESOLVER);
  14. if (hint == null) {
  15. return NullEntityResolver.INSTANCE;
  16. } else if (hint instanceof EntityResolver) {
  17. return (EntityResolver) hint;
  18. } else if (hint instanceof String) {
  19. String className = (String) hint;
  20. return instantiate(
  21. className, EntityResolver.class, PreventLocalEntityResolver.INSTANCE);
  22. }
  23. }
  24. return PreventLocalEntityResolver.INSTANCE;
  25. }

代码示例来源:origin: geotools/geotools

  1. protected void setUp() throws Exception {
  2. // this is the only thing that actually forces CRS object to give up
  3. // its configuration, necessary when tests are run by Maven, one JVM for all
  4. // the tests in this module
  5. Hints.putSystemDefault(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE);
  6. GeoTools.fireConfigurationChanged();
  7. ft =
  8. DataUtilities.createType(
  9. "testType", "geom:Point:srid=4326,line:LineString,name:String,id:int");
  10. ff = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints());
  11. reprojector = new ReprojectingFilterVisitor(ff, ft);
  12. }

代码示例来源:origin: geotools/geotools

  1. DataSource source = null;
  2. try {
  3. context = GeoTools.getInitialContext(new Hints(hints));
  4. source = (DataSource) context.lookup(datasourceName);
  5. } catch (IllegalArgumentException exception) {

代码示例来源:origin: geotools/geotools

  1. final URL classLocation = classLocation(type);
  2. String path = classLocation.toString();
  3. String jarVersion = jarVersion(path);
  4. if (jarVersion != null) {
  5. return new Version(jarVersion);
  6. URL manifestLocation = manifestLocation(path);
  7. Manifest manifest = new Manifest();
  8. try (InputStream content = manifestLocation.openStream()) {
  9. return GeoTools.getVersion();

代码示例来源:origin: geotools/geotools

  1. final URL classLocation = classLocation(type);
  2. Manifest manifest = new Manifest();
  3. URL manifestLocation = manifestLocation(classLocation.toString());
  4. if (manifestLocation != null) {
  5. try {
  6. || name.startsWith("net.opengis")) {
  7. String generated =
  8. "Manifest-Version: 1.0\n" + "Project-Version: " + getVersion() + "\n";

代码示例来源:origin: geotools/geotools

  1. /**
  2. * A helper method for {@linkplain #getGeoToolsJarInfo} which scans the classpath looking for
  3. * GeoTools jars matching the current version.
  4. *
  5. * @return a list of jar names
  6. */
  7. private static List<String> getGeoToolsJars() {
  8. final Pattern pattern = Pattern.compile(".*\\/" + getVersion() + "\\/(gt-.*jar$)");
  9. final List<String> jarNames = new ArrayList<String>();
  10. String pathSep = System.getProperty("path.separator");
  11. String classpath = System.getProperty("java.class.path");
  12. StringTokenizer st = new StringTokenizer(classpath, pathSep);
  13. while (st.hasMoreTokens()) {
  14. String path = st.nextToken();
  15. Matcher matcher = pattern.matcher(path);
  16. if (matcher.find()) {
  17. jarNames.add(matcher.group(1));
  18. }
  19. }
  20. Collections.sort(jarNames);
  21. return jarNames;
  22. }

代码示例来源:origin: geotools/geotools

  1. /**
  2. * Implementation of {@code fixName} method. If the context is {@code null}, then the
  3. * {@linkplain #getInitialContext GeoTools initial context} will be fetch only when first
  4. * needed.
  5. */
  6. private static String fixName(Context context, final String name, final Hints hints) {
  7. String fixed = null;
  8. if (name != null) {
  9. final StringTokenizer tokens = new StringTokenizer(name, ":/");
  10. while (tokens.hasMoreTokens()) {
  11. final String part = tokens.nextToken();
  12. if (fixed == null) {
  13. fixed = part;
  14. } else
  15. try {
  16. if (context == null) {
  17. context = getInitialContext(hints);
  18. }
  19. fixed = context.composeName(fixed, part);
  20. } catch (NamingException e) {
  21. Logging.unexpectedException(GeoTools.class, "fixName", e);
  22. return name;
  23. }
  24. }
  25. }
  26. return fixed;
  27. }

代码示例来源:origin: geotools/geotools

  1. /**
  2. * Returns summary information about the GeoTools version and the host environment.
  3. *
  4. * @return information as a String
  5. */
  6. public static String getEnvironmentInfo() {
  7. final String newline = String.format("%n");
  8. final StringBuilder sb = new StringBuilder();
  9. sb.append("GeoTools version ").append(getVersion().toString());
  10. if (sb.toString().endsWith("SNAPSHOT")) {
  11. sb.append(" (built from r").append(getBuildRevision().toString()).append(")");
  12. }
  13. sb.append(newline).append("Java version: ");
  14. sb.append(System.getProperty("java.version"));
  15. sb.append(newline).append("Operating system: ");
  16. sb.append(System.getProperty("os.name"))
  17. .append(' ')
  18. .append(System.getProperty("os.version"));
  19. return sb.toString();
  20. }

代码示例来源:origin: geotools/geotools

  1. /** Sets the metadata information. */
  2. private void setInfo() {
  3. Map<String, String> info = new HashMap<String, String>();
  4. info.put("name", "ArcSDE Raster");
  5. info.put("description", "ArcSDE Raster Format");
  6. info.put("vendor", "Geotools ");
  7. info.put("docURL", "");
  8. info.put("version", GeoTools.getVersion().toString());
  9. mInfo = info;
  10. readParameters =
  11. new ParameterGroup(
  12. new DefaultParameterDescriptorGroup(
  13. mInfo,
  14. new GeneralParameterDescriptor[] {
  15. READ_GRIDGEOMETRY2D, OVERVIEW_POLICY
  16. }));
  17. }

代码示例来源:origin: geoserver/geoserver

  1. /**
  2. * Builds the default coverage contained in the current store
  3. *
  4. * @param nativeCoverageName the native name for the coverage
  5. * @param specifiedName the published name for the coverage. If null, the name will be
  6. * determined from the coverage store.
  7. * @return coverage for the specified name
  8. * @throws Exception if the coverage store was not found or could not be read, or if the
  9. * coverage could not be created.
  10. */
  11. public CoverageInfo buildCoverageByName(String nativeCoverageName, String specifiedName)
  12. throws Exception {
  13. if (store == null || !(store instanceof CoverageStoreInfo)) {
  14. throw new IllegalStateException("Coverage store not set.");
  15. }
  16. CoverageStoreInfo csinfo = (CoverageStoreInfo) store;
  17. GridCoverage2DReader reader =
  18. (GridCoverage2DReader)
  19. catalog.getResourcePool()
  20. .getGridCoverageReader(csinfo, GeoTools.getDefaultHints());
  21. if (reader == null)
  22. throw new Exception(
  23. "Unable to acquire a reader for this coverage with format: "
  24. + csinfo.getFormat().getName());
  25. return buildCoverageInternal(reader, nativeCoverageName, null, specifiedName);
  26. }

代码示例来源:origin: geotools/geotools

  1. /**
  2. * Determines if the datastore is available.
  3. *
  4. * <p>Check in an Initial Context is available, that is all what can be done Checking for the
  5. * right jdbc jars in the classpath is not possible here
  6. */
  7. public boolean isAvailable() {
  8. try {
  9. GeoTools.getInitialContext(GeoTools.getDefaultHints());
  10. return true;
  11. } catch (NamingException e) {
  12. return false;
  13. }
  14. }

代码示例来源:origin: geotools/geotools

  1. /**
  2. * Adds a class loader to be included in the list of class loaders that are used to locate
  3. * GeoTools plug-ins.
  4. *
  5. * <p>Client code that calls this method may also need to call {@link
  6. * FactoryRegistry#scanForPlugins()} on any existing registry to force it to clear its cache and
  7. * use the added class loader to locate plugins.
  8. *
  9. * @param classLoader The class loader.
  10. */
  11. public static void addClassLoader(ClassLoader classLoader) {
  12. addedClassLoaders.add(classLoader);
  13. fireConfigurationChanged();
  14. }

代码示例来源:origin: geotools/geotools

  1. public AbstractEpsgFactory(final Hints userHints) throws FactoryException {
  2. super(MAXIMUM_PRIORITY - 20);
  3. // The following hints have no effect on this class behaviour,
  4. // but tell to the user what this factory do about axis order.
  5. hints.put(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.FALSE);
  6. hints.put(Hints.FORCE_STANDARD_AXIS_DIRECTIONS, Boolean.FALSE);
  7. hints.put(Hints.FORCE_STANDARD_AXIS_UNITS, Boolean.FALSE);
  8. //
  9. // We need to obtain our DataSource
  10. if (userHints != null) {
  11. Object hint = userHints.get(Hints.EPSG_DATA_SOURCE);
  12. if (hint instanceof String) {
  13. String name = (String) hint;
  14. try {
  15. dataSource = (DataSource) GeoTools.getInitialContext(userHints).lookup(name);
  16. } catch (NamingException e) {
  17. throw new FactoryException("A EPSG_DATA_SOURCE hint is required:" + e);
  18. }
  19. hints.put(Hints.EPSG_DATA_SOURCE, dataSource);
  20. } else if (hint instanceof DataSource) {
  21. dataSource = (DataSource) hint;
  22. hints.put(Hints.EPSG_DATA_SOURCE, dataSource);
  23. } else {
  24. throw new FactoryException("A EPSG_DATA_SOURCE hint is required.");
  25. }
  26. } else {
  27. throw new FactoryException("A EPSG_DATA_SOURCE hint is required.");
  28. }
  29. }

代码示例来源:origin: geoserver/geoserver

  1. final Hints defHints = GeoTools.getDefaultHints();

相关文章