2

With this tutorial

http://docs.codehaus.org/display/GEOTOOLS/Data+Writing

When I try to insert a feature

try {
DataStore geoToolsClient = getGeoToolsClient();

Transaction transaction = new DefaultTransaction();
try {

FeatureWriter<SimpleFeatureType, SimpleFeature> featureWriter = geoToolsClient.getFeatureWriterAppend(typeName, transaction);

            SimpleFeature simpleFeature = featureWriter.next(); // The problem is here!
              simpleFeature.setAttributes(featureToInsert.getAttributes());

              featureWriter.write();

              transaction.commit();

            } catch (Exception ex) {
                transaction.rollback();
            throw ex;   
            }  

This bug occurs at featureWriter.next(); statement which is supposed to provide an empty SimpleFeature. Then, we have to fill and save it.

This attempt to create an empty SimpleFeature by giving a value to NULL nillable attributes and default non nillable attributes.

We have a column of SDO_GEOMETRY type is not nillable in the bind table.

When the "next ()" attempts to create a default value for this attribute, the following method is called to create a default instance:

org.geotools.data.DataUtilities # defaultValue (Class Type)

But then the attribute is "com.vividsolutions.jts.geom.Geometry" type and defaultValue method does not know how to create a default instance of this type. This exception is thrown :

throw new IllegalArgumentException(type + " is not supported by this method");

And I’m not able to insert a spatial feature in the database

Thanks for any ideas!

Jeremie

1 Answer 1

1

That is a very old (7+ years) tutorial - have a look at http://docs.geotools.org/stable/userguide/tutorial/feature/csv2shp.html which shows how the new FeatureStores work. You'll need something like:

                double latitude = Double.parseDouble(tokens[0]);
                double longitude = Double.parseDouble(tokens[1]);
                String name = tokens[2].trim();
                int number = Integer.parseInt(tokens[3].trim());

                /* Longitude (= x coord) first ! */
                Point point = geometryFactory.createPoint(new Coordinate(longitude, latitude));

                featureBuilder.add(point);
                featureBuilder.add(name);
                featureBuilder.add(number);
                SimpleFeature feature = featureBuilder.buildFeature(null);
                features.add(feature);
1
  • Thanks! It's useful, but I couldn't promote the answer, I don't have 15 reputations... Commented May 28, 2014 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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