From: Andy T. <A.G...@le...> - 2007-05-17 10:02:03
|
Hi geotools-gt2-users, I have joined the club again after years of just lurking on the email list. I want to generate a load of static image files which are geographic maps that I can insert into web pages. Can you help? I am using GeoTools 2.3.1 (bin) and the javadocs. I can load the shapefile and iterate through the features and see the attribute on which I want to link. That is this bit: // Read Boundary data using ShapefileDataStore URL _URL =3D new URL( "file:///C:/temp/test.shp" ); //boolean readDBF =3D true; ShapefileDataStoreFactory _ShapefileDataStoreFactory =3D new ShapefileDataStoreFactory(); ShapefileDataStore _ShapefileDataStore =3D ( ShapefileDataStore = ) _ShapefileDataStoreFactory.createDataStore( _URL ); //ShapefileDataStore _ShapefileDataStore =3D new ShapefileDataStore( _URL ); FeatureType _FeatureType =3D _ShapefileDataStore.getSchema(); AttributeType[] _AttributeTypes =3D _FeatureType.getAttributeTypes(); for ( int i =3D 0; i < _AttributeTypes.length; i ++ ) { System.out.println( _AttributeTypes[ i ].getName() ); } FeatureSource _FeatureSource =3D _ShapefileDataStore.getFeatureSource(); FeatureCollection _FeatureCollection =3D _FeatureSource.getFeatures(); FeatureIterator _FeatureIterator =3D _FeatureCollection.features(); // Feature _Feature; // while ( _FeatureIterator.hasNext() ) { // _Feature =3D _FeatureIterator.next(); // System.out.println( _Feature.toString() ); // } Next I wanted to create an image of the polygons in the shapefile. This is where I got stuck. Here is what I currently have: // Create image using _ShapefileRenderer ShapefileRenderer _ShapefileRenderer =3D new = ShapefileRenderer(); // Set _MapContext // CoordinateReferenceSystem _CoordinateReferenceSystem =3D new CoordinateReferenceSystem(); // DefaultMapContext context =3D new DefaultMapContext( _CoordinateReferenceSystem ); DefaultMapContext _MapContext =3D new DefaultMapContext(); // Set some extra information to the map _MapContext.setTitle( "_Title" ); _MapContext.setContactInformation( "_ContactInformation" ); _MapContext.setAbstract( "_Abstract" ); _ShapefileRenderer.setContext( _MapContext ); // Create _Style StyleFactoryImpl _StyleFactoryImpl =3D new StyleFactoryImpl(); PolygonSymbolizer _PolygonSymbolizer =3D _StyleFactoryImpl.createPolygonSymbolizer(); // Fill _Fill =3D new Fill(); // Expression _Expression =3D new Expression(); // _Fill.setColor( _Expression ); // _PolygonSymbolizer.setFill( _Fill ); Rule _Rule =3D _StyleFactoryImpl.createRule(); _Rule.setSymbolizers( new Symbolizer[] { _PolygonSymbolizer } ); Style _Style =3D _StyleFactoryImpl.createStyle(); _Style.setName( "Style" ); _Style.addFeatureTypeStyle( _StyleFactoryImpl.createFeatureTypeStyle( new Rule[] { _Rule } ) ); =20 // Create _MapLayer from the _Style MapLayer _MapLayer =3D new DefaultMapLayer( _FeatureCollection, _Style, "_MapLayer1"); =20 // Create _BufferedImage BufferedImage _BufferedImage =3D new BufferedImage( = _Chart_Width, _Chart_Height, BufferedImage.TYPE_INT_RGB ); Graphics _Graphics =3D _BufferedImage.getGraphics(); _Graphics.setColor( Color.white ); _Graphics.fillRect( 0, 0, _Chart_Width, _Chart_Height ); _ShapefileRenderer.paint( ( Graphics2D ) _Graphics , new Rectangle( 0, 0, _Chart_Width, _Chart_Height ), new AffineTransform() ); // Create image file String type =3D "PNG"; javax.imageio.ImageIO.write( _BufferedImage, type, new File( "C:/temp/test" + "." + type ) ); =20 I have tried quite a few things, but had no luck. Please advise? I am now working on linking the other attribute data that I have and trying to figure how to shade these in different colours. Linking the data I was going to do myself as I don't expect there to be anything in GT2 to help. Styling is going to be tricky unless I can figure how to see some output. I have tried to use JMapPane but sofar had no success in displaying an image on screen. Any advice much appreciated. Many thanks for your help and for GT2 etc... Best wishes, Andy http://www.geog.leeds.ac.uk/people/a.turner/ =20 |