概述

前文中,提到了等值面的生成,后面有人经常会问等值线的生成,本文在前文的基础上做了一点修改,完成了等值线的geotools生成。

效果

实现代码

package com.lzugis.geotools;import com.amazonaws.util.json.JSONObject;
import com.lzugis.CommonMethod;
import com.lzugis.geotools.utils.FeaureUtil;
import com.lzugis.geotools.utils.GeoJSONUtil;
import com.vividsolutions.jts.geom.Geometry;
import org.geotools.data.FeatureSource;
import org.geotools.data.shapefile.ShapefileDataStore;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.data.simple.SimpleFeatureSource;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.FeatureIterator;
import org.geotools.geojson.feature.FeatureJSON;
import org.opengis.feature.Feature;
import org.opengis.feature.simple.SimpleFeature;
import wContour.Contour;
import wContour.Global.Border;
import wContour.Global.PointD;
import wContour.Global.PolyLine;
import wContour.Global.Polygon;
import wContour.Interpolate;import java.io.File;
import java.io.StringWriter;
import java.nio.charset.Charset;
import java.util.*;/*** Created by admin on 2017/8/29.*/
public class EquiSurfaceLine {private static String rootPath = System.getProperty("user.dir");/*** 生成等值面** @param trainData    训练数据* @param dataInterval 数据间隔* @param size         大小,宽,高* @param boundryFile  四至* @param isclip       是否裁剪* @return*/public String calEquiSurface(double[][] trainData,double[] dataInterval,int[] size,String boundryFile,boolean isclip) {String geojsonline = "";try {double _undefData = -9999.0;SimpleFeatureCollection polylineCollection = null;List<PolyLine> cPolylineList = new ArrayList<PolyLine>();List<Polygon> cPolygonList = new ArrayList<Polygon>();int width = size[0],height = size[1];double[] _X = new double[width];double[] _Y = new double[height];File file = new File(boundryFile);ShapefileDataStore shpDataStore = null;shpDataStore = new ShapefileDataStore(file.toURL());//设置编码Charset charset = Charset.forName("GBK");shpDataStore.setCharset(charset);String typeName = shpDataStore.getTypeNames()[0];SimpleFeatureSource featureSource = null;featureSource = shpDataStore.getFeatureSource(typeName);SimpleFeatureCollection fc = featureSource.getFeatures();double minX = fc.getBounds().getMinX();double minY = fc.getBounds().getMinY();double maxX = fc.getBounds().getMaxX();double maxY = fc.getBounds().getMaxY();Interpolate.CreateGridXY_Num(minX, minY, maxX, maxY, _X, _Y);double[][] _gridData = new double[width][height];int nc = dataInterval.length;_gridData = Interpolate.Interpolation_IDW_Neighbor(trainData,_X, _Y, 12, _undefData);// IDW插值int[][] S1 = new int[_gridData.length][_gridData[0].length];/*** double[][] S0,* double[] X,* double[] Y,* int[][] S1,* double undefData*/List<Border> _borders = Contour.tracingBorders(_gridData, _X, _Y,S1, _undefData);/*** double[][] S0,* double[] X,* double[] Y,* int nc,* double[] contour,* double undefData,* List<Border> borders,* int[][] S1*/cPolylineList = Contour.tracingContourLines(_gridData, _X, _Y, nc,dataInterval, _undefData, _borders, S1);// 生成等值线cPolylineList = Contour.smoothLines(cPolylineList);// 平滑geojsonline = getPolylineGeoJson(cPolylineList);if (isclip) {polylineCollection = GeoJSONUtil.readGeoJsonByString(geojsonline);FeatureSource dc = clipFeatureCollection(fc, polylineCollection);geojsonline = getPolylineGeoJson(dc.getFeatures());}} catch (Exception e) {e.printStackTrace();}return geojsonline;}public String getPolylineGeoJson(FeatureCollection fc) {FeatureJSON fjson = new FeatureJSON();StringBuffer sb = new StringBuffer();try {sb.append("{\"type\": \"FeatureCollection\",\"features\": ");FeatureIterator itertor = fc.features();List<String> list = new ArrayList<String>();while (itertor.hasNext()) {SimpleFeature feature = (SimpleFeature) itertor.next();StringWriter writer = new StringWriter();fjson.writeFeature(feature, writer);list.add(writer.toString());}itertor.close();sb.append(list.toString());sb.append("}");} catch (Exception e) {e.printStackTrace();}return sb.toString();}public FeatureSource clipFeatureCollection(FeatureCollection fc,SimpleFeatureCollection gs) {FeatureSource cs = null;try {List<Map<String, Object>> values = new ArrayList<Map<String, Object>>();FeatureIterator contourFeatureIterator = gs.features();FeatureIterator dataFeatureIterator = fc.features();while (dataFeatureIterator.hasNext()) {Feature dataFeature = dataFeatureIterator.next();Geometry dataGeometry = (Geometry) dataFeature.getProperty("the_geom").getValue();while (contourFeatureIterator.hasNext()) {Feature contourFeature = contourFeatureIterator.next();Geometry contourGeometry = (Geometry) contourFeature.getProperty("geometry").getValue();double v = (Double) contourFeature.getProperty("value").getValue();if (dataGeometry.intersects(contourGeometry)) {Geometry geo = dataGeometry.intersection(contourGeometry);Map<String, Object> map = new HashMap<String, Object>();map.put("the_geom", geo);map.put("value", v);values.add(map);}}}contourFeatureIterator.close();dataFeatureIterator.close();SimpleFeatureCollection sc = FeaureUtil.creatSimpleFeatureByFeilds("polygons","crs:4326,the_geom:LineString,value:double",values);cs = FeaureUtil.creatFeatureSourceByCollection(sc);} catch (Exception e) {e.printStackTrace();return cs;}return cs;}public String getPolylineGeoJson(List<PolyLine> cPolylineList) {String geo = null;String geometry = " { \"type\":\"Feature\",\"geometry\":";String properties = ",\"properties\":{ \"value\":";String head = "{\"type\": \"FeatureCollection\"," + "\"features\": [";String end = "  ] }";if (cPolylineList == null || cPolylineList.size() == 0) {return null;}try {for (PolyLine pPolyline : cPolylineList) {List<Object> ptsTotal = new ArrayList<Object>();for (PointD ptD : pPolyline.PointList) {List<Double> pt = new ArrayList<Double>();pt.add(ptD.X);pt.add(ptD.Y);ptsTotal.add(pt);}JSONObject js = new JSONObject();js.put("type", "LineString");js.put("coordinates", ptsTotal);geo = geometry + js.toString() + properties + pPolyline.Value + "} }" + "," + geo;}if (geo.contains(",")) {geo = geo.substring(0, geo.lastIndexOf(","));}geo = head + geo + end;} catch (Exception e) {e.printStackTrace();return geo;}return geo;}public static void main(String[] args) {long start = System.currentTimeMillis();EquiSurfaceLine equiSurface = new EquiSurfaceLine();CommonMethod cm = new CommonMethod();double[] bounds = {110.759, 31.23, 113.112, 32.6299};double[][] trainData = new double[3][100];for (int i = 0; i < 100; i++) {double x = bounds[0] + new Random().nextDouble() * (bounds[2] - bounds[0]),y = bounds[1] + new Random().nextDouble() * (bounds[3] - bounds[1]),v = 0 + new Random().nextDouble() * (45 - 0);trainData[0][i] = x;trainData[1][i] = y;trainData[2][i] = v;}double[] dataInterval = new double[]{20, 25, 30, 35, 40, 45};String boundryFile = rootPath + "/data/shp/XY_01_XZQH_PY.shp";int[] size = new int[]{100, 100};boolean isclip = true;try {String strJson = equiSurface.calEquiSurface(trainData, dataInterval, size, boundryFile, isclip);String strFile = rootPath + "/out/XY_01_XZQH_PY_line1.geojson";cm.append2File(strFile, strJson);System.out.println(strFile + "差值成功, 共耗时" + (System.currentTimeMillis() - start) + "ms");} catch (Exception e) {e.printStackTrace();}}
}

技术博客
CSDN:http://blog.csdn.NET/gisshixisheng
在线教程
https://edu.csdn.net/course/detail/799
https://edu.csdn.net/course/detail/7471
联系方式

类型 内容
qq 1004740957
公众号 lzugis15
e-mail niujp08@qq.com
webgis群 452117357
Android群 337469080
GIS数据可视化群 458292378

“GIS讲堂”知识星球今天开通了,在星球,我将提供一对一的问答服务,你问我答,期待与你相见。

geotools等值线生成相关推荐

