依赖jar包

读取shp

	public static void main(String[] path) {
DbaseFileReader reader = null;
try {
reader = new DbaseFileReader(new ShpFiles("C:\\Users\\lilei3774\\Desktop\\wuhan\\1\\split-hanzi\\poi.shp"), false,
Charset.forName("utf-8"));
DbaseFileHeader header = reader.getHeader();
int numFields = header.getNumFields(); while (reader.hasNext()) {
try {
Object[] entry = reader.readEntry();
for (int i = 0; i < numFields; i++) {
String title = header.getFieldName(i);
Object value = entry[i];
System.out.println(title + "=" + value);
}
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (reader != null) { try {
reader.close();
} catch (Exception e) {
}
}
}
}

  

	public static void main(String[] args) {
// TODO Auto-generated method stub ShapefileDataStore shpDataStore = null;
try{
shpDataStore = new ShapefileDataStore(new File("C:\\Users\\lilei3774\\Desktop\\wuhan\\1\\split-hanzi\\poi.shx").toURI().toURL());
// shpDataStore.setStringCharset(Charset.forName("GBK"));
shpDataStore.setCharset(Charset.forName("utf-8"));
String typeName = shpDataStore.getTypeNames()[0];
FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = null;
featureSource = (FeatureSource<SimpleFeatureType, SimpleFeature>)shpDataStore.getFeatureSource(typeName);
FeatureCollection<SimpleFeatureType, SimpleFeature> result = featureSource.getFeatures();
System.out.println(result.size());
FeatureIterator<SimpleFeature> itertor = result.features();
while(itertor.hasNext()){
SimpleFeature feature = itertor.next();
Collection<Property> p = feature.getProperties();
Iterator<Property> it = p.iterator();
while(it.hasNext()) {
Property pro = it.next();
if (pro.getValue() instanceof Point) {
System.out.println("PointX = " + ((Point)(pro.getValue())).getX());
System.out.println("PointY = " + ((Point)(pro.getValue())).getY());
} else {
System.out.println(pro.getName() + " = " + pro.getValue());
}
}
}
itertor.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch(IOException e) { e.printStackTrace(); }
}

  

写shp

	public static void main(String[] args) {
try{
File file = new File("C:\\Users\\lilei3774\\Desktop\\wuhan\\1\\split-hanzi\\self.shp");
Map<String, Serializable> params = new HashMap<String, Serializable>();
params.put( ShapefileDataStoreFactory.URLP.key, file.toURI().toURL() );
ShapefileDataStore ds = (ShapefileDataStore) new ShapefileDataStoreFactory().createNewDataStore(params);
//定义图形信息和属性信息
SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
tb.setCRS(DefaultGeographicCRS.WGS84);
tb.setName("shapefile");
tb.add("the_geom", Point.class);
tb.add("POIID", Long.class);
tb.add("NAMEC", String.class);
ds.createSchema(tb.buildFeatureType());
ds.setCharset(Charset.forName("utf-8"));
//设置Writer
FeatureWriter<SimpleFeatureType, SimpleFeature> writer = ds.getFeatureWriter(ds.getTypeNames()[0], Transaction.AUTO_COMMIT);
//写下一条
SimpleFeature feature = writer.next();
feature.setAttribute("the_geom", new GeometryFactory().createPoint(new Coordinate(116.123, 39.345)));
feature.setAttribute("POIID", 1234567890l);
feature.setAttribute("NAMEC", "某兴趣点1");
feature = writer.next();
feature.setAttribute("the_geom", new GeometryFactory().createPoint(new Coordinate(116.456, 39.678)));
feature.setAttribute("POIID", 1234567891l);
feature.setAttribute("NAMEC", "某兴趣点2");
writer.write();
writer.close();
ds.dispose();
} catch (Exception e) {
e.printStackTrace();
}
}

  

通过geotools读写shp文件的更多相关文章

  1. GeoJson的生成与解析,JSON解析,Java读写geojson,geotools读取shp文件,Geotools中Geometry对象与GeoJson的相互转换

    GeoJson的生成与解析 一.wkt格式的geometry转成json格式 二.json格式转wkt格式 三.json格式的数据进行解析 四.Java读写geojson 五.geotools读取sh ...

  2. geotools导入shp文件到Oracle数据库时表名带下划线的问题解决

    问题: 最近在做利用geotools导入shp文件到Oracle表中,发现一个问题Oracle表名带下划线时导入失败,问题代码行: dsOracle.getFeatureWriterAppend(or ...

  3. python GDAL 读写shp文件

    gdal包用于处理栅格数据,ogr用于处理矢量数据. 1 #!C:\Program Files\pythonxy\python\python.exe 2 #-*- coding:gb2312 -*- ...

  4. C#、C++用GDAL读shp文件(转载)

    C#.C++用GDAL读shp文件 C#用GDAL读shp文件 (2012-08-14 17:09:45) 标签: 杂谈 分类: c#方面的总结 1.目前使用开发环境为VS2008+GDAL1.81 ...

  5. Android GIS开发系列-- 入门季(13)Gdal简单写个shp文件

    Gdal是用来读写栅格与矢量数据的,在Gdal官网,可以下载相关的资源进行平台的编译.其实Arcgis底层也是用Gdal来读取shp文件的,那在Android中可以直接读写shp文件吗,是可以的.这里 ...

  6. shp系列(一)——利用C++进行shp文件的读(打开)与写(创建)开言

    博客背景和目的 最近在用C++写一个底层的东西,需要读取和创建shp文件.虽然接触shp文件已经几年了,但是对于shp文件内到底包含什么东西一直是一知半解.以前使用shp文件都是利用软件(如ArcGI ...

  7. JAVA用geotools读写shape格式文件

    转自:http://toplchx.iteye.com/blog/1335007 JAVA用geotools读写shape格式文件 (对应geotools版本:2.7.2) (后面添加对应geotoo ...

  8. 简析服务端通过geotools导入SHP至PG的方法

    文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1.背景 项目中需要在浏览器端直接上传SHP后服务端进行数据的自动入PG ...

  9. GDAL1.11版本号对SHP文件索引加速測试

    GDAL库中对于矢量数据的读取中能够设置一些过滤器来对矢量图形进行筛选.对于Shapefile格式来说.假设数据量太大,设置这个过滤器时间慢的简直无法忍受.好在GDAL1.10版本号開始支持读取Sha ...

随机推荐

  1. 笨鸟先飞之ASP.NET MVC系列之过滤器(02授权过滤器)

    授权过滤器 概念介绍 在之前的文章中我们已经带大家简单的了解了下过滤器,本次我们开始介绍授权过滤器. 我们之前提到过授权过滤器在认证过滤器之后,其他过滤器和方法被调用之前运行,而授权过滤器和它名字的含 ...

  2. PowerBI开发 第七篇:数据集和数据刷新

    PowerBI报表是基于数据分析的引擎,数据真正的来源(Data Source)是数据库,文件等数据存储媒介,PowerBI支持的数据源类型多种多样.PowerBI Service(云端)有时不直接访 ...

  3. Ubuntu16.04 install android-studio-ide-162.4069837-linux

    本文讲解如何在Ununtu 16.04上安装jdk.Android Sdk.Anroid Studio.Genymotion.AndroidStudio与Genymotion绑定. 由于第一次装了双系 ...

  4. Python自学笔记-列表生成式(来自廖雪峰的官网Python3)

    感觉廖雪峰的官网http://www.liaoxuefeng.com/里面的教程不错,所以学习一下,把需要复习的摘抄一下. 以下内容主要为了自己复习用,详细内容请登录廖雪峰的官网查看. 列表生成式 列 ...

  5. java web 学习总结之 Servlet/JSP 编码问题

    Servlet和JSP编码问题 字节流: 1.得到OutputStream  字节流 OutputStream os = response.getOutputStream();   用默认编码输出数据 ...

  6. DataGrid 如何得到DataGridRow 和DataGridCell 对象

    第一行为不可编辑  DataGridRow row = (DataGridRow)dataGrid1.ItemContainerGenerator.ContainerFromIndex(0);     ...

  7. 重学C语言---04字符串和格式化输入/输出

    1.程序示例 //talkback.c一个能为你提供一些信息的对话框 #include <stdio.h> #include <string.h> //提供strlen函数原型 ...

  8. 张高兴的 Windows 10 IoT 开发笔记:使用 MAX7219 驱动 8×8 点阵

    GitHub:https://github.com/ZhangGaoxing/windows-iot-demo/tree/master/MAX7219

  9. Java IO(Properties/对象序列化/打印流/commons-io)

    Java IO(Properties/对象序列化/打印流/commons-io) Properties Properties 类表示了一个持久的属性集.Properties 可保存在流中或从流中加载. ...

  10. HTML5-前端开发很火且工资很高?

    前言 晚上逛论坛看到一篇对从事HTML5前端开发的文章写的非常不错,和目前的市场形势差不多,然后我在其基础上给大家进行加工总结一下分享给大家.今天我们谈论的话题是<<为什么从事HTML5前 ...