android开发——使用java读取.shp(shapefile)矢量文件
来源:互联网 发布:spyder tensorflow 编辑:程序博客网 时间:2024/05/19 17:09
读取shapefile文件对于地图软件开发的人员来说是至关重要的,所以在这里给大家分享一下在android studio平台下如何读取shapefile空间数据文件;
闲话不多说直接上代码(绝对可以读取):
(注意:这段代码仅仅是读取 polyline的,其他集合类型的读取原理基本一致,参照就可以)
(代码说明:ShpPolyline 是自定义的一个model类)
String shpfilepath = path;//.shp文件的全路径path = path.replace("shp","shx");String shxfilepath = path;try{ File fs = new File(shxfilepath); long BytesSum = fs.length(); int shapecount = (int)(BytesSum - 100) / 8;//计算.shp中存储的信息条目个数 System.out.print(shapecount+"个"); if (shxfilepath == "") { return; }
***************************************************//读取头记录
fs = new File(shpfilepath); DataInputStream BinaryFile = new DataInputStream(new FileInputStream(fs)); for(int i=0;i<7;i++){ System.out.println(BinaryFile.readInt()+""); } BinaryFile.read(buf); System.out.println(bytesToInt(buf,0)+"nei");
**************************************************** BinaryFile.read(buf); int shapetype = bytesToInt(buf,0); System.out.println(shapetype+"");//输出几何类型(有0,1,3,5,8....)(不懂百度一下说明很详细) BinaryFile.read(buf2); BinaryFile.read(buf2); BinaryFile.read(buf2); BinaryFile.read(buf2); BinaryFile.read(new byte[32]); double x, y; int partcount; int pointcount; switch (shapetype)//根据几何类型进行读取 { case 1://single point break; case 8://multi points layer break; case 3://Polyline layer System.out.println("111111111111111111111111111111111111"); for (int i = 0; i < shapecount; i++) { ShpPolyline shapePolyline = new ShpPolyline(); BinaryFile.read(new byte[12]); BinaryFile.read(buf2); BinaryFile.read(buf2); BinaryFile.read(buf2); BinaryFile.read(buf2); BinaryFile.read(buf); partcount = bytesToInt(buf,0); BinaryFile.read(buf); pointcount = bytesToInt(buf,0); System.out.println(pointcount+"6666666"); System.out.println(partcount+"8888888"); int[] parts = new int[partcount]; int[] partspos = new int[partcount]; double[] xpoints = new double[pointcount]; double[] ypoints = new double[pointcount]; double[] zpoints = new double[pointcount]; for (int j = 0; j < partcount; j++) { BinaryFile.read(buf); parts[j] = bytesToInt(buf,0); System.out.println(parts[j]); } for (int j = 0; j < pointcount; j++) { BinaryFile.read(buf2); x = bytes2Double(buf2); BinaryFile.read(buf2); y = bytes2Double(buf2); System.out.println(x+"woqu"); System.out.println(y+"woqu1"); xpoints[j] = x; ypoints[j] = y; zpoints[j] = 0; } if (pointcount > 1) { shapePolyline.OID = i; shapePolyline.XPOINTS = xpoints; shapePolyline.YPOINTS = ypoints; } shpPolylineList.add(shapePolyline); } BinaryFile.close(); break;
数据的转化高地位变化:
//int数据的高地位变化
如果有什么问题请留言public static int bytesToInt(byte[] src, int offset) { int value; value = (int) ((src[offset] & 0xFF) | ((src[offset+1] & 0xFF)<<8) | ((src[offset+2] & 0xFF)<<16) | ((src[offset+3] & 0xFF)<<24)); return value; }//double数据的转化public static double bytes2Double(byte[] arr) { long value = 0; for (int i = 0; i < 8; i++) { value |= ((long) (arr[i] & 0xff)) << (8 * i); } return Double.longBitsToDouble(value); }
阅读全文
1 0
- android开发——使用java读取.shp(shapefile)矢量文件
- shapefile文件(shp)读取
- 使用GMap控件读取.shp多边形文件(shapefile)
- 空间矢量数据(.shp文件)之JAVA操作
- World Wind Java开发之五——读取本地shp文件
- android 平台下通过GDAL创建SHP(ShapeFile)文件至SD卡
- c++ 使用MapWinGis读取shp文件
- IDL读取Shapefile文件
- geotools读取shapefile文件
- 使用PostGIS 2.0 Shapefile and DBF Loader Exporter工具导入shp文件
- Java读取shapefile
- shp文件的读取
- shp文件的读取
- GDAL矢量(.shp)文件读写与创建
- 【GDAL/OGR】利用GDAL/OGR读取shp文件并转换为json文件(Java版)
- C#不用ArcEngine,生成Shp文件(一)---------shapefile数据说明
- GDAL读写矢量文件——Java
- GDAL读写矢量文件——Java
- EasyUI学习总结(六)——EasyUI布局
- Spring Security(03)——核心类简介
- 松下FP系列PLC以太网modbusTCP通讯
- websocket入门(2)——使用socket.io实现网络对战版五子棋
- 客户端C#读取opc数据
- android开发——使用java读取.shp(shapefile)矢量文件
- android应用中去掉标题栏的方法
- Spring Security(04)——认证简介
- Android 应用发布流程
- 如何禁止TextBox的记忆功能
- MUI开发时genymotion模拟器连不上Hbuilder解决办法
- ajax请求与UI进程阻塞
- JavaScript 类型判定
- 0159 使用 Linux 搭建 VPN