Package org.geotools.validation

Examples of org.geotools.validation.FeatureValidation


   * @see org.geotools.validation.ValidationProcessor.addValidation
   */
  public void addValidation(Validation validation, PlugInDTO plugin, Object testSuiteDTOKey) {
    //call the appropriate superclass method to add the validation to the feature/integrity lookup
    if (validation instanceof FeatureValidation) {
      FeatureValidation FV = (FeatureValidation) validation;
      super.addValidation(FV);
    } else if (validation instanceof IntegrityValidation) {
      IntegrityValidation IV = (IntegrityValidation) validation;
      super.addValidation(IV);
    }
View Full Code Here


     * @throws Exception
     */
  public void runFeatureTest(Object testName, ILayer[] layers, ValidationResults results, IProgressMonitor monitor) throws Exception {

    // get the validator from testKey
    FeatureValidation validator = null;
    // (navigate through the featureLookup until we find an instance of the test)
    for (Iterator i = featureLookup.keySet().iterator(); i.hasNext();) {
      ArrayList testList = (ArrayList) featureLookup.get(i.next());
      // iterate through each item in the list
      for (Object thisTest : testList) {
        Validation test = (Validation) thisTest;
        // this is the matching validation for the given test
        if (test.getName().equals(testName)) {
          validator = (FeatureValidation) test;
          break;
        }
      }
    }

    // run the test
    if (validator != null) // if we found the test
    {
      results.setValidation(validator);
      //get a list of typeRefs to figure out which layers to run the test on
      String[] typeRefs = validator.getTypeRefs();
      if (typeRefs == null) {
        //unfortunately, ALL typeRefs = null; we'll override that for now
        typeRefs = new String[1];
        typeRefs[0] = "*"; //$NON-NLS-1$
//      } else if (typeRefs.length == 0) {
//        return; //TODO: add messageBox "there are no typeRefs!"
      }
      Set<ILayer> relevantLayers = new HashSet<ILayer>();
      for (int i = 0; i < typeRefs.length; i++) {
        String typeRef = (String) typeRefs[i];
        if (typeRef.equals("") || (typeRef.equals("*"))) {  //$NON-NLS-1$//$NON-NLS-2$
          //wildcard (I assume); add all layers to the relevantLayers and break
          for (int j = 0; j < layers.length; j++) {
            ILayer thisLayer = layers[j];
            relevantLayers.add(thisLayer);
          }           
          break;
        }
        //find the layer that matches the typeRef
        for (int j = 0; j < layers.length; j++) {
          ILayer thisLayer = layers[j];
          //make the typeRef
          SimpleFeatureType schema = thisLayer.getSchema();
          if(schema == null)
            continue;
         
          String dataStoreID = schema.getName().getNamespaceURI();
          String thisTypeRef = dataStoreID+":"+schema.getName().getLocalPart(); //$NON-NLS-1$
          //if the typeRefs match, add the layer to our set
          if (thisTypeRef.equals(typeRef)) {
            relevantLayers.add(thisLayer);
            break;
          }
        }
      }
     
      //for each relevant layer
      for (Iterator k = relevantLayers.iterator(); k.hasNext();) {
                ILayer thisLayer = (ILayer) k.next();
        //get the SimpleFeatureType
        SimpleFeatureType type = thisLayer.getSchema();
        //create a FeatureReader (collection.reader)
        FeatureSource<SimpleFeatureType, SimpleFeature> source;
        source = thisLayer.getResource(FeatureSource.class, monitor);
                FeatureCollection<SimpleFeatureType, SimpleFeature> collection = source.getFeatures();
                //hmm... pretty pictures or efficiency?
                int count = collection.size();
                monitor.beginTask("", count); //$NON-NLS-1$
                FeatureIterator<SimpleFeature> reader = collection.features();
                // iterate through each feature and run  the test on it
            int position = 0;
                while (reader.hasNext())
            {
                    //check for the cancel button
                    if (monitor.isCanceled()) {
                        reader.close();
                        break;
                    }
                    //validate this feature
                    monitor.subTask(++position + "/" + count); //$NON-NLS-1$
                    SimpleFeature feature = (SimpleFeature) reader.next();
          try {
            validator.validate(feature, type, results);
          } catch (Throwable e) {
            results.error(feature, e.getMessage());
          }
                    monitor.worked(1);
            }
View Full Code Here

                }
            }
           
        });
       
        final FeatureValidation featureValidation = getValidator();
        if (featureValidation == null) return;
        //IsValidGeometryValidation geometryValidation = new IsValidGeometryValidation();
        SimpleFeatureType type;
       
        // iterate through the collection and validate each feature
        FeatureIterator<SimpleFeature> iterator = collection.features();
        while( iterator.hasNext()){
           
            SimpleFeature feature = (SimpleFeature) iterator.next();
           
            type = feature.getFeatureType();
            if (canValidate(type)) {
                featureValidation.validate(feature, type, results);
            }
        }
        iterator.close();
       
        OpUtils.setSelection(layer, results);
View Full Code Here

TOP

Related Classes of org.geotools.validation.FeatureValidation

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.