Collection<StackedPoint> stackedPts = stackPoints(data, crsTransform, cellSizeSrc,
outputEnv.getMinX(), outputEnv.getMinY());
SimpleFeatureType schema = createType(srcCRS, normalize);
ListFeatureCollection result = new ListFeatureCollection(schema);
SimpleFeatureBuilder fb = new SimpleFeatureBuilder(schema);
GeometryFactory factory = new GeometryFactory(new PackedCoordinateSequenceFactory());
double[] srcPt = new double[2];
double[] dstPt = new double[2];
// Find maxima of the point stacks if needed.
int maxCount = 0;
int maxCountUnique = 0;
if(normalize){
for (StackedPoint sp : stackedPts) {
if(maxCount<sp.getCount()) maxCount = sp.getCount();
if(maxCountUnique<sp.getCount()) maxCountUnique = sp.getCountUnique();
}
}
for (StackedPoint sp : stackedPts) {
// create feature for stacked point
Coordinate pt = getStackedPointLocation(preserveLocation, sp);
// transform back to src CRS, since RT rendering expects the output to be in the same CRS
srcPt[0] = pt.x;
srcPt[1] = pt.y;
invTransform.transform(srcPt, 0, dstPt, 0, 1);
Coordinate psrc = new Coordinate(dstPt[0], dstPt[1]);
Geometry point = factory.createPoint(psrc);
fb.add(point);
fb.add(sp.getCount());
fb.add(sp.getCountUnique());
if(normalize){
fb.add(((double)sp.getCount())/maxCount);
fb.add(((double)sp.getCountUnique())/maxCountUnique);
}
result.add(fb.buildFeature(null));
}
return result;
}