  1. Python 等值线生成(TIN三角网)

    基于TIN三角网生成不光滑等值线 等值线功能实现 等值点插值 TIN 边界边查找 单个三角形内生长等值线 一条等值线生成 按等高距生成全部等值线 可视化结果 可视化代码 等值线(未平滑) 全部代码 等 ...

  2. 【geotools】生成类似geoserver的geojson

    这里只做了点的 , 线,多线 等同理 下面例子中的结果,如图 import org.geotools.feature.DefaultFeatureCollection; import org.geot ...

  3. PIE SDK栅格生成等值线、面

      1.算法功能简介 等值线图能直观地展示数据的变化趋势,是众多领域展示成果的重要图建之一,被广泛应用于石油勘探.矿物开采.气象预报等众多领域.等值线的绘制是指从大量采样数据中提取出具有相同值的点的信 ...

  4. PIE SDK矢量点生成等值线、面

    1.算法功能简介 等值线图能直观地展示数据的变化趋势,是众多领域展示成果的重要图建之一,被广泛应用于石油勘探.矿物开采.气象预报等众多领域.等值线的绘制是指从大量采样数据中提取出具有相同值的点的信息, ...

  5. Grads画等值线(一)-----心得感言

    之前研究了如何用surfer画等值线,总体来说还算不错,在实际项目中得到了应用.但是在surfer等软件中使用的插值法都是纯数学差值法,在孤立点附近容易产生一些不合理区域.后来知道Grads中有在气象 ...

