当前位置: 首页 > news >正文

企业网站模板文件管理建设网站公司有哪些

企业网站模板文件管理,建设网站公司有哪些,俄语网站建设注意事项,网店代运营公司哪家好前言 在GIS开发中#xff0c;经常需要进行数据的转换处理。在之前的文章中讲了如何使用GeoTools读取Shapefile数据#xff0c;并且展示了将Shapefile数据导入PostGIS空间数据库的多种方式。但是还缺少Shapefile数据转换来源的操作。 本篇教程在之前文章的基础上讲解如何将CSV…前言 在GIS开发中经常需要进行数据的转换处理。在之前的文章中讲了如何使用GeoTools读取Shapefile数据并且展示了将Shapefile数据导入PostGIS空间数据库的多种方式。但是还缺少Shapefile数据转换来源的操作。 本篇教程在之前文章的基础上讲解如何将CSV文件转换为我们熟悉的Shapefile数据。 开发环境 本文使用开发环境如下仅供参考。 :::block-1 时间2025年 GeoTools34-SNAPSHOT IDEIDEA2025.1.2 JDK17 ::: 1. 准备CSV文件 CSVComma-Separated Values文件是一种纯文本格式用于存储表格数据如电子表格或数据库。它以结构简单、兼容性广泛而著称是数据交换中最常用的格式之一。 CSV文本结构 Name,Age,Occupation Alice,28,Engineer Bob,32,Designer Charlie,45,ManagerCSV表格结构 2. 安装依赖 在之前开发的基础上增加gt-epsg-hsql依赖包。 dependencygroupIdorg.geotools/groupIdartifactIdgt-shapefile/artifactIdversion${geotools.version}/version /dependency dependencygroupIdorg.geotools/groupIdartifactIdgt-epsg-hsql/artifactIdversion${geotools.version}/version /dependency3. 读取CSV文件 使用showOpenFile方法打开文件选择框然后使用createType构造要素结构第一个参数location为要素类型第二个参数为要素属性。the_geom字段表明数据几何类型为Pointsrid表明数据坐标系为4326以及后面的字段名称和对应字段类型。 // 设置外观 UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());// 选择文件 File file JFileDataStoreChooser.showOpenFile(csv,null); if(file null ){return; }// 创建要素类型 final SimpleFeatureType TYPE DataUtilities.createType(location,the_geom:Point:srid4326,name:String,number:Integer );现在可以读取CSV数据并构造Features使用GeometryFactory来创建几何属性。 // 创建要素 ListSimpleFeature features new ArrayList(); // GeometryFactory 用来为要素创建几何属性 GeometryFactory geometryFactory JTSFactoryFinder.getGeometryFactory(null); SimpleFeatureBuilder featureBuilder new SimpleFeatureBuilder(TYPE);try(BufferedReader reader new BufferedReader(new FileReader(file))){// 读取第一行头部数据String line reader.readLine();for(line reader.readLine(); line ! null; line reader.readLine()){if(line.trim().length()0){String[] tokens line.split(\,);double latitude Double.parseDouble(tokens[0]);double longitude Double.parseDouble(tokens[1]);String name tokens[2].trim();int number Integer.parseInt(tokens[3].trim());// 构造点Point point geometryFactory.createPoint(new Coordinate(longitude,latitude));featureBuilder.add(point);featureBuilder.add(name);featureBuilder.add(number);SimpleFeature feature featureBuilder.buildFeature(null);features.add(feature);}} }4. 创建Shapefile ShapefileDataStoreFactory创建Shp工厂在createDataStore参数中将属性create spatial index设置为true标明为Shp数据创建空间索引。 // 从要素集创建Shapefile File newFile getNewShapeFile(file); ShapefileDataStoreFactory dataStoreFactory new ShapefileDataStoreFactory();MapString, Serializable params new HashMap(); params.put(url,newFile.toURI().toURL()); params.put(create spatial index,Boolean.TRUE);ShapefileDataStore dataStore (ShapefileDataStore) dataStoreFactory.createDataStore(params);// TYPE 用作描述文件内容的模板 dataStore.createSchema(TYPE);通过确认FeatureSource对象实现了FeatureStore方法来检查是否具有读写权限使用ListFeatureCollection包装FeatureCollection对象。最后使用transaction.comit()一次性安全地写出所有数据。 // 输出要素数据到Shapefile Transaction transaction new DefaultTransaction(create); String typeName dataStore.getTypeNames()[0];SimpleFeatureSource featureSource dataStore.getFeatureSource(typeName); SimpleFeatureType featureType featureSource.getSchema();if(featureSource instanceof SimpleFeatureStore){SimpleFeatureStore featureStore (SimpleFeatureStore) featureSource;SimpleFeatureCollection featureCollection new ListFeatureCollection(featureType,features);featureStore.setTransaction(transaction);try {featureStore.addFeatures(featureCollection);transaction.commit();}catch (Exception e){e.printStackTrace();transaction.rollback();}finally {transaction.close();}System.exit(0); }else {System.out.println(typeName 缺少读|写权限);System.exit(1); }5. Shapefile输出位置 使用getNewShapeFile方法选择Shp输出位置。 // 提示输出Shapefile private static File getNewShapeFile(File csvFile){String path csvFile.getAbsolutePath();String newPath path.substring(0,path.length()-4).shp;JFileDataStoreChooser chooser new JFileDataStoreChooser(.shp);chooser.setDialogTitle(保存 ShapeFile);chooser.setSelectedFile(new File(newPath));int returnVal chooser.showSaveDialog(null);if(returnVal ! JFileDataStoreChooser.APPROVE_OPTION){System.exit(0);}File newFile chooser.getSelectedFile();if(newFile.equals(csvFile)){System.out.println(Error:不能替换 csvFile);System.exit(0);}return newFile; }
http://www.yingshimen.cn/news/82153/

相关文章:

  • 东莞建设网官方网站首页有经验的武进网站建设
  • 无锡专业制作网站网页设计制作论文
  • 网站建设和前端开发的区别wordpress主题汉化是什么意思
  • 上海专业网站建站公做球衣外贸用什么网站
  • 163网站是jsp做的吗wordpress在php下安装教程
  • 深圳网站建设968织梦和wordpress哪个seo好
  • 网站开发待遇怎么样网站制作实例
  • 做的比较好的几个宠物网站珠海市做网站
  • 公司网站开发费摊销wordpress 添加微博
  • 哪里可以做外贸网站开通网站必须做域名空间
  • 网站开发的排期网站建设中山
  • 企业内部门户网站建设惠州做百度网站多少
  • 新手如何自己建网站30_10_郑州网站制作
  • 湖北建设银行官方网站首页营销网红
  • 网站 架构设计购物网站怎么做推广
  • 苏州建网站多少钱网络营销培训课程
  • 电子商务网站开发过程论文6wordpress文章伪静态
  • 在线编辑图片的网站有哪些杭州做网站套餐
  • 网站建设有哪种方式社区app网站模板下载
  • 做公司 网站建设做文案策划需要知道些什么网站
  • 东莞网站优化推广方案夜无忧论坛官网
  • 巢湖路桥建设集团有限公司网站国外对于网站开发
  • WordPress建站步骤高端网站建设熊掌号
  • 西安代做毕业设计网站黄岛网站建设多少钱
  • 做网站 用哪个网盘好试用网站如何做
  • 建设阅读网站的目的广告公司怎么找客户资源
  • o2o系统网站建设网站推广怎么优化
  • pc端网站建设哪里有网站开发项目进度安排
  • 精彩的网格布局网站android应用商店
  • 天津网站制作维护固始县住房和城乡规划建设局网站