I've resolved the problem
I want publish it, hoping it helps anyone.
I'm using Jdk 1.5 and geotools 2.2.
This is the right code:
import
java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.util.HashMap;
import java.util.Map;
import javax.swing.
JFrame;
import javax.swing.WindowConstants;
import org.geotools.data.
FeatureSource;
import org.geotools.data.postgis.PostgisDataStore;
import org.geotools.data.postgis.PostgisDataStoreFactory;
import org.
geotools.gui.swing.JMapPane;
import org.geotools.map.DefaultMapContext;
import org.geotools.map.DefaultMapLayer;
import org.geotools.map.
MapContext;
import org.geotools.map.MapLayer;
import org.geotools.
renderer.GTRenderer;
import org.geotools.renderer.lite.
StreamingRenderer;
import org.geotools.styling.Graphic;
import org.
geotools.styling.LineSymbolizer;
import org.geotools.styling.Mark;
import org.geotools.styling.PointSymbolizer;
import org.geotools.
styling.PolygonSymbolizer;
import org.geotools.styling.Rule;
import org.
geotools.styling.Style;
import org.geotools.styling.StyleBuilder;
import org.geotools.styling.Symbolizer;
import org.geotools.styling.
TextSymbolizer;
import com.vividsolutions.jts.geom.Envelope;
public
class SpearfishPostGIS {
public static void main(String[] args)
throws Exception {
//create the PostGISDataStore
Map params = new HashMap();
params.put("dbtype",
"postgis");
params.put("host", "localhost");
params.put
("port", new Integer(5432));
params.put("database",
"spearfish");
params.put("user", "postgres");
params.put
("passwd", "postgres");
PostgisDataStoreFactory f =
new PostgisDataStoreFactory();
PostgisDataStore pgDatastore =
(PostgisDataStore) f.createDataStore( params );
//
Prepare feature sources
// ... roads
FeatureSource
fsRoads = pgDatastore.getFeatureSource("roads");
System.out.
println(fsRoads.toString());
if (fsRoads==null) System.out.
println("fsroad null");
System.out.println(fsRoads.getSchema().
getTypeName());
// ... streams
FeatureSource fsStreams
= pgDatastore.getFeatureSource("streams");
// ... bug sites
FeatureSource fsBugs = pgDatastore.getFeatureSource
("bugsites");
// ... arch sites
FeatureSource fsArch =
pgDatastore.getFeatureSource("archsites");
// ... restricted
aread
FeatureSource fsRestricted = pgDatastore.getFeatureSource
("rstrct");
// Prepare styles
StyleBuilder sb = new
StyleBuilder();
// ... streams style
LineSymbolizer
lsStream = sb.createLineSymbolizer(Color.BLUE, 3);
Style
streamsStyle = sb.createStyle(lsStream);
// ... roads style
LineSymbolizer ls1 = sb.createLineSymbolizer(Color.YELLOW, 1);
LineSymbolizer ls2 = sb.createLineSymbolizer(Color.BLACK, 5);
Style roadsStyle = sb.createStyle();
roadsStyle.
addFeatureTypeStyle(sb.createFeatureTypeStyle(null, sb.createRule
(ls2)));
roadsStyle.addFeatureTypeStyle(sb.
createFeatureTypeStyle(null, sb.createRule(ls1)));
// ... bugs
style
Mark redCircle = sb.createMark(StyleBuilder.MARK_CIRCLE,
Color.RED, Color.BLACK, 0);
Graphic grBugs = sb.createGraphic
(null, redCircle, null);
PointSymbolizer psBugs = sb.
createPointSymbolizer(grBugs);
Style bugsStyle = sb.createStyle
(psBugs);
// ... archeological sites style
Mark
yellowTri = sb.createMark(StyleBuilder.MARK_TRIANGLE, Color.YELLOW,
Color.BLACK, 0);
Graphic grArch = sb.createGraphic(null,
yellowTri, null, 1, 15, 0);
PointSymbolizer psArch = sb.
createPointSymbolizer(grArch);
org.geotools.styling.Font font =
sb.createFont(new Font("Arial", Font.PLAIN, 12));
TextSymbolizer tsArch = sb.createTextSymbolizer(Color.BLACK, font,
"cat_desc");
tsArch.setHalo(sb.createHalo(Color.WHITE, 1, 2));
Rule archRule = sb.createRule(new Symbolizer[] {psArch,
tsArch});
Style archStyle = sb.createStyle();
archStyle.
addFeatureTypeStyle(sb.createFeatureTypeStyle(null, archRule));
// ... restricted area style
PolygonSymbolizer restrictedSymb =
sb.createPolygonSymbolizer(Color.LIGHT_GRAY, Color.BLACK,
0);
restrictedSymb.getFill().setOpacity(sb.literalExpression
(0.7));
Style restrictedStyle = sb.createStyle(restrictedSymb);
// Build the map
final MapContext map = new
DefaultMapContext();
map.getLayerBounds();
map.addLayer
(new DefaultMapLayer(fsStreams, streamsStyle));
map.addLayer
(new DefaultMapLayer(fsRoads, roadsStyle));
map.addLayer
(fsRestricted, restrictedStyle);
map.addLayer(fsBugs,
bugsStyle);
map.addLayer(fsArch, archStyle);
/* Show
the map */
JFrame frame = new JFrame();
frame.setTitle
("Spearfish map");
frame.setDefaultCloseOperation
(WindowConstants.EXIT_ON_CLOSE);
frame.setSize(640, 480);
JMapPane mapPane = new JMapPane();
com.
vividsolutions.jts.geom.Envelope env = new Envelope() {
{
for
(int i = 0; i < map.getLayers().length; i++) {
MapLayer mapLayer =
map.getLayer(i);
expandToInclude(mapLayer.getFeatureSource().
getFeatures()
.getBounds());
}
}
};
mapPane.
setMapArea(env);
GTRenderer renderer;
renderer
= new StreamingRenderer();
mapPane.setRenderer(renderer);
mapPane.setContext(map);
frame.
getContentPane().add(mapPane,BorderLayout.CENTER);
frame.
getContentPane().doLayout();
frame.getContentPane().setVisible
(true);
frame.show();
}
}
Now It run perfectly and show
me the map!!!!!
:)
I Hope it helps anyone.
Orazio
----Messaggio
originale----
Da: [EMAIL PROTECTED]
Data: 9-nov-2006 12.16 PM
A:
<[email protected]>
Ogg: [Geotools-gt2-users]
Problem using "SpearfishSample using PostGIS"
Hi to all,
I'm
newbie in geotools and i'm trying to run the
"SpearfishSample using
PostGIS"
http://geotools.codehaus.
org/How+to+use+a+PostGISDataStore
I've followed the description steps
in the Html page.
I've created
the PostGIS database with the spearfish
data
(by The attached file
spearfish_data_pg.sql.zip that contains
all of the sample data as
zipped SQL insert statements.)
BUT
It doesn't work properly and give
me the following output:
'9-nov-2006
11.54.11 org.geotools.data.db2.
DB2DataStoreFactory isAvailable
INFO: DB2 driver found: false'
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users