GeoTools
  1. GeoTools
  2. GEOT-2619

getFeatureWriter method failing

    Details

    • Type: Bug Bug
    • Status: Open Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.5.4
    • Fix Version/s: 2.7.6
    • Component/s: None
    • Labels:
      None
    • Environment:
      Using Windows Vista SP1/SP2 & 7RC. Java version 1.6.0_14.

      Description

      Here is the problem : i'm working on a town generator. So using pre-existing data such as town shapes, river or roads, i must create realistic village maps. I'm working on the roads right now, and for most of the villages I'm working on, there are no data about the roads. So I have to create them myself. What I want to do is create new features and add them to my MapLayer, so that I can display them to see if there are good or not. But when I try to add new features to my layer, I get this error :

      "
      java.lang.UnsupportedOperationException: Schema creation not supported
      at org.geotools.data.AbstractDataStore.getFeatureWriter(AbstractDataStore.java:207)
      at org.geotools.data.TransactionStateDiff.applyDiff(TransactionStateDiff.java:197)
      at org.geotools.data.TransactionStateDiff.commit(TransactionStateDiff.java:151)
      at org.geotools.data.DefaultTransaction.commit(DefaultTransaction.java:182)
      at msi.sig.towngenerator.shapelab.ShapeTools.ajouterSurLayer(ShapeTools.java:193)
      at msi.sig.towngenerator.generator.Generator.genereRoutes(Generator.java:386)
      at msi.sig.towngenerator.generator.Generator.readCommune(Generator.java:189)
      "

      I don't really understanf what it means, since I think I've already checked if the layer was editable or not. Here is the code I run:

      "
      public static void ajouterSurLayer(Geometry geometry, MapLayer layer)
      {
      FeatureStore store;

      SimpleFeatureType featureType = (SimpleFeatureType) layer.getFeatureSource().getSchema();

      Object[] values = new Object[featureType.getAttributeCount()];

      AttributeDescriptor geomAttribut = featureType.getGeometryDescriptor();
      List<AttributeDescriptor> attributes = featureType.getAttributeDescriptors();

      for (int i = 0, max = attributes.size(); i < max; i++) {
      AttributeDescriptor oneAttribut = attributes.get;

      if (oneAttribut.equals(geomAttribut))

      { values[i] = geometry; }

      else

      { values[i] = oneAttribut.getDefaultValue(); }

      }

      SimpleFeature myFeature = SimpleFeatureBuilder.build(featureType, values, null);

      FeatureCollection lstFeatures = FeatureCollections.newCollection();
      lstFeatures.add(myFeature);

      if (layer.getFeatureSource() instanceof FeatureStore) {
      store = (FeatureStore) layer.getFeatureSource();

      DefaultTransaction transaction = new DefaultTransaction();
      store.setTransaction(transaction);

      try

      { store.addFeatures(lstFeatures); transaction.commit(); }

      catch (Exception ex) {
      ex.printStackTrace();
      try

      { store.getTransaction().rollback(); }

      catch (IOException e)

      { e.printStackTrace(); }

      }finally

      { transaction.close(); }

      }
      }
      "

        Activity

        Hide
        Jody Garnett added a comment - - edited
        Looks like AbstractDataStore.getFeatureWriter is not being implemented by ShapefileDataStore - it does implement createFeatureWriter so I am going to assume that this is the victim of a rename or something.

        Here is the method in TransactionStateDiff:

        FeatureWriter<SimpleFeatureType, SimpleFeature> writer;
        try{
            writer = store.createFeatureWriter(typeName, transaction);
        } catch (UnsupportedOperationException e) {
            writer = store.getFeatureWriter(typeName);
        }

        So it looks like getFeatureWriter is only used as a fallback when working with old implementations that have not been upgraded to use createFeatureWriter. I will throw the original exception then .... as of -r33595 on trunk.

        Show
        Jody Garnett added a comment - - edited Looks like AbstractDataStore.getFeatureWriter is not being implemented by ShapefileDataStore - it does implement createFeatureWriter so I am going to assume that this is the victim of a rename or something. Here is the method in TransactionStateDiff: FeatureWriter<SimpleFeatureType, SimpleFeature> writer; try{     writer = store.createFeatureWriter(typeName, transaction); } catch (UnsupportedOperationException e) {     writer = store.getFeatureWriter(typeName); } So it looks like getFeatureWriter is only used as a fallback when working with old implementations that have not been upgraded to use createFeatureWriter. I will throw the original exception then .... as of -r33595 on trunk.
        Hide
        Andrea Aime added a comment -
        ShapefileDataStore most definitely implements createFeatureWriter. Fabrice, can you implement a small, self contained "main" that reproduces the issue?
        As a first check I would ensure that you're not mixing up jars coming from different versions of GeoTools thought.
        Show
        Andrea Aime added a comment - ShapefileDataStore most definitely implements createFeatureWriter. Fabrice, can you implement a small, self contained "main" that reproduces the issue? As a first check I would ensure that you're not mixing up jars coming from different versions of GeoTools thought.
        Hide
        Fabrice added a comment -
        I'm totally sure that I only use jars from GeoTools 2.5.4, except for the gt2-mappane-2.3.0-M1. As I'm using Eclipse with a poor Internet connection (and sometimes no connection at all), I followed the "Eclipse users" tutorial on GeoTools website, and included the entire 2.5.4 library in my project. As I only downloaded this version when the project strated, I don't see any way I can use jars from other versions.

        So, what would you like to see in this "small main", the layer creation? file handling? geometry creation?
        Show
        Fabrice added a comment - I'm totally sure that I only use jars from GeoTools 2.5.4, except for the gt2-mappane-2.3.0-M1. As I'm using Eclipse with a poor Internet connection (and sometimes no connection at all), I followed the "Eclipse users" tutorial on GeoTools website, and included the entire 2.5.4 library in my project. As I only downloaded this version when the project strated, I don't see any way I can use jars from other versions. So, what would you like to see in this "small main", the layer creation? file handling? geometry creation?
        Hide
        Andrea Aime added a comment -
        I mean a 50-100loc application that will throw the same exception as the code you have above.
        It's also strange you're getting exceptions given the shapefile datastore has tests for the addFeatures method, in particular ShapefileReadWriteTest.
        I'm not saying there is no problem, but I need your help to pinpoint how exactly it is triggered.
        Show
        Andrea Aime added a comment - I mean a 50-100loc application that will throw the same exception as the code you have above. It's also strange you're getting exceptions given the shapefile datastore has tests for the addFeatures method, in particular ShapefileReadWriteTest. I'm not saying there is no problem, but I need your help to pinpoint how exactly it is triggered.
        Hide
        Fabrice added a comment -
        Ok. So I made the program as light as possible, but it's still a bit big cause I had to keep some data to have it runnable. Here's the link to get it : (I'm getting some trouble uploading this version, still working ^^)

        And here it is without the data if you want only to see the code : http://uploadmirrors.com/download/RCXQKEYP/generator_light_nodata_1.zip

        (please be indulgent for the poor quality of the code, I'm a beginner ^^)
        Show
        Fabrice added a comment - Ok. So I made the program as light as possible, but it's still a bit big cause I had to keep some data to have it runnable. Here's the link to get it : (I'm getting some trouble uploading this version, still working ^^) And here it is without the data if you want only to see the code : http://uploadmirrors.com/download/RCXQKEYP/generator_light_nodata_1.zip (please be indulgent for the poor quality of the code, I'm a beginner ^^)
        Hide
        Fabrice added a comment -
        Hi,

        There is my code, with the data so that it can be run. Sorry it took so long, I had some connection issues.

        http://uploadmirrors.com/download/2KEXX9OF/generator_light.zip
        Show
        Fabrice added a comment - Hi, There is my code, with the data so that it can be run. Sorry it took so long, I had some connection issues. http://uploadmirrors.com/download/2KEXX9OF/generator_light.zip

          People

          • Assignee:
            Unassigned
            Reporter:
            Fabrice
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: