Hello!
I didn't know where else I should post my problem so I'm sorry if this is
the wrong place.
Here's what's happening:
I'm trying to access a Postgis database using Geotools but I simply can't. I
have tried several different ways and different versions. Here's the code:
public static void main(String[] args) throws Exception {
// display a data store file chooser dialog for shapefiles
//File file = JFileDataStoreChooser.showOpenFile("shp", null);
HashMap<String, Object> params = new HashMap<String, Object>();
params.put("dbtype", "postgis");
params.put("host", "localhost");
params.put("port", new Integer(5432));
params.put("database", "Feira");
params.put("user", "postgres");
params.put("passwd", "XXXXX");
//FileDataStore store = FileDataStoreFinder.getDataStore(file);
DataStore store = DataStoreFinder.getDataStore(params);
if(store == null){
System.out.println("failed to connect");
System.exit(1);
}
SimpleFeatureSource featureSource =
store.getFeatureSource(store.getTypeNames()[1]);
// Create a map content and add our shapefile to it
MapContent map = new MapContent();
map.setTitle("Quickstart");
Style style = SLD.createSimpleStyle(featureSource.getSchema());
Layer layer = new FeatureLayer(featureSource, style);
map.addLayer(layer);
// Now display the map
JMapFrame.showMap(map);
}
This throws an exception:
27/09/2011 17:12:24 org.geotools.renderer.lite.StreamingRenderer
fireErrorEvent
GRAVE: org.geotools.data.Query cannot be cast to
org.geotools.data.DefaultQuery
java.lang.ClassCastException: org.geotools.data.Query cannot be cast to
org.geotools.data.DefaultQuery
at org.geotools.data.jdbc.JDBC1DataStore.getFeatureReader(
JDBC1DataStore.java:585)
at org.geotools.data.jdbc.JDBCFeatureCollection.reader(
JDBCFeatureCollection.java:86)
at org.geotools.data.store.DataFeatureCollection.openIterator(
DataFeatureCollection.java:229)
at org.geotools.data.store.DataFeatureCollection.iterator(
DataFeatureCollection.java:197)
at org.geotools.renderer.lite.StreamingRenderer.drawPlain(
StreamingRenderer.java:2258)
at org.geotools.renderer.lite.StreamingRenderer.processStylers(
StreamingRenderer.java:1967)
at org.geotools.renderer.lite.StreamingRenderer.paint(
StreamingRenderer.java:797)
at org.geotools.swing.RenderingTask.call(RenderingTask.java:105)
at org.geotools.swing.RenderingTask.call(RenderingTask.java:40)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(
ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(
ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)
This is my pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.geotools</groupId>
<artifactId>postgis_access</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>postgis_access</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<geotools.version>8-SNAPSHOT</geotools.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-shapefile</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-swing</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-postgis</artifactId>
<version>${geotools.version}</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net repository</name>
<url>http://download.java.net/maven/2</url>
</repository>
<repository>
<id>osgeo</id>
<name>Open Source Geospatial Foundation Repository</name>
<url>http://download.osgeo.org/webdav/geotools/</url>
</repository>
<repository>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>opengeo</id>
<name>OpenGeo Maven Repository</name>
<url>http://repo.opengeo.org</url>
</repository>
</repositories>
</project>
In the postgis dependency I have also tried version 2.5.3 as in
http://www.mvnbrowser.com/artifact-details.html?groupId=org.geotools&artifactId=gt-postgisbut
when I do that, the SimpleFeatureSource class disappears.
How can I access a PostGIS database?
Thanks,
Diego
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users