/*
 * GeoTools - The Open Source Java GIS Toolkit
 * http://geotools.org
 *
 * (C) 2016, Open Source Geospatial Foundation (OSGeo)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 2.1 of the License.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */

package org.geotools.gce.imagemosaic.geomhandler;

import org.geotools.coverage.grid.io.GridCoverage2DReader;
import org.geotools.coverage.grid.io.StructuredGridCoverage2DReader;
import org.geotools.gce.imagemosaic.MosaicConfigurationBean;
import org.geotools.geometry.jts.ReferencedEnvelope;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.geometry.Envelope;

import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.PrecisionModel;

/**
 * Default granule handling
 */
public class DefaultGranuleHandler implements GranuleHandler {

    private final static PrecisionModel PRECISION_MODEL = new PrecisionModel(PrecisionModel.FLOATING);
    private final static GeometryFactory GEOM_FACTORY = new GeometryFactory(PRECISION_MODEL);

    @Override
    public void handleGeometry(GridCoverage2DReader inputReader,
            SimpleFeature targetFeature, SimpleFeatureType targetFeatureType,
            SimpleFeature feature, SimpleFeatureType inputFeatureType,
            MosaicConfigurationBean mosaicConfiguration) {

        if(inputReader instanceof StructuredGridCoverage2DReader){
            Object geometryAttribute = feature.getAttribute(inputFeatureType.getGeometryDescriptor().getName());
            targetFeature.setAttribute(targetFeatureType.getGeometryDescriptor().getName(), geometryAttribute); 
        }else {
            Envelope coverageEnvelope = inputReader.getOriginalEnvelope();
            feature.setAttribute(inputFeatureType.getGeometryDescriptor().getLocalName(),
                    GEOM_FACTORY.toGeometry(new ReferencedEnvelope(coverageEnvelope)));
        }

    }
}

@@ -2029,16 +2029,17 @@
        %7D
+ 
 else %7B%0A 
@@ -2124,17 +2124,23 @@
         
-f
+targetF
 eature.s
@@ -2143,36 +2143,37 @@
 re.setAttribute(
-inpu
+targe
 tFeatureType.get

Update to correctly use target feature and not input feature for regular coverages