• <s id="aiiqm"></s>
  • 
    
    • <sup id="aiiqm"></sup>
    • <sup id="aiiqm"></sup>
       

      當前熱訊:Geotools基本增刪改查Feature

      發布時間:2023-04-24 05:27:35  |  來源:博客園  


      (資料圖片)

      postgis依賴

          org.geotools    gt-main    27.2    org.geotools    gt-jdbc-postgis    27.2

      創建連接JDBCDataStore

      Map params = Map.of(    PostgisNGDataStoreFactory.HOST.key, host,    PostgisNGDataStoreFactory.PORT.key, port,    PostgisNGDataStoreFactory.DATABASE.key, database,    PostgisNGDataStoreFactory.SCHEMA.key, schema,    PostgisNGDataStoreFactory.USER.key, user,    PostgisNGDataStoreFactory.PASSWD.key, passwd,    PostgisNGDataStoreFactory.DBTYPE.key, dbtype);JDBCDataStore jdbcDataStore = (JDBCDataStore)DataStoreFinder.getDataStore(params);

      JDBCDataStore連接參數

      ParameterDescription
      dbtypeMust be the string postgis
      hostMachine name or IP address to connect to
      portPort number to connect to, default 5432
      schemaThe database schema to access
      databaseThe database to connect to
      userUser name
      passwdPassword
      loose bboxFlag controlling loose bbox comparisons, default is true
      preparedStatementsFlag controlling whether prepared statements are used, default is false
      encode functionsFlag controlling if some common functions can be encoded into their SQL equivalent

      連接池參數

      ParameterDescription
      max connectionsMaximum number of connection the pool will hold at any time, default is 10
      min connectionsMinimum number of connection the pool will hold at any time, default is 1
      connection timeoutMaximum number of second the pool will wait when trying to obtain a connection, default is 20 seconds
      validate connectionsFlag controlling if the pool should validate connections when a new connection is obtained
      Max open prepared statementsMaximum number of prepared statements kept open and cached for each connection in the pool. Set to 0 to have unbounded caching, -1 to disable
      Test while idlePeriodically test if the connections are still valid also while idle in the pool
      Time between evictor runsNumber of seconds between idle object evictor runs. The default value is 300 seconds.
      Min evictable timeNumber of seconds a connection needs to stay idle before the evictor starts to consider closing it
      Evictor tests per runNumber of connections checked by the idle connection evictor for each of its runs. The default value is 3 connections.

      過濾器-Filter

      使用過濾器來定義要對其進行操作的Feature集合。過濾器也可以組合成一個操作集合使用。簡單說,過濾器相當于SQL語句的WHERE子句中存在的信息。Filter有多個子類,實現了許多類型的過濾器,包括簡單的屬性比較和空間查詢。

      // 普通字段FilterFactory ff = CommonFactoryFinder.getFilterFactory();/** * field 字段名 * value 條件值 * geometry 條件幾何體 *  *  * matchCase 是否區分大小寫,默認true-區分 * MatchAction(實現MultiValuedFilter的會有),匹配邏輯 * MatchAction.ANY-任何一個滿足,默認值 * MatchAction.ALL-全部滿足 * MatchAction.ONE-只有一個滿足 * */PropertyIsEqualTo equal = ff.equal(ff.property(field), ff.literal(value), true);//等于PropertyIsLike like = ff.like(ff.property(field), "%keywords%");//模糊匹配PropertyIsNotEqualTo notEqualTo = ff.notEqual(ff.property(field), ff.literal(value));//不等于PropertyIsNull aNull = ff.isNull(ff.property(field));//nullPropertyIsGreaterThan greater = ff.greater(ff.property(field), ff.literal(value));// 大于PropertyIsGreaterThanOrEqualTo greaterOrEqual = ff.greaterOrEqual(ff.property(field), ff.literal(value));// 大于等于PropertyIsLessThan less = ff.less(ff.property(field), ff.literal(value));//小于PropertyIsLessThanOrEqualTo lessOrEqual = ff.lessOrEqual(ff.property(field), ff.literal(value));//小于等于PropertyIsBetween between = ff.between(ff.property(field), ff.literal(value), ff.literal(value));//在...之間During during = ff.during(ff.property(field), ff.literal(value));//在時間期間Before before = ff.before(ff.property(field), ff.literal(value));//在時間之前After after = ff.after(ff.property(field), ff.literal(value));//在時間之后// Geometry字段FilterFactory2 ff2 = CommonFactoryFinder.getFilterFactory2();Beyond beyond = ff2.beyond(ff2.property(featureSource.schema.geometryDescriptor.localName), ff2.literal(geometry), 100.0, Units.METRE.name);// 圖層幾何字段超出給定幾何100米距離的Contains contains = ff2.contains(ff2.property(featureSource.schema.geometryDescriptor.localName), ff2.literal(geometry));// 圖層幾何字段包含給定幾何Within within = ff2.within(ff2.property(featureSource.schema.geometryDescriptor.localName), ff2.literal(geometry));// 圖層幾何字段被給定幾何包含Intersects intersects = ff2.intersects(ff2.property(featureSource.schema.geometryDescriptor.localName), ff2.literal(geometry));// 圖層幾何字段與給定幾何相交Disjoint disjoint = ff2.disjoint(ff2.property(featureSource.schema.geometryDescriptor.localName), ff2.literal(geometry));// 圖層幾何字段與給定幾何不相交Touches touches = ff2.touches(ff2.property(featureSource.schema.geometryDescriptor.localName), ff2.literal(geometry));// 圖層幾何字段與給定幾何相切// filter集合的邏輯關系,and并,or或,not非And and = ff.and(List.of(equal,like,beyond));//Or or = ff.or(List.of(notEqualTo,greater,contains));Not not = ff.not(during);// Function的實現類具體實現函數,name-函數名,例如:min,strReplace,toWKTFunction function = ff.function(name,expr1,exprN);PropertyName property = ff.property(field);Literal v = ff.literal(value);Function min = ff.function("min", property, v);PropertyName property = ff.property(field);Literal search = ff.literal("search");Literal replace = ff.literal("replace");Literal all = ff.literal( true );Function replace = ff.function("strReplace", new Expression[]{property,search,replace,all});PropertyName property = ff.property(featureSource.schema.geometryDescriptor.localName);Function toWKT = ff.function("toWKT", property);

      查詢

      /** * tableName 表名 * filter 過濾器 * List propNames 字段名列表 *  * startIndex 起始位 * maxFeatures 最大條數 * sortField 排序字段名 * */ContentFeatureSource featureSource = (ContentFeatureSource) jdbcDataStore.getFeatureSource(tableName);//返回字段列List propertyNames = propNames.stream().map(ff::property).collect(Collectors.toList());Query query = new Query(tableName,filter,propertyNames);int count = featureSource.getCount(query);//計數// 分頁,倒序query.setStartIndex(startIndex);query.setMaxFeatures(maxFeatures);query.setSortBy(new SortByImpl(ff.property(sortField), SortOrder.DESCENDING));ContentFeatureCollection collection = featureSource.getFeatures(query);SimpleFeatureIterator iterator = collection.features();// SimpleFeatureIterator必須關閉,否則會造成內存泄漏iterator.close();

      新增

      /*** tableName 圖層名* fieldName1 字段名* fieldValue1 字段值**/ContentFeatureSource featureSource = (ContentFeatureSource) jdbcDataStore.getFeatureSource(tableName);SimpleFeatureStore store = (SimpleFeatureStore)featureSource;  // write access!SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(store.getSchema());featureBuilder.set(fieldName1,fieldValue1);featureBuilder.set(fieldNameN,fieldValueN);SimpleFeature feature = featureBuilder.buildFeature(null);ListFeatureCollection featureCollection = new ListFeatureCollection(store.getSchema(), List.of(feature));List addFeatures = store.addFeatures(featureCollection);

      刪除

      /**** typeName 圖層名* fliter 過濾條件**/ContentFeatureSource featureSource = (ContentFeatureSource) jdbcDataStore.getFeatureSource(tableName);SimpleFeatureStore store = (SimpleFeatureStore)featureSource;  // write access!store.removeFeatures(filter);

      修改

      /*** * typeName 圖層名* names 修改字段名數組* values 修改值數組* fliter 過濾條件* names和values順序保持一致*/ContentFeatureSource featureSource = (ContentFeatureSource) jdbcDataStore.getFeatureSource(tableName);SimpleFeatureStore store = (SimpleFeatureStore)featureSource;  // write access!store.modifyFeature(names, values, filter)

      關鍵詞:

       

      關于我們 - 聯系我們 - 版權聲明 - 招聘信息 - 友鏈交換

      2014-2020  電腦商網 版權所有. All Rights Reserved.

      備案號:京ICP備2022022245號-1 未經過本站允許,請勿將本站內容傳播或復制.

      聯系我們:435 226 40@qq.com

      国内精品一区视频在线播放,嫩草影视在线观看,天天久久狠狠伊人第一麻豆,波多野结衣视频免费看
    • <s id="aiiqm"></s>
    • 
      
      • <sup id="aiiqm"></sup>
      • <sup id="aiiqm"></sup>
        主站蜘蛛池模板: 亚洲精品字幕在线观看| 免费观看激色视频网站(性色)| 稚嫩进出嗯啊湿透公交车漫画| 欧美乱大交xxxxxbbb| 国产精品爽爽va在线观看无码| 亚洲精品无码专区| 91麻豆久久久| 毛片免费视频在线观看| 成人片黄网站a毛片免费| 国产男女爽爽爽免费视频| 免看**一片成人123| freehd麻豆| 羞羞社区在线观看视频| 日韩精品极品视频在线观看免费 | 日产欧产va高清| 国产精品JIZZ在线观看无码| 亚洲综合激情视频| 一级片在线播放| 精品人妻少妇一区二区三区不卡| 日本熟妇乱人伦XXXX| 国产特黄特色一级特色大片| 亚洲av无码成人网站在线观看 | 性欧美video在线播放| 国产午夜福利100集发布| 亚洲一级视频在线观看| free性欧美另类高清| 激情小说视频在线观看| 国内少妇人妻丰满AV| 亚洲乱亚洲乱少妇无码| 97国产在线视频公开免费| 日本特黄特黄刺激大片| 四虎影视永久免费观看地址| 久久国产精品亚洲综合| 色综合久久天天影视网| 日韩亚洲欧美视频| 国产成人精品免费视频大全麻豆| 久久九九久精品国产日韩经典| 激情综合五月天| 日本japanese丰满奶水| 免费网站无遮挡| 91精品国产自产91精品|