Search in sources :

Example 1 with NullProgressListener

use of org.geotoolkit.util.NullProgressListener in project geotoolkit by Geomatys.

the class WPSClientDemo method main.

public static void main(String[] args) throws Exception {
    // force loading all image readers/writers
    ImageIO.scanForPlugins();
    // global initialization
    Setup.initialize(null);
    // Instantiate client :
    final URL wpsURL = new URL(SERVICE_URL);
    final WebProcessingClient wpsClient = new WebProcessingClient(wpsURL, WPSVersion.v100.getCode());
    // Once initialized, we can ask a description of wanted process, using its id.
    final WPSProcessingRegistry registry = new WPSProcessingRegistry(wpsClient);
    ProcessDescriptor desc = registry.getDescriptor(PROCESS_ID);
    // We can check process input & output.
    ParameterDescriptorGroup inputDesc = desc.getInputDescriptor();
    ParameterDescriptorGroup outputDesc = desc.getOutputDescriptor();
    // Iterate on wanted parameters. If one is missing, an exception is raised.
    LOGGER.log(Level.INFO, "INPUT : \n");
    for (INPUT in : INPUT.values()) {
        final GeneralParameterDescriptor current = inputDesc.descriptor(in.name);
        LOGGER.log(Level.INFO, "Parameter : " + current.getName().getCode() + " : \n\t" + current.getRemarks());
    }
    LOGGER.log(Level.INFO, "OUTPUT : \n");
    for (OUTPUT out : OUTPUT.values()) {
        final GeneralParameterDescriptor current = outputDesc.descriptor(out.name);
        LOGGER.log(Level.INFO, "Parameter : " + current.getName().getCode() + " : \n\t" + current.getRemarks());
    }
    GeometryFactory factory = org.geotoolkit.geometry.jts.JTS.getFactory();
    Geometry geometry = factory.toGeometry(new Envelope(1.0, 2.0, 43.3, 43.9));
    geometry.setUserData(CommonCRS.WGS84.geographic());
    final double bufDistance = 0.5;
    // Instantiate inputs. Those objects get the same behaviour that the descriptors. If we cannot find a specific
    // parameter, an exception is thrown.
    ParameterValueGroup input = inputDesc.createValue();
    input.parameter(INPUT.geom.name).setValue(geometry);
    input.parameter(INPUT.distance.name).setValue(bufDistance);
    // Process execution. It's synchronous here (talking only of client side, WPS can execute asynchronous process).
    // For asynchronous execution, we must execute it in a thread, using a process listener to get process state.
    org.geotoolkit.process.Process toExecute = desc.createProcess(input);
    toExecute.addListener(new NullProgressListener());
    ParameterValueGroup output = toExecute.call();
    // Get output values :
    for (OUTPUT out : OUTPUT.values()) {
        LOGGER.log(Level.INFO, String.format("%s parameter value : %s", out.name(), output.parameter(out.name).getValue()));
    }
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) ParameterDescriptorGroup(org.opengis.parameter.ParameterDescriptorGroup) GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor) WebProcessingClient(org.geotoolkit.wps.client.WebProcessingClient) Envelope(org.locationtech.jts.geom.Envelope) URL(java.net.URL) WPSProcessingRegistry(org.geotoolkit.wps.client.process.WPSProcessingRegistry) Geometry(org.locationtech.jts.geom.Geometry) NullProgressListener(org.geotoolkit.util.NullProgressListener) ProcessDescriptor(org.geotoolkit.process.ProcessDescriptor)

Example 2 with NullProgressListener

use of org.geotoolkit.util.NullProgressListener in project geotoolkit by Geomatys.

the class IndexedShapefileFeatureStore method buildQuadTree.

/**
 * Builds the QuadTree index. Usually not necessary since reading features
 * will index when required
 *
 * @param maxDepth depth of the tree. if < 0 then a best guess is made.
 */
