2016-08-08 1 views
0

J'essaie d'implémenter un programme de vectorisation où j'ai l'erreur de compilation suivante. J'utilise GeoTools 14.4.La méthode add (SimpleFeature) est indéfinie pour le type SimpaleFeatureCollection

private SimpleFeatureCollection assembleFeatures(GridCoverage2D grid, int band, 
     boolean insideEdges, SimpleFeatureType type, ProgressListener monitor) { 
    if (monitor == null) { 
     monitor = new NullProgressListener(); 
    } 

    SimpleFeatureCollection features = FeatureCollections.newCollection(); 

    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); 

    Point2D p = new Point2D.Double(); 
    double[] bandData = new double[grid.getNumSampleDimensions()]; 

    polygonizer.add(lines); 
    Collection polygons = polygonizer.getPolygons(); 
    final int size = polygons.size(); 
    try { 
     float progressScale = 100.0f/size; 
     monitor.started(); 

     int index = 0; 
     for (Iterator i = polygons.iterator(); i.hasNext(); index++) { 

      if (monitor.isCanceled()) { 
       throw new CancellationException(); 
      } 
      monitor.progress(progressScale * index); 

      Polygon poly = (Polygon) i.next(); 
      InteriorPointArea ipa = new InteriorPointArea(poly); 
      Coordinate c = ipa.getInteriorPoint(); 
      Point insidePt = geomFactory.createPoint(c); 

      if (!poly.contains(insidePt)) { 
       // try another method to generate an interior point 
       boolean found = false; 
       for (Coordinate ringC : poly.getExteriorRing().getCoordinates()) { 
        c.x = ringC.x + cellWidthX/2; 
        c.y = ringC.y; 
        insidePt = geomFactory.createPoint(c); 
        if (poly.contains(insidePt)) { 
         found = true; 
         break; 
        } 
       } 

       if (!found) { 
        throw new IllegalStateException("Can't locate interior point for polygon"); 
       } 
      } 

      p.setLocation(c.x, c.y); 
      bandData = grid.evaluate(p, bandData); 

      if (!isOutside(bandData[band])) { 
       builder.add(poly); 

       if (insideEdges) { 
        builder.add(bandData[band]); 
       } else { 
        builder.add(INSIDE_FLAG_VALUE); 
       } 
       features.add(builder.buildFeature(null)); 
       // here it gives error "The method add(SimpleFeature) is undefined for the type SimpaleFeatureCollection" 
      } 
     } 
     return features; 
    } finally { 
     monitor.complete(); 
    } 
} 

Le code source est here

En fait, je copié 2 classes RasterToVectorFactory.java et RasterToVectorProcess.java et le reste est mon GeoTiff 14.4 code où j'ai ci-dessous erreur.

La méthode add (SimpleFeature) est définie pour le type SimpaleFeatureCollection

+0

Regarder Javadoc pour [SimpleFeatureCollection] (http://docs.geotools.org/stable/javadocs/org/geotools/data/simple/ SimpleFeatureCollection.html) et c'est superinterface [FeatureCollection] (http://docs.geotools.org/stable/javadocs/org/geotools/feature/FeatureCollection.html), je ne vois aucune méthode 'add' – binoternary

Répondre

0

J'ai essayé en utilisant le code suivant comme solution de contournement.

Mais l'auteur qui a fourni le code sur son site Web dit que le code ne fonctionnera pas !!

//features.add(builder.buildFeature(null)); 

//add 
System.out.println("adding..."); 
SimpleFeature feature = builder.buildFeature(null); 
((Collection<SimpleFeature>) features).add(feature); 
0

Modifier déclaration de SimpleFeatureCollection à la classe DefaultFeatureCollection

DefaultFeatureCollection features = new DefaultFeatureCollection("your_id",type);