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

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

本文整理了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

/** Builds the default coverage contained in the current store */
public CoverageInfo buildCoverage(String coverageName) throws Exception {
  if (store == null || !(store instanceof CoverageStoreInfo)) {
    throw new IllegalStateException("Coverage store not set.");
  }
  CoverageStoreInfo csinfo = (CoverageStoreInfo) store;
  GridCoverage2DReader reader =
      (GridCoverage2DReader)
          catalog.getResourcePool()
              .getGridCoverageReader(csinfo, GeoTools.getDefaultHints());
  if (reader == null)
    throw new Exception(
        "Unable to acquire a reader for this coverage with format: "
            + csinfo.getFormat().getName());
  return buildCoverage(reader, coverageName, null);
}

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

/** Make sure a JNDI context is available */
  public boolean isAvailable() {
    try {
      GeoTools.getInitialContext(GeoTools.getDefaultHints());
      return true;
    } catch (Exception e) {
      return false;
    }
  }
}

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

/**
 * Provides GeoTools with the JNDI context for resource lookup.
 *
 * @param applicationContext The initial context to use.
 * @see #getInitialContext
 * @since 2.4
 */
public static void init(final InitialContext applicationContext) {
  synchronized (GeoTools.class) {
    context = applicationContext;
  }
  fireConfigurationChanged();
}

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

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

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

public String newRequestHandle(WFSOperationType operation) {
  StringBuilder handle =
      new StringBuilder("GeoTools ")
          .append(GeoTools.getVersion())
          .append("(")
          .append(GeoTools.getBuildRevision())
          .append(") WFS ")
          .append(getVersion())
          .append(" DataStore @");
  try {
    handle.append(InetAddress.getLocalHost().getHostName());
  } catch (Exception ignore) {
    handle.append("<uknown host>");
  }
  AtomicLong reqHandleSeq = requestHandleSequences.get(operation);
  handle.append('#').append(reqHandleSeq.incrementAndGet());
  return handle.toString();
}

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

/**
   * Reports the GeoTools {@linkplain #getVersion version} number to the {@linkplain System#out
   * standard output stream}.
   *
   * @param args Command line arguments.
   */
  public static void main(String[] args) {
    final Arguments arguments = new Arguments(args);
    args = arguments.getRemainingArguments(0);
    arguments.out.print("GeoTools version ");
    arguments.out.println(getVersion());
    final Hints hints = getDefaultHints();
    if (hints != null && !hints.isEmpty()) {
      arguments.out.println(hints);
    }
  }
}

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

/**
 * Returns the default entity resolver, used to configure {@link SAXParser}.
 *
 * @param hints An optional set of hints, or {@code null} if none, see {@link
 *     Hints#ENTITY_RESOLVER}.
 * @return An entity resolver (never {@code null})
 */
public static EntityResolver getEntityResolver(Hints hints) {
  if (hints == null) {
    hints = getDefaultHints();
  }
  if (hints.containsKey(Hints.ENTITY_RESOLVER)) {
    Object hint = hints.get(Hints.ENTITY_RESOLVER);
    if (hint == null) {
      return NullEntityResolver.INSTANCE;
    } else if (hint instanceof EntityResolver) {
      return (EntityResolver) hint;
    } else if (hint instanceof String) {
      String className = (String) hint;
      return instantiate(
          className, EntityResolver.class, PreventLocalEntityResolver.INSTANCE);
    }
  }
  return PreventLocalEntityResolver.INSTANCE;
}

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

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

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

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

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

