AbstractGridFormat lookupGridFormat(Object obj) { AbstractGridFormat format = GridFormatFinder.findFormat(obj); if (format == null) { throw new RuntimeException("No format for " + obj); } return format; }
public static List listDataFormats() { List list = new ArrayList(); Format[] formats = GridFormatFinder.getFormatArray(); final int length = formats.length; for (int i = 0; i < length; i++) { if (!list.contains(formats[i])) { list.add(formats[i]); } } return Collections.synchronizedList(list); }
/** * return a gridcoverage for Raster file. Use a Map containing key "url" * @param params * @return GridCoverage */ public static GridCoverageReader getGridCoverageReader(Map params){ URL url = (URL) params.get("url"); if (url != null) { File file = DataUtilities.urlToFile(url); if (file != null&&file.exists()&&file.canRead()) { // try a geotiff gridcoverage GridFormatFinder.scanForPlugins(); final Format format=GridFormatFinder.findFormat(file); if(format!=null&&!(format instanceof UnknownFormat)) return ((AbstractGridFormat)format).getReader(file); } } return null; } }
/** * Returns all the {@link Format}s that can read the supplied {@link Object} o. * * @param o is the object to search a {@link Format} that is able to read * @return an unmodifiable {@link Set} comprising all the {@link Format} that can read the * {@link Object} o. */ public static synchronized Set<AbstractGridFormat> findFormats(Object o) { return findFormats(o, GeoTools.getDefaultHints()); }
/** * Finds all avalaible implementations of {@link GridFormatFactorySpi} which have registered * using the services mechanism, and that have the appropriate libraries on the classpath. * * @return An unmodifiable {@link Set} of all discovered datastores which have registered * factories, and whose available method returns true. */ public static synchronized Set<GridFormatFactorySpi> getAvailableFormats() { // get all GridFormatFactorySpi implementations scanForPlugins(); return getServiceRegistry() .getFactories(GridFormatFactorySpi.class, true) .filter(GridFormatFactorySpi::isAvailable) .collect(toUnmodifiableSet()); }
/** * Returns an array with all available {@link GridFormatFactorySpi} implementations. * * <p>It can be used toget basic information about all the available {@link GridCoverage} * plugins. Note that this method finds all the implemented plugins but returns only the * available one. * * <p>A plugin could be implemented but not available due to missing dependencies. * * @return an array with all available {@link GridFormatFactorySpi} implementations. */ public static Format[] getFormatArray() { final Set<GridFormatFactorySpi> formats = GridFormatFinder.getAvailableFormats(); final List<Format> formatSet = new ArrayList<Format>(formats.size()); for (Iterator<GridFormatFactorySpi> iter = formats.iterator(); iter.hasNext(); ) { final GridFormatFactorySpi element = iter.next(); formatSet.add(element.createFormat()); } return formatSet.toArray(new Format[formatSet.size()]); }
final Set<AbstractGridFormat> formats = findFormats(o, hints);
/** * Finds all avalaible implementations of {@link GridFormatFactorySpi} which * have registered using the services mechanism, and that have the * appropriate libraries on the classpath. * * @return An unmodifiable {@link Set} of all discovered datastores which * have registered factories, and whose available method returns * true. */ public static synchronized Set<GridFormatFactorySpi> getAvailableFormats() { // get all GridFormatFactorySpi implementations scanForPlugins(); final Iterator<GridFormatFactorySpi> it = getServiceRegistry(). getServiceProviders(GridFormatFactorySpi.class, true); final Set<GridFormatFactorySpi> formats= new HashSet<GridFormatFactorySpi>(); while (it.hasNext()) { final GridFormatFactorySpi spi = (GridFormatFactorySpi) it.next(); if (spi.isAvailable()) formats.add(spi); } return Collections.unmodifiableSet(formats); }
/** * Returns all the {@link Format}s that can read the supplied {@link Object} o. * * @param o is the object to search a {@link Format} that is able to read * @param hints the {@link Hints} to control the format search. * @return an unmodifiable {@link Set} comprising all the {@link Format} that can read the * {@link Object} o. */ public static synchronized Set<AbstractGridFormat> findFormats(Object o, Hints hints) { final Set<GridFormatFactorySpi> availableFormats = getAvailableFormats(); final Set<AbstractGridFormat> formats = new HashSet<AbstractGridFormat>(); final Iterator<GridFormatFactorySpi> it = availableFormats.iterator(); while (it.hasNext()) { // get the factory final GridFormatFactorySpi spi = it.next(); // create a format for it final AbstractGridFormat retVal = spi.createFormat(); // check if we can accept it if (retVal instanceof AbstractGridFormat) { if (retVal.accepts(o, hints)) formats.add(retVal); } } return Collections.unmodifiableSet(formats); }
private void addCoverageFromPath(QName name, File coverage, String relpath, String styleName) throws Exception { coverageInfo(name, coverage, styleName); // setup the meta information to be written in the catalog AbstractGridFormat format = (AbstractGridFormat) GridFormatFinder.findFormat(coverage); namespaces.put(name.getPrefix(), name.getNamespaceURI()); coverageStoresNamespaces.put(name.getLocalPart(), name.getPrefix()); Map params = new HashMap(); params.put(CatalogWriter.COVERAGE_TYPE_KEY, format.getName()); params.put(CatalogWriter.COVERAGE_URL_KEY, relpath); coverageStores.put(name.getLocalPart(), params); }
/** * Returns all the {@link Format}s that can read the supplied {@link Object} * o. * * @param o * is the object to search a {@link Format} that is able to read * @return an unmodifiable {@link Set} comprising all the {@link Format} * that can read the {@link Object} o. */ public static synchronized Set<AbstractGridFormat> findFormats(Object o) { return findFormats(o, GeoTools.getDefaultHints()); }
/** * Finds all avalaible implementations of {@link GridFormatFactorySpi} which * have registered using the services mechanism, and that have the * appropriate libraries on the classpath. * * @return An unmodifiable {@link Set} of all discovered datastores which * have registered factories, and whose available method returns * true. */ public static synchronized Set getAvailableFormats() { // get all GridFormatFactorySpi implementations scanForPlugins(); Iterator it = getServiceRegistry(). getServiceProviders(GridFormatFactorySpi.class, true); final Set formats= new HashSet(5); GridFormatFactorySpi spi; while (it.hasNext()) { spi = (GridFormatFactorySpi) it.next(); if (spi.isAvailable()) formats.add(spi); } return Collections.unmodifiableSet(formats); }
/** * When loading from DTO use the params to locate factory. * * <p>bleck */ public static Format aquireFactoryByType(String type) { final Format[] formats = GridFormatFinder.getFormatArray(); Format format = null; final int length = formats.length; for (int i = 0; i < length; i++) { format = formats[i]; if (format.getName().equals(type)) { return format; } } return null; }
/** * Returns an array with all available {@link GridFormatFactorySpi} * implementations. * * <p> * It can be used toget basic information about all the available * {@link GridCoverage} plugins. Note that this method finds all the * implemented plugins but returns only the availaible one. * * <p> * A plugin could be implemented but not availaible due to missing * dependencies. * * * @return an array with all available {@link GridFormatFactorySpi} * implementations. */ public static Format[] getFormatArray() { final Set<GridFormatFactorySpi> formats = GridFormatFinder.getAvailableFormats(); final List<Format> formatSet = new ArrayList<Format>(formats.size()); for (Iterator<GridFormatFactorySpi> iter = formats.iterator(); iter.hasNext();) { final GridFormatFactorySpi element = (GridFormatFactorySpi) iter.next(); formatSet.add(element.createFormat()); } return (Format[]) formatSet.toArray(new Format[formatSet.size()]); }
@Override public void createIndividuals() { LOG.info("Loading population from raster file {}", sourceFilename); try { File rasterFile = new File(sourceFilename); // determine file format and CRS, then load raster AbstractGridFormat format = GridFormatFinder.findFormat(rasterFile); AbstractGridCoverage2DReader reader = format.getReader(rasterFile); GridCoverage2D coverage = reader.read(null); this.coverageCRS = coverage.getCoordinateReferenceSystem(); GridGeometry2D gridGeometry = coverage.getGridGeometry(); GridEnvelope2D gridEnvelope = gridGeometry.getGridRange2D(); gridGeometry.getGridToCRS(); // because we may want to produce an empty raster rather than loading one, alongside the coverage we // store the row/col dimensions and the referenced envelope in the original coordinate reference system. this.cols = gridEnvelope.width; this.rows = gridEnvelope.height; this.createIndividuals0(); } catch (Exception ex) { throw new IllegalStateException("Error loading population from raster file: ", ex); } LOG.info("Done loading raster from file."); }
/** * Returns a {@link Format} that is able to read a certain object. If no * {@link Format} is able to read such an {@link Object} we return an * {@link UnknownFormat} object. * * <p> * It is worth to point out that this method will try to convert each format * implementation to {@link AbstractGridFormat} because the original * {@link Format} interface did not allow for an accept method hence we had * to subclass the interface to add such method and we did so by the * {@link AbstractGridFormat} abstract class. * * @param o * the object to check for acceptance. * @return an {@link AbstractGridFormat} that has stated to accept this * {@link Object} o or <code>null</code> in no plugins was able to * accept it. */ public static synchronized Format findFormat(Object o) { final Set formats = findFormats(o); final Iterator it = formats.iterator(); if (it.hasNext()) return (Format) it.next(); return new UnknownFormat(); } }
public static Format acquireFormat(String type) throws IOException { Format[] formats = GridFormatFinder.getFormatArray(); Format format = null; final int length = formats.length; for (int i = 0; i < length; i++) { if (formats[i].getName().equals(type)) { format = formats[i]; break; } } if (format == null) { throw new IOException("Cannot handle format: " + type); } else { return format; } }
/** * Returns an array with all available {@link GridFormatFactorySpi} * implementations. * * <p> * It can be used toget basic information about all the available * {@link GridCoverage} plugins. Note that this method finds all the * implemented plugins but returns only the availaible one. * * <p> * A plugin could be implemented but not availaible due to missing * dependencies. * * * @return an array with all available {@link GridFormatFactorySpi} * implementations. */ public static Format[] getFormatArray() { GridFormatFactorySpi element; Set formats = GridFormatFinder.getAvailableFormats(); List formatSet = new ArrayList(formats.size()); for (Iterator iter = formats.iterator(); iter.hasNext();) { element = (GridFormatFactorySpi) iter.next(); formatSet.add(element.createFormat()); } return (Format[]) formatSet.toArray(new Format[formatSet.size()]); }
/** Keys for overriding default layer properties */ public static class StyleProperty<T> { T get(Map<StyleProperty, Object> map, T def) { return map != null && map.containsKey(this) ? (T) map.get(this) : def; } public static StyleProperty<String> FORMAT = new StyleProperty<String>(); public static StyleProperty<Version> FORMAT_VERSION = new StyleProperty<Version>(); public static StyleProperty<LegendInfo> LEGEND_INFO = new StyleProperty<LegendInfo>(); }
/** * Returns a {@link Format} that is able to read a certain object. If no * {@link Format} is able to read such an {@link Object} we return an * {@link UnknownFormat} object. * * <p> * It is worth to point out that this method will try to convert each format * implementation to {@link AbstractGridFormat} because the original * {@link Format} interface did not allow for an accept method hence we had * to subclass the interface to add such method and we did so by the * {@link AbstractGridFormat} abstract class. * * @param o * the object to check for acceptance. * @param hints * the {@link Hints} to control the format search. * @return an {@link AbstractGridFormat} that has stated to accept this * {@link Object} o or <code>null</code> in no plugins was able to * accept it. */ public static synchronized AbstractGridFormat findFormat(Object o, Hints hints) { final Set<AbstractGridFormat> formats = findFormats(o,hints); final Iterator<AbstractGridFormat> it = formats.iterator(); if (it.hasNext()){ return (AbstractGridFormat) it.next(); } return new UnknownFormat(); } }