Package org.geotools.data

Examples of org.geotools.data.DataStore


    private boolean error = false;

    public void op( final Display display, final Object target, final IProgressMonitor monitor )
            throws Exception {
        final IService service = (IService) target;
        final DataStore ds = service.resolve(DataStore.class, monitor);
        if (!(ds instanceof ShapefileDataStore)) {
            try {
                ds.createSchema(null);
            } catch (UnsupportedOperationException e) {
                if (testing) {
                    error = true;
                    return;
                } else {
                    display.asyncExec(new Runnable(){
                        public void run() {
                            MessageDialog
                                    .openInformation(display.getActiveShell(),
                                            Messages.NewFeatureTypeOp_title,
                                            Messages.NewFeatureTypeOp_message);
                        }
                    });
                    return;
                }
            } catch (Exception e) {
                // try it
            }
        }

        final SimpleFeatureType[] featureType = new SimpleFeatureType[1];
        if (!testing) {
           
            final FeatureTypeEditorDialog[] dialog=new FeatureTypeEditorDialog[1];
            PlatformGIS.syncInDisplayThread(new Runnable(){
                public void run() {
                    dialog[0] = new FeatureTypeEditorDialog(display
                            .getActiveShell(), new ValidateFeatureType(){

                                public String validate( SimpleFeatureType featureBuilder ) {
                                    return null;
                                }
                       
                    });
                }
            });
            int code=-1;
            do {
                code=openDialog(display, dialog[0], ds);
                if( code==Window.CANCEL){
                    featureType[0]=null;
                }else
                    featureType[0]=dialog[0].getFeatureType(true);
            } while( featureType[0] == null && code==Window.OK);
        } else {
            featureType[0] = DataUtilities.createType("TestName", "Geom:MultiLineString"); //$NON-NLS-1$ //$NON-NLS-2$
        }
        if (featureType[0] == null)
            return;

        try {

            if (ds instanceof ShapefileDataStore) {
                createShapefile(display, monitor, featureType[0], service.getIdentifier());
            } else {
                ds.createSchema(featureType[0]);
                long start=System.currentTimeMillis();
                while( !Arrays.asList(ds.getTypeNames()).contains(featureType[0].getName().getLocalPart() ) && start+5000>System.currentTimeMillis()){
                    Thread.sleep(300);
                }
                       
                ResetService.reset(Collections.singletonList(service), new SubProgressMonitor(monitor, 2));
            }
        } catch (IOException e) {
            CatalogUIPlugin.log("Error creating feature type in datastore: "+ds.getClass(), e); //$NON-NLS-1$
            display.asyncExec(new Runnable(){
                public void run() {
                    MessageDialog.openError(display.getActiveShell(), Messages.NewFeatureTypeOp_0,
                            Messages.NewFeatureTypeOp_1 +
                            Messages.NewFeatureTypeOp_2+ds.getClass().getSimpleName())
                }
            });
            return;
        }
View Full Code Here


        ShapefileDataStoreFactory factory = new ShapefileDataStoreFactory();
        Map<String, Serializable> params = new HashMap<String, Serializable>();
        params.put(ShapefileDataStoreFactory.URLP.key, file.toURI().toURL());
        params.put(ShapefileDataStoreFactory.CREATE_SPATIAL_INDEX.key, true);
       
        DataStore ds = factory.createDataStore(params);
        ds.createSchema(type);
        List<IService> service = CatalogPlugin.getDefault().getServiceFactory().createService(
                file.toURI().toURL());
        for( IService service2 : service ) {
            try {
                if (service2.resolve(DataStore.class, monitor) instanceof ShapefileDataStore)
View Full Code Here

            try {
                IGeoResource geoResource = layer.findGeoResource(FeatureSource.class);
                IService service = geoResource.service(ProgressManager.instance().get());
               
                if (service != null) {
                    DataStore ds = service.resolve(DataStore.class,
                            ProgressManager.instance().get());
                    if (ds == null){
                        return resource; // not a datastore give up!
                    }
                    String typeName = resource.getSchema().getTypeName();
View Full Code Here

    }
    /*
     * @see org.locationtech.udig.catalog.IService#getInfo(org.eclipse.core.runtime.IProgressMonitor)
     */
    protected IServiceInfo createInfo( IProgressMonitor monitor ) throws IOException {
        DataStore dataStore = getDS(monitor); // load ds
        if (dataStore == null) {
            return null; // could not connect no info for you
        }
        rLock.lock();
        try {
View Full Code Here

                String value = labelProvider.getText(domain);
                itemNames.add(value);
            }
            itemLayers = new ArrayList<DataStore>();
            for( String name : itemNames ) {
                DataStore tmpLayer = itemsMap.get(name);
                if (tmpLayer != null) {
                    itemLayers.add(tmpLayer);
                }
            }
        }
View Full Code Here

        try {
            MemoryServiceExtensionImpl ext = new MemoryServiceExtensionImpl();
            URL id = new URL("http://localhost/scratch"); //$NON-NLS-1$
            params = ext.createParams(id);
            IService service = ext.createService(id, params);
            DataStore ds = service.resolve(DataStore.class, monitor);
            int i=0;
            String typename="New_Type_"; //$NON-NLS-1$
            List<String> typenames = Arrays.asList(ds.getTypeNames());
            while( typenames.contains(typename+i)){
                i++;
            }
            SimpleFeatureTypeBuilder build = new SimpleFeatureTypeBuilder();
            build.setName(typename+i);
            build.setNamespaceURI( "http://udig.refractions.net");
            build.setAbstract(false);
            build.add(Messages.NewServiceConnectionFactory_defaultGeom,com.vividsolutions.jts.geom.Geometry.class);
           
            SimpleFeatureType schema = build.buildFeatureType();
           
            ds.createSchema( schema ); //$NON-NLS-1$
        } catch (Exception e) {
            CatalogUIPlugin.log("Error creating MemoryDatastore or feature type", e); //$NON-NLS-1$
            return null;
        }finally{
            monitor.done();
View Full Code Here

                throw new RuntimeException("Error creating the SimpleFeatureType schema, this is a bug", e);
            }
           
            assert mapper.isValid();

            DataStore dataStore;
            try {
                dataStore = getDataStore();
            } catch (IOException e) {
                return "Unable to connect to the datastore, check connection parameters";
            }
           
            try {
                if( Arrays.asList(dataStore.getTypeNames()).contains(layer)){
                    return "Type exists choose a new name";
                }
            } catch (IOException e) {
                return "Error communicating with datastore, check connection and availability of service";
            }
           
            try {
                dataStore.createSchema(mapper.getSchema());
            } catch (IOException e) {
                return "Error creating SimpleFeatureType verify that you have write access";
            }
           
            return null;
View Full Code Here

    }
   
    protected abstract DataStore getDataStore() throws IOException;

    protected synchronized FeatureStore<SimpleFeatureType, SimpleFeature> getFeatureStore() throws IOException {
        DataStore ds=getDataStore();
        if ( ds==null )
            return null;
        if( featureStore!=null )
            return featureStore;
       
        List<String> typeNames = Arrays.asList(ds.getTypeNames());
        if( !typeNames.contains(layer) )
            return null;
        FeatureSource<SimpleFeatureType, SimpleFeature> fs = ds.getFeatureSource(layer);
        if( fs instanceof FeatureStore )
            featureStore=(FeatureStore<SimpleFeatureType, SimpleFeature>) fs;
       
        return featureStore;
    }
View Full Code Here

        File file = new File("data/point.shp");
       
        Map<String, Serializable> map = new HashMap<String, Serializable>();
        map.put( "url", file.toURI().toURL() );
        map.put( "fstype", "shape-ng" );
        DataStore dataStore = DataStoreFinder.getDataStore(map);
       
        boolean test = false;
       
        if(dataStore instanceof org.geotools.data.shapefile.ShapefileDataStore){
            test  = true;
        }
        assertTrue( "Check Next Generation ShapefileDataStore", test );
        assertEquals("package",dataStore.getClass().getPackage(), org.geotools.data.shapefile.ShapefileDataStore.class.getPackage());
    }
View Full Code Here

       
        File file = new File("data/point.shp");
        Map<String, Serializable> map = new HashMap<String, Serializable>();
        map.put( "url", file.toURI().toURL() );
        map.put( "fstype", "shape" );
        DataStore dataStore = DataStoreFinder.getDataStore(map);
       
        String packageName = dataStore.getClass().getPackage().getName();
        System.out.println(packageName);
       
//        boolean test = false;
//        if(dataStore instanceof IndexedShapefileDataStore){
//            test  = true;
View Full Code Here

TOP

Related Classes of org.geotools.data.DataStore

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.