<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    sinoly

       :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
      29 隨筆 :: 76 文章 :: 189 評論 :: 0 Trackbacks

    ?

    ?1 package ?com.geotools.test;
    ?2
    ?3 /**
    ?4 ?*?
    ?5 ?*?CopyRight?(C)?All?rights?reserved.
    ?6 ?*?<p>?*?WuHan?Inpoint?Information?Technology?Development,Inc.
    ?7 ?*?<p>?*?Author?sinoly?<p>??Project?Name:?PostGeo
    ?8 ?*?<p>
    ?9 ?*?Base?on?:?JDK1.5
    10 ?*?<p>
    11 ?*?
    12 ? */
    ?
    13 import ?java.io.IOException;
    14 import ?java.util.HashMap;
    15 import ?java.util.Map;
    16
    17 import ?org.geotools.data.DataStore;
    18 import ?org.geotools.data.DataStoreFinder;
    19 import ?org.geotools.data.FeatureSource;
    20
    21 public ? class ?GetPostgisData? {
    22 ?
    23 ? static ?DataStore?pgDatastore;?? // 數(shù)據(jù)容器
    24 ?
    25 ?@SuppressWarnings( " unchecked " )
    26 ? private ? static ? void ?ConnPostGis(String?dbtype,String?URL, int ?port,String?database,String?user,String?password) {
    27 ??Map?params? = ? new ?HashMap();
    28 ??params.put( " dbtype " ,? " postgis " );
    29 ??params.put( " host " ,?URL);
    30 ??params.put( " port " ,? new ?Integer(port));
    31 ??params.put( " database " ,?database);
    32 ??params.put( " user " ,?user);
    33 ??params.put( " passwd " ,?password);??
    34 ?? try ? {
    35 ???pgDatastore? = ?DataStoreFinder.getDataStore(params);
    36 ??? if (pgDatastore != null ) {
    37 ????System.out.println( " 系統(tǒng)連接到位于: " + URL + " 的空間數(shù)據(jù)庫 " + database + " 成功! " );
    38 ????
    39 ???}
    else {
    40 ????System.out.println( " 系統(tǒng)連接到位于: " + URL + " 的空間數(shù)據(jù)庫 " + database + " 失敗!請檢查相關(guān)參數(shù) " );
    41 ???}

    42 ??}
    ? catch ?(IOException?e)? {
    43 ???e.printStackTrace();
    44 ???System.out.println( " 系統(tǒng)連接到位于: " + URL + " 的空間數(shù)據(jù)庫 " + database + " 失敗!請檢查相關(guān)參數(shù) " );
    45 ??}

    46 ?}

    47 ?
    48 ? public ? static ? void ?main(String[]?args)? throws ?IOException {
    49 ??ConnPostGis( "" , " localhost " , 5432 , " navigation " , " root " , " 123 " );
    50 ?? /* 讀取指定類型名的地理特征? */
    51 ??FeatureSource?fsBC? = ?pgDatastore.getFeatureSource( " roads " );
    52 ??System.out.println(fsBC.getFeatures().size());
    53 ?? /* 得到空間數(shù)據(jù)庫中所有特征表的表名 */
    54 ??String[]?typeName = pgDatastore.getTypeNames();
    55 ?? for ( int ?i = 0 ;i < typeName.length;i ++ ) {
    56 ???System.out.println(typeName[i]);
    57 ??}

    58 ?}

    59 }

    60
    61



    ???? 進(jìn)行Geotools的開發(fā)工作,肯定會參考GeoTools的官方參考文檔。不過我想很多人估計都遇到了和我一樣的問題,就是官方參考指南中幾乎沒有可以編譯通過的代碼,也就無法談及用這些代碼進(jìn)行學(xué)習(xí)了。昨天抽空將Geotools指南中連接到POSTGIS的代碼進(jìn)行了重新編譯,才發(fā)現(xiàn)指南中的代碼是在geotools 2.1.4中編譯的。。。狂汗ing。。我居然一直認(rèn)為是我的人品問題,才導(dǎo)致這些代碼在我機(jī)器上就無法編譯成功滴。。看來說明了一個問題:4475_200361112122146460.gif.。。。
    ????? 同時在編譯過程中還翻閱了2.3的API,也在其中發(fā)現(xiàn)了幾個對原有方法進(jìn)行功能修改或者干脆廢棄的方法,在此列出:
    ??????1、如果你和我一樣使用了POSTGRESQL 8.4,sorry,麻煩你不要用其自帶的任何JDBC驅(qū)動,直接使用geotools中帶的數(shù)據(jù)庫驅(qū)動吧。不要問我為什么,我也不知道,我唯一知道的就是只有這樣程序才能真正的連接到postgis。
    ??? 2、gt2-main.jar;gt2-postgis.jar;JTS-1.4.jar;geoapi-1.1.0alpha.jar;vecmath-1.2.1.jar。你需要確定這幾個文件存在與你的項目構(gòu)建之中。
    ?? 3、原有取得指定圖層Feature總數(shù)的方法是FeatureSource.getCount(Query.ALL)),這個方法已經(jīng)不能使用了,可以更換成getFeatures().size()方法來取得Feature的總數(shù)。(ps:雖說取得總數(shù)的方法用的不多,不過我覺得用這個方法來測試是否能連接到postgis還是很方便的。)
    ?? 4、應(yīng)用中最好能自己重寫postgis的連接池(可不是上面例子中的這種簡單玩意,嘿嘿),一般關(guān)系數(shù)據(jù)庫額連接池有很多中解決方式,但postgis的數(shù)據(jù)庫連接池目前我還不知道有什么好的解決方式,之所以要自己寫連接池的目的就是為了更好的控制postgis的空間索引關(guān)系。



    posted on 2007-01-25 09:55 sinoly 閱讀(7203) 評論(9)  編輯  收藏 所屬分類: POSTGISGEOTOOLS

    評論

    # re: 使用GeoTools 2.3M連接到POSTGIS數(shù)據(jù)庫[未登錄] 2007-01-25 10:07 sinoly
    如果有兄弟對開源GIS平臺開發(fā)感興趣的,考慮一下,一起搞搞:)
      回復(fù)  更多評論
      

    # re: 使用GeoTools 2.3M連接到POSTGIS數(shù)據(jù)庫 2007-01-25 12:49 Flyingis
    我有興趣,但現(xiàn)在自由的時間少了,大家可以一起探討。
    有沒有興趣加入WebGIS開發(fā)設(shè)計組,把3S相關(guān)的文章整理在一起?  回復(fù)  更多評論
      

    # re: 使用GeoTools 2.3M連接到POSTGIS數(shù)據(jù)庫[未登錄] 2007-05-22 09:16 過客
    有探討的群沒?我在學(xué)習(xí),想&大家一塊探討。有的話加我啊
    373572418  回復(fù)  更多評論
      

    # re: 使用GeoTools 2.3M連接到POSTGIS數(shù)據(jù)庫 2007-12-29 16:17 前進(jìn)
    我了很想和大家一起探討,79666049  回復(fù)  更多評論
      

    # re: 使用GeoTools 2.3M連接到POSTGIS數(shù)據(jù)庫 2008-01-02 11:32 前進(jìn)
    為了方便大家交流,請加入我的開源GIS項目分析的QQ群40087303,現(xiàn)在已經(jīng)有很多碩士和博士,有興趣的朋友快加入吧,我們一起為提高中國開源實力而努力!現(xiàn)階段分析的項目是SharpMap、Geoserver、Openlayers、GRASS、PostgerSQL、Geotools等
    我的QQ號:79666049


    群號:40087303
    群名:開源GIS項目分析
      回復(fù)  更多評論
      

    # re: 使用GeoTools 2.3M連接到POSTGIS數(shù)據(jù)庫 2008-01-02 17:13 kenzhang
    最近一直在學(xué)openGis,博主的文章也一直在看,收獲頗多,感謝!  回復(fù)  更多評論
      

    # re: 使用GeoTools 2.3M連接到POSTGIS數(shù)據(jù)庫 2008-07-15 10:10 ads
    請問一下hibernate hql 支持 postgis函數(shù)嗎???  回復(fù)  更多評論
      

    # re: 使用GeoTools 2.3M連接到POSTGIS數(shù)據(jù)庫 2008-12-08 11:01 songhf
    for (int i = 0; i < shapes.length; i++) {
    filter = new SeShapeFilter(tableName, spatialCol, shapes[i], SeFilter.METHOD_ENVP);
    filters[i] = filter;
    }
    try {
    String[] cols = new String[tableDef.length];
    for (int i = 0; i < tableDef.length; i++)
    cols[i] = tableDef[i].getName();
    SeSqlConstruct sqlCons = new SeSqlConstruct(tableName);
    SeQuery spatialQuery =session.createSeQuery(cols, sqlCons);
    System.out.println("run1");
    spatialQuery.prepareQuery();
    System.out.println("run2");
    spatialQuery.setSpatialConstraints(SeQuery.SE_OPTIMIZE, false,
    filters);
    spatialQuery.execute();
    SeRow row = spatialQuery.fetch();
    SeColumnDefinition colDef = new SeColumnDefinition();
    int numCols = 0;
    try {
    numCols = row.getNumColumns();
    } catch (NullPointerException ne) {

    System.out.println("\n No shape retrieved");
    spatialQuery.close();
    return;
    }
    while (row != null) {
    for (int i = 0; i < numCols; i++) {
    colDef = row.getColumnDef(i);
    int type = colDef.getType();
    if (row.getIndicator((short) i) != SeRow.SE_IS_NULL_VALUE) {
    switch (type) {
    case SeColumnDefinition.TYPE_INT16:
    System.out.println("\t" + colDef.getName() + " : "
    + row.getShort(i));
    break;
    case SeColumnDefinition.TYPE_DATE:
    System.out.println("\t" + colDef.getName() + " : "
    + (row.getTime(i)).getTime());
    break;
    case SeColumnDefinition.TYPE_INT32:
    System.out.println("\n\t" + colDef.getName()
    + " : " + row.getInteger(i));
    break;
    case SeColumnDefinition.TYPE_FLOAT32:
    System.out.println("\t" + colDef.getName() + " : "
    + row.getFloat(i));
    break;
    case SeColumnDefinition.TYPE_FLOAT64:
    System.out.println("\t" + colDef.getName() + " : "
    + row.getDouble(i));
    break;
    case SeColumnDefinition.TYPE_STRING:
    System.out.println("\t" + colDef.getName() + " : "
    + row.getString(i));
    break;
    case SeColumnDefinition.TYPE_SHAPE:
    SeShape spVal = (SeShape) row.getShape(i);
    SeExtent sExt=spVal.getExtent();
    double dCenterX=(sExt.getMaxX()+sExt.getMinX())/2;
    double dCenterY=(sExt.getMaxY()+sExt.getMinY())/2;
    break;
    case SeColumnDefinition.TYPE_NSTRING:
    System.out.println("\t" + colDef.getName() + " : "
    + row.getString(i));
    break;
    default:
    System.out.println("Unknown Type");

    System.out.println("\t" + colDef.getName() + " : ");
    break;
    }
    }
    }
    row = spatialQuery.fetch();
    }
    spatialQuery.close();
    SeState s=null;
    session.close(s);
    } catch (SeException sexp) {
    System.out.println("SeException : "
    + sexp.getSeError().getErrDesc());
    }
    } catch (Exception e) {
    }
    }
    }  回復(fù)  更多評論
      

    # re: 使用GeoTools 2.3M連接到POSTGIS數(shù)據(jù)庫 2008-12-08 11:02 songhf
    幫忙看看這個問題:
    SeException : THIS CONNECTION IS LOCKED TO A DIFFERENT THREAD.
    package com.easymap.demo;
    import com.esri.sde.sdk.client.*;
    import com.esri.sde.sdk.sg.ENVELOPE;
    import org.geotools.arcsde.pool.*;
    import org.geotools.data.*;
    import java.io.IOException;
    import java.util.*;
    public class ReadSde {
    private static SeLayer layer = null;
    private static SeTable table = null;
    public static void main(String args[]) {
    HashMap m = new HashMap();
    m.put(ArcSDEConnectionConfig.DBTYPE_PARAM,
    ArcSDEConnectionConfig.DBTYPE_PARAM_VALUE);
    m.put(ArcSDEConnectionConfig.SERVER_NAME_PARAM, "192.168.10.90");
    m.put(ArcSDEConnectionConfig.PORT_NUMBER_PARAM, "5151");
    m.put(ArcSDEConnectionConfig.INSTANCE_NAME_PARAM, "orasrv");
    m.put(ArcSDEConnectionConfig.USER_NAME_PARAM, "cwgtgis");
    m.put(ArcSDEConnectionConfig.PASSWORD_PARAM, "cwgtgis");
    ArcSDEConnectionConfig config = new ArcSDEConnectionConfig(m);
    SessionPoolFactory sessionFactory = SessionPoolFactory.getInstance();
    String tableName = "CWGTGIS.JSYD_PG_500";
    String spatialCol = "";
    try {
    SessionPool sessionPool = sessionFactory.createPool(config);
    ISession session = sessionPool.getSession();
    SeColumnDefinition[] tableDef = session
    .describe(tableName);
    for (int i = 0; i < tableDef.length; i++) {
    System.out.println(tableDef[i].getName());
    if (tableDef[i].getType() == SeColumnDefinition.TYPE_SHAPE) {
    spatialCol = tableDef[i].getName();
    break;
    }
    }
    layer = session.createSeLayer(tableName,spatialCol);
    SeShape shape = new SeShape(layer.getCoordRef());
    double minX = 502151.15789, minY = 298837.65948, maxX = 508619.77825, maxY = 304522.20465;
    SeExtent extent = new SeExtent(minX, minY, maxX, maxY);
    shape.generateRectangle(extent);
    SeShape[] shapes = new SeShape[1];
    shapes[0] = shape;
    SeShapeFilter filters[] = new SeShapeFilter[shapes.length];
    SeShapeFilter filter = null;
    for (int i = 0; i < shapes.length; i++) {
    filter = new SeShapeFilter(tableName, spatialCol, shapes[i], SeFilter.METHOD_ENVP);
    filters[i] = filter;
    }
    try {
    String[] cols = new String[tableDef.length];
    for (int i = 0; i < tableDef.length; i++)
    cols[i] = tableDef[i].getName();
    SeSqlConstruct sqlCons = new SeSqlConstruct(tableName);
    SeQuery spatialQuery =session.createSeQuery(cols, sqlCons);
    System.out.println("run1");
    spatialQuery.prepareQuery();
    System.out.println("run2");
    spatialQuery.setSpatialConstraints(SeQuery.SE_OPTIMIZE, false,
    filters);
    spatialQuery.execute();
    SeRow row = spatialQuery.fetch();
    SeColumnDefinition colDef = new SeColumnDefinition();
    int numCols = 0;
    try {
    numCols = row.getNumColumns();
    } catch (NullPointerException ne) {

    System.out.println("\n No shape retrieved");
    spatialQuery.close();
    return;
    }
    while (row != null) {
    for (int i = 0; i < numCols; i++) {
    colDef = row.getColumnDef(i);
    int type = colDef.getType();
    if (row.getIndicator((short) i) != SeRow.SE_IS_NULL_VALUE) {
    switch (type) {
    case SeColumnDefinition.TYPE_INT16:
    System.out.println("\t" + colDef.getName() + " : "
    + row.getShort(i));
    break;
    case SeColumnDefinition.TYPE_DATE:
    System.out.println("\t" + colDef.getName() + " : "
    + (row.getTime(i)).getTime());
    break;
    case SeColumnDefinition.TYPE_INT32:
    System.out.println("\n\t" + colDef.getName()
    + " : " + row.getInteger(i));
    break;
    case SeColumnDefinition.TYPE_FLOAT32:
    System.out.println("\t" + colDef.getName() + " : "
    + row.getFloat(i));
    break;
    case SeColumnDefinition.TYPE_FLOAT64:
    System.out.println("\t" + colDef.getName() + " : "
    + row.getDouble(i));
    break;
    case SeColumnDefinition.TYPE_STRING:
    System.out.println("\t" + colDef.getName() + " : "
    + row.getString(i));
    break;
    case SeColumnDefinition.TYPE_SHAPE:
    SeShape spVal = (SeShape) row.getShape(i);
    SeExtent sExt=spVal.getExtent();
    double dCenterX=(sExt.getMaxX()+sExt.getMinX())/2;
    double dCenterY=(sExt.getMaxY()+sExt.getMinY())/2;
    break;
    case SeColumnDefinition.TYPE_NSTRING:
    System.out.println("\t" + colDef.getName() + " : "
    + row.getString(i));
    break;
    default:
    System.out.println("Unknown Type");
    System.out.println("\t" + colDef.getName() + " : ");
    break;
    }
    }
    }
    row = spatialQuery.fetch();
    }
    spatialQuery.close();
    SeState s=null;
    session.close(s);
    } catch (SeException sexp) {
    System.out.println("SeException : "
    + sexp.getSeError().getErrDesc());
    }
    } catch (Exception e) {
    }
    }
    }  回復(fù)  更多評論
      

    主站蜘蛛池模板: 中国xxxxx高清免费看视频| 亚洲香蕉久久一区二区| 亚洲欧洲日产国码无码网站| 免费日本黄色网址| 免费一级做a爰片性色毛片| 看全色黄大色大片免费久久 | 中文字幕在线日亚洲9| 亚洲av极品无码专区在线观看| 亚洲毛片一级带毛片基地| 亚洲精品欧洲精品| 亚洲日本人成中文字幕| 在线观看亚洲AV日韩AV| 亚洲AV无码AV吞精久久| 一级视频在线免费观看| 成人无码a级毛片免费| 无码精品一区二区三区免费视频 | 亚洲国产成人AV网站| 色吊丝性永久免费看码| 久久国产精品免费一区| 日本在线免费观看| 国产免费的野战视频| 午夜免费不卡毛片完整版| 免费国产精品视频| 亚洲午夜久久久久久噜噜噜| 亚洲国产精久久久久久久| 亚洲国产成人精品久久 | 亚洲午夜视频在线观看| 亚洲18在线天美| 成人婷婷网色偷偷亚洲男人的天堂| 猫咪www免费人成网站| 免费无码又爽又刺激一高潮| 少妇无码一区二区三区免费| 免费人成在线视频| 亚洲第一页日韩专区| 亚洲成av人片在www鸭子| 黄人成a动漫片免费网站| 国产色无码精品视频免费| 青娱分类视频精品免费2| 国产乱子伦精品免费无码专区| 亚洲av无码无在线观看红杏| 亚洲va在线va天堂成人|