From: <av...@sa...> - 2004-01-28 17:24:17
|
First, hi to all people from this mail list, and sorry for my english. Im currently in a project trying to manage and display archives in GML format. I have studied GEOTOOLS estructure for various days and i tried several examples. -I was able to parse and display GML1.0 archives with geotools v0.8.0. with GMLReader _Also with GMLDatasource i was able to parse and display sonly some of that GML1.0 archives. ...but I just cant display GML2.0 archives. I have studied lot of java samples from geotools2 test folders, but cant find anything that render the geometrics defined inside a GML2.0 archive. Ive read geotools2 FAQ and says there is GML2.0 support. Please, can i obtain something of help. thanks in advance to ALL. Alberto Vivar Guerra Departamento de Sistemas de Negocio en Red E-mail: av...@sa... Extensión: 51448 SATEC, S.A. Avenida de Europa, 34 A 28023 Aravaca (Madrid) Teléfono: +34 91 708 90 00 Fax : +34 91 708 90 90 -----BEGIN PGP PUBLIC KEY BLOCK----- Version: 6.5.8ckt http://www.ipgpp.com/ mQGiBD/gqhoRBADkW8YZlM8BYRivP7gA9Muu6ov8ozh9sRMxDs5uFUZ9/LqJE+yi YQbjnmHM6buITXai+YyqOx0LHLVeehYpoWaOxf16EUS5gBYLAOcxaa7UvGCaWe1s V5hcQiRqDBQPdHuptrf6hrjPJbjDutECgUKpaa7jmSaRSyNkbEgdNrkIzQCg/8xE Skz6cOX9mAjsU8eydNv+LN8EAKSdE9FkrXpZ9f9qEwsSB+jfVTCqQ5XIrkDngJGV zm4WcS+CX+7g1AmzwhcpsuXk8MGtogV69rYlOh0PsSkj7Exm9FxE+s+tugLB5J7J basOdBuNkPXe7jNA6UJ6JeKznrPd+tX58JFUh9nUyIR6IVmx/AmANzN0yq+FcDSd NZxwBAC0cpEG1LB19Tr0AlqX3GrqGQjrq2zCmF5kUqNOXAD/UwQachgpwy1lHbmJ p48OZATDP0smHxIbERYYtsezAaF57E5g+eDGVza3iD63fRliF5powl/i6M+fIrFm LYRLxtVjDNY21wWoUyZ7oQ0el4prDn6xpBQjWIprPPpj9b2/grQqQWxiZXJ0byBW aXZhciBHdWVycmEgPGFsYmVydG92aXZhckB5YS5jb20+iQBTBBARAgATBQI/4Koa CQsJCggCBwMBBAIZAQAKCRCKFXHficYXmwFkAJ9hEI/cQ0W6SGXyObOkey5MSBZu LgCdHJmiW/Sk+94REAovFUeu5WI2RhW0JkFsYmVydG8gVml2YXIgR3VlcnJhIDxh dml2YXJAc2F0ZWMuZXM+iQBQBBARAgAQBQI/4KqCCQsJCggCBwMBBAAKCRCKFXHf icYXm714AJ9l2YlBRdMT1Ax723VdpfpCrQLa+QCdF5TCZdvhJOMvzJ1eYrY+DnDd QCC5Ag0EP+CqIBAIAMf51hH5qmIGICfMP5nswZgI31aMrXgfqgVBQmfsQ/cXJRqU ROdP3gwjkzxWptIq6N3aMxtXaQDJw+cfb4VABuojKF9LHImrxwyC4/2k91jMUskx eEYZs0Mxx/uaM+gSTn8yp3G4sI2Xbm+QX0JOD/4eejKL4x5lgxhSN8kyRek1vwC5 7K2bszhgjebrdhFzu63oDY18kffb32mujEp4ydxO/rpiHY64loka8P7XleDgtmGu iKNlcMM0cuwQKCQYtr5dL6vJ0L27F5fk1q/vnxXUPamDmZ1JoNGRo+cw2lUun/JK mtjjzF992f+MnHP5hoxqIhCAJcORfI+uiklCtz0AAgIIAJuByyj3Yyt1xc4aws6p qjmLMrgMWRNv3TQA0DTh0ThXAy/t0rMsqRU5nd1hwaLOQNEpppkNFGrWX+3RTj3E u2pCqUVu0jfVKdMJfCPS5NxJzvXuD8OxeUWvSLafSKWFGwOUGrh8pqZu6mbAvb0K P5fKb8SgdApjg6+VferbyK8djhH/+AXB5ltnkTk0Av4d8ALwLjUmLGpxPofZlmWu njyVVu2ZccvJBYRCb4tp2T88d3VNSJ7mhfb7IguuRCLh6kp+QAr+NkhIdt1Qv2NS /gLgQG4xWUnQOXB6LLONmrTSaqLvgOLk9iiQleyUqnfuXuxjG6ERXwLBwiJ1vwhj JxiJAEYEGBECAAYFAj/gqiAACgkQihVx34nGF5sEaQCeNYYN7S2zmnYdaJenEIIy Lk+owA0An3ZaxP2udAJdHKm/KUTLuWPdSLsq =o2vC -----END PGP PUBLIC KEY BLOCK----- |
From: Casson S. <cas...@ea...> - 2004-04-14 02:02:30
|
Hi all, I wanted to pull features out of a DataStore and move them to a JTS class so I could work with the spatial operators.Below is the set of operations I came up with. The code basically goes from DataStore to an array of jts.geo.Geometry. Is there a simpler method to do this? If not I'll write up a small how to. ShapefileDataStore dsRoads = new ShapefileDataStore(popURL); FeatureSource fsRoads = dsRoads.getFeatureSource("dotprimrds"); FeatureResults features = fsRoads.getFeatures(); FeatureReader reader = features.reader(); List list = new ArrayList(); Feature f = null; try { com.vividsolutions.jts.geom.Geometry geomarr[] = new com.vividsolutions.jts.geom.Geometry[10]; while(reader.hasNext() ){ f = reader.next(); geomarr[<increment counter>] = f.getDefaultGeometry(); } Thanks. Casson Stallings cas...@ea... |
From: <ch...@op...> - 2004-04-14 05:52:43
|
> Hi all, > > I wanted to pull features out of a DataStore and move them to a JTS > class so I could work with the spatial operators.Below is the set of > operations I came up with. The code basically goes from DataStore to > an array of jts.geo.Geometry. > > Is there a simpler method to do this? If not I'll write up a small > how to. To go from a shapefile datastore to an array of geometries that's how I'd do it. If you were working with a JDBC datastore, such as postgis or oracle then you can load just the geometries faster by just asking for that attribute. To do that you would need to find out the name of the geometry attribute, about as follows (may have syntax errors, this is from memory) Map postgisParams = (your connection params) PostgisDataStore pgDS = DataStoreFinder.getDataStore(postgisParams); FeatureSource fsRoads = dsRoads.getFeatureSource("dotprimrds"); FeatureType schema = fsRoads.getSchema(); String geomName = schema.getDefaultGeometry().getName(); DefaultQuery dsQuery = new DefaultQuery("dotprimrds"); dsQuery.setPropertyNames(Collections.singletonList(geomName)); FeatureResults features = fsRoads.getFeatures(); ... rest is the same. One other thing to note is that you can work with a number of the spatial operators using Filters in geotools. You can't do difference and union, and things that return geometries, but the ones that are just comparisons, like touches, within, intersects, disjoint, ect., can be directly filtered. You make a geometry Filter on the geometry attribute: GeometryFilter filter = filterFactory.createGeometryFilter(AbstractFilter.GEOMETRY_CONTAINS); AttributeExpression left = filterFactory.createAttributeExpression(schema, geomName); LiteralExpression right = filterFactory.createLiteralExpression(Geometry compareGeom); filter.addLeftGeometry(left); filter.addRightGeometry(right); You can use the filter in the query you made: dsQuery.setFilter(filter); Or you can also just do a fsRoads.getFeatures(filter); Then you'll only be returned features from the datastore that meet the filter, that are contained in the compareGeom you passed in. This leads to better performance with postgis or oracle, because they can do the filtering themselves, without having to send all the geometries over the jdbc connection, parse all the features into java code, and then use jts. They just directly return the features. Our filters really could use some nice refactoring love, they're still a pain to work with... And yes, I know I'm supposed to do a filter tutorial...I'll try to get at least something basic up relatively soon. A howto would be great. You've signed up for a wiki account right? You can just add it with the tutorials, and if you get anything wrong the someone else can just correct it. Chris > > > ShapefileDataStore dsRoads = new ShapefileDataStore(popURL); > FeatureSource fsRoads = > dsRoads.getFeatureSource("dotprimrds"); > FeatureResults features = fsRoads.getFeatures(); > FeatureReader reader = features.reader(); > List list = new ArrayList(); > Feature f = null; > > try { > com.vividsolutions.jts.geom.Geometry geomarr[] = new > com.vividsolutions.jts.geom.Geometry[10]; > while(reader.hasNext() ){ > f = reader.next(); > geomarr[<increment counter>] = > f.getDefaultGeometry(); > } > > Thanks. > > Casson Stallings > cas...@ea... ---------------------------------------------------------- This mail sent through IMP: https://webmail.limegroup.com/ |
From: dominik <dom...@gm...> - 2004-05-24 22:50:48
|
hi all, I'm working on a university project. I was wondering if there is any module which I can use to travers roads (polylines) in a Shapefile if I have some start and end point (with a PathFinder.) I found the Graph class but there are only GraphBuilder for Linear features (I suppose that a polyline is not a linear feature, furthermore nodes are added only if features have the same end points or also if two polylines intersect??) Since I allready managed to display my shapefiles and do some nice things on the map using Geotools2 I would by happy if the things mentioned abouve would be possible to do. I appreciated all hints and infos! thanks -- "Sie haben neue Mails!" - Die GMX Toolbar informiert Sie beim Surfen! Jetzt aktivieren unter http://www.gmx.net/info |
From: dominik <dom...@gm...> - 2004-05-24 22:53:19
|
hi all, I'm working on a university project. I was wondering if there is any module which I can use to travers roads (polylines) in a Shapefile if I have some start and end point (with a PathFinder.) I found the Graph class but there are only GraphBuilder for Linear features (I suppose that a polyline is not a linear feature, furthermore nodes are added only if features have the same end points or also if two polylines intersect??) Since I allready managed to display my shapefiles and do some nice things on the map using Geotools2 I would by happy if the things mentioned abouve would be possible to do. I appreciated all hints and infos! thanks -- "Sie haben neue Mails!" - Die GMX Toolbar informiert Sie beim Surfen! Jetzt aktivieren unter http://www.gmx.net/info -- NEU : GMX Internet.FreeDSL Ab sofort DSL-Tarif ohne Grundgebühr: http://www.gmx.net/dsl |
From: dominik <dom...@gm...> - 2004-05-26 22:06:19
|
hi, I have a shapefile with roads and I want to search the shortest path between two points on the map. to calculate the shortest path I found the Graph class but when I tryed to implement I got the following exception: java.lang.IllegalArgumentException: LineString geometry required for graph at org.geotools.graph.build.LineGraphBuilder.add(LineGraphBuilder.java:121) at radlweg2.reader.main(reader.java:125) and thats my code: FeatureReader reader = fsShape.reader(); Feature feature = reader.next(); LineGraphBuilder bgrafo = new LineGraphBuilder(); bgrafo.add(feature); Graph grafo = bgrafo.build(); I suppose it is because I use MultiLineString instead of LineStrings! Someone knows or can give ma a hint how to use the Graph class with MultiLineStings or can give my another method to search Pahts on Shapefiles. It would save me a lot of time if we could use the Graph class or some other code so I hope that someone can help me Waiting for your kindness, dominik at Politecnico di Milano -- "Sie haben neue Mails!" - Die GMX Toolbar informiert Sie beim Surfen! Jetzt aktivieren unter http://www.gmx.net/info |
From: Martin D. <mar...@te...> - 2004-05-27 07:53:32
|
dominik a =E9crit : > I have a shapefile with roads and I want to search the shortest path be= tween > two points on the map. I'm not sure what you want to do, but if it is just computing the=20 distance between two points on an ellipsoid (i.e. orthodromic distance),=20 then org.geotools.referencing.datum.Ellipsoid can do that. You can also=20 use org.geotools.cs.GeodeticCalculator for performing more advanced=20 calculation (however, this class will move in an other package shortly).=20 But if you want to performs something more complex involving path, then=20 the above solution may not be appropriate. Martin. |
From: dominik <dom...@gm...> - 2004-05-27 14:42:06
|
hi, thanks for you answer. I would like to use paths. -- "Sie haben neue Mails!" - Die GMX Toolbar informiert Sie beim Surfen! Jetzt aktivieren unter http://www.gmx.net/info |
From: dominik <dom...@gm...> - 2004-05-27 14:43:23
|
hi, thanks for you answer. I would like to use paths. -- NEU : GMX Internet.FreeDSL Ab sofort DSL-Tarif ohne Grundgebühr: http://www.gmx.net/dsl |
From: dominik <dom...@gm...> - 2004-06-03 19:16:59
|
hi, aren't features serializable?? I would like to store a graph which has edges which has features! can someone say me how to do that?? thanks dominik kirchler -- +++ Jetzt WLAN-Router für alle DSL-Einsteiger und Wechsler +++ GMX DSL-Powertarife zudem 3 Monate gratis* http://www.gmx.net/dsl |
From: dominik <dom...@gm...> - 2004-06-03 23:02:25
|
hi, first of all a great compliment to all of you!!! I am working on a project for university and geotools is dooing just fine. My question (perhaps rather silly): I am using the map from spearfish example with my one shapefiles! How do I get the Style of my shapefile as I can see it in Arcview in the map?? thanks dominik -- "Sie haben neue Mails!" - Die GMX Toolbar informiert Sie beim Surfen! Jetzt aktivieren unter http://www.gmx.net/info |
From: Ian T. <i.t...@ge...> - 2004-06-07 11:34:13
|
> From: geo...@li... > [mailto:geo...@li...] On > Behalf Of dominik > Sent: 04 June 2004 00:02 > To: geo...@li... > Subject: [Geotools-gt2-users] Style > > > hi, > first of all a great compliment to all of you!!! I am working > on a project for university and geotools is dooing just fine. > Cool - when you're finished may be you can share the results with the list. > My question (perhaps rather silly): I am using the map from > spearfish example with my one shapefiles! How do I get the > Style of my shapefile as I can see it in Arcview in the map?? GeoTools makes use of the OGC Styled Layer Description (SLD) specification (http://www.opengis.org/docs/02-070.pdf). I'll be honest and say that I haven't yet looked at the spearfish example but I assume it loads a style from a file somewhere. Ian Ian Turton, Director, Centre for Computational Geography, University of Leeds, Leeds, LS2 9JT http://www.geog.leeds.ac.uk/people/i.turton http://www.ccg.leeds.ac.uk http://www.geotools.org +44 (0) 113 343 3392 fax: +44 (0) 113 343 3308 |
From: <di...@tr...> - 2004-06-09 16:11:23
|
Hi, I can't see how to unsubscribe from the list.=20 Could you help me ? Sorry for this mail out of topic. Fred |
From: dominik <dom...@gm...> - 2004-06-22 19:58:15
|
Hi all, I have got release 2.0 B4 of Geotools. I would like to use the class ImageDataSource but I cant find it in the jars. can it be that it is not included in the releas? and if not where can I get it easily? best regards dominik -- "Sie haben neue Mails!" - Die GMX Toolbar informiert Sie beim Surfen! Jetzt aktivieren unter http://www.gmx.net/info |
From: Martin D. <mar...@te...> - 2004-06-23 08:03:54
|
dominik a =E9crit : > I would like to use the class ImageDataSource but I cant find it in the > jars. >=20 > can it be that it is not included in the releas? >=20 > and if not where can I get it easily? I can't speak for B4 release content. But generally speaking, you can=20 get the latest code using SVN. For example install the following software= : http://tortoisesvn.tigris.org/ Once it is installed, you can click with the right mouse button in the=20 explorer, select "checkout" and enter the following URL: http://svn.geotools.org/geotools/trunk/gt/ Enter a destination directory too. This need to be done only once. Then,=20 you can get latest update at anytime with a right mouse click on the=20 directory just created, and selecting "update" from the contextual menu. Martin. |
From: dominik <dom...@gm...> - 2004-06-25 13:08:55
|
hello, I have the following files: DTM coverage AInfo (digitales Geländemodell 20m x 20m) INFO directory AInfo dtm.asc (digitales Geländemodell 20m x 20m in ASCII Format) dtm_projection_file.prj (file mit Informationen zur Georeferenzierung des digitalen Modells) hill.tif (File mit 3DBild des digitalen Modells) hill.tfw (world file) can I display them in Geotools using ImageDataSource? (in arcview it works) I tried String url1 = new String("d:/data/terra/hill.tif"); String url2 = new String("d:/data/terra/hill.tfw"); ImageDataSource i = new ImageDataSource(url1,url2); FeatureCollection schum = i.getFeatures(); but it gives me an exception when I create the ImageDataSource _______________________________________________________________ java.lang.IllegalArgumentException: No suitable image reader for this input source. at org.geotools.io.coverage.GridCoverageReader.setInput(GridCoverageReader.java:250) at org.geotools.io.coverage.ExoreferencedGridCoverageReader.setInput(ExoreferencedGridCoverageReader.java:156) at out.ImageDataSource.load(ImageDataSource.java:99) at out.ImageDataSource.<init>(ImageDataSource.java:81) at out.appletout.jbInit(appletout.java:312) at out.appletout.init(appletout.java:106) at sun.applet.AppletPanel.run(AppletPanel.java:353) at java.lang.Thread.run(Thread.java:534) _________________________________________________ does it mean that the files I use arent compatible?? thanks dominik -- "Sie haben neue Mails!" - Die GMX Toolbar informiert Sie beim Surfen! Jetzt aktivieren unter http://www.gmx.net/info |
From: Rueben S. <r_j...@ya...> - 2004-05-30 03:09:51
Attachments:
graph.html
|
To Dominik, Hi. The graph code is relatively new and I have not used it. It does sound like it will do what you need. Unfortunately, the people that can help you with this are busy re-organizing our code and getting it to build. The only documentation I can find is the start of a tutorial in sdocbook. I have attached a copy in html. This tutorial gives some code examples, but note that they use the older dataSource interface. There also appears to be some javadocs. Good luck, Rueben On Wed, 2004-05-26 at 15:06, dominik wrote: > hi, > I have a shapefile with roads and I want to search the shortest path between > two points on the map. > > to calculate the shortest path I found the Graph class but when I tryed to > implement I got the following exception: > > java.lang.IllegalArgumentException: LineString geometry required for > graph at > org.geotools.graph.build.LineGraphBuilder.add(LineGraphBuilder.java:121) > at radlweg2.reader.main(reader.java:125) > > and thats my code: > > FeatureReader reader = fsShape.reader(); > Feature feature = reader.next(); > LineGraphBuilder bgrafo = new LineGraphBuilder(); > bgrafo.add(feature); > Graph grafo = bgrafo.build(); > > I suppose it is because I use MultiLineString instead of LineStrings! > > Someone knows or can give ma a hint how to use the Graph class with > MultiLineStings or can give my another method to search Pahts on Shapefiles. > > It would save me a lot of time if we could use the Graph class or some other > code so I hope that someone can help me > > Waiting for your kindness, > dominik > > at Politecnico di Milano |
From: Steffen G. <ste...@in...> - 2004-07-13 08:55:12
|
Thanks Martin, I also wrote my own MouseMotionListener which is working . Now I did the statusbar thing and it is also working. BUT: For the first time the map is drawn the Pixelcoordinates are drawn as well in the status bar as in my text print of my motionlistener. Only after zooming in once, the values are correct. What is happening? Thanks in advance. Steffen. Steffen Gebhardt a écrit : > I visualised a basic country shp by esri which is in geographic > coordinates but do not know how to modify the units for the > mapscalebar. How to do that? I don't know which renderer you are using (there is 2 renderer currently provided in Geotools: "j2d" and "lite"). Since you have a map scale, I assume you are using j2d renderer. The map scale is drawn by the RenderedMapScale class. This class has a 'setUnit' method. Just invoke this method with the unit you want to see. http://modules.geotools.org/main/apidocs/org/geotools/renderer/j2d/RenderedMapScale.html#setUnits(org.geotools.units.Unit) > And the last question is how to add mouse events for displaying > geographic position on mouse over? If you just want to display mouse coordinate, the easiest way is to uses StatusBar. StatusBar is a widget that you can put anywhere (usually just below the MapPane), and is by itself a MouseListener which will listen for MapPane event. http://modules.geotools.org/main/apidocs/org/geotools/gui/swing/StatusBar.html Martin. -- --------------------- Steffen Gebhardt Informus GmbH Gustav-Meyer-Allee 25 13355 Berlin --------------------- |
From: Martin D. <mar...@te...> - 2004-07-13 09:41:00
|
Steffen Gebhardt a =E9crit : > For the first time the map=20 > is drawn the Pixelcoordinates are drawn as well in the status bar as in= =20 > my text print of my motionlistener. Only after zooming in once, the=20 > values are correct. What is happening? This is a know bug: http://jira.codehaus.org/browse/GEOT-194 Maybe you can try to change the order in which layers are added to the=20 MapPane (for example adding RenderedMapScale last). Please add comments=20 in the above-cited task if you have some new details. I will try to fix=20 that as soon as I have a chance, but it may take a while since I'm=20 already overbooked... Regards, Martin. |
From: <tis...@ya...> - 2004-08-25 13:34:24
|
hello, i try to create a shapefile but i've got a warning. Can you tell me why? When execute the following code : import org.geotools.data.shapefile.ShapefileDataStore; import org.geotools.feature.FeatureTypeFactory; import org.geotools.feature.FeatureType; import org.geotools.feature.AttributeTypeFactory; import org.geotools.data.FeatureWriter; import org.geotools.data.Transaction; import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.Point; import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.PrecisionModel; import java.net.URL; public class Test { public Test() { } public static void main(String[] args) { try { URL shpfile = new URL("file:D:/Documents/W3T2004/W3T2004OpenSource/shapefile/test2"); ShapefileDataStore store = new ShapefileDataStore(shpfile); FeatureTypeFactory factory = FeatureTypeFactory.newInstance("point"); factory.addType(AttributeTypeFactory.newAttributeType("Shape",Geometry.class)); factory.addType(AttributeTypeFactory.newAttributeType("id",Number.class)); FeatureType type = factory.getFeatureType(); store.createSchema(type); FeatureWriter fw = store.getFeatureWriter(store.getTypeNames()[0], Transaction.AUTO_COMMIT); double x1 = -117.7; double y1 = 34.8; double x2 = -117.71; double y2 = 34.81; fw.next().setAttributes(new Object[]{ new Point(new Coordinate(x1,y1), new PrecisionModel(),4326), new Integer(0) }); fw.write(); fw.next().setAttributes(new Object[]{ new Point(new Coordinate(x2,y2), new PrecisionModel(),4326), new Integer(1) }); fw.write(); fw.close(); } catch (Exception e) { System.out.println(e); } } } I've got the following error: Aug 25, 2004 2:39:26 PM org.geotools.data.shapefile.dbf.DbaseFileHeader warn WARNING: Field Length for id set to 33 Preserving length, but should be set to Max of 18 for dbase III specification. thanks for your help morgane --------------------------------- Créez gratuitement votre Yahoo! Mail avec 100 Mo de stockage ! Créez votre Yahoo! Mail Le nouveau Yahoo! Messenger est arrivé ! Découvrez toutes les nouveautés pour dialoguer instantanément avec vos amis.Téléchargez GRATUITEMENT ici ! |
From: Christian E. <ch...@cy...> - 2004-08-25 14:38:09
|
Hi Some comments Mail with Subjects are easier to find ;-) .... > fw.next().setAttributes(new Object[]{ > new Point(new Coordinate(x1,y1), new > PrecisionModel(),4326), Is it better to use the GeometryFactory because the Point constructor is deprecated. http://www.vividsolutions.com/jts/javadoc/com/vividsolutions/jts/geom/GeometryFactory.html > I've got the following error: > > Aug 25, 2004 2:39:26 PM org.geotools.data.shapefile.dbf.DbaseFileHeader warn > WARNING: Field Length for id set to 33 Preserving length, but should > be set to Max of 18 for dbase III specification. This Error is because you are using the Number class for id. > factory.addType(AttributeTypeFactory.newAttributeType("id",Number.class)); try Integer or String Number seems too big for dbase ;-). Remeber the max IndexLength is only 10 ;-) cu chege |
From: Robert N. <rn...@cs...> - 2004-08-25 16:26:52
Attachments:
ShapefileDataStore.java
|
Hi, The attached file fixes a bug in the ShapefileDataStore.java file Nick Collier found it while we were working on a project involving GeoTools. I noticed the fix did not make it into the RC1 release, so I thought I would resubmit it here. The relevant lines are in the org.geotools.data.shapefile.ShapefileDataStore.copyAndDelete(URL src) function. the FileChannels are not closed. protected void copyAndDelete(URL src) throws IOException { File storage = getStorageFile(src); File dest = new File(src.getFile()); FileChannel in = new FileInputStream(storage).getChannel(); FileChannel out = new FileOutputStream(dest).getChannel(); long len = in.size(); long copied = out.transferFrom(in,0,in.size()); if (len != copied) throw new IOException("unable to complete write"); storage.delete(); in.close(); ///// <------ these two lines have out.close(); ///// <------ been added to close the FileChannels } Thanks. Robert |
From: Mustafa C. <ac...@ya...> - 2004-09-22 16:16:05
|
Hi, I would like to be removed from the list. I did not see any link in geotools site. Please point me to the URL. Thanks, Mustafa _______________________________ Do you Yahoo!? Declare Yourself - Register online to vote today! http://vote.yahoo.com |
From: <Fre...@ao...> - 2004-10-15 06:21:29
|
I developped a programm which write feature (line) in a shape file by following tutorial. However I have an Exception error : "java.io.IOException: Shp has extra record" I think the problem is in my method which display the map, however I don't find any solutions ... Thank's for helping ... This is my main methods : First method : public static void place(){ geom = AttributeTypeFactory.newAttributeType("the_geom", LineString.class); epaisseur = AttributeTypeFactory.newAttributeType("width", Float.class); commentaire = AttributeTypeFactory.newAttributeType("commentaire", String.class); try{ Coordinate c1 = new Coordinate(797133, 2093372); Coordinate c2 = new Coordinate(797580, 2093453); Coordinate[] tab = new Coordinate[] {c1,c2}; ftRoad = FeatureTypeFactory.newFeatureType(new AttributeType[] {geom, epaisseur,commentaire}, "maison"); WKTReader wktReader = new WKTReader(); String str = miseEnForme(tab); geometry = (LineString) wktReader.read(str); width = new Float(10); c = new String ("on essaye"); theRoad = ftRoad.create(new Object[] {geometry, width,c}, "goo"); FeatureReader reader = DataUtilities.reader(new Feature[] { theRoad}); //---------------------------------Creation dataStore et schema----------------------------- String newStoreURLString ; ShapefileDataStore newShapefileDataStore; newStoreURLString = "file:/C:/Documents and Settings/STG/Bureau/geo/bin/org/geotools/sampleData/tutu_MASSE_DIJON_lin.shp"; newShapefileDataStore = new ShapefileDataStore(new URL(newStoreURLString)); newShapefileDataStore.createSchema(ftRoad); FeatureSource fs = newShapefileDataStore.getFeatureSource("maison"); FeatureStore ft = (FeatureStore)fs; t = ft.getTransaction(); //---------------------------------Feature Writer ----------------------------- fw = newShapefileDataStore.getFeatureWriterAppend("maison", t); Feature f = fw.next(); f.setAttributes(new Object[] { geometry, width, c}); System.out.println("sdf" +f); System.out.println("bla "+fw); /**/ } catch(Exception e){ System.out.println(e); } } Second method : public static void ajout1(){ try{ System.out.println("passe dans ajout1"); Feature f2 = fw.next(); Coordinate c3 = new Coordinate(795714, 2092068); Coordinate c4 = new Coordinate(794250, 2087890); Coordinate[] tab2 = new Coordinate[] {c3,c4}; WKTReader wktReader2 = new WKTReader(); String str2 = miseEnForme(tab2); LineString geometry3 = (LineString) wktReader2.read(str2); Float width3 = new Float(10); String c5 = new String ("on essaye"); f2.setAttributes(new Object[] {geometry3, width3, c5}); System.out.println(f2); } catch(Exception e){ System.out.println(e); } } third : display the map : and last the methode which display : public static void aff(){ System.out.println("fjsifj"); URL roadsURL = getResource("org/geotools/sampleData/tutu_MASSE_DIJON_lin.shp"); try{ ShapefileDataStore dsRoads = new ShapefileDataStore(roadsURL); String name = dsRoads.getTypeNames()[0]; FeatureSource fsRoads = dsRoads.getFeatureSource("tutu_MASSE_DIJON_lin"); StyleBuilder sb2 = new StyleBuilder(); LineSymbolizer ls2 = sb2.createLineSymbolizer(Color.RED, 10); Style roadsStyle2 = sb2.createStyle(ls2); // map.addLayer(fsRoads, roadsStyle2); Envelope mapArea = map.getLayerBounds(); Rectangle2D fullArea = new Rectangle2D.Double( mapArea.getMinX(),mapArea.getMinY(),mapArea.getWidth(),mapArea.getHeight()); mapPane.setMapContext(map); } catch(Exception e){ System.out.println(e); } } and finally the main method : public static void main(String[] args) throws Exception { //----------------------------------creation attribute type-------------- try{ place(); ajout1(); aff(); t.commit(); t.close(); } |
From: Rueben S. <r_j...@ya...> - 2004-10-19 03:42:58
|
Hi, I do not know the exact cause of the error you are getting, but I can see a number of mistakes or unused code below that may be causing problems. My comments on things to change are below. Unfortunatly I have not compiled or tested this and there will likely be some small errors in my changes. I think that the mayor problem is that you are not calling write() on the featureWriter and are not closing the DataStore (should probably be closed before you read it in the third method). For an example of writing a new shapefile, see the TransformData demo at http://svn.geotools.org/geotools/trunk/gt/demo/referencing/src/org/geotools/demo/referencing/TransformData.java Good luck, Rueben On Thu, 2004-10-14 at 23:20, Fre...@ao... wrote: > I developped a programm which write feature (line) in a shape file by following tutorial. However I have an Exception error : "java.io.IOException: Shp has extra record" > > I think the problem is in my method which display the map, however I don't find any solutions ... Thank's for helping ... > > > This is my main methods : > First method : //note that static methods are usually not desirable in java. You can call non-static methods from the constructor and then call the constructor from main. > public static void place(){ > > geom = AttributeTypeFactory.newAttributeType("the_geom", LineString.class); > epaisseur = AttributeTypeFactory.newAttributeType("width", Float.class); > commentaire = AttributeTypeFactory.newAttributeType("commentaire", String.class); > > try{ > Coordinate c1 = new Coordinate(797133, 2093372); > Coordinate c2 = new Coordinate(797580, 2093453); > Coordinate[] tab = new Coordinate[] {c1,c2}; > //You could also create the linestring geometry using: geometry = new LineString(tab, PrecisionModel, SRID); //you will need to find an example for details. > ftRoad = FeatureTypeFactory.newFeatureType(new AttributeType[] {geom, epaisseur,commentaire}, "maison"); > WKTReader wktReader = new WKTReader(); > String str = miseEnForme(tab); > > geometry = (LineString) wktReader.read(str); > width = new Float(10); > c = new String ("on essaye"); > > theRoad = ftRoad.create(new Object[] {geometry, width,c}, "goo"); > //I don't think the next line is needed > //FeatureReader reader = DataUtilities.reader(new Feature[] { theRoad}); > > > //---------------------------------Creation dataStore et schema----------------------------- > > String newStoreURLString ; //change the folowing to: DataStore newShapefileDataStore; //Refering to the interface instead of the class is more flexible > //ShapefileDataStore newShapefileDataStore; > newStoreURLString = "file:/C:/Documents and Settings/STG/Bureau/geo/bin/org/geotools/sampleData/tutu_MASSE_DIJON_lin.shp"; > newShapefileDataStore = new ShapefileDataStore(new URL(newStoreURLString)); > newShapefileDataStore.createSchema(ftRoad); > //I don't think the next few lines are needed, you only need a feature writer. > //FeatureSource fs = newShapefileDataStore.getFeatureSource("maison"); > //FeatureStore ft = (FeatureStore)fs; > //t = ft.getTransaction(); > > //---------------------------------Feature Writer ----------------------------- > //change to: fw = newShapefileDataStore.getFeatureWriter("maison", Transaction.AUTO_COMMIT); //I am assuming you are adding a feature to a new shapefile (not an existing one). > //fw = newShapefileDataStore.getFeatureWriterAppend("maison", t); > > Feature f = fw.next(); > f.setAttributes(new Object[] { geometry, width, c}); //you need to also call write and close the DataStore fw.write(); newShapefileDataStore.close(); > > System.out.println("sdf" +f); > System.out.println("bla "+fw); > /**/ > > > } > catch(Exception e){ > System.out.println(e); > } > } > > > Second method : > public static void ajout1(){ > try{ > System.out.println("passe dans ajout1"); > Feature f2 = fw.next(); > > Coordinate c3 = new Coordinate(795714, 2092068); > Coordinate c4 = new Coordinate(794250, 2087890); > Coordinate[] tab2 = new Coordinate[] {c3,c4}; > > WKTReader wktReader2 = new WKTReader(); > String str2 = miseEnForme(tab2); > LineString geometry3 = (LineString) wktReader2.read(str2); > Float width3 = new Float(10); > String c5 = new String ("on essaye"); > f2.setAttributes(new Object[] {geometry3, width3, c5}); //again you need to call write and close the datastore fw.write() newShapefileDataStore.close(); //note: since you are re-using the featureWriter here, you probably should not close the datastore in the first method above. You will need to close it eventually thought. > System.out.println(f2); > } > catch(Exception e){ > System.out.println(e); > } > } > > third : display the map : > and last the methode which display : > public static void aff(){ > System.out.println("fjsifj"); > URL roadsURL = getResource("org/geotools/sampleData/tutu_MASSE_DIJON_lin.shp"); > > try{ > ShapefileDataStore dsRoads = new ShapefileDataStore(roadsURL); > String name = dsRoads.getTypeNames()[0]; > > FeatureSource fsRoads = dsRoads.getFeatureSource("tutu_MASSE_DIJON_lin"); > StyleBuilder sb2 = new StyleBuilder(); > LineSymbolizer ls2 = sb2.createLineSymbolizer(Color.RED, 10); > Style roadsStyle2 = sb2.createStyle(ls2); > > // map.addLayer(fsRoads, roadsStyle2); > Envelope mapArea = map.getLayerBounds(); > Rectangle2D fullArea = new Rectangle2D.Double( > mapArea.getMinX(),mapArea.getMinY(),mapArea.getWidth(),mapArea.getHeight()); > > mapPane.setMapContext(map); > } > catch(Exception e){ > System.out.println(e); > } > } > > > > and finally the main method : > public static void main(String[] args) throws Exception { > //----------------------------------creation attribute type-------------- > try{ > place(); > ajout1(); > aff(); //you don't need the transaction here (set to auto commit above now). > //t.commit(); > //t.close(); > } > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: IT Product Guide on ITManagersJournal > Use IT products in your business? Tell us what you think of them. Give us > Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more > http://productguide.itmanagersjournal.com/guidepromo.tmpl > _______________________________________________ > Geotools-gt2-users mailing list > Geo...@li... > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users |