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 = new URL( "file:///C:/temp/test.shp" );
//boolean readDBF = true;
ShapefileDataStoreFactory _ShapefileDataStoreFactory = new
ShapefileDataStoreFactory();
ShapefileDataStore _ShapefileDataStore = ( ShapefileDataStore )
_ShapefileDataStoreFactory.createDataStore( _URL );
//ShapefileDataStore _ShapefileDataStore = new
ShapefileDataStore( _URL );
FeatureType _FeatureType = _ShapefileDataStore.getSchema();
AttributeType[] _AttributeTypes =
_FeatureType.getAttributeTypes();
for ( int i = 0; i < _AttributeTypes.length; i ++ ) {
System.out.println( _AttributeTypes[ i ].getName() );
}
FeatureSource _FeatureSource =
_ShapefileDataStore.getFeatureSource();
FeatureCollection _FeatureCollection =
_FeatureSource.getFeatures();
FeatureIterator _FeatureIterator =
_FeatureCollection.features();
// Feature _Feature;
// while ( _FeatureIterator.hasNext() ) {
// _Feature = _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 = new ShapefileRenderer();
// Set _MapContext
// CoordinateReferenceSystem _CoordinateReferenceSystem = new
CoordinateReferenceSystem();
// DefaultMapContext context = new DefaultMapContext(
_CoordinateReferenceSystem );
DefaultMapContext _MapContext = 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 = new StyleFactoryImpl();
PolygonSymbolizer _PolygonSymbolizer =
_StyleFactoryImpl.createPolygonSymbolizer();
// Fill _Fill = new Fill();
// Expression _Expression = new Expression();
// _Fill.setColor( _Expression );
// _PolygonSymbolizer.setFill( _Fill );
Rule _Rule = _StyleFactoryImpl.createRule();
_Rule.setSymbolizers( new Symbolizer[] { _PolygonSymbolizer } );
Style _Style = _StyleFactoryImpl.createStyle();
_Style.setName( "Style" );
_Style.addFeatureTypeStyle(
_StyleFactoryImpl.createFeatureTypeStyle( new Rule[] { _Rule } ) );
// Create _MapLayer from the _Style
MapLayer _MapLayer = new DefaultMapLayer( _FeatureCollection,
_Style, "_MapLayer1");
// Create _BufferedImage
BufferedImage _BufferedImage = new BufferedImage( _Chart_Width,
_Chart_Height, BufferedImage.TYPE_INT_RGB );
Graphics _Graphics = _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 = "PNG";
javax.imageio.ImageIO.write( _BufferedImage, type, new File(
"C:/temp/test" + "." + type ) );
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/
<<attachment: test.PNG>>
------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/
_______________________________________________ Geotools-gt2-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
