Package org.geotools.data.simple

Examples of org.geotools.data.simple.SimpleFeatureSource


        });
    }

    protected void moveFeatures( final Display display, IProgressMonitor monitor, ILayer selectedLayer, boolean moveUp )
            throws IOException {
        SimpleFeatureSource featureSource = (SimpleFeatureSource) selectedLayer.getResource(FeatureSource.class,
                new SubProgressMonitor(monitor, 1));
        if (featureSource == null) {
            return;
        }

        int delta = 1;
        if (!moveUp) {
            delta = -1;
        }

        IMap activeMap = ApplicationGIS.getActiveMap();
        List<ILayer> mapLayers = activeMap.getMapLayers();
        int currentPosition = mapLayers.indexOf(selectedLayer);

        int toPosition = currentPosition + delta;
        if (toPosition < 0 || toPosition > mapLayers.size() - 1) {
            showMessage(display,
                    Messages.getString("OperationUtils_warning"), Messages.getString("OperationUtils_nolayer"), MSGTYPE.WARNING); //$NON-NLS-1$ //$NON-NLS-2$
            return;
        }
        ILayer toLayer = mapLayers.get(toPosition);

        SimpleFeatureType toSchema = toLayer.getSchema();
        SimpleFeatureType selectedSchema = selectedLayer.getSchema();
        int compare = DataUtilities.compare(toSchema, selectedSchema);
        if (compare != 0) {
            showMessage(display,
                    Messages.getString("OperationUtils_warning"), Messages.getString("OperationUtils_sametypeproblem"), //$NON-NLS-1$ //$NON-NLS-2$
                    MSGTYPE.WARNING);
            return;
        }

        SimpleFeatureCollection featureCollection = featureSource.getFeatures(selectedLayer.getQuery(true));
        if (featureCollection.size() < 1) {
            showMessage(
                    display,
                    Messages.getString("OperationUtils_warning"), Messages.getString("OperationUtils_nofeaturesproblem"), MSGTYPE.WARNING); //$NON-NLS-1$ //$NON-NLS-2$
            return;
View Full Code Here


  @Override
  public void run() {
    ILayer selectedLayer = getContext().getSelectedLayer();
    Filter selectionFilter = selectedLayer.getFilter();
    try {
      SimpleFeatureSource source = selectedLayer.getResource(SimpleFeatureSource.class, ProgressManager.instance().get());
      ReferencedEnvelope bounds = source.getFeatures(selectionFilter).getBounds();
      getContext().sendASyncCommand(new SetViewportBBoxCommand(bounds, true));
    } catch (IOException e) {
      e.printStackTrace();
    }
   
View Full Code Here

   
    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
View Full Code Here

        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();
View Full Code Here

    private void prepareDraw( IProgressMonitor monitor ) throws IOException, SchemaException {

        // check for style information on the blackboard
        ILayer layer = getContext().getLayer();
        StyleBlackboard styleBlackboard = (StyleBlackboard) layer.getStyleBlackboard();
        SimpleFeatureSource featureSource;
        featureSource = layer.getResource(SimpleFeatureStore.class, new SubProgressMonitor(monitor, 0));
        if (featureSource == null) {
            featureSource = layer.getResource(SimpleFeatureSource.class, new SubProgressMonitor(monitor,
                    0));
        }
        Style style = getStyle(styleBlackboard, featureSource);
        layers = new Layer[1];
        CoordinateReferenceSystem layerCRS = layer.getCRS();
        SimpleFeatureType schema = featureSource.getSchema();
       
        // Original Query provided by Layer.getFilter() as adjusted by selection and edit filter
        Query query = getContext().getFeatureQuery();
        if( styleBlackboard.contains(ProjectBlackboardConstants.LAYER__STYLE_FILTER)){
            if( query == null ){
                query = new Query( schema.getTypeName() );
            }
            // Additional Filter provided as Style used to reduce onscreen clutter
            FilterStyle filterStyle = (FilterStyle) styleBlackboard.get(ProjectBlackboardConstants.LAYER__STYLE_FILTER);
            Filter styleFilter = filterStyle.toFilter(schema);
            if( styleFilter != Filter.INCLUDE ){
                Filter queryFilter = query.getFilter();
                if( queryFilter == Filter.INCLUDE ){
                    query.setFilter( styleFilter );
                }
                else {
                    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
                    Filter combinedFilter = ff.and(styleFilter, queryFilter);
                    query.setFilter( combinedFilter );
                }
            }
        }

        CoordinateReferenceSystem dataCRS = schema.getCoordinateReferenceSystem();
        if (!layerCRS.equals(dataCRS)) {
            // need to force the coordinate reference system to match the layer definition
            FeatureLayer featureLayer = new FeatureLayer(featureSource, style, layer.getName()); //$NON-NLS-1$
            if( query == null ){
                query = new Query(schema.getTypeName());
            }
            query.setCoordinateSystem(layerCRS);
            featureLayer.setQuery(query);
            // double check the implementation is respecting our layer CRS
            FeatureCollection<SimpleFeatureType, SimpleFeature> features = featureSource.getFeatures( query );
            CoordinateReferenceSystem queryCRS = features.getSchema().getCoordinateReferenceSystem();
           
            if(queryCRS.equals(layerCRS)){
                layers[0] = featureLayer;
            } else {
View Full Code Here

                 */
                pm.beginTask(Messages.getString("KmlExportWizard.taskExportingMap"), IProgressMonitor.UNKNOWN); //$NON-NLS-1$
                try {
                    if (geoResource.canResolve(SimpleFeatureSource.class)) {

                        SimpleFeatureSource featureStore = (SimpleFeatureSource) geoResource.resolve(SimpleFeatureSource.class,
                                pm);
                        KmlUtils.writeKml(new File(filePath), featureStore.getFeatures());
                    } else {
                        throw new IOException(Messages.getString("KmlExportWizard.error.ResourceIsNotAFeatureLayer") + geoResource.getTitle()); //$NON-NLS-1$
                    }

                } catch (Exception e) {
View Full Code Here

        if (adaptee.isAssignableFrom(IGeoResourceInfo.class)){
            return adaptee.cast(createInfo(monitor));
        }
        if (adaptee.isAssignableFrom(SimpleFeatureSource.class)) {
            WFSDataStore wfs = parent.getDS(monitor);
            SimpleFeatureSource featureSource = wfs.getFeatureSource(typename);
            return adaptee.cast(featureSource);           
        }
        if (adaptee.isAssignableFrom(FeatureStore.class)) {
            WFSDataStore wfs = parent.getDS(monitor);
            SimpleFeatureSource featureSource = wfs.getFeatureSource(typename);
            if( featureSource instanceof FeatureStore){
                return adaptee.cast(featureSource);
            }
            else {
                return null; // write access not available
View Full Code Here

   
      //get the dataStoreID
      String dataStoreID = thisLayer.getSchema().getName().getNamespaceURI();
   
      //create a FeatureReader (collection.reader)
      SimpleFeatureSource source;
      source = thisLayer.getResource(SimpleFeatureSource.class, monitor);
          SimpleFeatureCollection collection = source.getFeatures();
   
      //run the tests on this layer
      runFeatureTests(dataStoreID, collection, results);
    }
    }
View Full Code Here

public class CalculateLengthOp implements IOp {

  public void op(final Display display, Object target,
      IProgressMonitor monitor) throws Exception {   
    SimpleFeatureSource source = (SimpleFeatureSource) target;

    SimpleFeatureCollection featureCollection = source.getFeatures();

    double length = 0.0;
    FeatureIterator<SimpleFeature> iterator = featureCollection.features();
    try {
      while (iterator.hasNext()) {
        SimpleFeature feature = iterator.next();
        Geometry geometry = (Geometry) feature.getDefaultGeometry();

        length = length + geometry.getLength();
      }
    } finally {
      iterator.close();
    }
    final Name name = source.getName();
    final double answer = length;
    display.asyncExec(new Runnable() {
      public void run() {
        Shell shell = display.getActiveShell();
        MessageDialog.openInformation(shell, "Total Length",
View Full Code Here

  }

  @Override
  public synchronized ReferencedEnvelope getBounds() {
        if (bounds == null) {
            SimpleFeatureSource source = null;
            try {
                source = owner.resolve(SimpleFeatureSource.class, new NullProgressMonitor());
            } catch (IOException e) {
                PostgisPlugin.log("Could not establish bounds of dataset.", e); //$NON-NLS-1$
                bounds = new ReferencedEnvelope(new Envelope(), null);
                return bounds;
            }
            try {
                ReferencedEnvelope temp = source.getBounds();
                bounds = temp;
            } catch (Exception e) {
                PostgisPlugin.log("PostGIS unable to calculate bounds directly: "+e, e); //$NON-NLS-1$
            }
            if (bounds == null) {
                try {
                    CoordinateReferenceSystem crs = getCRS();
                    // try getting an envelope out of the crs
                    org.opengis.geometry.Envelope envelope = CRS.getEnvelope(crs);

                    if (envelope != null) {
                        bounds = new ReferencedEnvelope(new Envelope(envelope.getLowerCorner()
                                .getOrdinate(0), envelope.getUpperCorner().getOrdinate(0), envelope
                                .getLowerCorner().getOrdinate(1), envelope.getUpperCorner()
                                .getOrdinate(1)), crs);
                    } else {
                        // TODO: perhaps access a preference which indicates
                        // whether to do a full table scan
                        // bounds = new ReferencedEnvelope(new Envelope(),crs);
                        // as a last resort do the full scan
                        bounds = new ReferencedEnvelope(new Envelope(), crs);
                        FeatureIterator<SimpleFeature> iter = source.getFeatures().features();
                        try {
                            while (iter.hasNext()) {
                                SimpleFeature element = iter.next();
                                if (bounds.isNull())
                                    bounds.init(element.getBounds());
View Full Code Here

TOP

Related Classes of org.geotools.data.simple.SimpleFeatureSource

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.