From: Valerio Di G. <val...@in...> - 2011-07-29 12:50:46
|
Dear all, I modified the GeoTools ShapefileViewer example (http://www.opensourcejavaphp.net/java/geotools/org/geotools/demo/swing/ShapefileViewer.java.html) in order to use the B3partners BV DXF plugin: public void loadDXF() throws IOException { File file = JFileDataStoreChooser.showOpenFile("dxf", null); if (file != null) { addDXF(file.toURI().toURL(), true); } } public boolean addDXF(URL dxfURL, boolean defaultStyle) throws IOException { if (dxfURL == null) { throw new IllegalArgumentException("shapefileURL must not me null"); } DXFDataStore dstore = null; DataStore found = repository.dataStore(dxfURL.toString()); if(found != null && found instanceof FileDataStore){ dstore = (DXFDataStore) found; } else { dstore = new DXFDataStore(dxfURL, "EPSG:3004"); repository.register(dxfURL.toString(), dstore); } /* * Before doing anything else we attempt to connect to the * shapefile to check that it exists and is reachable. An * IOException will be thrown if this fails. */ String typeName = dstore.getTypeNames()[0]; dstore.getSchema(typeName); /* * We assume from this point that the shapefile exists and * is accessible */ Style style = null; URL sldURL = getShapefileSLD(dxfURL); if (sldURL != null) { /* * The DXF has an associated SLD file. We read this and * use the (first) style for the new layer */ StyleFactory factory = CommonFactoryFinder.getStyleFactory(null); SLDParser stylereader = new SLDParser(factory, sldURL); style = stylereader.readXML()[0]; } else if (defaultStyle) { /* * There was no associated SLD file so we attempt to create * a minimal style to display the layer */ style = JSimpleStyleDialog.showDialog(this, dstore); if (style == null) { return false; } } else { /* * We are not having a good day... */ return false; } MapLayer layer = new DefaultMapLayer(dstore.getFeatureSource(typeName), style); addLayer(layer); return true; } I need to open, display, zoom and pan a DXF map. But I can't display it because i have the following problem: Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: java.lang.UnsupportedOperationException: No style method for com.vividsolutions.jts.geom.Geometry at org.geotools.swing.styling.JSimpleStyleDialog.init(JSimpleStyleDialog.java:413) at org.geotools.swing.styling.JSimpleStyleDialog.<init>(JSimpleStyleDialog.java:366) at org.geotools.swing.styling.JSimpleStyleDialog.showDialog(JSimpleStyleDialog.java:302) at org.geotools.swing.styling.JSimpleStyleDialog.showDialog(JSimpleStyleDialog.java:268) at org.geotools.swing.styling.JSimpleStyleDialog.showDialog(JSimpleStyleDialog.java:243) at org.geotools.demo.swing.ShapefileViewer.addDXF(ShapefileViewer.java:358) at org.geotools.demo.swing.ShapefileViewer.loadDXF(ShapefileViewer.java:157) at org.geotools.demo.swing.ShapefileViewer$1.actionPerformed(ShapefileViewerjava:107) [...] Caused by: java.lang.UnsupportedOperationException: No style method for com.vividsolutions.jts.geom.Geometry at org.geotools.swing.styling.JSimpleStyleDialog.setType(JSimpleStyleDialog.java:727) at org.geotools.swing.styling.JSimpleStyleDialog.init(JSimpleStyleDialog.java:409) ... 45 more The faulty code is: GeometryDescriptor desc = schema.getGeometryDescriptor(); Class<?> clazz = desc.getType().getBinding(); String labelText = schema.getTypeName(); if (Polygon.class.isAssignableFrom(clazz) || MultiPolygon.class.isAssignableFrom(clazz)) { geomType = GeomType.POLYGON; labelText = labelText + " (polygon)"; } else if (LineString.class.isAssignableFrom(clazz) || MultiLineString.class.isAssignableFrom(clazz)) { geomType = GeomType.LINE; labelText = labelText + " (line)"; } else if (Point.class.isAssignableFrom(clazz) || MultiPoint.class.isAssignableFrom(clazz)) { geomType = GeomType.POINT; labelText = labelText + " (point)"; } else { throw new UnsupportedOperationException("No style method for " + clazz.getName()); } Here, the JSimpleStyleDialog.setType() does not recognize the clazz object and it throws the exception. With regards to the addDXF() function above, consider that: clazz == dstore.getSchema(typeName).getGeometryDescriptor().getType().getBinding() and clazz.getName() == "com.vividsolutions.jts.geom.Geometry" Where Geometry is an abstract class! For that I'm wondering why I have the fault (shapefiles don't generate it). It seems I have a not recognized GeometryDescriptor created by the DXF Plugin. What do you think about? Thank you very much, Valerio LEGAL DISCLAIMER: The contents of this email and any transmitted files are confidential and intended solely for the use of the individual or entity to whom they are addressed. We hereby exclude any warranty and any liability as to the quality or accuracy of the contents of this email and any attached transmitted files. If you are not the intended recipient, be advised that you have received this email in error and that any use, dissemination, forwarding, printing or copying of this email is strictly prohibited. If you have received this email in error please contact the sender and delete the material from any computer. |