public void buildQuadTree(final int maxDepth) throws TreeException {
    if (shpFiles.isWritable()) {
        shpFiles.unloadIndexes();
        getLogger().fine("Creating spatial index for " + shpFiles.get(SHP));
        final ShapeFileIndexer indexer = new ShapeFileIndexer();
        indexer.setIdxType(IndexType.QIX);
        indexer.setShapeFileName(shpFiles);
        indexer.setMax(maxDepth);
        try {
            indexer.index(false, new NullProgressListener());
        } catch (MalformedURLException e) {
            throw new TreeException(e);
        } catch (Exception e) {
            if (e instanceof TreeException) {
                throw (TreeException) e;
            } else {
                throw new TreeException(e);
            }
        }
    }
}
Also used : NullProgressListener(org.geotoolkit.util.NullProgressListener) MalformedURLException(java.net.MalformedURLException) TreeException(org.geotoolkit.index.TreeException) MismatchedFeatureException(org.opengis.feature.MismatchedFeatureException) TreeException(org.geotoolkit.index.TreeException) DataStoreException(org.apache.sis.storage.DataStoreException) UnsupportedQueryException(org.apache.sis.storage.UnsupportedQueryException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 3 with NullProgressListener

use of org.geotoolkit.util.NullProgressListener in project geotoolkit by Geomatys.

the class ShapeFileIndexer method main.

public static void main(final String[] args) throws IOException {
    if ((args.length < 1) || (((args.length - 1) % 2) != 0)) {
        usage();
    }
    long start = System.currentTimeMillis();
    ShapeFileIndexer idx = new ShapeFileIndexer();
    for (int i = 0; i < args.length; i++) {
        if (args[i].equals("-t")) {
            idx.setIdxType(IndexType.valueOf(args[++i]));
        } else if (args[i].equals("-M")) {
            idx.setMax(Integer.parseInt(args[++i]));
        } else if (args[i].equals("-m")) {
            idx.setMin(Integer.parseInt(args[++i]));
        } else if (args[i].equals("-b")) {
            idx.setByteOrder(args[++i]);
        } else {
            if (!args[i].toLowerCase().endsWith(".shp")) {
                System.out.println("File extension must be '.shp'");
                System.exit(1);
            }
            idx.setShapeFileName(new ShpFiles(args[i]));
        }
    }
    try {
        System.out.print("Indexing ");
        int cnt = idx.index(true, new NullProgressListener());
        System.out.println();
        System.out.print(cnt + " features indexed ");
        System.out.println("in " + (System.currentTimeMillis() - start) + "ms.");
        System.out.println();
    } catch (Exception e) {
        e.printStackTrace();
        usage();
        System.exit(1);
    }
}
Also used : NullProgressListener(org.geotoolkit.util.NullProgressListener) ShpFiles(org.geotoolkit.data.shapefile.lock.ShpFiles) TreeException(org.geotoolkit.index.TreeException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) StoreException(org.geotoolkit.index.quadtree.StoreException) DataStoreException(org.apache.sis.storage.DataStoreException)

Aggregations

NullProgressListener (org.geotoolkit.util.NullProgressListener)3 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 DataStoreException (org.apache.sis.storage.DataStoreException)2 TreeException (org.geotoolkit.index.TreeException)2 URL (java.net.URL)1 UnsupportedQueryException (org.apache.sis.storage.UnsupportedQueryException)1 ShpFiles (org.geotoolkit.data.shapefile.lock.ShpFiles)1 StoreException (org.geotoolkit.index.quadtree.StoreException)1 ProcessDescriptor (org.geotoolkit.process.ProcessDescriptor)1 WebProcessingClient (org.geotoolkit.wps.client.WebProcessingClient)1 WPSProcessingRegistry (org.geotoolkit.wps.client.process.WPSProcessingRegistry)1 Envelope (org.locationtech.jts.geom.Envelope)1 Geometry (org.locationtech.jts.geom.Geometry)1 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)1 MismatchedFeatureException (org.opengis.feature.MismatchedFeatureException)1 GeneralParameterDescriptor (org.opengis.parameter.GeneralParameterDescriptor)1 ParameterDescriptorGroup (org.opengis.parameter.ParameterDescriptorGroup)1 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)1