  6. SuperMap iDesktop中DEM数字高程模型数据的生成

    作者:xinxin 一. 前言   DEM(Digital Elevation Model,数字高程模型)主要描述地表起伏形态特征的空间数据模型,由地面规则格网点的高程值构成的矩阵,形成栅格结构数据. ...

  7. 用gis打开tif格式_如何下载SHP矢量格式的等高线

    一.什么是等高线? 等高线指的是地形图上高程相等的相邻各点所连成的闭合曲线,把地面上海拔高度相同的点连成的闭合曲线,并垂直投影到一个水平面上,并按比例缩绘在图纸上,就得到等高线.等高线也可以看作是不同 ...

  8. TLS 地面三维激光扫描仪

    Trimble 地面三维激光扫描系统 随着数字地球和数字城市的发展,三维数据获取工具和手段的不断进步,促进三维空间数据获取朝集成化.实时化.动态化. 数字化和智能化的方向发展,现实世界的立体信息快速地 ...

  9. 使用ArcGIS制作专题等值线图

    在arcgis中制作类似气温等值线图的专题图,一开始走了很多弯路,但最后发现其实可以很简单,结合模型构建器也可以快速的批量化制作,20幅等值线图最终制作时间2小时左右,包括了制作模型构建器和个性化细节 ...

  10. turfjs前端地理空间分析类库

    一.简介 turfjs是一个地理空间分析库,处理各种地图算法. 1. 简单 模块化,易于理解的JavaScript函数处理GeoJSON 2. 模块化 Turf是一系列小模板的集合,可以按需使用 3. ...

最新文章

  1. “三巨头”联合发布万字长文,深度学习将通往何方?
  2. C++文件流:myfstream,fstream,文件读写,随机文件读写【C++文件流】(59)
  3. 温州大学《深度学习》课程课件(六、机器学习实践)
  4. irms模拟数据生成及数据分析
  5. c++ 字符串转数字
  6. springboot设置默认值_spring boot jpa存储数据的默认值为java的默认值
  7. 5款神器级别Github 的Chrome插件
  8. 飞秋2010下载又用什么样的技术
  9. c++语言读txt数据,关于C++中读取txt文件中字符串 - 程序语言 - 小木虫 - 学术 科研 互动社区...
  10. torch GPU分布式训练 模型并行
  11. 【JavaScript 封装库】BETA 1.0 测试版发布!
  12. 勤哲excel服务器自动计算工资,用勤哲Excel服务器做财务软件
  13. 磁力计的基本工作原理
  14. 社交网络分析(igraph)
  15. java 枚举命名规则,枚举命名惯例 - 复数
  16. Python Basic - python 文件对象的文件交互各类方法描述与实现
  17. 《大话西游3》首曝海报 韩庚唐嫣分饰至尊宝和紫霞
  18. 从零开始学习STM32(一)—— 新建工程模板
  19. 慕了!17年阿里Java开发大佬把Spring Boot的精髓都总结出来了
  20. 工业机器人运动轨迹规划方法简述

热门文章

  1. 服务器显示RL011,台达伺服驱动器维修之AL011故障原因和方法
  2. matlab做经济地理、地理距离、经济距离空间权重矩阵
  3. java实现文字跑马灯_跑马灯的问题
  4. 《深入浅出数据分析》资源汇总
  5. 惠普打印机136w硒鼓芯片怎么清零_惠普136w打印机怎么清零
  6. 数字图像处理matlab 版下载,数字图像处理(MATLAB版)
  7. 同时带多个文件生成软盘镜像的方法
  8. 【转】程序员10月书讯
  9. Android 10.0修改语言设置简体中文(中国)为简体中文(中国大陆)
  10. android引用X5内核webview部分问题记录