I'm trying to test the code example on the page http://docs.geotools.org/stable/userguide/tutorial/geometry/geometrycrs.html I copied this example into eclipse

 Transaction transaction = new DefaultTransaction("Reproject");
    try (FeatureWriter<SimpleFeatureType, SimpleFeature> writer =
                    dataStore.getFeatureWriterAppend(createdName, transaction);
            SimpleFeatureIterator iterator = featureCollection.features()) {
        while (iterator.hasNext()) {
            // copy the contents of each feature and transform the geometry
            SimpleFeature feature = iterator.next();
            SimpleFeature copy = writer.next();

            Geometry geometry = (Geometry) feature.getDefaultGeometry();
            Geometry geometry2 = JTS.transform(geometry, transform);

        JOptionPane.showMessageDialog(null, "Export to shapefile complete");
    } catch (Exception problem) {
        JOptionPane.showMessageDialog(null, "Export to shapefile failed");
    } finally {

But I got some error with transform function. Eclipse "ask" to change Geometry type to Envelope. But when I changed it didn't solve this problem . Eclipse asked to change envelope to geometry again. How can I fix this error?

  • 1
    please don't post pictures of code. What is the error message? – Ian Turton Nov 17 '18 at 10:13

I don't see any errors in the code when I plug it into my eclipse. The most likely issue is that you have imported the "wrong" geometry class. Make sure it is a JTS geometry - import org.locationtech.jts.geom.Geometry; or import com.vividsolutions.jts.geom.Geometry; depending on the version of GeoTools you are using.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.