Parth Trivedi Parth Trivedi - 1 year ago 112
Java Question

The method add(SimpleFeature) is undefined for the type SimpaleFeatureCollection

I am trying to implement one program for vectorization where I have following compile time error. I am using GeoTools 14.4.

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()];

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

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

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

Polygon poly = (Polygon);
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;

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])) {

if (insideEdges) {
} else {
// here it gives error "The method add(SimpleFeature) is undefined for the type SimpaleFeatureCollection"
return features;
} finally {

The full source code is here

Actually I copied 2 classes
and the rest is my GeoTiff 14.4 Code where I have below error.

The method add(SimpleFeature) is undefined for the type SimpaleFeatureCollection

Answer Source

I tried using following code as a workaround.

But the author who provided code on his website says the code will not work!!


 SimpleFeature feature = builder.buildFeature(null);
 ((Collection<SimpleFeature>) features).add(feature);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download