2012-04-06 4 views
2

BEARBEITEN: Für Informationen: Erstellen Sie mit StyleLab Beispiel Stil und es wird angezeigt, was Sie wollen.Anzeigen von POSTGIS-Daten in einem JMapFrame mit GeoTools

Ich versuche POSTGIS Daten mit GeoTools Ich habe die Beispiele in anzuzeigen: http://docs.geotools.org/stable/userguide/examples/: Mit QueryLab i eine Registerkarte der POSTGIS Daten Mit Quick anzeigen kann ich eine Karte eines Shape-Datei anzeigen kann (SHP)

Aber ich habe in Misch diese Quellcodes, um eine Karte anzuzeigen mit meiner postgis Daten

in Bezug auf die Fehlermeldung nicht gelingt, kann es aus dem Fehlen von stil~~POS=TRUNC kommen. Trotzdem funktioniert es perfekt für Shapefiles, also verstehe ich nicht. Außerdem finde ich nicht, wie man einen geeigneten Stil erstellt, um dieses Problem zu lösen.

Wie kann ich die POSTGIS Geometries in einer Karte anzeigen? Weiß jemand, wie man dieses Problem löst oder irgendwelche Ideen hat?

hier meine Quellcode und Fehlermeldung:

package org.geotools.tuto; 

import java.io.IOException; 
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.data.Query; 
import org.geotools.map.*; 
import org.geotools.swing.JMapPane; 

public class test { 
    public test() throws IOException{ 
     Map params = new HashMap(); 
     params.put("dbtype", "postgis"); //must be postgis 
     //the name or ip address of the machine running PostGIS 
     params.put("host", "localhost"); 
     //the port that PostGIS is running on (generally 5432) 
     params.put("port", new Integer(5432)); 
     //the name of the database to connect to. 
     params.put("database", "***"); 
     params.put("user", "***");   //the user to connect with 
     params.put("passwd", "***");    //the password of the user. 

     FeatureSource fsBC = null; 
     DataStore pgDatastore; 
     try { 
      pgDatastore = DataStoreFinder.getDataStore(params); 

      fsBC = pgDatastore.getFeatureSource("pumas_sections"); 
      System.out.println("bc count: " + fsBC.getCount(Query.ALL)); 
      } catch (IOException e) { 
      e.printStackTrace(); 
     } 

     MapContext map = new DefaultMapContext(); 
     map.setTitle("Quickstart"); 
     map.addLayer(fsBC, null); 

     //... 
    } 

    public static void main(String[] args) throws Exception { 
      test t = new test(); 
    } 
} 

Fehler:

Exception in thread "main" java.lang.UnsupportedOperationException: No 
style method for com.vividsolutions.jts.geom.Geometry 
     at org.geotools.styling.SLD.createSimpleStyle(SLD.java:1967) 
     at org.geotools.styling.SLD.createSimpleStyle(SLD.java:1923) 
     at org.geotools.map.DefaultMapContext.checkStyle(DefaultMapContext.java:389) 
     at org.geotools.map.DefaultMapContext.addLayer(DefaultMapContext.java:222) 
     at org.geotools.tuto.test.<init>(test.java:45) 
     at org.geotools.tuto.test.main(test.java:52) 

Antwort

1

habe ich Ihren Code versuchen, und es funktionierte. Ich habe Geotools 10 verwendet, nachdem ich fsBC bekommen habe, benutzte ich MapContent.

Style style = SLD.createSimpleStyle(fsBC.getSchema()); 
Layer layer = new FeatureLayer(fsBC, style); 
MapContent map =new MapContent(); 
map.addLayer(layer); 

Ich hoffe, das ist nützlich.