geoTools向shp文件中写数据
来源:互联网 发布:手机迅雷提示无网络 编辑:程序博客网 时间:2024/05/16 15:56
package test;import java.io.File;import java.io.Serializable;import java.util.HashMap;import java.util.Map;import org.geotools.data.DataUtilities;import org.geotools.data.DefaultTransaction;import org.geotools.data.Transaction;import org.geotools.data.shapefile.ShapefileDataStore;import org.geotools.data.shapefile.ShapefileDataStoreFactory;import org.geotools.data.simple.SimpleFeatureCollection;import org.geotools.data.simple.SimpleFeatureSource;import org.geotools.data.simple.SimpleFeatureStore;import org.geotools.feature.FeatureCollections;import org.geotools.feature.simple.SimpleFeatureBuilder;import org.geotools.referencing.crs.DefaultGeographicCRS;import org.junit.Test;import org.opengis.feature.simple.SimpleFeature;import org.opengis.feature.simple.SimpleFeatureType;import com.vividsolutions.jts.geom.Coordinate;import com.vividsolutions.jts.geom.GeometryFactory;import com.vividsolutions.jts.geom.Point;//使用geotools2.7.2public class WriteData { @Test public void write2() { try{ //定义属性 final SimpleFeatureType TYPE = DataUtilities.createType("Location", "location:Point," + // <- the geometry attribute: Point type "POIID:String," + // <- a String attribute "MESHID:String," + // a number attribute "OWNER:String" ); SimpleFeatureCollection collection = FeatureCollections.newCollection(); GeometryFactory geometryFactory = new GeometryFactory(); SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE); double latitude = Double.parseDouble("116.123456789"); double longitude = Double.parseDouble("39.120001"); String POIID = "2050003092"; String MESHID = "0"; String OWNER = "340881"; Point point = geometryFactory.createPoint(new Coordinate(longitude, latitude)); Object[] obj = {point, POIID, MESHID, OWNER}; SimpleFeature feature = featureBuilder.buildFeature(null, obj); collection.add(feature); feature = featureBuilder.buildFeature(null, obj); collection.add(feature); File newFile = new File("D:/newPoi.shp"); ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory(); Map<String, Serializable> params = new HashMap<String, Serializable>(); params.put("url", newFile.toURI().toURL()); params.put("create spatial index", Boolean.TRUE); ShapefileDataStore newDataStore = (ShapefileDataStore) dataStoreFactory.createNewDataStore(params); newDataStore.createSchema(TYPE); newDataStore.forceSchemaCRS(DefaultGeographicCRS.WGS84); Transaction transaction = new DefaultTransaction("create"); String typeName = newDataStore.getTypeNames()[0]; SimpleFeatureSource featureSource = newDataStore.getFeatureSource(typeName); if (featureSource instanceof SimpleFeatureStore) { SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource; featureStore.setTransaction(transaction); try { featureStore.addFeatures(collection); transaction.commit(); } catch (Exception problem) { problem.printStackTrace(); transaction.rollback(); } finally { transaction.close(); } } else { System.out.println(typeName + " does not support read/write access"); } } catch (Exception e) { e.printStackTrace(); } } }
0 0
- geoTools向shp文件中写数据
- Geotools读取shp文件并在Ol2中展示
- 【GeoTools】shp文件坐标转换
- 向文件中写数据
- Geotools 对shp数据的样式修改
- geotools实现shp数据的缓冲区分析
- 向Ini文件中写入流数据
- 向文件中写数据,读数据
- Java向Excel文件中写数据
- 向文件中写数据的方法
- BufferedWriter向文件中写数据
- Java向文件中写数据
- 多线程向一个文件中写数据
- arcgis连接oracle,并向oracle中导入shp数据
- arcgis连接oracle,并向oracle中导入shp数据
- arcgis连接oracle,并向oracle中导入shp数据
- geotools中shp和geojson格式的相互转换
- 向txt文件中写数据(每行三个数据)
- Linux 快速删除大量小文件方法
- 深度学习Matlab工具箱代码详解
- oracle导出txt文本数据的2中方法
- 树
- 排序算法-选择类排序
- geoTools向shp文件中写数据
- Python中os与sys两模块的区别
- Ubuntu 安装 Python
- CentOS7下安装nginx与php
- Linux 中/var/spool/postfix/maildrop目录下堆积大量小文件
- 算法基础之字符串2
- 指令和控制器之间的交互
- nginx 重写规则,过滤某些url
- 曾经使用过的Linux命令