前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Geotools Vector ShapeFile 打开矢量文件,根据传入范围获取几何模型及属性

Geotools Vector ShapeFile 打开矢量文件,根据传入范围获取几何模型及属性

作者头像
Freedom123
发布2024-03-29 08:56:55
580
发布2024-03-29 08:56:55
举报
文章被收录于专栏:DevOpsDevOps
代码语言:javascript
复制
/**
 * 根据点集获取面几何模型
 * @param points 点集
 * @return 返回polygon
 */
public static ShapefileDataStore instance(){
  File file = new File (Utils.getFeatureFile());
  if(featureSource == null){
    try{
      featureSource = new ShapefileDataStore(file.toURL());
    }catch (Exception e){
      e.printStackTrace();
    }
  }

  return  featureSource;
}

/**
 * 返回与geom相交的进行相交处理的几何模型
 * @param features 要素集
 * @param geom 几何模型
 * @return 返回几何模型集
 */
public static List<String> getFieldByEnvelop(ShapefileDataStore source,Geometry geom,String fieldName){
  List<String> files = new ArrayList<>();
  try{
    ContentFeatureSource featureSource = source.getFeatureSource();
    SimpleFeatureIterator iterator = featureSource.getFeatures().features();
    while(iterator.hasNext()){
      SimpleFeature feature =iterator.next();
      SimpleFeatureType featureType = feature.getFeatureType();
      Geometry  defaultGeometry = (Geometry)feature.getDefaultGeometry();

      //相交
      if(defaultGeometry.intersects(geom)){
        String jc = feature.getProperty(fieldName).getValue().toString();
        files.add(jc);
      }
    }
  }catch (Exception e){
    e.printStackTrace();
    return null;
  }

  return files;
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2024-03-28,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档