package cn.cepec.talroad.air.common;
import cn.cepec.talroad.air.common.geoutil.FeaureUtil;
import cn.cepec.talroad.air.common.geoutil.GeoJSONUtil;
import com.vividsolutions.jts.geom.Geometry;
import net.sf.json.JSONObject;
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.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class InterpolationUtils {
     * 生成等值面
     * @param trainData    训练数据double[size][3],r,lon、lat、value
     * @param dataInterval 数据间隔double[0.0001,25,50,100,200,300]
     * @param size         大小,宽,高new int[]{100, 100};
     * @param boundryFile  四至.shp
     * @param isclip       是否裁剪
     * @return
    // 解析Shapefile文件
    public static String calEquiSurface(double[][] trainData, double[] dataInterval, int[] size, String boundryFile,
                                 boolean isclip) {
        String geojsonpogylon = "";
        try {
            double _undefData = -9999.0;
            // 多边形集合
            SimpleFeatureCollection polygonCollection = null;
            // 多边形线集合
            List<PolyLine> cPolylineList = new ArrayList<PolyLine>();
            // 多边形List
            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);
            // 源shape文件
            ShapefileDataStore shpDataStore = null;
            shpDataStore = new ShapefileDataStore(file.toURL());
            // 设置编码
            Charset charset = Charset.forName("GBK");
            shpDataStore.setCharset(charset);
            // 获取文件后缀名
            String typeName = shpDataStore.getTypeNames()[0];
            // SimpleFeatureSource相当于AE中的featureClass,设置属性
            SimpleFeatureSource featureSource = null;
            featureSource = shpDataStore.getFeatureSource();
            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;
            // IDW插值 (训练数据(离散数据阵列)、宽(栅格X阵)、高(栅格Y阵)、默认数(最近邻居数))
            _gridData = Interpolate.interpolation_IDW_Neighbor(trainData, _X, _Y, 12, _undefData);
            int[][] S1 = new int[_gridData.length][_gridData[0].length];
            // 边界
            List<Border> _borders = Contour.tracingBorders(_gridData, _X, _Y, S1, _undefData);
            // 生成等值线(IDW插值、宽、高、数据间隔长度、数据间隔、默认值、边界、IDW长度)
            cPolylineList = Contour.tracingContourLines(_gridData, _X, _Y, nc, dataInterval, _undefData, _borders, S1);
            // 平滑
            cPolylineList = Contour.smoothLines(cPolylineList);
            cPolygonList = Contour.tracingPolygons(_gridData, cPolylineList, _borders, dataInterval);
            // 多边形Json
            geojsonpogylon = getPolygonGeoJson(cPolygonList);
            if (isclip) {
                // 读取GeoJSON字符串 返回 SimpleFeatureCollection 要素集合
                polygonCollection = GeoJSONUtil.readGeoJsonByString(geojsonpogylon);
                // 裁剪等值面
                FeatureSource dc = clipFeatureCollection(fc, polygonCollection);
                // 得到多边形GeoJson
                geojsonpogylon = getPolygonGeoJson(dc.getFeatures());
        } catch (Exception e) {
            e.printStackTrace();
        return geojsonpogylon;
     * 生成等值线
     * @param trainData    训练数据
     * @param dataInterval 数据间隔
     * @param size         大小,宽,高
     * @param boundryFile  四至
     * @param isclip       是否裁剪
     * @return
    public static String calEquiSurfaceLine(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 = clipFeatureLineCollection(fc, polylineCollection);
                geojsonline = getPolylineGeoJson(dc.getFeatures());
        } catch (Exception e) {
            e.printStackTrace();
        return geojsonline;
    // 等值面
    private static String getPolygonGeoJson(List<Polygon> cPolygonList) {
        String geo = null;
        String geometry = " { \"type\":\"Feature\",\"geometry\":";
        String properties = ",\"properties\":{ \"hvalue\":";
        String head = "{\"type\": \"FeatureCollection\"," + "\"features\": [";
        String end = "  ] }";
        if (cPolygonList == null || cPolygonList.size() == 0) {
            return null;
        try {
            for (Polygon pPolygon : cPolygonList) {
                List<Object> ptsTotal = new ArrayList<Object>();
                List<Object> pts = new ArrayList<Object>();
                PolyLine pline = pPolygon.OutLine;
                for (PointD ptD : pline.PointList) {
                    List<Double> pt = new ArrayList<Double>();
                    pt.add(ptD.X);
                    pt.add(ptD.Y);
                    pts.add(pt);
                ptsTotal.add(pts);
                if (pPolygon.HasHoles()) {
                    for (PolyLine cptLine : pPolygon.HoleLines) {
                        List<Object> cpts = new ArrayList<Object>();
                        for (PointD ccptD : cptLine.PointList) {
                            List<Double> pt = new ArrayList<Double>();
                            pt.add(ccptD.X);
                            pt.add(ccptD.Y);
                            cpts.add(pt);
                        if (cpts.size() > 0) {
                            ptsTotal.add(cpts);
                JSONObject js = new JSONObject();
                js.put("type", "Polygon");
                js.put("coordinates", ptsTotal);
                double hv = pPolygon.HighValue;
                double lv = pPolygon.LowValue;
                if (hv == lv) {
                    if (pPolygon.IsClockWise) {
                        if (!pPolygon.IsHighCenter) {
                            hv = hv - 0.1;
                            lv = lv - 0.1;
                    } else {
                        if (!pPolygon.IsHighCenter) {
                            hv = hv - 0.1;
                            lv = lv - 0.1;
                } else {
                    if (!pPolygon.IsClockWise) {
                        lv = lv + 0.1;
                    } else {
                        if (pPolygon.IsHighCenter) {
                            hv = hv - 0.1;
                geo = geometry + js.toString() + properties + hv + ", \"lvalue\":" + lv + "} }" + "," + geo;
            if (geo.contains(",")) {
                geo = geo.substring(0, geo.lastIndexOf(","));
            geo = head + geo + end;
        } catch (Exception e) {
            e.printStackTrace();
            return geo;
        return geo;
    private static String getPolygonGeoJson(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();
    // 裁剪等值面
    private static 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();
                // 数据"the_geom"属性的值
                Geometry dataGeometry = (Geometry) dataFeature.getProperty("the_geom").getValue();
                while (contourFeatureIterator.hasNext()) {
                    Feature contourFeature = contourFeatureIterator.next();
                    Geometry contourGeometry = (Geometry) contourFeature.getProperty("geometry").getValue();
                    double lv = (Double) contourFeature.getProperty("lvalue").getValue();
                    double hv = (Double) contourFeature.getProperty("hvalue").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("lvalue", lv);
                        map.put("hvalue", hv);
                        values.add(map);
            contourFeatureIterator.close();
            dataFeatureIterator.close();
            SimpleFeatureCollection sc = FeaureUtil.creatSimpleFeatureByFeilds("polygons",
                    "crs:4326,the_geom:MultiPolygon,lvalue:double,hvalue:double", values);
            cs = FeaureUtil.creatFeatureSourceByCollection(sc);
        } catch (Exception e) {
            e.printStackTrace();
            return cs;
        return cs;
    public static 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 static 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 FeatureSource clipFeatureLineCollection(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;

二、关键结构

三、代码调用

 四、访问请求结果

五、iClientOL配置调用

六、展示效果 

 如果对您有帮助

 感谢支持技术分享,请扫码点赞支持:

技术合作交流qq:2401315930

一、java代码package cn.cepec.talroad.air.common;import cn.cepec.talroad.air.common.geoutil.FeaureUtil;import cn.cepec.talroad.air.common.geoutil.GeoJSONUtil;import com.vividsolutions.jts.geom.Geometry;import net.sf.json.JSONObject;import org.geotools.
echart山西省geojson矢量地图包含省级市级县级多级geojson.json数据, 访问地址如 ?orgCode=100000&orgName;=中国 可层层点击加载矢量地图动态显示不同颜色 文件包含代码和json数据
插值查找算法类似于二分查找,不同的是插值查找每次从自适应mid处开始查找。 插值查找是对二分查找的一种改进,适用于均匀分布的有序表。 将折半查找中的求mid索引的公式进行改写 low:左边索引。 high:右边索引。 key:要查找的值。 假设数组arr=[1,2,3,…,100] 此时我们需要查找的是100; 1、使用二分查找:需要递归多次,才能找到100。 2、使用插值查找算法: int mid=low+(high-low)*(key-arr[low])/(arr[r
Geo.Library-.NET的2D地理空间库 Geo 2D库可读取/写入wkt / wkb / geojson并进行交集,并集,差等计算。 支持点,多点,多边形,多面体。 Install-Package GeoLibrary -Version 1.1.0 支持几何类型 LineString WKT支持 从WKT字符串读取 写入WKT字符串 GeoJson支持 从GeoJson字符串读取 写入GeoJson字符串 WKB支持 从WKB十六进制字符串读取 写入WKB十六进位字串 交叉口检查 多点和多点 点和多边形(点是否在多边形内) MultiPoint&Polygon(是否任何点在多边形内) 多点和多点 多点和多点 点特殊功能 IsBetweenLinear:
生成随机特征 turf.random([type='point'], [count=1], options, options.bbox, [options.num_vertices=10], [options.max_radial_length=10]) 生成随机 GeoJSON 数据,包括 Point|Points 和 Polygon|Polygons,用于测试和实验。 [type='point'] 可选:所需的特征类型:“点”或“多边形” [count=1] 可选:应该生成多少几何图形。 options 与所需功能相关的选项。 可以包括: options.bbox 数组.<编号> 一个边界框,其中放置了几何图形。 在点特征的情况下,它们保证在这个范围内, 而多边形特征的质心在边界内。 [options.num_ var geotile = require ( 'geotile' ) ; // load some source data var land = require ( './geojson/land.json' ) ; var borders = require ( './geojson/borders.json' ) ; var lakes = require ( './geojson/lakes.json' ) ; var places = require ( './geojson/places.json' ) ; // get a specific region of a single source var region = geotile ( land ) .
private void IDWpointToRaster() IFeatureLayer pLayer = axMapControl1.get_Layer(0) as IFeatureLayer; IFeatureLayer pExtentLyr = axMapControl1.get_Layer(1) a...
要在Cesium中加载GeoJSON点数据,您可以按照以下步骤操作: 1. 将GeoJSON文件加载到Cesium中。您可以使用Cesium的load方法来加载文件,如下所示: Cesium.load('/path/to/your/geojson/file.geojson').then(function(data) { // Do something with the data 2. 解析GeoJSON数据。您可以使用Cesium的GeoJsonDataSource来解析数据,如下所示: var dataSource = new Cesium.GeoJsonDataSource(); dataSource.load('/path/to/your/geojson/file.geojson').then(function() { // Do something with the data source 3. 将数据源添加到场景中。您可以使用Cesium的viewer对象来添加数据源,如下所示: viewer.dataSources.add(dataSource); 4. 设置点的样式。您可以使用Cesium的点图形来设置点的样式,如下所示: dataSource.entities.point = { pixelSize: 10, color: Cesium.Color.RED 以上是加载GeoJSON点数据的基本步骤,您可以根据自己的需求进行调整和修改。 ### 回答2: Cesium是一款开源的地图可视化引擎,能够快速高效地展示地理数据,支持多种数据格式。GeoJSON是一种常用的地理数据格式,可用于描述地图上的点、线和面等要素。Cesium提供了丰富的API,能够便捷地加载GeoJSON点数据,并在地图上展示。 要加载GeoJSON点数据,首先需要将数据转换为Cesium可识别的格式。Cesium支持将GeoJSON转换为Cesium的Entities、Primitives和Imagery Layers等形式,其中Entities是最常用的一种形式。通过Cesium的GeoJsonDataSource对象可以实现GeoJSON点数据加载为Entities,并在地图上展示。 接下来,我们可以通过Cesium内置的Viewer对象,创建一个基础地图,并将GeoJSON点数据添加到地图上。下面是一段示例代码: ```javascript var viewer = new Cesium.Viewer('cesiumContainer'); //创建Viewer对象,将地图加载到'cesiumContainer'元素中 var dataSource = new Cesium.GeoJsonDataSource('myData'); //创建GeoJsonDataSource对象,并指定数据名称为'myData' var promise = dataSource.load('myPoints.geojson'); //通过load方法加载GeoJSON数据文件 viewer.dataSources.add(dataSource); //将数据源添加到Viewer中 promise.then(function() { viewer.zoomTo(dataSource); //当数据加载完毕,将Viewer缩放至图层范围 在上面的代码中,我们首先创建了一个Viewer对象,并将它加载到HTML元素'cesiumContainer'中。然后,创建一个GeoJsonDataSource对象,并通过load方法加载GeoJSON数据文件'myPoints.geojson'。将数据源添加到Viewer中后,使用promise.then()回调函数,在数据加载完成后将Viewer缩放至图层范围。 需要注意的是,GeoJSON点数据中的属性信息将自动转换为Cesium的Entity属性,并可用于自定义标签、颜色和大小等信息。此外,通过调用Entity的show和position属性,可以方便地控制Entity的显示状态和位置。 ### 回答3: Cesium是一款开源的WebGIS平台,支持加载geojson点数据。GeoJson是一种基于JavaScript对象表示法(JSON)的地理数据交换格式,它能够将矢量地理数据以一种简单、轻量级的方式表示出来。 在Cesium中,加载GeoJson点数据可以通过以下步骤实现: 1.创建数据源 首先,我们需要创建一个Cesium.GeoJsonDataSource对象,用于加载GeoJson数据。我们可以使用以下代码创建一个空的GeoJson数据源: var dataSource = new Cesium.GeoJsonDataSource(); 2.加载GeoJson数据 接下来,我们需要读取包含GeoJson数据的URL并加载这些数据。可以使用Cesium的load方法读取GeoJson文件并将其加载到数据源中。以下是加载GeoJson数据并将其添加到数据源的示例代码: Cesium.load('path/to/geojson.json').then(function (geojson) { dataSource.load(geojson); 3.显示GeoJson数据 一旦我们将GeoJson数据添加到数据源中,就可以将其添加到场景中显示。以下是将GeoJson数据添加到场景中的示例代码: viewer.dataSources.add(dataSource); 完成这些步骤后,应该可以在Cesium应用程序中看到已加载的GeoJson点数据。 总而言之,Cesium支持加载GeoJson点数据,只需要使用Cesium.GeoJsonDataSource对象方法读取、加载和显示GeoJson数据即可。这种方法使得加载大规模点数据的展示和分析变得简单,方便且易于操作。