Q&A: - You get a new FeatureSource each time so you can use each one on a different transaction (think many threads at once) - http://docs.codehaus.org/display/GEOTDOC/10+Communication+and+Support
To be clear - you are doing everything correct. It really looks like you have found a bug in AbstractDataStore / ShapefileDataStore; the method that is not implemented has been renamed - and we need get the code updated to match. Cheers, Jody -----Original Message----- From: Fab Trillaud [mailto:fab.trill...@gmail.com] Sent: Friday, 17 July 2009 5:52 PM To: Jody Garnett Subject: Re: Shape Lab Hi, I don't really understand why layer.getFeatureSource() returns a different result each time? I don't actually now how to create a JIRA report, and I'm not signed up in the geotools-users list, but I will right now : where can I sign up? I'm sorry but I've been working on GIS and Geotools for a very short time. I posted about my problem at several french forums (as I'm a french working in Vietnam) like developpez.com, forumsig ans georezo, and I also asked to the only other person who knows geotools in my lab. I'm not sure what the header of the shapefile contains, I read the doc once, but I forgot. Can it make a difference if the shapefiles already contains the layer on which I want to add features or not? Thanks a lot for your answer :) Fab Jody Garnett a écrit : > Hi Fab: > > I have been too busy to work on geotools in the last month - although you > would be welcome to employee me for support/training. > > For now let's see if I can help - I am trying to update this tutorial for the > FOSS4G conference. It is a sad part of open source that nobody is willing to > pay for documentation :-) The GeoTools wiki is open to the public - so you > are welcome to update the wiki page once we have things sorted out. > > Shapefiles cannot modifier their header after they have been created - I > wonder if that is what "Schema creation not supported" is about? Usually the > shapefile data store writes out a temporary file - and then uses rename to > shuffle it into place of the original.... > > The getFeatureWriter method is failing here; and it does not look like > ShapefileDataStore provides an implementation. It provides an implementation > of createFeatureWriter( String, Transaction) - so I am going > To have to conclude that people have been using the feature writer directly > on this one. > > Jody > > One comment about your code - layer.getFeatureSource() returns a different > result each time! > > -----Original Message----- > From: Fab Trillaud [mailto:fab.trill...@gmail.com] > Sent: Friday, 17 July 2009 3:06 PM > To: Jody Garnett > Subject: (pas de sujet) > > Hi, > > I'm actually working on a project using GeoTools in a computer science > lab in Hanoi. I'm one the first to use GeoTools here so no one can help > me, and I encountered a problem I posted on several forums, but there > too no one could answer me. > > Here is my 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(i); > > > 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(); > } > } > } > " > > If you have an idea of what I am doing wrong, please tell me, I'm stuck > with this for some time now. > > Thank you > > Fab Trillaud > > > > ------------------------------------------------------------------------------ Enter the BlackBerry Developer Challenge This is your chance to win up to $100,000 in prizes! For a limited time, vendors submitting new applications to BlackBerry App World(TM) will have the opportunity to enter the BlackBerry Developer Challenge. See full prize details at: http://p.sf.net/sfu/Challenge _______________________________________________ Geotools-gt2-users mailing list Geotools-gt2-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users