2012-04-06 2 views
2

EDIT : 자세한 내용은 StyleLab 예제로 스타일을 작성하면 원하는 것을 표시합니다.GeoTools가있는 JMapFrame에서 POSTGIS 데이터를 표시하십시오.

내가했던 예에서 GeoTools 와 PostGIS와 데이터를 표시하기 위해 노력하고있어 : http://docs.geotools.org/stable/userguide/examples/ : QueryLab와 내가 퀵 스타트와 나는 모양 파일의지도를 표시 할 수 PostGIS와 데이터의 탭을 표시 할 수 있습니다 (.shp 인)

하지만 오류 메시지에 대해서는 내 PostGIS와의 datas

과지도를 표시하는 소스 코드를 혼합에 성공하지 못했습니다, 그것은 스타일 정의의 부재에서 올 수 있습니다. 그럼에도 불구하고 그것은 셰이프 파일에 대해 완벽하게 작동하므로 이해하지 못합니다. 게다가, 나는이 문제를 해결할 수있는 적절한 스타일을 만드는 방법을 찾지 못한다.

어떻게지도에 POSTGIS 도형을 표시 할 수 있습니까? 누구든지이 문제를 해결하거나 아이디어가있는 방법을 알고 있습니까?

여기 내 소스 코드 및 메시지 오류 :

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(); 
    } 
} 

오류 :

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) 

답변

1

내가 코드를 시도했고,이 일했다. geotools 10을 사용하여 fsBC를 얻은 후 MapContent를 사용했습니다.

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

호프 유용합니다.

관련 문제