1

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();
            copy.setAttributes(feature.getAttributes());

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

            copy.setDefaultGeometry(geometry2);
            writer.write();
        }
        transaction.commit();
        JOptionPane.showMessageDialog(null, "Export to shapefile complete");
    } catch (Exception problem) {
        problem.printStackTrace();
        transaction.rollback();
        JOptionPane.showMessageDialog(null, "Export to shapefile failed");
    } finally {
        transaction.close();
    }
}

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
0

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.