From: <bf...@ne...> - 2004-07-22 12:03:53
|
Hi Ian and all, Thanks for your helps Actually there is a geotools.jar in the repast2.2 release, I just use that part. In this case I can load some shape file e.g. tomszi= ps.shp. but has problems (attribue[7] got wrong type ,etc)with some others like a= campus map I am wokring on. The code segment are=20 GisLayer layer =3D new GisLayer(LayerType.POLYGON, "shapefile"); ShapefileDataSource datasource =3Dnull;=20 AttributeType[] atts =3D null; try{ datasource =3D new ShapefileDataSource(new URL(file)); }catch(MalformedURLException e){ e.printStackTrace(); System.out.println("PROBLEM with the URL of the GIS file supplied= "); } =20 com.vividsolutions.jts.geom.Envelope env =3D DatasourceHandler.getBounds(datasource);=20 xFact =3D env.getWidth()/worldXSize; yFact =3D env.getHeight()/worldYSize; xMin =3D env.getMinX(); yMin =3D env.getMinY(); layer.setBounds(env); Feature[] features =3D DatasourceHandler.getFeatures(datasource); =20 for (int i=3D0; i < features.length; i++){ DrawablePolygon dp=3Dnull; dp =3D new DrawablePolygon(features[i]); dp.setColor(new java.awt.Color(180+(int)(10*Math.random()), 180+(int)(10*Math.random()), 180+(int)(10*Math.random()))); layer.add(dp);} return layer; } I look into the class API and found there is a bit different with the=20 geotools 2.0 RC0 version. Does it meanrepast has its own implementations = of geotools??? Also I also found some other errors when trying different way to load=20 shape files. In those cases, it even can't load any shape files Such as : Exception in thread "AWT-EventQueue-0" java.lang.NoSuchFieldError: NONE at org.geotools.data.DefaultQuery.<init>(DefaultQuery.java:48) at simulation.CampusModel.getGeoLayer(CampusModel.java:416) at simulation.CampusModel.buildModel(CampusModel.java:87) at simulation.CampusModel.begin(CampusModel.java:160) Exception in thread "AWT-EventQueue-0" java.lang.NoSuchMethodError: org.geotools.feature.Feature.getSchema()Lorg/geotools/feature/FeatureType= ; at uchicago.src.sim.gis.PolygonAdapter.setFeature(Unknown Source) at uchicago.src.sim.gis.PolygonAdapter.<init>(Unknown Source) at uchicago.src.sim.gui.DrawablePolygon.<init>(Unknown Source) at simulation.CampusModel.getGeoLayer(CampusModel.java:447) at simulation.CampusModel.buildModel(CampusModel.java:87) The relevant codes are=20 GisLayer layer =3D new GisLayer(LayerType.POLYGON, "shapefile"); ShapefileDataSource datasource =3Dnull; AttributeType[] atts =3D null; try{ System.out.println("So far so good before datasource created"); datasource =3D new ShapefileDataSource(new URL(file)); }catch(MalformedURLException e){ e.printStackTrace(); System.out.println("PROBLEM with the URL of the GIS file supplied= "); System.exit(1); } =09 System.out.println("So far so good before dfc created"); DefaultFeatureCollection dfc =3D=20 (DefaultFeatureCollection)(DefaultFeatureCollections.newCollectio= n()); System.out.println("So far so good before dq claimed"); DefaultQuery dq; try{ dq =3D new DefaultQuery(); datasource.getFeatures(dfc, dq); }catch(DataSourceException e){ e.printStackTrace(); System.out.println("PROBLEM reading the GIS datasource"); System.exit(1);} FeatureIterator fi =3D dfc.features(); try{ layer.setBounds(datasource.getBounds()); }catch(DataSourceException e){e.printStackTrace();} while(fi.hasNext()){ DrawablePolygon dp=3Dnull; Feature f =3D fi.next(); dp =3D new DrawablePolygon(f); dp.setColor(new java.awt.Color(180+(int)(10*Math.random()), 180+(int)(10*Math.random()), 180+(int)(10*Math.random()))); layer.add(dp); } Thank you in advance Bin > Which version of geotools are you using? >=20 > I've copied the geotools user list in which may get you a better answer= . >=20 > Ian >=20 > 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=20 >=20 > > -----Original Message----- > > From: rep...@li...=20 > > [mailto:rep...@li...] On=20 > > Behalf Of bf...@ne... > > Sent: 22 July 2004 04:46 > > To: rep...@li... > > Subject: [Repast-interest] Help: Loading Shapefile Errors > >=20 > >=20 > > Hi all, > >=20 > > I am currently developing a small software to load and=20 > > display shape file. > >=20 > > Now I can load and display the tomszips.shp as included in=20 > > the demo folder of repast 2.2 release. > >=20 > > But when I tried to load another shape file, > > I got following runtime error: > > And I can not find any Attribute[] in the source code of=20 > > repast. That shape file can be loaded and displayed using=20 > > geotools 0.8.0, > >=20 > > Can anyone please tell me why this happened and any=20 > > suggestion on that? > >=20 > >=20 > >=20 > > org.geotools.data.DataSourceException: Illegal Feature=20 > > Exception loading data : Attribute[7] is of wrong type.=20 > > expected class java.lang.Float got java.lang.Double > > at > > org.geotools.shapefile.ShapefileDataSource.getFeatures(Shapefi > > leDataSource.java:228) > > at > > org.geotools.feature.FeatureCollectionDefault.getFeatures(Feat > > ureCollectionDefault.java:184) > > at=20 > > uchicago.src.sim.gis.DatasourceHandler.getFeatures(Unknown Source) > > at=20 > > uchicago.src.repastdemos.schellingGis.SchellingGis.<init>(Sche > > llingGis.java:169) > > at=20 > > uchicago.src.repastdemos.schellingGis.SchellingGis.main(Schell > > ingGis.java:282) > >=20 > >=20 > > ------------------------------------------------------------ > > This email was sent from Netspace Webmail: http://www.netspace.net.au > >=20 > >=20 > >=20 > > ------------------------------------------------------- > > This SF.Net email is sponsored by BEA Weblogic Workshop > > FREE Java Enterprise J2EE developer tools! > > Get your free copy of BEA WebLogic Workshop 8.1 today. > > http://ads.osdn.com/?ad_idG21&alloc_id=10040&op=CCk > > _______________________________________________ > > Repast-interest mailing list Rep...@li... > > https://lists.sourceforge.net/lists/listinfo/repast-interest > >=20 > >=20 >=20 >=20 ------------------------------------------------------------ This email was sent from Netspace Webmail: http://www.netspace.net.au |