From: Justin D. <jde...@op...> - 2009-06-16 22:52:57
|
Hi Mark, Unfortunately, depending on the WFS server, and the backend datasource it is using it might report the geometry type as a specific type, or just as a generic geometry type, which I am guessing is happening in this specific case. One option would be to "morph" the feature type you get back from the WFS and explicitly set its geometry type to point. For example: SimpleFeatureType schema = ...; SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.setName( schema.getName()) tb.setCRS( schema.getCoordinateReferenceSystem()); for ( AttributeDescriptor at : schema.getAttributeDescriptors() ) { String name = at.getLocalName(); Class type = at.getType().getBinding(); if ( at instanceof GEometryDescriptor ) { type = Point.class; } tb.add(name,type); } schema = tb.buildFeatureType(); And then create the shapefile with that schema. A second option if you are using geoserver is to use the SHAPE-ZIP output format, which gives you back a zipped shapefile. Not sure if you are using geoserver though. -Justin Mark Ackerman wrote: > Hi, > I'm new to geotools. I'm trying to read from a WFS and write the data > to a shape file. Reading from > the WFS seems to be working fine, but when I go to create the > shapefile's schema I get the following > exception: > > toShpAction:IOException org.geotools.data.DataSourceException: Cannot > create a shapefile whose geometry type is class > com.vividsolutions.jts.geom.Geometry > org.geotools.data.DataSourceException: Cannot create a shapefile whose > geometrytype is class com.vividsolutions.jts.geom.Geometry > at > org.geotools.data.shapefile.ShapefileDataStore.createSchema(ShapefileDataStore.java:804) > > at > hec.dgt.plugins.WfsToShpPlugin.toShpAction(WfsToShpPlugin.java:303) > at > hec.dgt.plugins.GageToShpPlugin.doDownload(GageToShpPlugin.java:49) > at hec.dgt.DgtFrame.downloadData(DgtFrame.java:1076) > > From what I've been able to find, this error can occur when you're > returned more than one geometry type, > but in this case, at least as far as I'm able to determine, I'm only > getting points back. > > ShapefileDataStore dest; > try > { > dest = new ShapefileDataStore(f.toURI().toURL()); > } > catch (MalformedURLException e) > { > System.out.println("toShpAction:MalformedURLException "+e); > e.printStackTrace(); > return; > } > > try > { > dest.createSchema(schema); > } > catch (IOException e) > { > System.out.println("toShpAction:IOException "+e); > e.printStackTrace(); > return; > } > > > I'm using geotools 2.5.5 and Java 1.6 with my code running on windows xp. > > Thanks > Mark > > > > > > ------------------------------------------------------------------------------ > Crystal Reports - New Free Runtime and 30 Day Trial > Check out the new simplified licensing option that enables unlimited > royalty-free distribution of the report engine for externally facing > server and web deployment. > http://p.sf.net/sfu/businessobjects > _______________________________________________ > Geotools-gt2-users mailing list > Geo...@li... > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users -- Justin Deoliveira OpenGeo - http://opengeo.org Enterprise support for open source geospatial. |