final URL classLocation = classLocation(type);
String path = classLocation.toString();
  String jarVersion = jarVersion(path);
  if (jarVersion != null) {
    return new Version(jarVersion);
    URL manifestLocation = manifestLocation(path);
    Manifest manifest = new Manifest();
    try (InputStream content = manifestLocation.openStream()) {
  return GeoTools.getVersion();

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

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

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

/**
 * A helper method for {@linkplain #getGeoToolsJarInfo} which scans the classpath looking for
 * GeoTools jars matching the current version.
 *
 * @return a list of jar names
 */
private static List<String> getGeoToolsJars() {
  final Pattern pattern = Pattern.compile(".*\\/" + getVersion() + "\\/(gt-.*jar$)");
  final List<String> jarNames = new ArrayList<String>();
  String pathSep = System.getProperty("path.separator");
  String classpath = System.getProperty("java.class.path");
  StringTokenizer st = new StringTokenizer(classpath, pathSep);
  while (st.hasMoreTokens()) {
    String path = st.nextToken();
    Matcher matcher = pattern.matcher(path);
    if (matcher.find()) {
      jarNames.add(matcher.group(1));
    }
  }
  Collections.sort(jarNames);
  return jarNames;
}

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

/**
 * Implementation of {@code fixName} method. If the context is {@code null}, then the
 * {@linkplain #getInitialContext GeoTools initial context} will be fetch only when first
 * needed.
 */
private static String fixName(Context context, final String name, final Hints hints) {
  String fixed = null;
  if (name != null) {
    final StringTokenizer tokens = new StringTokenizer(name, ":/");
    while (tokens.hasMoreTokens()) {
      final String part = tokens.nextToken();
      if (fixed == null) {
        fixed = part;
      } else
        try {
          if (context == null) {
            context = getInitialContext(hints);
          }
          fixed = context.composeName(fixed, part);
        } catch (NamingException e) {
          Logging.unexpectedException(GeoTools.class, "fixName", e);
          return name;
        }
    }
  }
  return fixed;
}

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

/**
 * Returns summary information about the GeoTools version and the host environment.
 *
 * @return information as a String
 */
public static String getEnvironmentInfo() {
  final String newline = String.format("%n");
  final StringBuilder sb = new StringBuilder();
  sb.append("GeoTools version ").append(getVersion().toString());
  if (sb.toString().endsWith("SNAPSHOT")) {
    sb.append(" (built from r").append(getBuildRevision().toString()).append(")");
  }
  sb.append(newline).append("Java version: ");
  sb.append(System.getProperty("java.version"));
  sb.append(newline).append("Operating system: ");
  sb.append(System.getProperty("os.name"))
      .append(' ')
      .append(System.getProperty("os.version"));
  return sb.toString();
}

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

/** Sets the metadata information. */
private void setInfo() {
  Map<String, String> info = new HashMap<String, String>();
  info.put("name", "ArcSDE Raster");
  info.put("description", "ArcSDE Raster Format");
  info.put("vendor", "Geotools ");
  info.put("docURL", "");
  info.put("version", GeoTools.getVersion().toString());
  mInfo = info;
  readParameters =
      new ParameterGroup(
          new DefaultParameterDescriptorGroup(
              mInfo,
              new GeneralParameterDescriptor[] {
                READ_GRIDGEOMETRY2D, OVERVIEW_POLICY
              }));
}

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

/**
 * Builds the default coverage contained in the current store
 *
 * @param nativeCoverageName the native name for the coverage
 * @param specifiedName the published name for the coverage. If null, the name will be
 *     determined from the coverage store.
 * @return coverage for the specified name
 * @throws Exception if the coverage store was not found or could not be read, or if the
 *     coverage could not be created.
 */
public CoverageInfo buildCoverageByName(String nativeCoverageName, String specifiedName)
    throws Exception {
  if (store == null || !(store instanceof CoverageStoreInfo)) {
    throw new IllegalStateException("Coverage store not set.");
  }
  CoverageStoreInfo csinfo = (CoverageStoreInfo) store;
  GridCoverage2DReader reader =
      (GridCoverage2DReader)
          catalog.getResourcePool()
              .getGridCoverageReader(csinfo, GeoTools.getDefaultHints());
  if (reader == null)
    throw new Exception(
        "Unable to acquire a reader for this coverage with format: "
            + csinfo.getFormat().getName());
  return buildCoverageInternal(reader, nativeCoverageName, null, specifiedName);
}

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

/**
 * Determines if the datastore is available.
 *
 * <p>Check in an Initial Context is available, that is all what can be done Checking for the
 * right jdbc jars in the classpath is not possible here
 */
public boolean isAvailable() {
  try {
    GeoTools.getInitialContext(GeoTools.getDefaultHints());
    return true;
  } catch (NamingException e) {
    return false;
  }
}

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

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

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

public AbstractEpsgFactory(final Hints userHints) throws FactoryException {
  super(MAXIMUM_PRIORITY - 20);
  // The following hints have no effect on this class behaviour,
  // but tell to the user what this factory do about axis order.
  hints.put(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.FALSE);
  hints.put(Hints.FORCE_STANDARD_AXIS_DIRECTIONS, Boolean.FALSE);
  hints.put(Hints.FORCE_STANDARD_AXIS_UNITS, Boolean.FALSE);
  //
  // We need to obtain our DataSource
  if (userHints != null) {
    Object hint = userHints.get(Hints.EPSG_DATA_SOURCE);
    if (hint instanceof String) {
      String name = (String) hint;
      try {
        dataSource = (DataSource) GeoTools.getInitialContext(userHints).lookup(name);
      } catch (NamingException e) {
        throw new FactoryException("A EPSG_DATA_SOURCE hint is required:" + e);
      }
      hints.put(Hints.EPSG_DATA_SOURCE, dataSource);
    } else if (hint instanceof DataSource) {
      dataSource = (DataSource) hint;
      hints.put(Hints.EPSG_DATA_SOURCE, dataSource);
    } else {
      throw new FactoryException("A EPSG_DATA_SOURCE hint is required.");
    }
  } else {
    throw new FactoryException("A EPSG_DATA_SOURCE hint is required.");
  }
}

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

final Hints defHints = GeoTools.getDefaultHints();

相关文章