2016-08-08 70 views
0

我想实现一个矢量化程序,我有以下编译时错误。我正在使用GeoTools 14.4。方法添加(简单特征)是未定义的类型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(); 
    } 
} 

完整的源代码是here

其实我复制了2班RasterToVectorFactory.javaRasterToVectorProcess.java,剩下的就是我的支持GeoTiff 14.4代码,我有以下错误。

的方法Add(SimpleFeature)是未定义的类型SimpaleFeatureCollection

+0

看Javadoc文档[SimpleFeatureCollection](http://docs.geotools.org/stable/javadocs/org/geotools/data/simple/ SimpleFeatureCollection.html),它是超级接口[FeatureCollection](http://docs.geotools.org/stable/javadocs/org/geotools/feature/FeatureCollection.html),我没有看到任何'add'方法 – binoternary

回答

0

我尝试使用以下代码作为一种解决方法。

但是在他的网站上提供了代码的作者说代码不起作用! SimpleFeatureCollection的

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

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

更改声明DefaultFeatureCollection类

DefaultFeatureCollection features = new DefaultFeatureCollection("your_id",type); 
相关问题