Package org.locationtech.udig.catalog

Examples of org.locationtech.udig.catalog.IGeoResource


                    FeatureCollection<SimpleFeatureType, SimpleFeature> csvFileFeatureCollection = csvFileToFeatureCollection(
                            csvFile, crs, fieldsAndTypesIndex, separator, pm);

                    SimpleFeatureType featureType = csvFileFeatureCollection.getSchema();
                    JGrassCatalogUtilities.removeMemoryServiceByTypeName(featureType.getTypeName());
                    IGeoResource resource = CatalogPlugin.getDefault().getLocalCatalog().createTemporaryResource(featureType);

                    SimpleFeatureStore resolve = (SimpleFeatureStore) resource.resolve(FeatureStore.class, pm);
                    resolve.addFeatures(csvFileFeatureCollection);
                    ApplicationGIS.addLayersToMap(ApplicationGIS.getActiveMap(), Collections.singletonList(resource), -1);

                } catch (Exception e) {
                    e.printStackTrace();
View Full Code Here


     *
     * @param layer
     */
    public void setLayer( Layer layer ) {
        this.layer = layer;
        IGeoResource resource = layer.getGeoResource();
        try {
            gridCoverage = resource.resolve(GridCoverage2D.class, new NullProgressMonitor());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
View Full Code Here

               
                if( element instanceof IService){
                    return selection;
                }               
                else if (element instanceof IGeoResource ){
                    IGeoResource resource = (IGeoResource) element;
                    return toServiceSelection(resource);
                }
                else if (element instanceof IResolve ){
                    IResolve resolve = (IResolve) element;
                    if( resolve.canResolve( IService.class)){
                        try {
                            IService service = resolve.resolve( IService.class, new NullProgressMonitor() );
                            return new StructuredSelection( service );
                        } catch (IOException e) {
                            return StructuredSelection.EMPTY;
                        }
                    }
                }
                // check IAdaptable incase ILayer or another selection wants to play
                if( element instanceof IAdaptable ){
                    IAdaptable adaptable = (IAdaptable) element;
                    IService service = (IService) adaptable.getAdapter(IService.class);
                    if( service != null ){
                        return new StructuredSelection( service );
                    }
                    IGeoResource resource = (IGeoResource) adaptable.getAdapter(IGeoResource.class);
                    if( resource != null ){
                        return toServiceSelection(resource);
                    }
                    IResolve resolve = (IResolve) adaptable.getAdapter(IResolve.class);
                    if( resolve != null ){
View Full Code Here

public class TransformOperation implements IOp {

   
    public void op(final Display display, Object target, final IProgressMonitor monitor)
            throws Exception {
        final IGeoResource handle = (IGeoResource) target;
        final SimpleFeatureSource featureSource = handle.resolve( SimpleFeatureSource.class, null);
        SimpleFeature feature;
        final FeatureCollection<SimpleFeatureType, SimpleFeature> collection = featureSource
                .getFeatures();
        FeatureIterator<SimpleFeature> iterator = collection.features();
        try {
            if (!iterator.hasNext()) {
                return; // no contents ... ignore
            }
            feature = iterator.next();
        } finally {
            iterator.close();
        }
        final SimpleFeature sample = feature;
        PlatformGIS.asyncInDisplayThread( new Runnable(){
            public void run() {
                final TransformDialog dialog = new TransformDialog( display.getActiveShell(), sample );
                int result = dialog.open();
                if( result == Window.CANCEL ){
                    return;
                }
                if( result == Window.OK){
                    try {
                        PlatformGIS.runBlockingOperation( new IRunnableWithProgress(){
                            public void run(IProgressMonitor monitor) {
                                try {
                                    final IGeoResource reshaped = process( featureSource, dialog, monitor );
                                    PlatformGIS.asyncInDisplayThread(new Runnable(){

                                        public void run() {
                                            dialog.executePostAction(handle, reshaped);
                                        }
View Full Code Here

            SimpleFeatureCollection output = process.executeList(collection, transform);

           
            final SimpleFeatureType featureType = output.getSchema();
           
            IGeoResource scratch = CatalogPlugin.getDefault().getLocalCatalog().createTemporaryResource( featureType );
            final SimpleFeatureStore store = scratch.resolve(SimpleFeatureStore.class, SubMonitor.convert(monitor,Messages.ReshapeOperation_createTempSpaceTask, 10));
           
            store.setTransaction( transaction );
           
            ProgressListener progessListener = GeoToolsAdapters.progress( SubMonitor.convert(monitor,"processing "+source.getName(), 90));         //$NON-NLS-1$
View Full Code Here

    public String getText( Object element ) {
        if (element instanceof IResolve) {
            IResolve resolve = (IResolve) element;
            try {
                if (resolve instanceof IGeoResource) {
                    IGeoResource resource = (IGeoResource) resolve;
                    String title = resource.getTitle();
// This provider should be non-blocking                   
//                    if (title == null) {
//                        IGeoResourceInfo info = resource.getInfo(new NullProgressMonitor());
//                        if(info != null) {
//                          title = info.getTitle();
//                        }
//                    }
                    ID id = resource.getID();
                    if(title == null) {
                      title = id.labelResource();
                    }
                    return title;
View Full Code Here

                    notifyListeners(object);
                }

            });

            final IGeoResource resource = object.findGeoResource(FeatureStore.class);
            if (resource != null && ids.add(resource.getIdentifier())) {
                CatalogPlugin.getDefault().getLocalCatalog().addCatalogListener(
                        new ObjectPropertyCatalogListener(object, resource, isEvaluating, this));
            }
           
//TODO codereview: This resolves http://jira.codehaus.org/browse/UDIG-1686
//            final FeatureStore<?,?> store  = object.getResource(FeatureStore.class, ProgressManager.instance().get());
//            return store != null;
            boolean canResolve = resource.canResolve(FeatureStore.class);
            return canResolve;
        } catch (Exception e) {
            return false;
        } finally {
            isEvaluating.set(false);
View Full Code Here

                public void blackBoardCleared( IBlackboard source ) {
                    notifyListeners(object);
                }
            });

            final IGeoResource resource = object.findGeoResource(FeatureSource.class);
            if (resource != null && ids.add(resource.getIdentifier())) {
                CatalogPlugin.getDefault().getLocalCatalog().addCatalogListener(
                        new ObjectPropertyCatalogListener(object, resource, isEvaluating, this));
            }
            boolean canResolve = resource.canResolve(FeatureSource.class);
            return canResolve;
        } catch (Exception e) {
            return false;
        } finally {
            isEvaluating.set(false);
View Full Code Here

    private boolean exportResource( Data data, IProgressMonitor monitor ) {
        if (monitor == null)
            monitor = new NullProgressMonitor();

        final WizardDialog wizardDialog = (WizardDialog) getContainer();
        IGeoResource resource = data.getResource();

        try {
            SimpleFeatureSource fs = resource.resolve(SimpleFeatureSource.class, null);
            SimpleFeatureCollection fc = fs.getFeatures(data.getQuery());

            // TODO: remove from catalog/close layers if open?
            SimpleFeatureType schema = fs.getSchema();
            if (data.getName() != null) {
                SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
                builder.init(schema);
                builder.setName(data.getName());
                schema = builder.buildFeatureType();
            }

            File file = determineDestinationFile(data);

            monitor.beginTask("", IProgressMonitor.UNKNOWN); //$NON-NLS-1$

            CoordinateReferenceSystem fromCRS = schema.getCoordinateReferenceSystem();
            CoordinateReferenceSystem crs = data.getCRS();
            MathTransform mt;

            if (fromCRS != null && crs != null) {
                mt = CRS.findMathTransform(fromCRS, crs, true);
            } else {
                if (crs != null)
                    mt = IdentityTransform.create(crs.getCoordinateSystem().getDimension());
                else if (fromCRS != null)
                    mt = IdentityTransform.create(fromCRS.getCoordinateSystem().getDimension());
                else
                    mt = IdentityTransform.create(2);

            }

            if (isAbstractGeometryType(schema)) {
                // possibly multiple geometry types
                String geomName = schema.getGeometryDescriptor().getName().getLocalPart();

                DefaultFeatureCollection pointCollection = new DefaultFeatureCollection();
                DefaultFeatureCollection lineCollection = new DefaultFeatureCollection();
                DefaultFeatureCollection polygonCollection = new DefaultFeatureCollection();

                SimpleFeatureCollection featureCollection = fs.getFeatures();
                FeatureIterator<SimpleFeature> featureIterator = featureCollection.features();
                while( featureIterator.hasNext() ) {
                    SimpleFeature feature = featureIterator.next();
                    String geometryType = ((Geometry) feature.getDefaultGeometry())
                            .getGeometryType();

                    if (geometryType.endsWith("Point")) {
                        pointCollection.add(feature);
                    } else if (geometryType.endsWith("LineString")) {
                        lineCollection.add(feature);
                    } else if (geometryType.endsWith("Polygon")) {
                        polygonCollection.add(feature);
                    }
                }

                if (polygonCollection.size() > 0) {
                    exportPolygonFeatures(data, monitor, file, polygonCollection, schema, geomName,
                            mt);
                }
                if (pointCollection.size() > 0) {
                    exportPointFeatures(data, monitor, file, pointCollection, schema, geomName, mt);
                }
                if (lineCollection.size() > 0) {
                    exportLineFeatures(data, monitor, file, lineCollection, schema, geomName, mt);
                }
            } else {
                // single geometry type
                SimpleFeatureType destinationFeatureType = createFeatureType(schema,
                        (Class< ? extends Geometry>) schema.getGeometryDescriptor().getType()
                                .getBinding(), crs);
                ReprojectingFeatureCollection processed = new ReprojectingFeatureCollection(fc,
                        monitor, destinationFeatureType, mt);
                boolean success = writeToShapefile(processed, destinationFeatureType, file);
                if (success) {
                    addToCatalog(file, data);
                } else {
                    Display.getDefault().asyncExec(new Runnable(){
                        public void run() {
                            String msg = "No features were exported; did you select anything?"; //$NON-NLS-1$
                            CatalogUIPlugin.log(msg, null);
                            wizardDialog.setErrorMessage(msg);
                        }
                    });
                    return false;
                }
            }
        } catch (IOException e) {
            String msg = MessageFormat.format(Messages.CatalogExport_layerFail, resource
                    .getIdentifier());
            CatalogUIPlugin.log(msg, e);
            wizardDialog.setErrorMessage(msg);
            return false;
        } catch (IllegalFilterException e) {
            String msg = MessageFormat.format(Messages.CatalogExport_layerFail, resource
                    .getIdentifier());
            CatalogUIPlugin.log(msg, e);
            wizardDialog.setErrorMessage(msg);
            return false;
        } catch (SchemaException e) {
            String msg = MessageFormat.format(Messages.CatalogExport_layerFail, resource
                    .getIdentifier());
            CatalogExport.setError(wizardDialog, msg, e);
            return false;
        } catch (FactoryException e) {
            String msg = resource.getIdentifier() + Messages.CatalogExport_reprojectError;
            CatalogExport.setError(wizardDialog, msg, e);
            return false;
        } catch (RuntimeException e) {
            e.printStackTrace();
            if (e.getCause() instanceof TransformException) {
                String msg = resource.getIdentifier() + Messages.CatalogExport_reprojectError;
                CatalogExport.setError(wizardDialog, msg, e);
            } else {
                String msg = MessageFormat.format(Messages.CatalogExport_layerFail, resource
                        .getIdentifier());
                CatalogExport.setError(wizardDialog, msg, e);
            }
            return false;
        }
View Full Code Here

                    parent = null;
                }
                List<IResolve> path = new ArrayList<IResolve>();

                if (parent instanceof IGeoResource) {
                    IGeoResource parentResource = (IGeoResource) parent;
                    path.addAll(toTreePath(parentResource));
                } else if (parent instanceof IService) {
                    IService service = (IService) parent;
                    path.add(service);
                }
View Full Code Here

TOP

Related Classes of org.locationtech.udig.catalog.IGeoResource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.