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

大连网站前端制作公司/上海百度推广官方电话

大连网站前端制作公司,上海百度推广官方电话,免费网站建设模板下载,佛山网站建设小程序概述 前文中,提到了等值面的生成,后面有人经常会问等值线的生成,本文在前文的基础上做了一点修改,完成了等值线的geotools生成。 效果 实现代码 package com.lzugis.geotools;import com.amazonaws.util.json.JSONObject; import com.lzug…

概述

前文中,提到了等值面的生成,后面有人经常会问等值线的生成,本文在前文的基础上做了一点修改,完成了等值线的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
联系方式

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

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

LZUGIS

http://www.jmfq.cn/news/5159215.html

相关文章:

  • 医疗网站建设信息/老鬼seo
  • 惠州网站建设选惠州邦/武汉百度快速排名提升
  • 做城市分类信息网站好做吗/图片识别 在线识图
  • 做任务网站建设/云南优化公司
  • 建站购物网站/免费网站大全
  • 西安企业网站建设代理机构/免费信息推广网站
  • 东营网站建设优化/推广引流渠道有哪些
  • 仙居手机网站开发/河南今日头条新闻
  • 广州开发网站设计/杭州seo网站建设靠谱
  • 做网站设计的/湖南seo推广服务
  • 个人建设网站流程/大数据营销专业
  • dw做高逼格的网站/网站推广怎么弄
  • wordpress模板博客/济南公司网站推广优化最大的
  • 怎么建自己公司网站/站长工具平台
  • 枣强网站建设/优化大师兑换码
  • logo素材网站有哪些/seo建站营销
  • 网站备案与域名备案/代运营公司排行榜
  • 广州海珠建网站/神秘网站
  • 石河子网站建设公司/天津的网络优化公司排名
  • 微信微网站开发教程/网络推广外包
  • 新疆建设厅网站/凡科官网免费制作小程序
  • wordpress主题古风/seo优化网络推广
  • pc网站做app京东/河南做网站优化
  • 合肥学习做网站/手机网站模板
  • 网站建设中主页源码/郑州全域静态管理
  • 青岛城乡建筑设计院有限公司/济南seo优化外包服务公司
  • 风格网站建设/电商平台的营销方式
  • 青岛网站互联网公司/产品优化是什么意思
  • 网站公司优势/app推广是什么工作
  • 新手学做网站电子版/网站优化网站优化