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.)
Then, I've
run following code:
* Created on 1-july-2004 */
package demo.postgres;
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.DataStore;
import org.geotools.data.DataStoreFinder;
import org.
geotools.data.FeatureSource;
import org.geotools.gui.swing.JMapPane;
import org.geotools.map.DefaultMapContext;
import org.geotools.map.
MapContext;
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;
/**
* Simple map viewer. Change
database params for your own system.
* @author wolf
* @author rschulz
*/
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");
DataStore pgDatastore =
DataStoreFinder.getDataStore(params);
// Prepare
feature sources
// ... roads
FeatureSource fsRoads =
pgDatastore.getFeatureSource("roads");
// ... 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
MapContext map = new DefaultMapContext();
map.addLayer(fsStreams, streamsStyle);
map.addLayer(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 = fsStreams.
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();
}
}
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'
Can anybody help me?
Thanks. Orazio
-------------------------------------------------------------------------
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