├── .gitignore ├── LICENSE ├── README.md ├── _config.yml ├── pic ├── 1555286763223.png ├── Kmean.PNG ├── 凹点切割1.png ├── 凹点切割2.jpg ├── 凹点切割流程示意图.jpg ├── 凹点延长线1.png ├── 凹点延长线2.png ├── 凹点计算.png ├── 拟合球体.png ├── 最.png ├── 最大内接圆.jpg ├── 最小外接圆.png ├── 最小外接面.gif ├── 面选择_线段.png └── 面选择_结点.png ├── pom.xml ├── python-planar-algorithm ├── 拟合椭球.py └── 拟合球体.py └── src ├── main ├── java │ └── com │ │ └── huifer │ │ └── planar │ │ └── aset │ │ ├── algo │ │ ├── AverageWidthAverageLength.java │ │ ├── CuttingConcavePolygon.java │ │ ├── DateInterface.java │ │ ├── DijlstraInterface.java │ │ ├── GraphInterface.java │ │ ├── KmeanPolygonSplitInterface.java │ │ ├── LineOverInterface.java │ │ ├── MatirxInterface.java │ │ ├── MinimumEnclosingInterface.java │ │ ├── MyRectangleOver.java │ │ ├── NearbyInterface.java │ │ ├── PolygonAngleInterface.java │ │ ├── PolygonCenterOfGravityInterface.java │ │ ├── PolygonRemoveNodeInterface.java │ │ ├── RailInterface.java │ │ ├── RamerDouglasPeuckerInterface.java │ │ ├── RemoveNodesInterface.java │ │ ├── VoronoiInterface.java │ │ └── impl │ │ │ ├── AverageWidthAverageLengthImpl.java │ │ │ ├── DateInterfaceImpl.java │ │ │ ├── MatirxCore.java │ │ │ ├── NearbyInterfaceImpl.java │ │ │ ├── concave │ │ │ ├── ConcaveSplit.java │ │ │ ├── CutPolygon.java │ │ │ ├── IsConcave.java │ │ │ ├── SimpleCutPolygon.java │ │ │ └── 切割凹多边形的测试用例.csv │ │ │ ├── line │ │ │ ├── RamerDouglasPeuckerInterfaceCore.java │ │ │ ├── RemoveLine.java │ │ │ ├── RemoveNodesCore.java │ │ │ └── SimpleDijkstra.java │ │ │ ├── minrect │ │ │ ├── MaximumInnerCircle.java │ │ │ ├── MinCircle.java │ │ │ ├── MinCircleToE.java │ │ │ ├── MinimumBoundingRectangle.java │ │ │ ├── MinimumEnclosingCore.java │ │ │ ├── Rotation.java │ │ │ └── WelzlAlgo.java │ │ │ ├── ovlayer │ │ │ ├── GraphCore.java │ │ │ └── LineOverCore.java │ │ │ └── polygon │ │ │ ├── CuttingConcavePolygonImpl.java │ │ │ ├── KmeanPolygonSplitCore.java │ │ │ ├── MyRecatngleOverCore.java │ │ │ ├── PolygonAngleCore.java │ │ │ ├── PolygonCenterOfGravityCore.java │ │ │ ├── PolygonRemoveNodeByLength.java │ │ │ ├── PolygonSegmentationCore.java │ │ │ ├── RailCore.java │ │ │ └── VoronoiInterfaceImpl.java │ │ ├── entity │ │ ├── ConcavePolygonCut.java │ │ ├── FourBox.java │ │ ├── KmeanPolygonResult.java │ │ ├── Kmeans.java │ │ ├── MyLine.java │ │ ├── MyPoint.java │ │ ├── MyPolygon.java │ │ ├── MyRectangle.java │ │ ├── OvlayerEnum.java │ │ ├── PolygonAngleResult.java │ │ ├── PolygonRemoveNodeResult.java │ │ ├── PublicRadial.java │ │ ├── RefObject.java │ │ ├── ResultShortestPath.java │ │ └── SortPoint.java │ │ ├── factory │ │ └── MyGeoFactory.java │ │ ├── mappingalgo │ │ ├── Convolution.java │ │ ├── coortrans │ │ │ ├── ReadHelper.java │ │ │ ├── RunT.java │ │ │ ├── lib │ │ │ │ ├── AllData.java │ │ │ │ ├── Ellipsoid.java │ │ │ │ ├── Gauss.java │ │ │ │ ├── PointInfo.java │ │ │ │ ├── Position.java │ │ │ │ └── Rad2Dms.java │ │ │ └── 坐标数据.txt │ │ ├── fanjuli │ │ │ ├── InverseDistanceCore.java │ │ │ ├── MyPoint.java │ │ │ ├── ReadHelper.java │ │ │ └── 测站坐标.txt │ │ ├── grid │ │ │ ├── GRID数据.txt │ │ │ ├── ReadHelper.java │ │ │ └── lib │ │ │ │ ├── Convex.java │ │ │ │ ├── GeoCalc.java │ │ │ │ ├── Grid.java │ │ │ │ ├── GridCell.java │ │ │ │ ├── HeightCalc.java │ │ │ │ ├── PointInfo.java │ │ │ │ ├── ResultData.java │ │ │ │ ├── Stack.java │ │ │ │ └── Vector.java │ │ ├── sortpath │ │ │ ├── Edge.java │ │ │ ├── Graph.java │ │ │ ├── SortPathRunt.java │ │ │ ├── Vertex.java │ │ │ └── 路径数据.txt │ │ ├── trajectorycompression │ │ │ ├── DpLine.java │ │ │ ├── Point.java │ │ │ ├── ReadText.java │ │ │ └── read.txt │ │ └── zongduanmian │ │ │ ├── ReadHelper.java │ │ │ ├── Zongduanmian.java │ │ │ ├── lib │ │ │ ├── AllData.java │ │ │ ├── CrossSection.java │ │ │ ├── Dwh.java │ │ │ ├── HeightCal.java │ │ │ ├── PointInfo.java │ │ │ └── VerticleSection.java │ │ │ └── 断面数据.txt │ │ ├── utils │ │ ├── AdjacentMatrixUtil.java │ │ ├── Arith.java │ │ ├── CommonUtils.java │ │ ├── DijkstraUtil.java │ │ ├── FileCommonMethod.java │ │ ├── JSONUtil.java │ │ ├── KmeanPolygon.java │ │ ├── Miact.java │ │ ├── PolygonUtils.java │ │ ├── Project.java │ │ ├── TmeanLength.java │ │ ├── geo │ │ │ ├── ColorUtil.java │ │ │ ├── GeoJsonUtil.java │ │ │ ├── GeoMapContentUtil.java │ │ │ ├── GeoStyleUtil.java │ │ │ ├── GeomtryUtil.java │ │ │ └── GridUtil.java │ │ ├── kriging │ │ │ ├── Kpoint.java │ │ │ ├── KriginCore.java │ │ │ └── ReadFile.java │ │ ├── polygonselect │ │ │ ├── Algo.java │ │ │ ├── ReadShpHelper.java │ │ │ ├── ToceLineString.java │ │ │ ├── TocePoint.java │ │ │ └── TocePolygon.java │ │ ├── shptools │ │ │ ├── Shp2Wkt.java │ │ │ ├── ShpClip.java │ │ │ ├── ShpUtils.java │ │ │ ├── center │ │ │ │ ├── Regression.java │ │ │ │ ├── Run.java │ │ │ │ └── ThiessenPolygon.java │ │ │ ├── geojson │ │ │ │ └── MainTest.java │ │ │ ├── overlay │ │ │ │ └── Operation.java │ │ │ ├── polygontools │ │ │ │ ├── ForTest.java │ │ │ │ ├── PolygonGravityCenter.java │ │ │ │ ├── PolygonNodeTriangle.java │ │ │ │ ├── entity │ │ │ │ │ └── LatLngEntity.java │ │ │ │ └── geometry │ │ │ │ │ ├── Bounds.java │ │ │ │ │ ├── ComparatorLatLng.java │ │ │ │ │ ├── ConvexHull.java │ │ │ │ │ ├── ConvexTest.java │ │ │ │ │ └── Polygon.java │ │ │ └── triangulation │ │ │ │ ├── 1c.txt │ │ │ │ ├── DelaunayTriangulator.java │ │ │ │ ├── Edge2D.java │ │ │ │ ├── EdgeDistancePack.java │ │ │ │ ├── FileRd.java │ │ │ │ ├── NotEnoughPointsException.java │ │ │ │ ├── Triangle2D.java │ │ │ │ ├── Triangle2DEnum.java │ │ │ │ ├── Triangle2dTools.java │ │ │ │ ├── TriangleSoup.java │ │ │ │ └── Vector2D.java │ │ ├── simplecycles │ │ │ ├── SearchCycles.java │ │ │ ├── SimpleCycles.java │ │ │ └── SimpleResult.java │ │ └── threepoint │ │ │ └── SortThreePoint.java │ │ └── view │ │ ├── KmeanView.java │ │ ├── MyContext.java │ │ ├── PolygonAngleMergeView.java │ │ ├── PolygonAngleView.java │ │ └── base │ │ ├── Aframe.java │ │ ├── BaseFrame.java │ │ ├── FrameContext.java │ │ └── ViewHelper.java └── resources │ ├── 1.csv │ ├── data │ └── shp │ │ ├── 555555.cpg │ │ ├── 555555.dbf │ │ ├── 555555.sbn │ │ ├── 555555.sbx │ │ ├── 555555.shp │ │ ├── 555555.shp.xml │ │ ├── 555555.shx │ │ ├── 省范围.cpg │ │ ├── 省范围.dbf │ │ ├── 省范围.prj │ │ ├── 省范围.sbn │ │ ├── 省范围.sbx │ │ ├── 省范围.shp │ │ └── 省范围.shx │ ├── logback.xml │ └── polygon_select │ ├── 原始数据.dwg │ ├── 根据点 │ ├── 中间过程数据.csv │ ├── 原始数据.dwg │ ├── 数据要求.txt │ ├── 测试数据.cpg │ ├── 测试数据.dbf │ ├── 测试数据.sbn │ ├── 测试数据.sbx │ ├── 测试数据.shp │ ├── 测试数据.shx │ ├── 测试数据.xml │ ├── 结果.cpg │ ├── 结果.dbf │ ├── 结果.sbn │ ├── 结果.sbx │ ├── 结果.shp │ ├── 结果.shx │ └── 说明.png │ ├── 根据线 │ ├── 中间过程数据.csv │ ├── 原始数据.dwg │ ├── 测试数据.cpg │ ├── 测试数据.dbf │ ├── 测试数据.sbn │ ├── 测试数据.sbx │ ├── 测试数据.shp │ ├── 测试数据.shx │ └── 测试数据.xml │ ├── 测试数据.cpg │ ├── 测试数据.dbf │ ├── 测试数据.sbn │ ├── 测试数据.sbx │ ├── 测试数据.shp │ ├── 测试数据.shx │ └── 测试数据.xml └── test └── java └── com └── huifer └── planar └── aset ├── OT.java ├── algo ├── DigraphCoreTest.java ├── KmeanPolygonSplitInterfaceTest.java ├── LineOverCoreTest.java ├── PolygonAngleInterfaceTest.java ├── PolygonCenterOfGravityInterfaceTest.java ├── PolygonRemoveNodeInterfaceTest.java ├── RailCoreTest.java ├── SimpleDijkstraTest.java └── impl │ ├── AverageWidthAverageLengthImplTest.java │ ├── KmeanPolygon.java │ ├── MyRecatngleOverCoreTest.java │ ├── NearbyInterfaceImplTest.java │ ├── PolygonAngleCoreTest.java │ ├── PolygonSegmentationCoreTest.java │ ├── RemoveLineTest.java │ ├── RemoveNodesCoreTest.java │ ├── VoronoiInterfaceImplTest.java │ ├── concave │ ├── ConcaveSplitTest.java │ ├── CutPolygonTest.java │ ├── IsConcaveTest.java │ ├── LineEquationTest.java │ ├── PolygonizerT.java │ └── SimpleCutPolygonTest.java │ └── minrect │ ├── MaximumInnerCircleTest.java │ ├── MinCircleToETest.java │ ├── MinimumBoundingRectangleTest.java │ ├── MinimumEnclosingCoreTest.java │ └── WelzlAlgoTest.java ├── entity ├── MyLineTest.java ├── MyPointTest.java └── PublicRadialTest.java ├── mappingalgo ├── ConvolutionTest.java ├── coortrans │ └── CoortransTest.java ├── fanjuli │ └── InverseDistanceCoreTest.java ├── grid │ └── GridTest.java ├── sortpath │ └── SortPathRuntTest.java ├── trajectorycompression │ └── DpLineTest.java └── zongduanmian │ └── ZongduanmianTest.java └── utils ├── AdjacentMatrixUtilTest.java ├── CommonUtilsTest.java ├── GeomtryUtilTest.java ├── KmeansTest.java ├── PolygonUtilsTest.java ├── TmeanLengthTest.java ├── geo ├── GeoJsonUtilTest.java └── GridUtilTest.java ├── shptools └── ShpUtilsTest.java └── simplecycles ├── SearchCyclesTest.java └── SimpleCyclesTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### JetBrains template 3 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm 4 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 5 | 6 | # User-specific stuff 7 | .idea/**/workspace.xml 8 | .idea/**/tasks.xml 9 | .idea/**/usage.statistics.xml 10 | .idea/**/dictionaries 11 | .idea/**/shelf 12 | 13 | # Generated files 14 | .idea/**/contentModel.xml 15 | 16 | # Sensitive or high-churn files 17 | .idea/**/dataSources/ 18 | .idea/**/dataSources.ids 19 | .idea/**/dataSources.local.xml 20 | .idea/**/sqlDataSources.xml 21 | .idea/**/dynamic.xml 22 | .idea/**/uiDesigner.xml 23 | .idea/**/dbnavigator.xml 24 | 25 | # Gradle 26 | .idea/**/gradle.xml 27 | .idea/**/libraries 28 | 29 | # Gradle and Maven with auto-import 30 | # When using Gradle or Maven with auto-import, you should exclude module files, 31 | # since they will be recreated, and may cause churn. Uncomment if using 32 | # auto-import. 33 | # .idea/modules.xml 34 | # .idea/*.iml 35 | # .idea/modules 36 | # *.iml 37 | # *.ipr 38 | 39 | # CMake 40 | cmake-build-*/ 41 | 42 | # Mongo Explorer plugin 43 | .idea/**/mongoSettings.xml 44 | 45 | # File-based project format 46 | *.iws 47 | 48 | # IntelliJ 49 | out/ 50 | 51 | # mpeltonen/sbt-idea plugin 52 | .idea_modules/ 53 | 54 | # JIRA plugin 55 | atlassian-ide-plugin.xml 56 | 57 | # Cursive Clojure plugin 58 | .idea/replstate.xml 59 | 60 | # Crashlytics plugin (for Android Studio and IntelliJ) 61 | com_crashlytics_export_strings.xml 62 | crashlytics.properties 63 | crashlytics-build.properties 64 | fabric.properties 65 | 66 | # Editor-based Rest Client 67 | .idea/httpRequests 68 | 69 | # Android studio 3.1+ serialized cache file 70 | .idea/caches/build_file_checksums.ser 71 | 72 | ### Java template 73 | # Compiled class file 74 | *.class 75 | 76 | # Log file 77 | *.log 78 | 79 | # BlueJ files 80 | *.ctxt 81 | 82 | # Mobile Tools for Java (J2ME) 83 | .mtj.tmp/ 84 | 85 | # Package Files # 86 | *.jar 87 | *.war 88 | *.nar 89 | *.ear 90 | *.zip 91 | *.tar.gz 92 | *.rar 93 | 94 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 95 | hs_err_pid* 96 | 97 | /.idea/ 98 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # planar_algorithm 2 | ![jdk >=1.8](https://img.shields.io/badge/Jdk->=1.8-orange.svg?style=flat&color=brightgreen) 3 | ![Apache ](https://img.shields.io/badge/licenes-Apache-orange.svg?style=flat&color=brightgreen) 4 | #### 介绍 5 | 平面算法 6 | 7 | 关于 二维点 二维线的基础算法 8 | 9 | - 坐标转换算法 10 | 11 | - 反距离加权插值 12 | 13 | - 利用构建规则网格(GRID) 计算体积 14 | 15 | - 最短路径 16 | 17 | - 纵断面计算 18 | 19 | - [根据K-means 分割多边形](https://blog.csdn.net/staHuri/article/details/86482967) 20 | ![](pic/Kmean.PNG) 21 | 22 | - [最小外接矩形](#) 23 | ![](pic/最小外接面.gif) 24 | - [凹点切割](https://blog.csdn.net/staHuri/article/details/88057017) 25 | ![](pic/凹点切割流程示意图.jpg) 26 | ![](pic/凹点切割2.jpg) 27 | 28 | - 最大内接圆 29 | ![](pic/最大内接圆.jpg) 30 | - 最小外接圆 31 | ![](pic/最小外接圆.png) 32 | 33 | ![](pic/最.png) 34 | - 拟合球体 35 | - 拟合球体 36 | ![](pic/拟合球体.png) 37 | - 拟合椭球 38 | ![](pic/1555286763223.png) 39 | 40 | - 多边形选择 41 | - 根据结点选择 42 | ![](pic/面选择_结点.png) 43 | - 根据线段选择 44 | ![](pic/面选择_线段.png) 45 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-architect -------------------------------------------------------------------------------- /pic/1555286763223.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/pic/1555286763223.png -------------------------------------------------------------------------------- /pic/Kmean.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/pic/Kmean.PNG -------------------------------------------------------------------------------- /pic/凹点切割1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/pic/凹点切割1.png -------------------------------------------------------------------------------- /pic/凹点切割2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/pic/凹点切割2.jpg -------------------------------------------------------------------------------- /pic/凹点切割流程示意图.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/pic/凹点切割流程示意图.jpg -------------------------------------------------------------------------------- /pic/凹点延长线1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/pic/凹点延长线1.png -------------------------------------------------------------------------------- /pic/凹点延长线2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/pic/凹点延长线2.png -------------------------------------------------------------------------------- /pic/凹点计算.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/pic/凹点计算.png -------------------------------------------------------------------------------- /pic/拟合球体.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/pic/拟合球体.png -------------------------------------------------------------------------------- /pic/最.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/pic/最.png -------------------------------------------------------------------------------- /pic/最大内接圆.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/pic/最大内接圆.jpg -------------------------------------------------------------------------------- /pic/最小外接圆.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/pic/最小外接圆.png -------------------------------------------------------------------------------- /pic/最小外接面.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/pic/最小外接面.gif -------------------------------------------------------------------------------- /pic/面选择_线段.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/pic/面选择_线段.png -------------------------------------------------------------------------------- /pic/面选择_结点.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/pic/面选择_结点.png -------------------------------------------------------------------------------- /python-planar-algorithm/拟合球体.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # __file__: 拟合球体 4 | # __date__: 5 | # __author__: huifer 6 | import numpy as np 7 | import math 8 | from matplotlib import pyplot as plt 9 | from mpl_toolkits.mplot3d import Axes3D 10 | import csv 11 | 12 | 13 | def qiuti(x_list, y_list, z_list): 14 | """ 15 | 球体计算 16 | :param x_list: 17 | :param y_list: 18 | :param z_list: 19 | :return: 20 | """ 21 | # 右侧矩阵 22 | x_list = np.array(x_list) 23 | y_list = np.array(y_list) 24 | z_list = np.array(z_list) 25 | 26 | right_mat = np.zeros((len(x_list), 4)) 27 | right_mat[:, 0] = x_list * 2 28 | right_mat[:, 1] = y_list * 2 29 | right_mat[:, 2] = z_list * 2 30 | right_mat[:, 3] = 1 31 | 32 | # 等号左侧 33 | left_mat = np.zeros((len(x_list), 1)) 34 | left_mat[:, 0] = (x_list * x_list) + (y_list * y_list) + (z_list * z_list) 35 | 36 | C, residules, rank, singval = np.linalg.lstsq(right_mat, left_mat) 37 | 38 | # 求半径 39 | t = (C[0] * C[0]) + (C[1] * C[1]) + (C[2] * C[2]) + C[3] 40 | radius = math.sqrt(t) 41 | return radius, C[0], C[1], C[2] 42 | 43 | 44 | def show_qiut(x_list, y_list, z_list): 45 | """ 46 | 三维展示球体 47 | :param x_list: 48 | :param y_list: 49 | :param z_list: 50 | :return: 51 | """ 52 | 53 | fig = plt.figure() 54 | ax = plt.axes(projection='3d') 55 | 56 | # 计算拟合 57 | r, x0, y0, z0 = qiuti(x_list, y_list, z_list) 58 | print("圆心:", [x0[0], y0[0], z0[0]]) 59 | print("半径:", r) 60 | 61 | u, v = np.mgrid[0:2 * np.pi:20j, 0:np.pi:10j] 62 | 63 | x = np.cos(u) * np.sin(v) * r 64 | y = np.sin(u) * np.sin(v) * r 65 | z = np.cos(v) * r 66 | 67 | x = x + x0 68 | y = y + y0 69 | z = z + z0 70 | 71 | # 三维展示 72 | 73 | ax.scatter(x_list, y_list, z_list, zdir='z', s=20, c='b', rasterized=True) 74 | ax.plot_wireframe(x, y, z, color="r") 75 | 76 | ax.set_aspect('equal') 77 | 78 | plt.show() 79 | 80 | 81 | def write_csv(x, y, z): 82 | r, x0, y0, z0 = qiuti(x, y, z) 83 | 84 | with open('qiuti.csv', "w") as csv_file: 85 | csv_file.write("x,y,z,r\n") 86 | for x_, y_, z_ in zip(x, y, z): 87 | csv_file.write("{},{},{},{}\n".format(x_, y_, z_, 0.5)) 88 | 89 | csv_file.write("{},{},{},{}\n".format(x0[0], y0[0], z0[0], r)) 90 | pass 91 | 92 | 93 | if __name__ == '__main__': 94 | random_x = np.random.randint(0, 10, 30) 95 | random_y = np.random.randint(0, 10, 30) 96 | random_z = np.random.randint(0, 10, 30) 97 | 98 | show_qiut(x_list=random_x, y_list=random_y, z_list=random_z) 99 | write_csv(random_x, random_y, random_z) 100 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/algo/AverageWidthAverageLength.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo; 2 | 3 | /** 4 | *

Title : AverageWidthAverageLength

5 | *

Description : 多边形(非回型)平均宽度 平均长度

6 | * 7 | * @author huifer 8 | * @date 2019-01-14 9 | */ 10 | public interface AverageWidthAverageLength { 11 | 12 | /** 13 | * 平均宽度 14 | * 15 | * @param count 分成多少分 16 | * @param wkt polygon wkt 描述 17 | * @return 平均宽度 18 | */ 19 | double calcAverageWidth(int count, String wkt); 20 | 21 | 22 | /** 23 | * 平均长度 24 | * 25 | * @param count 分成多少分 26 | * @param wkt polygon wkt 描述 27 | * @return 平均长度 28 | */ 29 | double calcAverageLength(int count, String wkt); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/algo/CuttingConcavePolygon.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo; 2 | 3 | import com.huifer.planar.aset.algo.impl.concave.ConcaveSplit.TroughLineWithSort; 4 | import org.locationtech.jts.geom.Polygon; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | *

Title : CuttingConcavePolygon

10 | *

Description : 凹多边形的切割

11 | * 12 | * @author huifer 13 | * @date 2019-03-01 14 | */ 15 | public interface CuttingConcavePolygon { 16 | 17 | /** 18 | * 凹多边形的凸多边形拆分 19 | * 20 | * @param polygon 凹多边形 21 | * @return {@link TroughLineWithSort} 22 | * @throws Exception 23 | */ 24 | List concaveSplit(Polygon polygon) throws Exception; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/algo/DateInterface.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo; 2 | 3 | import java.text.ParseException; 4 | import java.util.List; 5 | 6 | /** 7 | * 工作日日期接口 8 | * 9 | * @author huifer 10 | */ 11 | public interface DateInterface { 12 | 13 | /** 14 | * 获取 xxxx 年 xx 月的所有日期 15 | * 16 | * @param year 年 17 | * @param month 月 18 | * @return 月历 19 | */ 20 | List monthlyCalendar(int year, int month); 21 | 22 | /** 23 | * 获取 xxxx 年 xx 月 总天数 24 | * 25 | * @param year 年 26 | * @param month 月 27 | * @return 天数 28 | */ 29 | int maxDayInMonth(int year, int month); 30 | 31 | /** 32 | * 是否是周末 33 | * 34 | * @param dateString 日期 2019-01-01 35 | * @return boolean 36 | * @throws ParseException 异常 37 | */ 38 | boolean isWeekends(String dateString) throws ParseException; 39 | 40 | /** 41 | * 是否法定假日 42 | * 43 | * @param dateString 日期 2019-01-01 44 | * @return boolean 45 | */ 46 | boolean isStatutoryHoliday(String dateString); 47 | 48 | 49 | /** 50 | * 是否额外工作日 51 | * 52 | * @param dateString 日期 2019-01-01 53 | * @return boolean 54 | */ 55 | boolean isExtraWorkingDay(String dateString); 56 | 57 | 58 | /** 59 | * 是否休息日 60 | * 61 | * @param dateString 日期 2019-01-01 62 | * @return boolean 63 | * @throws ParseException 异常 64 | */ 65 | boolean isDayOff(String dateString) throws ParseException; 66 | 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/algo/DijlstraInterface.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo; 2 | 3 | import com.huifer.planar.aset.entity.ResultShortestPath; 4 | 5 | import java.util.ArrayList; 6 | 7 | /** 8 | * DijlstraInterface 接口 9 | * 10 | * @author huifer 11 | */ 12 | public interface DijlstraInterface { 13 | 14 | /** 15 | * 指定起点和终点,求最短路径 16 | * 17 | * @param cost 点列表 18 | * @param startPoint 起点 19 | * @param endPoint 终点 20 | * @return 路径值 21 | */ 22 | ResultShortestPath shortestPathByStartAndEnd(ArrayList> cost, int startPoint, 23 | int endPoint); 24 | 25 | /** 26 | * 单点所有最短距离 27 | * 28 | * @param cost 点列表 29 | * @param startPoint 指定点 30 | * @return 路径值 31 | */ 32 | ArrayList shortestPathByStart( 33 | ArrayList> cost, int startPoint); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/algo/GraphInterface.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo; 2 | 3 | 4 | import com.huifer.planar.aset.entity.MyLine; 5 | import com.huifer.planar.aset.entity.MyPoint; 6 | import com.huifer.planar.aset.entity.MyPolygon; 7 | import com.huifer.planar.aset.entity.OvlayerEnum; 8 | 9 | /** 10 | *

Title : GraphInterface

11 | *

Description : 点与线的关系

12 | * 13 | * @author huifer 14 | * @date 2018/12/12 15 | */ 16 | public interface GraphInterface { 17 | 18 | /** 19 | * 右手法则计算 线与点的关系 20 | * 21 | * @param point point 22 | * @param polyline polyline 23 | * @return {@link com.huifer.planar.aset.entity.OvlayerEnum} 24 | */ 25 | OvlayerEnum rightHandRule(MyPoint point, MyLine polyline); 26 | 27 | /** 28 | * 计算 两条线的交点 29 | * 30 | * @param linea 直线1 31 | * @param lineb 直线2 32 | * @return {@link com.huifer.planar.aset.entity.MyPoint} 33 | */ 34 | MyPoint getIntersectionPoint(MyLine linea, MyLine lineb); 35 | 36 | /** 37 | * 点和面的关系 38 | * 39 | * @param point point 40 | * @param polygon polygon 41 | * @return {@link com.huifer.planar.aset.entity.OvlayerEnum} 42 | */ 43 | OvlayerEnum pointWithPolygon(MyPoint point, MyPolygon polygon); 44 | 45 | /** 46 | * 线是否相交 47 | * 48 | * @param linea 直线1 49 | * @param lineb 直线2 50 | * @return int 51 | */ 52 | int lineWithLine(MyLine linea, MyLine lineb); 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/algo/KmeanPolygonSplitInterface.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo; 2 | 3 | import com.huifer.planar.aset.entity.KmeanPolygonResult; 4 | import org.locationtech.jts.io.ParseException; 5 | 6 | /** 7 | *

Title : KmeanPolygonSplitInterface

8 | *

Description : kmean 切割面

9 | * 10 | * @author huifer 11 | * @date 2019-01-16 12 | */ 13 | public interface KmeanPolygonSplitInterface { 14 | 15 | /** 16 | * 切割面 17 | * 18 | * @param wkt polygon wkt描述 19 | * @param setp 随机点数量 20 | * @param k 切几个面 21 | * @return {@link com.huifer.planar.aset.entity.KmeanPolygonResult} 22 | * @throws ParseException 异常 23 | */ 24 | KmeanPolygonResult splitPolygon(String wkt, int setp, int k) throws ParseException; 25 | 26 | 27 | /** 28 | * shp 切割 29 | * 30 | * @param path 文件位置 31 | * @param splitFiled 切分字段 32 | * @return 切分结果 33 | * @throws Exception 异常 34 | */ 35 | Object splitPolygonWithShp(String path, String splitFiled) throws Exception; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/algo/LineOverInterface.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo; 2 | 3 | import com.huifer.planar.aset.entity.MyLine; 4 | import com.huifer.planar.aset.entity.MyPoint; 5 | import com.huifer.planar.aset.entity.SortPoint; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | /** 12 | *

Title : LineOverInterface

13 | *

Description : 直线两侧排序

14 | * 15 | * @author huifer 16 | * @date 2018/12/17 17 | */ 18 | public interface LineOverInterface { 19 | 20 | /** 21 | * 直线两侧排序 22 | * 23 | * @param line 直线 24 | * @param points 点列表 25 | * @return 排序后结果 26 | */ 27 | Map> simpleLineSortPoint(MyLine line, ArrayList points); 28 | 29 | /** 30 | * 直线交点 31 | * 32 | * @param l1 直线1 33 | * @param l2 直线2 34 | * @return 相交点 {@link com.huifer.planar.aset.entity.MyPoint} 35 | */ 36 | MyPoint intersectPoint(MyLine l1, MyLine l2); 37 | 38 | /** 39 | * 求直线外一点到直线上的投影点 40 | * 41 | * @param line 直线 42 | * @param out 直线外一点 43 | * @return 投影点 {@link com.huifer.planar.aset.entity.MyPoint} 44 | */ 45 | MyPoint getProjectivePoint(MyLine line, MyPoint out); 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/algo/MatirxInterface.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo; 2 | 3 | import java.util.ArrayList; 4 | 5 | /** 6 | * 矩阵操作 7 | * 8 | * @author huifer 9 | */ 10 | public interface MatirxInterface { 11 | 12 | /** 13 | * 求行列式 14 | * 15 | * @param matrix 矩阵 16 | * @return 行列式 17 | */ 18 | double getRowColValue(ArrayList> matrix); 19 | 20 | /** 21 | * 求逆矩阵 22 | * 23 | * @param matrix 矩阵 24 | * @return 逆矩阵 25 | */ 26 | ArrayList> getInverseMatrix(ArrayList> matrix); 27 | 28 | /** 29 | * 矩阵 乘数 30 | * 31 | * @param matrixA 矩阵A 32 | * @param matrixB 矩阵B 33 | * @return 矩阵乘积 34 | */ 35 | ArrayList> getMultipMatrix(ArrayList> matrixA, 36 | ArrayList> matrixB); 37 | 38 | 39 | /** 40 | * 矩阵 加减 41 | * 42 | * @param matrixA 矩阵A 43 | * @param matrixB 矩阵B 44 | * @param opreation 操作值 45 | * @return 矩阵加减 46 | */ 47 | ArrayList> getAddRemoveMatrix(ArrayList> matrixA, 48 | ArrayList> matrixB, double opreation); 49 | 50 | /** 51 | * 矩阵 倍法运算 52 | * 53 | * @param matrix 矩阵 54 | * @param k 倍法值 55 | * @return 倍法运算结果 56 | */ 57 | ArrayList> getKMatrix(ArrayList> matrix, double k); 58 | 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/algo/MinimumEnclosingInterface.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo; 2 | 3 | import org.locationtech.jts.geom.Geometry; 4 | import org.locationtech.jts.geom.Point; 5 | import org.locationtech.jts.geom.Polygon; 6 | 7 | /** 8 | *

Title : MinimumEnclosingInterface

9 | *

Description : 最小外接矩形

10 | * 11 | * @author huifer 12 | * @date 2019-02-25 13 | */ 14 | public interface MinimumEnclosingInterface { 15 | 16 | /** 17 | * 最小外接矩形 18 | * 19 | * @param polygon 需要计算的面 20 | * @return 最小外接矩形结果 21 | */ 22 | Polygon getMinRect(Geometry polygon); 23 | 24 | /** 25 | * 最大内接圆 26 | * 27 | * @param pg 面 28 | * @return 最大外接圆圆心 29 | */ 30 | Point getInCirclePoint(Polygon pg); 31 | 32 | /** 33 | * 最大内接圆 34 | * 35 | * @param pg 面 36 | * @return 最大外接圆 37 | */ 38 | Polygon getInCirclePolygon(Polygon pg); 39 | 40 | 41 | /** 42 | * 最小外接圆 43 | * 44 | * @param pg 面 45 | * @return 最小外接圆 46 | */ 47 | Polygon getMinimumCircumscribedCircle(Polygon pg); 48 | 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/algo/MyRectangleOver.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo; 2 | 3 | import com.huifer.planar.aset.entity.MyRectangle; 4 | 5 | /** 6 | *

Title : MyRectangleOver

7 | *

Description : 矩阵拓扑

8 | * 9 | * @author huifer 10 | * @date 2018/12/20 11 | */ 12 | public interface MyRectangleOver { 13 | 14 | /** 15 | * 计算两个矩形相交面积 16 | * 17 | * @param r1 矩形1 18 | * @param r2 矩形2 19 | * @return 相交面积 20 | */ 21 | double calcAreaIntersectionRectangles(MyRectangle r1, MyRectangle r2); 22 | 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/algo/NearbyInterface.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo; 2 | 3 | import org.locationtech.jts.geom.Point; 4 | import org.locationtech.jts.geom.Polygon; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * 描述: 10 | * 邻近算法 11 | * 12 | * @author: huifer 13 | * @date: 2019-11-13 14 | */ 15 | public interface NearbyInterface { 16 | /** 17 | * 点附近的面 18 | * 19 | * @param point 点 20 | * @param polygonList 面集合 21 | * @return 最近的面 22 | */ 23 | Polygon pointNearbyPolygon(Point point, List polygonList); 24 | 25 | /** 26 | * 点附近的点 27 | * 28 | * @param point 点 29 | * @param points 点集合 30 | * @return 最近的点 31 | */ 32 | Point pointNearbyPoint(Point point, List points); 33 | 34 | /** 35 | * 点附近最近的点 36 | * 37 | * @param point 待测点 38 | * @param points 点集合 39 | * @param polygonList 作用范围 40 | * @return 最近的点 41 | */ 42 | Point pointNearByPointAndPolygon(Point point, List points, List polygonList); 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/algo/PolygonAngleInterface.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo; 2 | 3 | import com.huifer.planar.aset.entity.PolygonAngleResult; 4 | import org.locationtech.jts.io.ParseException; 5 | 6 | /** 7 | *

Title : PolygonAngleInterface

8 | *

Description : 面角度计算

9 | * 10 | * @author huifer 11 | * @date 2019-01-28 12 | */ 13 | public interface PolygonAngleInterface { 14 | 15 | 16 | /** 17 | * polygon每一个线段角度计算 18 | * 19 | * @param wkt polygon WKT描述 20 | * @return {@link PolygonAngleResult} 21 | * @throws ParseException 异常 22 | */ 23 | PolygonAngleResult polygonWktAngle(String wkt) throws ParseException; 24 | 25 | 26 | /** 27 | * 删除输入角度的值 28 | * 29 | * @param wkt polygon WKT描述 30 | * @param angle 角度 31 | * @return {@link PolygonAngleResult} 32 | * @throws ParseException 33 | */ 34 | PolygonAngleResult polygonWktAngleMerge(String wkt, Double angle) throws ParseException; 35 | 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/algo/PolygonCenterOfGravityInterface.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo; 2 | 3 | import org.locationtech.jts.geom.Point; 4 | import org.locationtech.jts.geom.Polygon; 5 | 6 | /** 7 | *

Title : PolygonCenterOfGravityInterface

8 | *

Description : 多边形重心

9 | * 10 | * @author huifer 11 | * @date 2019-02-21 12 | */ 13 | public interface PolygonCenterOfGravityInterface { 14 | 15 | /** 16 | * 计算凸多边形重心 17 | * 18 | * @param covenPolygon 多边形 19 | * @return 重心点 20 | */ 21 | Point calcGravityPointOfCovenPolygon(Polygon covenPolygon); 22 | 23 | 24 | /** 25 | * 计算凹多边形中心 26 | * 27 | * @param concavePolygon 凹多边形 28 | * @return 重心点 29 | */ 30 | Point calcGravityPointOfConcavePolygon(Polygon concavePolygon); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/algo/PolygonRemoveNodeInterface.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo; 2 | 3 | import com.huifer.planar.aset.entity.PolygonRemoveNodeResult; 4 | import org.locationtech.jts.geom.Geometry; 5 | import org.locationtech.jts.geom.Polygon; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * 描述: 面上删除节点值 11 | * 12 | * @author huifer 13 | * @date 2019-02-13 14 | */ 15 | public interface PolygonRemoveNodeInterface { 16 | 17 | /** 18 | * 面上删除节点,根据节点间距 19 | * 20 | * @param geometryList polygon list 21 | * @param tolerance 容差 22 | * @return {@link Geometry} 删除点列表 23 | * @throws Exception 异常 24 | */ 25 | PolygonRemoveNodeResult polygonRemoveNodeByLength(List geometryList, double tolerance) throws Exception; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/algo/RailInterface.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo; 2 | 3 | import com.huifer.planar.aset.entity.MyPoint; 4 | import com.huifer.planar.aset.entity.MyPolygon; 5 | 6 | /** 7 | * RailInterface 8 | * 9 | * @author huifer 10 | */ 11 | public interface RailInterface { 12 | 13 | /** 14 | * 点是否在在面内 15 | * 16 | * @param point point 17 | * @param polygon polygon 18 | * @return boolean 19 | */ 20 | boolean isInPolygon(MyPoint point, MyPolygon polygon); 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/algo/RamerDouglasPeuckerInterface.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | *

Title : RamerDouglasPeuckerInterfaceCore

7 | *

Description : 拉默-道格拉斯-普克算法 rdp

8 | * 9 | * @author huifer 10 | * @date 2019-01-24 11 | */ 12 | public interface RamerDouglasPeuckerInterface { 13 | 14 | /** 15 | * dp算法 16 | * 17 | * @param list 点集合 18 | * @param threshold 容差 19 | * @return 压缩后结果 20 | */ 21 | List douglasPeucke(List list, double threshold); 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/algo/RemoveNodesInterface.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo; 2 | 3 | import org.locationtech.jts.geom.Coordinate; 4 | import org.locationtech.jts.geom.Geometry; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | *

Title : RemoveNodesInterface

10 | *

Description : 移除节点通用级别

11 | * 12 | * @author huifer 13 | * @date 2019-02-25 14 | */ 15 | public interface RemoveNodesInterface { 16 | 17 | /** 18 | * 移除节点 19 | * 20 | * @param geometry 需要移除节点的坐标 21 | * @param coordinate 移除节点坐标 22 | * @return 移除后geometry 23 | */ 24 | Geometry remove(Geometry geometry, Coordinate coordinate); 25 | 26 | 27 | /** 28 | * 几何图形删除节点组 29 | * 30 | * @param geometry 需要移除节点的坐标 31 | * @param coordinateList 移除节点坐标集合 32 | * @return 移除后geometry 33 | */ 34 | Geometry removeList(Geometry geometry, List coordinateList); 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/algo/VoronoiInterface.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo; 2 | 3 | import org.locationtech.jts.geom.Coordinate; 4 | import org.locationtech.jts.geom.Geometry; 5 | import org.locationtech.jts.geom.Point; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | /** 11 | *

Title : VoronoiInterface

12 | *

Description : 泰森多边形相关

13 | * 14 | * @author huifer 15 | * @date 2019-01-16 16 | */ 17 | public interface VoronoiInterface { 18 | 19 | /** 20 | * 泰森多边形 21 | * 22 | * @param coords 坐标值 23 | * @return 泰森多边形面集合 24 | */ 25 | List voronoi(List coords); 26 | 27 | /** 28 | * 泰森多边形 29 | * 30 | * @param doubles 二维坐标组 31 | * @return 泰森多边形面集合 32 | */ 33 | List voronoi(double[][] doubles); 34 | 35 | /** 36 | * 泰森多边形 37 | * 38 | * @param points 点集合 39 | * @return 泰森多边形面集合 40 | */ 41 | List voronoi(ArrayList points); 42 | 43 | /** 44 | * 德劳内三角形 45 | * 46 | * @param coords 坐标值 47 | * @return 德劳内三角形面集合 48 | */ 49 | List delaunay(List coords); 50 | 51 | /** 52 | * 德劳内三角形 53 | * 54 | * @param doubles 二维坐标组 55 | * @return 德劳内三角形面集合 56 | */ 57 | List delaunay(double[][] doubles); 58 | 59 | /** 60 | * 德劳内三角形 61 | * 62 | * @param points 点集合 63 | * @return 德劳内三角形面集合 64 | */ 65 | List delaunay(ArrayList points); 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/algo/impl/minrect/MinimumBoundingRectangle.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo.impl.minrect; 2 | 3 | import org.locationtech.jts.algorithm.ConvexHull; 4 | import org.locationtech.jts.geom.Coordinate; 5 | import org.locationtech.jts.geom.Geometry; 6 | import org.locationtech.jts.geom.GeometryFactory; 7 | import org.locationtech.jts.geom.Polygon; 8 | 9 | /** 10 | *

Title : MinimumBoundingRectangle

11 | *

Description : 最小外包矩形

12 | * 13 | * @author huifer 14 | * @date 2019-02-22 15 | */ 16 | public class MinimumBoundingRectangle { 17 | 18 | /** 19 | * 最小外接矩形的获取 20 | * 21 | * @param geom 需要计算的面 22 | * @param gf 构造器 23 | * @return 最小外接矩形结果 24 | */ 25 | public static Polygon get(Geometry geom, GeometryFactory gf) { 26 | Geometry hull = (new ConvexHull(geom)).getConvexHull(); 27 | if (!(hull instanceof Polygon)) { 28 | return null; 29 | } 30 | Polygon convexHull = (Polygon) hull; 31 | // System.out.println(convexHull); 32 | 33 | // 直接使用中心值 34 | Coordinate c = geom.getCentroid().getCoordinate(); 35 | // System.out.println("==============旋转基点=============="); 36 | // System.out.println(new GeometryFactory().createPoint(c)); 37 | // System.out.println("==============旋转基点=============="); 38 | Coordinate[] coords = convexHull.getExteriorRing().getCoordinates(); 39 | 40 | double minArea = Double.MAX_VALUE; 41 | double minAngle = 0; 42 | Polygon ssr = null; 43 | Coordinate ci = coords[0]; 44 | Coordinate cii; 45 | for (int i = 0; i < coords.length - 1; i++) { 46 | cii = coords[i + 1]; 47 | double angle = Math.atan2(cii.y - ci.y, cii.x - ci.x); 48 | Polygon rect = (Polygon) Rotation.get(convexHull, c, -1 * angle, gf).getEnvelope(); 49 | double area = rect.getArea(); 50 | // 此处可以将 rotationPolygon 放到list中求最小值 51 | // Polygon rotationPolygon = Rotation.delete(rect, c, angle, gf); 52 | // System.out.println(rotationPolygon); 53 | if (area < minArea) { 54 | minArea = area; 55 | ssr = rect; 56 | minAngle = angle; 57 | } 58 | ci = cii; 59 | } 60 | 61 | return Rotation.get(ssr, c, minAngle, gf); 62 | } 63 | 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/algo/impl/minrect/MinimumEnclosingCore.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo.impl.minrect; 2 | 3 | import com.huifer.planar.aset.algo.MinimumEnclosingInterface; 4 | import org.locationtech.jts.geom.*; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | *

Title : MinimumEnclosingCore

11 | *

Description : 最小外接矩形实现

12 | * 13 | * @author huifer 14 | * @date 2019-02-25 15 | */ 16 | public class MinimumEnclosingCore implements MinimumEnclosingInterface { 17 | 18 | 19 | /** 20 | * 最小外接矩形 21 | * 22 | * @param polygon 需要计算的面 23 | * @return 最小外接矩形结果 24 | */ 25 | @Override 26 | public Polygon getMinRect(Geometry polygon) { 27 | GeometryFactory gf = new GeometryFactory(); 28 | Polygon result = MinimumBoundingRectangle.get(polygon, gf); 29 | return result; 30 | } 31 | 32 | /** 33 | * 最大内接圆 34 | * 35 | * @param pg 面 36 | * @return 最大外接圆圆心 37 | */ 38 | @Override 39 | public Point getInCirclePoint(Polygon pg) { 40 | return MaximumInnerCircle.inCirclePoint(pg, 0.0001); 41 | } 42 | 43 | /** 44 | * 最大内接圆 45 | * 46 | * @param pg 面 47 | * @return 最大外接圆 48 | */ 49 | @Override 50 | public Polygon getInCirclePolygon(Polygon pg) { 51 | return MaximumInnerCircle.inCirclePolygon(pg, 0.0001); 52 | } 53 | 54 | /** 55 | * 最小外接圆 56 | * 57 | * @param pg 面 58 | * @return 最小外接圆 59 | */ 60 | @Override 61 | public Polygon getMinimumCircumscribedCircle(Polygon pg) { 62 | Coordinate[] cs = pg.getCoordinates(); 63 | List p = new ArrayList<>(); 64 | for (Coordinate c : cs) { 65 | p.add( 66 | new GeometryFactory().createPoint(c) 67 | ); 68 | 69 | } 70 | MinCircle mec = WelzlAlgo.mec(p); 71 | return (Polygon) mec.getCenter().buffer(mec.getR()); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/algo/impl/minrect/WelzlAlgo.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo.impl.minrect; 2 | 3 | import org.locationtech.jts.geom.Point; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | /** 9 | *

Title : WelzlAlgo

10 | *

Description : 最小外接圆实现算法

11 | *

https://en.wikipedia.org/wiki/Smallest-circle_problem

12 | * 13 | * @author huifer 14 | * @date 2019-03-13 15 | */ 16 | public class WelzlAlgo { 17 | 18 | 19 | /** 20 | * mec算法 21 | * 22 | * @param pointSet 点集合 23 | * @param maxId 最大ID 24 | * @return {@link MinCircle} 最小外接圆 25 | */ 26 | public static MinCircle mec(List pointSet, int maxId) { 27 | MinCircle retCircle = null; 28 | if (maxId < 0) { 29 | retCircle = new MinCircle(0, 0, 0); 30 | } else { 31 | Point point = pointSet.get(maxId); 32 | retCircle = mec(pointSet, maxId - 1); 33 | if (!retCircle.contains(point)) { 34 | List boundarySet = new ArrayList<>(); 35 | boundarySet.add(point); 36 | retCircle = bMec(pointSet, maxId - 1, boundarySet); 37 | } 38 | } 39 | return retCircle; 40 | } 41 | 42 | /** 43 | * bMec 算法流程 44 | * 45 | * @param pointSet 点集合 46 | * @param maxId 最大id 47 | * @param boundarySet 边界点 48 | * @return 圆 49 | */ 50 | private static MinCircle bMec(List pointSet, int maxId, List boundarySet) { 51 | MinCircle resultMinCircle = new MinCircle(0, 0, 0); 52 | if (maxId < 0 || boundarySet.size() == 3) { 53 | if (boundarySet.size() == 1) { 54 | resultMinCircle = new MinCircle(boundarySet.get(0)); 55 | } else { 56 | if (boundarySet.size() == 2) { 57 | resultMinCircle = new MinCircle(boundarySet.get(0), 58 | boundarySet.get(1)); 59 | } else { 60 | if (boundarySet.size() == 3) { 61 | resultMinCircle = new MinCircle(boundarySet.get(0), 62 | boundarySet.get(1), boundarySet.get(2)); 63 | } 64 | } 65 | } 66 | } else { 67 | Point point = pointSet.get(maxId); 68 | resultMinCircle = bMec(pointSet, maxId - 1, boundarySet); 69 | if (!resultMinCircle.contains(point)) { 70 | boundarySet.add(point); 71 | resultMinCircle = bMec(pointSet, maxId - 1, boundarySet); 72 | boundarySet.remove(point); 73 | } 74 | } 75 | return resultMinCircle; 76 | } 77 | 78 | public static MinCircle mec(List p) { 79 | MinCircle circle = mec(p, p.size() - 1); 80 | return circle; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/algo/impl/polygon/CuttingConcavePolygonImpl.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo.impl.polygon; 2 | 3 | import com.huifer.planar.aset.algo.CuttingConcavePolygon; 4 | import com.huifer.planar.aset.algo.impl.concave.ConcaveSplit; 5 | import com.huifer.planar.aset.algo.impl.concave.ConcaveSplit.TroughLineWithSort; 6 | import org.locationtech.jts.geom.Polygon; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | *

Title : CuttingConcavePolygonImpl

12 | *

Description :

13 | * 14 | * @author huifer 15 | * @date 2019-03-01 16 | */ 17 | public class CuttingConcavePolygonImpl implements CuttingConcavePolygon { 18 | 19 | @Override 20 | public List concaveSplit(Polygon polygon) throws Exception { 21 | return ConcaveSplit.split(polygon); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/algo/impl/polygon/MyRecatngleOverCore.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo.impl.polygon; 2 | 3 | import com.huifer.planar.aset.algo.LineOverInterface; 4 | import com.huifer.planar.aset.algo.MyRectangleOver; 5 | import com.huifer.planar.aset.algo.impl.ovlayer.LineOverCore; 6 | import com.huifer.planar.aset.entity.MyRectangle; 7 | 8 | /** 9 | *

Title : MyRecatngleOverCore

10 | *

Description : 矩形相交

11 | * 12 | * @author huifer 13 | * @date 2018/12/20 14 | */ 15 | public class MyRecatngleOverCore implements MyRectangleOver { 16 | 17 | LineOverInterface over = new LineOverCore(); 18 | 19 | 20 | /** 21 | * 计算两个矩形相交面积 22 | */ 23 | @Override 24 | public double calcAreaIntersectionRectangles(MyRectangle r1, MyRectangle r2) { 25 | if (r1 == null || r2 == null) { 26 | return -1; 27 | } 28 | double p1x = r1.getLowLeft().getX(); 29 | double p1y = r1.getLowLeft().getY(); 30 | 31 | double p2x = p1x + r1.getLength(); 32 | double p2y = p1y + r1.getWidth(); 33 | 34 | double p3x = r2.getLowLeft().getX(); 35 | double p3y = r2.getLowLeft().getY(); 36 | 37 | double p4x = p3x + r2.getLength(); 38 | double p4y = p3y + r2.getWidth(); 39 | if (p1x > p4x || p2x < p3x || p1y > p4y || p2y < p3y) { 40 | return 0; 41 | } 42 | double len = Math.min(p2x, p4x) - Math.max(p1x, p3x); 43 | double wid = Math.min(p2y, p4y) - Math.max(p1y, p3y); 44 | return len * wid; 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/algo/impl/polygon/RailCore.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo.impl.polygon; 2 | 3 | import com.huifer.planar.aset.algo.RailInterface; 4 | import com.huifer.planar.aset.entity.MyLine; 5 | import com.huifer.planar.aset.entity.MyPoint; 6 | import com.huifer.planar.aset.entity.MyPolygon; 7 | 8 | import java.util.ArrayList; 9 | 10 | /** 11 | *

Title : RailCore

12 | *

Description : 点面交集

13 | * 14 | * @author huifer 15 | * @date 2018/12/14 16 | */ 17 | public class RailCore implements RailInterface { 18 | 19 | @Override 20 | public boolean isInPolygon(MyPoint point, MyPolygon polygon) { 21 | boolean result = false; 22 | ArrayList polylines = polygon.getPolylines(); 23 | for (MyLine edge : polylines) { 24 | 25 | if ((edge.getPoint1().getX() < point.getX() && edge.getPoint2().getX() >= point.getX()) 26 | || 27 | (edge.getPoint2().getX() < point.getX() && edge.getPoint1().getX() >= point 28 | .getX()) 29 | && (edge.getPoint1().getY() <= point.getY() 30 | || edge.getPoint2().getY() <= point 31 | .getY()) 32 | ) { 33 | result ^= (edge.getPoint2().getY() + 34 | (point.getX() - edge.getPoint2().getX()) / (edge.getPoint1().getX() - edge 35 | .getPoint2() 36 | .getX()) * (edge.getPoint1().getY() - edge.getPoint2().getY()) 37 | < point 38 | .getY()); 39 | } 40 | } 41 | 42 | return false; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/entity/ConcavePolygonCut.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | import org.locationtech.jts.geom.LineString; 7 | import org.locationtech.jts.geom.Point; 8 | import org.locationtech.jts.geom.Polygon; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | *

Title : ConcavePolygonCut

14 | *

Description : 凹多边形切割结果类

15 | * 16 | * @author huifer 17 | * @date 2019-03-08 18 | */ 19 | @Data 20 | @NoArgsConstructor 21 | @AllArgsConstructor 22 | public class ConcavePolygonCut { 23 | 24 | /** 25 | * 原始面 26 | */ 27 | private Polygon originalPolygon; 28 | /** 29 | * 凹点 30 | */ 31 | private List troughList; 32 | /** 33 | * 内部线段 34 | */ 35 | private List internalLine; 36 | 37 | /** 38 | * 切割后的面结果 39 | */ 40 | private List cutPolygonList; 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/entity/FourBox.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | /** 8 | *

Title : FourBox

9 | *

Description : 四至

10 | * 11 | * @author huifer 12 | * @date 2019-01-11 13 | */ 14 | @Data 15 | @NoArgsConstructor 16 | @AllArgsConstructor 17 | public class FourBox { 18 | 19 | private double leftX; 20 | private double leftY; 21 | private double rightX; 22 | private double rightY; 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/entity/KmeanPolygonResult.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | import org.locationtech.jts.geom.Geometry; 7 | import org.locationtech.jts.geom.Point; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | /** 13 | *

Title : KmeanPolygonResult

14 | *

Description : Kmean+泰森多边形平分多边形结果

15 | * 16 | * @author huifer 17 | * @date 2019-01-16 18 | */ 19 | @Data 20 | @NoArgsConstructor 21 | @AllArgsConstructor 22 | public class KmeanPolygonResult { 23 | 24 | /** 25 | * 原始平面 26 | */ 27 | private Geometry polygon; 28 | /** 29 | * 随机点集合 30 | */ 31 | private ArrayList pointList; 32 | /** 33 | * 分组后组id 34 | */ 35 | private int[] assignments; 36 | /** 37 | * 中心集合 38 | */ 39 | private double[][] centroids; 40 | /** 41 | * xlist 42 | */ 43 | private ArrayList xlist; 44 | /** 45 | * ylist 46 | */ 47 | private ArrayList ylist; 48 | /** 49 | * 构造泰森多边形 50 | */ 51 | private List voronoi; 52 | 53 | /** 54 | * 切割后图形 55 | */ 56 | private List geometryList; 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/entity/Kmeans.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.entity; 2 | 3 | import ca.pjer.ekmeans.EKmeans; 4 | import lombok.Data; 5 | 6 | /** 7 | *

Title : Kmeans

8 | *

Description : Kmeans 聚合

9 | * 10 | * @author huifer 11 | * @date 2019-01-15 12 | */ 13 | @Data 14 | public class Kmeans { 15 | 16 | /*** 17 | * 聚合总量 18 | */ 19 | private int n; 20 | /*** 21 | * 数据集合 22 | */ 23 | private double[][] points; 24 | /** 25 | * 簇族数量 26 | */ 27 | private int k; 28 | 29 | /** 30 | * 中心集合 31 | */ 32 | private double[][] centroids; 33 | /** 34 | * 分组后组id 35 | */ 36 | private int[] assignments; 37 | 38 | public Kmeans(double[][] points, int k) { 39 | this.n = points.length; 40 | this.points = points; 41 | this.k = k; 42 | this.centroids = new double[k][2]; 43 | init(); 44 | } 45 | 46 | /** 47 | * 求得分组数据 48 | */ 49 | public void init() { 50 | EKmeans eKmeans = new EKmeans(centroids, points); 51 | eKmeans.setIteration(128); 52 | eKmeans.setEqual(true); 53 | eKmeans.setDistanceFunction(EKmeans.EUCLIDEAN_DISTANCE_FUNCTION); 54 | eKmeans.run(); 55 | int[] assignments = eKmeans.getAssignments(); 56 | this.assignments = assignments; 57 | double[][] centroids = eKmeans.getCentroids(); 58 | this.centroids = centroids; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/entity/MyPolygon.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.ArrayList; 8 | 9 | /** 10 | *

Title : MyPolygon

11 | *

Description : 平面

12 | * 13 | * @author huifer 14 | * @date 2018/12/11 15 | */ 16 | @Data 17 | @AllArgsConstructor 18 | @NoArgsConstructor 19 | public class MyPolygon { 20 | 21 | private ArrayList polylines; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/entity/MyRectangle.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.entity; 2 | 3 | import com.huifer.planar.aset.algo.MyRectangleOver; 4 | import com.huifer.planar.aset.algo.impl.polygon.MyRecatngleOverCore; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | import lombok.ToString; 8 | 9 | import java.io.Serializable; 10 | 11 | /** 12 | *

Title : MyRectangle

13 | *

Description : 矩形

14 | * 15 | * @author huifer 16 | * @date 2018/12/20 17 | */ 18 | @Data 19 | @ToString 20 | @NoArgsConstructor 21 | public class MyRectangle implements Comparable, Serializable { 22 | 23 | 24 | private MyRectangleOver over = new MyRecatngleOverCore(); 25 | /** 26 | * 左上角 27 | */ 28 | private MyPoint topLeft; 29 | /** 30 | * 左下角 31 | */ 32 | private MyPoint lowLeft; 33 | 34 | /** 35 | * 右上角 36 | */ 37 | private MyPoint topRight; 38 | /** 39 | * 右下角 40 | */ 41 | private MyPoint lowRight; 42 | 43 | /** 44 | * 左侧线 45 | */ 46 | private MyLine leftLine; 47 | /** 48 | * 右侧线 49 | */ 50 | private MyLine rightLine; 51 | /** 52 | * 上侧线 53 | */ 54 | private MyLine topLine; 55 | /** 56 | * 下侧线 57 | */ 58 | private MyLine lowLine; 59 | /** 60 | * 长度 61 | */ 62 | private double length; 63 | /** 64 | * 宽度 65 | */ 66 | private double width; 67 | 68 | 69 | public MyRectangle(MyPoint lowLeft, double length, double width) { 70 | this.lowLeft = lowLeft; 71 | this.length = length; 72 | this.width = width; 73 | calcAllPoint(lowLeft, length, width); 74 | } 75 | 76 | @Override 77 | public int compareTo(MyRectangle o) { 78 | return Double.compare(this.getArea(), o.getArea()); 79 | } 80 | 81 | public double getArea() { 82 | return length * width; 83 | } 84 | 85 | public double calcAreaIntersectionRectangles(MyRectangle r2) { 86 | double v = over.calcAreaIntersectionRectangles(this, r2); 87 | return v; 88 | } 89 | 90 | private void calcAllPoint(MyPoint lowLeft, double length, double width) { 91 | this.lowRight = new MyPoint(lowLeft.getX() + length, lowLeft.getY()); 92 | this.topLeft = new MyPoint(lowLeft.getX(), lowLeft.getY() + width); 93 | this.topRight = new MyPoint(lowLeft.getX() + length, lowLeft.getY() + width); 94 | this.leftLine = new MyLine(lowLeft, topLeft); 95 | this.rightLine = new MyLine(lowRight, topRight); 96 | this.topLine = new MyLine(topLeft, topRight); 97 | this.lowLine = new MyLine(lowLeft, lowRight); 98 | } 99 | 100 | 101 | } 102 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/entity/OvlayerEnum.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.entity; 2 | 3 | import lombok.ToString; 4 | 5 | /** 6 | * 点线关系判断 7 | * 8 | * @author huifer 9 | */ 10 | @ToString 11 | public enum OvlayerEnum { 12 | /** 13 | * 在线上 14 | */ 15 | ON_LINE("在线上", 1), 16 | /** 17 | * 在线段延长线上 18 | */ 19 | ON_THE_EXTENSION_LINE("在线段延长线上", 2), 20 | /** 21 | * 在线段右侧 22 | */ 23 | ON_THE_RIGHT_OF_THE_LINE("在线段右侧", 3), 24 | /** 25 | * 在线段左侧 26 | */ 27 | ON_THE_LEFT_OF_THE_LINE("在线段左侧", 4), 28 | 29 | /** 30 | * 在多边形线上 31 | */ 32 | ON_THE_POLYGON_LINE("在多边形线上", 1), 33 | /** 34 | * 在多边形内 35 | */ 36 | INSIDE_THE_POLYGON("在多边形内", 2), 37 | /** 38 | * 在多边形外 39 | */ 40 | OUTSIDE_THE_POLYGON("在多边形外", 0), 41 | ; 42 | 43 | /** 44 | * 情况 45 | */ 46 | private String name; 47 | /** 48 | * 编号 49 | */ 50 | private int code; 51 | 52 | OvlayerEnum(String name, int code) { 53 | this.name = name; 54 | this.code = code; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/entity/PolygonAngleResult.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.entity; 2 | 3 | import com.huifer.planar.aset.algo.impl.polygon.PolygonAngleCore.PointF; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | import org.locationtech.jts.geom.Polygon; 8 | 9 | import java.util.HashMap; 10 | import java.util.List; 11 | 12 | /** 13 | *

Title : PolygonAngleResult

14 | *

Description : polygon 角度计算结果

15 | * 16 | * @author huifer 17 | * @date 2019-01-28 18 | */ 19 | @Data 20 | @NoArgsConstructor 21 | @AllArgsConstructor 22 | public class PolygonAngleResult { 23 | 24 | 25 | private List> polygonAngles; 26 | private Polygon polygon; 27 | 28 | private Polygon newPolygon; 29 | private double removeAngle; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/entity/PolygonRemoveNodeResult.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.entity; 2 | 3 | import com.huifer.planar.aset.algo.impl.polygon.PolygonRemoveNodeByLength.PointWithPolygon; 4 | import com.huifer.planar.aset.algo.impl.polygon.PolygonRemoveNodeByLength.PolygonEditor; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | import lombok.ToString; 9 | import org.locationtech.jts.geom.LineString; 10 | import org.locationtech.jts.geom.Point; 11 | import org.locationtech.jts.geom.Polygon; 12 | 13 | import java.util.List; 14 | import java.util.Set; 15 | 16 | /** 17 | *

Title : PolygonRemoveNodeResult

18 | *

Description : 面移除节点结果接收类

19 | * 20 | * @author huifer 21 | * @date 2019-02-15 22 | */ 23 | @Data 24 | @NoArgsConstructor 25 | @AllArgsConstructor 26 | @ToString 27 | public class PolygonRemoveNodeResult { 28 | 29 | /** 30 | * 异常点集合 31 | */ 32 | private Set errorPoints; 33 | /** 34 | * 没有保留精度的面,直接从数据中获取的面 35 | */ 36 | private List oldGeoms; 37 | /** 38 | * 精度保留后的面 39 | */ 40 | private List newGeoms; 41 | /** 42 | * 异常点和面的关系类 43 | */ 44 | private List pointWithPolygonArrayList; 45 | /** 46 | * 异常点的连接线 47 | */ 48 | private List lineStrings; 49 | /** 50 | * 保留小数后当前面是否能够被修改的判断类 51 | */ 52 | private List polygonEditorArrayList; 53 | /** 54 | * 推断需要删除的点集合 55 | */ 56 | private List deletPointList; 57 | /** 58 | * 删除点集合后的面 59 | */ 60 | private List resultPolygon; 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/entity/PublicRadial.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.entity; 2 | 3 | import lombok.Data; 4 | import lombok.NoArgsConstructor; 5 | import lombok.ToString; 6 | import org.locationtech.jts.geom.Point; 7 | 8 | /** 9 | *

Title : PublicRadial

10 | *

Description : 射线

11 | * 12 | * @author huifer 13 | * @date 2019-03-11 14 | */ 15 | @Data 16 | @NoArgsConstructor 17 | @ToString 18 | public class PublicRadial { 19 | /** 20 | * 射线起点 21 | */ 22 | private Point startPoint; 23 | /** 24 | * 射线终点 25 | */ 26 | private Point endPoint; 27 | 28 | 29 | /** 30 | * 直线方程系数A 31 | */ 32 | private double A; 33 | /** 34 | * 直线方程系数B 35 | */ 36 | private double B; 37 | /** 38 | * 直线方程常量C 39 | */ 40 | private double C; 41 | 42 | 43 | public PublicRadial(Point startPoint, Point endPoint) { 44 | this.startPoint = startPoint; 45 | this.endPoint = endPoint; 46 | 47 | double AA = endPoint.getY() - startPoint.getY(); 48 | double BB = startPoint.getX() - endPoint.getX(); 49 | double CC = endPoint.getX() * startPoint.getY() - startPoint.getX() * endPoint.getY(); 50 | this.A = AA; 51 | this.B = BB; 52 | this.C = CC; 53 | } 54 | 55 | 56 | public double calcXX(double y) { 57 | return (-B * y - C) / A; 58 | } 59 | 60 | public double calcYY(double x) { 61 | return ((-A * x) - C) / B; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/entity/RefObject.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.entity; 2 | 3 | /** 4 | * 矩阵运算 结果 5 | * 6 | * @author huifer 7 | */ 8 | public final class RefObject { 9 | 10 | public T argvalue; 11 | 12 | public RefObject(T refarg) { 13 | argvalue = refarg; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/entity/ResultShortestPath.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.entity; 2 | 3 | import lombok.Data; 4 | import lombok.ToString; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | *

Title : ResultShortestPath

10 | *

Description : DijlstraInterface 结果集合

11 | * 12 | * @author huifer 13 | * @date 2018/12/12 14 | */ 15 | @Data 16 | @ToString 17 | public class ResultShortestPath { 18 | 19 | private double length; 20 | private List pointsIndex; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/entity/SortPoint.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.entity; 2 | 3 | import lombok.Data; 4 | import lombok.ToString; 5 | 6 | /** 7 | *

Title : SortPoint

8 | *

Description : 排序点

9 | * 10 | * @author huifer 11 | * @date 2018/12/17 12 | */ 13 | @ToString 14 | @Data 15 | public class SortPoint extends MyPoint { 16 | 17 | private OvlayerEnum leftOrRight; 18 | /** 19 | * 点编号 20 | */ 21 | private int leftOrRightCode; 22 | /** 23 | * 投影点 24 | */ 25 | private MyPoint projectivePoint; 26 | /** 27 | * 到第一个点的距离 28 | */ 29 | private double distanceWithP1; 30 | 31 | public SortPoint() { 32 | } 33 | 34 | public SortPoint(double x, double y) { 35 | super(x, y); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/factory/MyGeoFactory.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.factory; 2 | 3 | import com.huifer.planar.aset.entity.MyLine; 4 | import com.huifer.planar.aset.entity.MyPoint; 5 | 6 | /** 7 | *

Title : MyGeoFactory

8 | *

Description : geo工厂

9 | * 10 | * @author huifer 11 | * @date 2018/12/14 12 | */ 13 | public class MyGeoFactory { 14 | 15 | public MyPoint createPoint(double x, double y) { 16 | return new MyPoint(x, y); 17 | } 18 | 19 | public MyLine createLine(MyPoint p1, MyPoint p2) { 20 | return new MyLine(p1, p2); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/mappingalgo/coortrans/lib/AllData.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.mappingalgo.coortrans.lib; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | *

Title : AllData

8 | *

Description : 数据整合

9 | * 10 | * @author huifer 11 | * @date 2018/11/12 12 | */ 13 | public class AllData { 14 | 15 | public Ellipsoid ellipsoid; 16 | public double l0; 17 | public List data = new ArrayList<>(); 18 | 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/mappingalgo/coortrans/lib/Ellipsoid.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.mappingalgo.coortrans.lib; 2 | 3 | /** 4 | *

Title : Ellipsoid

5 | *

Description : 椭球

6 | * 7 | * @author huifer 8 | * @date 2018/11/12 9 | */ 10 | public class Ellipsoid { 11 | 12 | 13 | /** 14 | * 长半轴 15 | */ 16 | public double a; 17 | 18 | /*** 19 | * 扁率 20 | */ 21 | public double f; 22 | 23 | /** 24 | * 第一偏心率的平方 25 | */ 26 | public double eccSq; 27 | 28 | /** 29 | * 第二偏心率的平方 30 | */ 31 | public double ecc2Sq; 32 | 33 | /** 34 | * m0 35 | */ 36 | public double m0; 37 | 38 | 39 | public Ellipsoid() { 40 | a = 6378137.0; 41 | f = 0.335281066475e-2; 42 | } 43 | 44 | /*** 45 | * 椭球构造 46 | * @param a 长半轴 47 | * @param invf f 48 | */ 49 | public Ellipsoid(double a, double invf) { 50 | this.a = a; 51 | f = 1 / invf; 52 | init(); 53 | } 54 | 55 | void init() { 56 | double b = a * (1 - f); 57 | eccSq = (a * a - b * b) / a / a; 58 | ecc2Sq = (a * a - b * b) / b / b; 59 | m0 = a * (1 - eccSq); 60 | } 61 | 62 | /*** 63 | * 计算W 64 | * @param b 纬度(以弧度为单位) 65 | * @return 66 | */ 67 | public double w(double b) { 68 | double w = Math.sqrt(1 - eccSq * Math.pow(Math.sin(b), 2)); 69 | return w; 70 | } 71 | 72 | /*** 73 | * 计算eta 74 | * @param b 纬度(以弧度为单位) 75 | * @return 76 | */ 77 | public double eta(double b) { 78 | double eta = Math.sqrt((ecc2Sq * Math.pow(Math.cos(b), 2))); 79 | return eta; 80 | } 81 | 82 | 83 | /*** 84 | * 计算tan 85 | * @param b 纬度(以弧度为单位) 86 | * @return 87 | */ 88 | public double tan(double b) { 89 | return Math.tan(b); 90 | } 91 | 92 | /*** 93 | * 计算 卯酉圈的曲率半径N 94 | * @param b 纬度(以弧度为单位) 95 | * @return 96 | */ 97 | public double n(double b) { 98 | double w = w(b); 99 | return a / w; 100 | } 101 | 102 | /*** 103 | * 子午圈曲率半径 m 104 | * @param b 105 | * @return 106 | */ 107 | public double m(double b) { 108 | double over = a * (1 - eccSq); 109 | double w = w(b); 110 | return over / (w * w * w); 111 | } 112 | 113 | } 114 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/mappingalgo/coortrans/lib/PointInfo.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.mappingalgo.coortrans.lib; 2 | 3 | /** 4 | *

Title : PointInfo

5 | *

Description : 点信息

6 | * 7 | * @author huifer 8 | * @date 2018/11/12 9 | */ 10 | public class PointInfo { 11 | 12 | public String name; 13 | /** 14 | * 大地坐标系b 15 | */ 16 | public double b; 17 | /** 18 | * 大地坐标系l 19 | */ 20 | public double l; 21 | /** 22 | * 大地坐标系h 23 | */ 24 | public double h; 25 | /** 26 | * 空间直角坐标系 x 27 | */ 28 | public double x; 29 | /** 30 | * 空间直角坐标系 y 31 | */ 32 | public double y; 33 | /** 34 | * 空间直角坐标系 z 35 | */ 36 | public double z; 37 | /** 38 | * 高斯平面直角坐标系 x 39 | */ 40 | public double gsx; 41 | /** 42 | * 高斯平面直角坐标系 y 43 | */ 44 | public double gsy; 45 | 46 | 47 | @Override 48 | public String toString() { 49 | return "PointInfo{" + 50 | "name='" + name + '\'' + 51 | ", b=" + b + 52 | ", l=" + l + 53 | ", h=" + h + 54 | ", x=" + x + 55 | ", y=" + y + 56 | ", z=" + z + 57 | ", gsx=" + gsx + 58 | ", gsy=" + gsy + 59 | '}'; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/mappingalgo/coortrans/lib/Position.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.mappingalgo.coortrans.lib; 2 | 3 | /** 4 | *

Title : Position

5 | *

Description : 三维坐标转换

6 | * 7 | * @author huifer 8 | * @date 2018/11/12 9 | */ 10 | public class Position { 11 | 12 | private Ellipsoid ellipsoid; 13 | 14 | public Position(Ellipsoid ellipsoid) { 15 | this.ellipsoid = ellipsoid; 16 | } 17 | 18 | 19 | /*** 20 | * 大地测量转换为笛卡尔坐标 21 | * @param lat 纬度 22 | * @param lon 经度 23 | * @param height 高度 24 | * @return 笛卡尔坐标系 xyz 25 | */ 26 | public double[] geodetic2Cartesian(double lat, double lon, double height) { 27 | double x, y, z; 28 | 29 | double n = ellipsoid.n(lat); 30 | double slat = Math.sin(lat); 31 | double clat = Math.cos(lat); 32 | x = (n + height) * clat * Math.cos(lon); 33 | y = (n + height) * clat * Math.sin(lon); 34 | z = (n * (1 - ellipsoid.eccSq) + height) * slat; 35 | return new double[]{x, y, z}; 36 | } 37 | 38 | /** 39 | * 笛卡尔坐标系转换 大地坐标系 40 | * 41 | * @param x x 42 | * @param y y 43 | * @param z z 44 | * @return 大地坐标系值 45 | */ 46 | public double[] cartesian2Geodetic(double x, double y, double z) { 47 | double lat = 0; 48 | double lon = 0; 49 | double height = 0; 50 | double positionTolerance = 0.0001; 51 | 52 | double p, slat, n, htold, latold; 53 | 54 | p = Math.sqrt(x * x + y * y); 55 | if (p < positionTolerance) { 56 | lat = (z > 0 ? 90.0 : -90.0); 57 | lon = 0; 58 | height = Math.abs(z - ellipsoid.a * Math.sqrt(1 - ellipsoid.eccSq)); 59 | } else { 60 | lat = Math.atan2(z, p); 61 | height = 0; 62 | for (int i = 0; i < 5; i++) { 63 | slat = Math.sin(lat); 64 | n = ellipsoid.n(lat); 65 | htold = height; 66 | height = p / Math.cos(lat) - n; 67 | latold = lat; 68 | lat = Math.atan2(z + n * ellipsoid.eccSq * slat, p); 69 | if (Math.abs(lat - latold) < 1.0e-9 70 | && Math.abs(height - htold) < 1.0e-9 * ellipsoid.a) { 71 | break; 72 | } 73 | lon = Math.atan2(y, x); 74 | { 75 | if (lon < 0.0) { 76 | lon += 2 * Math.PI; 77 | } 78 | } 79 | } 80 | } 81 | return new double[]{lat, lon, height}; 82 | } 83 | 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/mappingalgo/coortrans/lib/Rad2Dms.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.mappingalgo.coortrans.lib; 2 | 3 | /** 4 | *

Title : Rad2Dms

5 | *

Description : rad dms 互相转换

6 | * 7 | * @author huifer 8 | * @date 2018/11/12 9 | */ 10 | public class Rad2Dms { 11 | 12 | /*** 13 | * rad 转 dms 14 | * @param rad 15 | * @return double 16 | */ 17 | public static double rad2dms(double rad) { 18 | double dms = 0; 19 | double sec = 0; 20 | int deg = 0; 21 | int minu = 0; 22 | int sign = 1; 23 | if (rad < 0) { 24 | sign = -1; 25 | rad = -rad; 26 | } 27 | dms = rad / Math.PI * 180; 28 | deg = (int) Math.floor(dms); 29 | minu = (int) Math.floor((dms - deg) * 60.0); 30 | 31 | sec = (dms - deg - minu / 60.0) * 3600.0; 32 | dms = deg + minu / 100.0 + sec / 10000.0; 33 | dms = sign * dms; 34 | 35 | return dms; 36 | } 37 | 38 | 39 | /*** 40 | * dms 转 rad 41 | * @param dms 42 | * @return double 43 | */ 44 | public static double dms2rad(double dms) { 45 | int sign = 1; 46 | double rad = 0; 47 | double sec = 0; 48 | int deg = 0; 49 | int minu = 0; 50 | if (dms < 0) { 51 | sign = -1; 52 | dms = -dms; 53 | } 54 | deg = (int) Math.floor(dms); 55 | minu = (int) Math.floor((dms - deg) * 100.0); 56 | 57 | sec = (dms - deg - minu / 100.0) * 10000; 58 | rad = deg + minu / 60.0 + sec / 3600.0; 59 | rad = rad / 180.0 * Math.PI; 60 | rad = rad * sign; 61 | return rad; 62 | } 63 | 64 | /** 65 | * rad 转 dms 字符串 66 | * 67 | * @return str 68 | */ 69 | public static String rad2Str(double rad) { 70 | String res = ""; 71 | double d = rad / Math.PI * 180; 72 | String sign = ""; 73 | if (d < 0) { 74 | sign = "-"; 75 | } 76 | d = Math.abs(d); 77 | double dd, mm, ss; 78 | dd = Math.floor(d); 79 | mm = Math.floor((d - dd) * 60.0); 80 | ss = (d - dd - mm / 60.0) * 3600.0; 81 | res = sign + dd + "°" + mm + "′" + ss + "″"; 82 | return res; 83 | } 84 | 85 | 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/mappingalgo/coortrans/坐标数据.txt: -------------------------------------------------------------------------------- 1 | a,6378137.000 2 | 1/f,298.3 3 | L0,111 4 | 5 | Q71,36.082771,109.191366,5533.025 6 | P91,33.445550,110.154237,4785.906 7 | Q42,38.372964,108.023609,5453.323 8 | Q34,39.305664,111.361612,5800.386 9 | B99,37.264007,108.385066,5557.617 10 | A89,37.371094,112.321633,5282.713 11 | P90,36.035483,111.145753,5550.860 12 | P60,33.334965,109.295619,5496.801 13 | Q89,35.411290,112.303315,5625.113 14 | P72,36.456890,112.47257,4566.878 15 | A05,38.085189,109.182573,4712.183 16 | A46,35.221248,110.24663,5220.175 17 | Q03,36.182447,112.254924,5426.659 -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/mappingalgo/fanjuli/InverseDistanceCore.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.mappingalgo.fanjuli; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | 5 | import java.util.ArrayList; 6 | import java.util.Comparator; 7 | import java.util.HashMap; 8 | import java.util.List; 9 | 10 | /** 11 | *

Title : InverseDistanceCore

12 | *

Description : 运行工具

13 | * 14 | * @author huifer 15 | * @date 2018/11/12 16 | */ 17 | @Slf4j 18 | public class InverseDistanceCore { 19 | 20 | public static void main(String[] args) { 21 | ReadHelper readHelper = new ReadHelper( 22 | "E:\\mck\\planar_algorithm\\src\\main\\java\\com\\huifer\\planar\\aset\\mappingalgo\\fanjuli\\测站坐标.txt"); 23 | List points = readHelper.getPoints(); 24 | 25 | List paramList = new ArrayList<>(); 26 | MyPoint p = new MyPoint("Q1", 4310, 3600, 0); 27 | HashMap idw = idw(points, p, 5); 28 | // System.out.println(idw); 29 | log.info("idw = {}", idw); 30 | } 31 | 32 | /** 33 | * idw 主要流程 34 | * 35 | * @param points 36 | * @param point 37 | */ 38 | public static HashMap idw(List points, MyPoint point, int n) { 39 | 40 | HashMap res = new HashMap<>(); 41 | 42 | for (int i = 0; i < points.size(); i++) { 43 | double d = distance(points.get(i), point); 44 | points.get(i).setDist(d); 45 | } 46 | // 排序 47 | points.sort( 48 | Comparator.comparingDouble(MyPoint::getDist) 49 | ); 50 | double h = getH(points, n); 51 | point.setZ(h); 52 | res.put("参数点", point); 53 | res.put("参与插值", points.subList(0, n)); 54 | return res; 55 | } 56 | 57 | /** 58 | * 计算 距离 59 | * 60 | * @param p1 第一个点 61 | * @param p2 第二个点 62 | * @return double 距离 63 | */ 64 | private static double distance(MyPoint p1, MyPoint p2) { 65 | double dx = p1.getX() - p2.getX(); 66 | double dy = p1.getY() - p2.getY(); 67 | double ds = Math.sqrt(dx * dx + dy * dy); 68 | return ds; 69 | } 70 | 71 | /*** 72 | * 计算高 73 | * @param points 点列表 74 | * @param n 参与数量 75 | * @return double h 76 | */ 77 | private static double getH(List points, int n) { 78 | double over = 0; 79 | double under = 0; 80 | for (int i = 0; i < n; i++) { 81 | over += points.get(i).getZ() / points.get(i).getDist(); 82 | under += 1 / points.get(i).getDist(); 83 | } 84 | return over / under; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/mappingalgo/fanjuli/MyPoint.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.mappingalgo.fanjuli; 2 | 3 | /** 4 | *

Title : MyPoint

5 | *

Description : 测站坐标点

6 | * 7 | * @author huifer 8 | * @date 2018/11/12 9 | */ 10 | public class MyPoint { 11 | 12 | private String id; 13 | private double x; 14 | private double y; 15 | private double z; 16 | private double dist; 17 | 18 | public MyPoint(String id, double x, double y, double z) { 19 | this.id = id; 20 | this.x = x; 21 | this.y = y; 22 | this.z = z; 23 | } 24 | 25 | public MyPoint() { 26 | x = y = z = dist = 0; 27 | } 28 | 29 | public String getId() { 30 | return id; 31 | } 32 | 33 | public double getX() { 34 | return x; 35 | } 36 | 37 | public double getY() { 38 | return y; 39 | } 40 | 41 | public double getZ() { 42 | return z; 43 | } 44 | 45 | public void setZ(double z) { 46 | this.z = z; 47 | } 48 | 49 | public double getDist() { 50 | return dist; 51 | } 52 | 53 | public void setDist(double dist) { 54 | this.dist = dist; 55 | } 56 | 57 | @Override 58 | public String toString() { 59 | return "MyPoint{" + 60 | "id='" + id + '\'' + 61 | ", x=" + x + 62 | ", y=" + y + 63 | ", z=" + z + 64 | ", dist=" + dist + 65 | '}'; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/mappingalgo/fanjuli/ReadHelper.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.mappingalgo.fanjuli; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.FileInputStream; 5 | import java.io.InputStreamReader; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | *

Title : ReadHelper

11 | *

Description : 读文件工具

12 | * 13 | * @author huifer 14 | * @date 2018/11/12 15 | */ 16 | public class ReadHelper { 17 | 18 | 19 | private List points = new ArrayList<>(); 20 | 21 | 22 | public ReadHelper(String path) { 23 | List textData = ReadHelper.readFileHelper(path); 24 | this.points = getPointList(textData); 25 | } 26 | 27 | public static void main(String[] args) { 28 | 29 | ReadHelper readHelper = new ReadHelper( 30 | "E:\\idea_project\\cloud\\src\\main\\java\\com\\te\\fanjuli\\测站坐标.txt"); 31 | List points = readHelper.getPoints(); 32 | } 33 | 34 | /** 35 | * 获取每一行的 点信息 36 | */ 37 | private static List getPointList(List textData) { 38 | List points = new ArrayList<>(); 39 | for (int i = 0; i < textData.size(); i++) { 40 | String[] s = textData.get(i).split(","); 41 | MyPoint point = new MyPoint( 42 | s[0], 43 | Double.parseDouble(s[1]), 44 | Double.parseDouble(s[2]), 45 | Double.parseDouble(s[3]) 46 | ); 47 | 48 | points.add(point); 49 | } 50 | return points; 51 | } 52 | 53 | /*** 54 | * 读文件 55 | * @param path 56 | * @return 57 | */ 58 | private static List readFileHelper(String path) { 59 | InputStreamReader isr; 60 | try { 61 | isr = new InputStreamReader(new FileInputStream(path), "utf-8"); 62 | BufferedReader read = new BufferedReader(isr); 63 | String s = null; 64 | List list = new ArrayList(); 65 | while ((s = read.readLine()) != null) { 66 | if (s.trim().length() > 1) { 67 | list.add(s.trim()); 68 | } 69 | } 70 | return list; 71 | } catch (Exception e) { 72 | e.printStackTrace(); 73 | } 74 | return null; 75 | } 76 | 77 | public List getPoints() { 78 | return points; 79 | } 80 | 81 | 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/mappingalgo/fanjuli/测站坐标.txt: -------------------------------------------------------------------------------- 1 | P01,4302.047,3602.652,10.804 2 | P02,4305.768,3598.683,10.855 3 | P03,4310.610,3595.393,10.998 4 | P04,4313.138,3595.086,12.038 5 | P05,4316.843,3594.703,12.818 6 | P06,4320.164,3593.923,12.784 7 | P07,4324.247,3592.690,12.519 8 | P08,4327.704,3591.004,12.685 9 | P09,4331.911,3589.025,12.324 10 | P10,4335.742,3586.897,11.165 11 | P11,4339.844,3584.716,10.802 12 | P12,4333.566,3627.259,9.648 13 | P13,4329.376,3628.727,9.664 14 | P14,4325.037,3630.602,9.608 15 | P15,4321.569,3632.203,9.556 16 | P16,4316.825,3633.985,9.579 17 | P17,4310.382,3635.810,9.440 18 | P18,4306.162,3637.121,9.729 19 | P19,4302.145,3637.715,10.073 20 | P20,4300.700,3611.324,11.769 21 | P21,4303.182,3614.425,12.123 22 | P22,4306.755,3615.185,12.683 23 | P23,4310.931,3613.805,12.976 24 | P24,4314.595,3612.234,13.308 25 | P25,4318.979,3611.322,13.653 26 | P26,4323.632,3609.654,13.674 27 | P27,4327.618,3608.437,13.921 28 | P28,4330.858,3607.602,14.160 29 | P29,4334.909,3606.218,14.355 30 | P30,4339.637,3605.087,14.325 31 | P31,4342.549,3601.832,14.202 32 | P32,4343.144,3604.749,14.318 33 | P33,4343.057,3608.453,14.486 34 | P34,4343.454,3611.589,14.552 35 | P35,4341.930,3614.516,14.690 36 | P36,4341.758,3615.097,14.585 37 | P37,4338.861,3617.507,14.632 38 | P38,4334.937,3618.789,14.601 39 | P39,4331.481,3619.680,14.240 40 | P40,4327.580,3621.409,13.926 41 | P41,4323.586,3623.381,13.752 42 | P42,4319.758,3625.396,13.448 43 | P43,4315.545,3627.270,13.092 44 | P44,4311.801,3628.831,12.825 45 | P45,4308.221,3630.390,12.251 46 | P46,4305.945,3628.937,12.109 -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/mappingalgo/grid/GRID数据.txt: -------------------------------------------------------------------------------- 1 | P01,3793.011,2869.972,9.571 2 | P02,3795.959,2868.952,9.615 3 | P03,3799.283,2864.64,9.977 4 | P04,3799.039,2856.23,10.102 5 | P05,3795.293,2853.8,10.115 6 | P06,3789.301,2853.684,10.275 7 | P07,3784.585,2857.299,10.238 8 | P08,3780.326,2861.322,10.011 9 | P09,3776.541,2864.789,9.692 10 | P10,3779.115,2869.933,9.38 11 | P11,3785.879,2870.586,9.528 12 | P12,3792.979,2870.191,9.554 13 | P13,3790.221,2869.222,9.998 14 | P14,3791.97,2865.383,12.355 15 | P15,3787.793,2865.415,12.966 16 | P16,3781.747,2865.363,12.793 17 | P17,3785.322,2861.955,12.472 18 | P18,3788.845,2858.02,12.97 19 | P19,3793.866,2858.628,12.881 20 | P20,3794.916,2863.177,12.794 21 | P21,3795.059,2862.592,12.55 22 | P22,3786.324,2863.73,12.143 23 | P23,3776.468,2858.881,10.029 24 | P24,3780.976,2855.736,10.168 25 | P25,3784.596,2852.645,10.318 26 | P26,3781.654,2850.453,10.155 27 | P27,3780.524,2847.34,10.309 28 | P28,3778.428,2845.174,10.354 29 | P29,3772.222,2845.423,10.604 30 | P30,3764.824,2845.985,10.485 31 | P31,3757.095,2846.279,10.65 32 | P32,3749.893,2848.263,10.633 33 | P33,3744.116,2853.723,10.773 34 | P34,3744.891,2859.717,11.13 35 | P35,3751.04,2864.182,10.537 36 | P36,3758.577,2865.857,10.184 37 | P37,3765.204,2866.069,10.397 38 | P38,3770.445,2863.635,10.02 39 | P39,3775.82,2859.628,10.053 40 | P40,3764.334,2864.859,10.542 41 | P41,3768.128,2860.81,12.536 42 | P42,3768.634,2856.572,15.309 43 | P43,3768.382,2854.894,15.962 44 | P44,3765.924,2855.036,16.391 45 | P45,3762.297,2855.115,15.699 46 | P46,3757.805,2855.804,16.6 47 | P47,3748.804,2856.423,14.529 48 | P48,3750.621,2856.161,13.511 49 | P49,3748.429,2851.975,10.997 50 | P50,3750.342,2858.816,12.546 51 | P51,3769.646,2870.663,10.22 52 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/mappingalgo/grid/lib/GeoCalc.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.mappingalgo.grid.lib; 2 | 3 | /** 4 | *

Title : GeoCalc

5 | *

Description : 坐标计算

6 | * 7 | * @author huifer 8 | * @date 2018/11/14 9 | */ 10 | public class GeoCalc { 11 | 12 | /** 13 | * 叉积 14 | */ 15 | public static double crossMul(Vector v1, Vector v2) { 16 | return v1.x * v2.y - v1.y * v2.x; 17 | } 18 | 19 | /*** 20 | * 点乘 21 | * @param v1 22 | * @param v2 23 | * @return 24 | */ 25 | public static double dotMul(Vector v1, Vector v2) { 26 | return v1.x * v2.x + v1.y * v2.y; 27 | } 28 | 29 | /** 30 | * 取模 31 | * 32 | * @param vector 33 | * @return 34 | */ 35 | public static double model(Vector vector) { 36 | return Math.sqrt(Math.pow(vector.x, 2) + Math.pow(vector.y, 2)); 37 | } 38 | 39 | /** 40 | * 计算体积 41 | * 42 | * @param grid 网格 43 | * @param baseHeight 基准高度 44 | * @return 体积 45 | */ 46 | public static double calcVolumn(Grid grid, double baseHeight) { 47 | double voumnSum = 0; 48 | for (int row = 0; row < grid.height; row++) { 49 | for (int col = 0; col < grid.width; col++) { 50 | GridCell cell = grid.gridCells[row][col]; 51 | if (cell.isInSide) { 52 | // double vol = (cell.Height - baseheight) * cell.SideLength * cell.SideLength; 53 | double vol = (cell.height - baseHeight) * cell.sideLength * cell.sideLength; 54 | voumnSum += vol; 55 | } 56 | } 57 | 58 | } 59 | 60 | return voumnSum; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/mappingalgo/grid/lib/GridCell.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.mappingalgo.grid.lib; 2 | 3 | /** 4 | *

Title : GridCell

5 | *

Description : 单元网格 矩阵

6 | * 7 | * @author huifer 8 | * @date 2018/11/14 9 | */ 10 | public class GridCell { 11 | 12 | /** 13 | * 左上角 14 | */ 15 | public PointInfo upLeft; 16 | /** 17 | * 右上角 18 | */ 19 | public PointInfo upRight; 20 | /** 21 | * 左下角 22 | */ 23 | public PointInfo downLeft; 24 | /** 25 | * 右下角 26 | */ 27 | public PointInfo downRight; 28 | 29 | /** 30 | * 边长 31 | */ 32 | public double sideLength; 33 | 34 | /** 35 | * 高 36 | */ 37 | public double height; 38 | 39 | /** 40 | * 是否在内部 41 | */ 42 | public boolean isInSide; 43 | 44 | @Override 45 | public String toString() { 46 | return "GridCell{" + 47 | "upLeft=" + upLeft + 48 | ", upRight=" + upRight + 49 | ", downLeft=" + downLeft + 50 | ", downRight=" + downRight + 51 | ", sideLength=" + sideLength + 52 | ", height=" + height + 53 | ", isInSide=" + isInSide + 54 | '}'; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/mappingalgo/grid/lib/HeightCalc.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.mappingalgo.grid.lib; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | *

Title : HeightCalc

7 | *

Description : 高度计算

8 | * 9 | * @author huifer 10 | * @date 2018/11/15 11 | */ 12 | public class HeightCalc { 13 | 14 | private Grid grid; 15 | private List points; 16 | private double sortRange; 17 | private double sortRadius; 18 | 19 | public HeightCalc(Grid grid, List points, double sortRange) { 20 | this.points = points; 21 | this.grid = grid; 22 | this.sortRange = sortRange; 23 | } 24 | 25 | public void runCalc(double baseHeight) { 26 | sortRadius = sortRange * (grid.width + grid.height) * grid.interval / 2; 27 | for (int row = 0; row < grid.height; row++) { 28 | 29 | for (int col = 0; col < grid.width; col++) { 30 | 31 | GridCell cell = grid.gridCells[row][col]; 32 | if (cell.isInSide) { 33 | double h1 = cell.upLeft.h = calcHeight(cell.upLeft); 34 | double h2 = cell.upRight.h = calcHeight(cell.upRight); 35 | double h3 = cell.downLeft.h = calcHeight(cell.downLeft); 36 | double h4 = cell.downRight.h = calcHeight(cell.downRight); 37 | cell.height = (h1 + h2 + h3 + h4) / 4; 38 | } else { 39 | cell.upLeft.h = baseHeight; 40 | cell.upRight.h = baseHeight; 41 | cell.downLeft.h = baseHeight; 42 | cell.downRight.h = baseHeight; 43 | } 44 | } 45 | } 46 | } 47 | 48 | private double calcHeight(PointInfo pointInfo) { 49 | Vector vector; 50 | vector = new Vector(); 51 | double weightSum = 0; 52 | double heightSum = 0; 53 | for (int i = 0; i < points.size(); i++) { 54 | PointInfo tem = points.get(i); 55 | vector.x = tem.x - pointInfo.x; 56 | vector.y = tem.y - pointInfo.y; 57 | double dist = GeoCalc.model(vector); 58 | if (dist <= sortRadius) { 59 | double weight = 1.0 / dist; 60 | weightSum += weight; 61 | double height = tem.h * weight; 62 | heightSum += height; 63 | } 64 | } 65 | return heightSum / weightSum; 66 | 67 | } 68 | 69 | @Override 70 | public String toString() { 71 | return "HeightCalc{" + 72 | "grid=" + grid + 73 | ", points=" + points + 74 | ", sortRange=" + sortRange + 75 | ", sortRadius=" + sortRadius + 76 | '}'; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/mappingalgo/grid/lib/PointInfo.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.mappingalgo.grid.lib; 2 | 3 | /** 4 | *

Title : PointInfo

5 | *

Description : 单点信息

6 | * 7 | * @author huifer 8 | * @date 2018/11/14 9 | */ 10 | public class PointInfo { 11 | 12 | /** 13 | * 点名 14 | */ 15 | public String name; 16 | /** 17 | * x 18 | */ 19 | public double x; 20 | /** 21 | * y 22 | */ 23 | public double y; 24 | /** 25 | * z 26 | */ 27 | public double h; 28 | /** 29 | * 角度 30 | */ 31 | public double angle; 32 | 33 | 34 | @Override 35 | public String toString() { 36 | return "PointInfo{" + 37 | "name='" + name + '\'' + 38 | ", x=" + x + 39 | ", y=" + y + 40 | ", h=" + h + 41 | ", angle=" + angle + 42 | '}'; 43 | } 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/mappingalgo/grid/lib/ResultData.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.mappingalgo.grid.lib; 2 | 3 | /** 4 | *

Title : ResultData

5 | *

Description : 结果数据

6 | * 7 | * @author huifer 8 | * @date 2018/11/15 9 | */ 10 | public class ResultData { 11 | 12 | /** 13 | * 基准高程 14 | */ 15 | public double baseHeight; 16 | 17 | /** 18 | * 领域比例 19 | */ 20 | public double neighbor; 21 | 22 | /** 23 | * 间距 24 | */ 25 | public double inteval; 26 | 27 | /** 28 | * 凸包 29 | */ 30 | public Convex convex; 31 | 32 | /** 33 | * 网格 34 | */ 35 | public Grid grid; 36 | 37 | /** 38 | * 体积 39 | */ 40 | public double volumn; 41 | 42 | /** 43 | * 列 44 | */ 45 | public Integer col; 46 | 47 | /** 48 | * 行 49 | */ 50 | public Integer row; 51 | 52 | 53 | @Override 54 | public String toString() { 55 | return "ResultData{" + 56 | "baseHeight=" + baseHeight + 57 | ", neighbor=" + neighbor + 58 | ", inteval=" + inteval + 59 | ", convex=" + convex + 60 | ", grid=" + grid + 61 | ", volumn=" + volumn + 62 | ", col=" + col + 63 | ", row=" + row + 64 | '}'; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/mappingalgo/grid/lib/Stack.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.mappingalgo.grid.lib; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | *

Title : Stack

8 | *

Description : 堆

9 | * 10 | * @author huifer 11 | * @date 2018/11/14 12 | */ 13 | public class Stack { 14 | 15 | public List data; 16 | public int top; 17 | 18 | public Stack() { 19 | top = -1; 20 | data = new ArrayList<>(); 21 | } 22 | 23 | /** 24 | * 向点集追加数据返回总量 25 | * 26 | * @param pointInfo 27 | * @return 28 | */ 29 | public int pushStack(PointInfo pointInfo) { 30 | data.add(pointInfo); 31 | top++; 32 | return top; 33 | } 34 | 35 | /*** 36 | * 删除一个点 返回点信息 37 | * @return 38 | */ 39 | public PointInfo popStack() { 40 | PointInfo p = data.get(top); 41 | data.remove(p); 42 | top--; 43 | return p; 44 | } 45 | 46 | @Override 47 | public String toString() { 48 | return "Stack{" + 49 | "data=" + data + 50 | ", top=" + top + 51 | '}'; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/mappingalgo/grid/lib/Vector.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.mappingalgo.grid.lib; 2 | 3 | /** 4 | *

Title : Vector

5 | *

Description : 节点数据

6 | * 7 | * @author huifer 8 | * @date 2018/11/14 9 | */ 10 | public class Vector { 11 | 12 | public double x; 13 | public double y; 14 | 15 | @Override 16 | public String toString() { 17 | return "Vector{" + 18 | "x=" + x + 19 | ", y=" + y + 20 | '}'; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/mappingalgo/sortpath/Edge.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.mappingalgo.sortpath; 2 | 3 | /** 4 | *

Title : Edge

5 | *

Description : 起点 , 终点 , 长度

6 | * 7 | * @author huifer 8 | * @date 2018/11/08 9 | */ 10 | public class Edge { 11 | 12 | /** 13 | * 起点 14 | */ 15 | public String start; 16 | /*** 17 | * 终点 18 | */ 19 | public String end; 20 | /*** 21 | * 距离 22 | */ 23 | public double length; 24 | 25 | 26 | public Edge(String line) { 27 | String[] split = line.split(","); 28 | start = split[0]; 29 | end = split[1]; 30 | length = Double.parseDouble(split[2]); 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return "Edge{" + 36 | "start='" + start + '\'' + 37 | ", end='" + end + '\'' + 38 | ", length=" + length + 39 | '}'; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/mappingalgo/sortpath/Graph.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.mappingalgo.sortpath; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | *

Title : Digraph

8 | *

Description : 图

9 | * 10 | * @author huifer 11 | * @date 2018/11/08 12 | */ 13 | public class Graph { 14 | 15 | public List edges; 16 | public List vertices; 17 | 18 | 19 | public Graph(List edges) { 20 | this.edges = edges; 21 | parse(edges); 22 | } 23 | 24 | 25 | @Override 26 | public String toString() { 27 | return "Digraph{" + 28 | "edges=" + edges + 29 | ", vertices=" + vertices + 30 | '}'; 31 | } 32 | 33 | private void parse(List edgeList) { 34 | List aaa = new ArrayList<>(); 35 | for (Edge d : edgeList) { 36 | Vertex v = new Vertex(d.start); 37 | if (!aaa.contains(v)) { 38 | aaa.add(v); 39 | } 40 | v = new Vertex(d.end); 41 | if (!aaa.contains(v)) { 42 | aaa.add(v); 43 | } 44 | } 45 | vertices = aaa; 46 | } 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/mappingalgo/sortpath/SortPathRunt.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.mappingalgo.sortpath; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | 5 | import java.io.BufferedReader; 6 | import java.io.File; 7 | import java.io.FileInputStream; 8 | import java.io.InputStreamReader; 9 | import java.nio.charset.StandardCharsets; 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | /** 14 | *

Title : InverseDistanceCore

15 | *

Description : sortpath 运行测试

16 | * 17 | * @author huifer 18 | * @date 2018/11/08 19 | */ 20 | @Slf4j 21 | public class SortPathRunt { 22 | 23 | public static void main(String[] args) throws Exception { 24 | 25 | /////////////// 读文件 26 | 27 | List edges = new ArrayList<>(); 28 | String pathname = "E:\\mck\\planar_algorithm\\src\\main\\java\\com\\huifer\\planar\\aset\\mappingalgo\\sortpath\\路径数据.txt"; 29 | BufferedReader br; 30 | FileInputStream in = new FileInputStream(new File(pathname)); 31 | br = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8)); 32 | 33 | String line; 34 | while ((line = br.readLine()) != null) { 35 | edges.add(new Edge(line)); 36 | } 37 | Graph graph = new Graph(edges); 38 | /////////////// 39 | List res = graph.vertices; 40 | 41 | int n = res.size(); 42 | 43 | res.get(0).weight = 0; 44 | 45 | for (int i = 0; i < n; i++) { 46 | for (int j = i + 1; j < n; j++) { 47 | List rlux = new ArrayList<>(); 48 | for (Edge e : graph.edges) { 49 | if (e.start.equals(res.get(i).name) && e.end.equals(res.get(j).name)) { 50 | double w = res.get(i).weight + e.length; 51 | // System.out.println(String.format("当前点 %s - 连接点 %s", res.delete(i).name, 52 | // res.delete(j).name)); 53 | rlux.add(res.get(i)); 54 | rlux.add(res.get(j)); 55 | 56 | if (w < res.get(j).weight) { 57 | res.get(j).weight = w; 58 | // System.out.println(String.format("当前点 %s - 连接点 %s", res.delete(i).name, 59 | // res.delete(j).name)); 60 | rlux.remove(rlux.size() - 1); 61 | rlux.add(res.get(j)); 62 | } 63 | } 64 | } 65 | } 66 | } 67 | 68 | res.forEach( 69 | s -> { 70 | // System.out.println(s); 71 | log.info("{}", s); 72 | } 73 | ); 74 | } 75 | 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/mappingalgo/sortpath/Vertex.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.mappingalgo.sortpath; 2 | 3 | import java.util.Objects; 4 | 5 | /** 6 | *

Title : Vertex

7 | *

Description : 顶点

8 | * 9 | * @author huifer 10 | * @date 2018/11/08 11 | */ 12 | public class Vertex { 13 | 14 | public String name; 15 | public double weight = 100000; 16 | 17 | 18 | public Vertex(String newName) { 19 | this.name = newName; 20 | } 21 | 22 | @Override 23 | public boolean equals(Object o) { 24 | if (this == o) { 25 | return true; 26 | } 27 | if (o == null || getClass() != o.getClass()) { 28 | return false; 29 | } 30 | Vertex vertex = (Vertex) o; 31 | return Double.compare(vertex.weight, weight) == 0 && 32 | Objects.equals(name, vertex.name); 33 | } 34 | 35 | @Override 36 | public int hashCode() { 37 | return Objects.hash(name, weight); 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return "Vertex{" + 43 | "name='" + name + '\'' + 44 | ", weight=" + weight + 45 | '}'; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/mappingalgo/sortpath/路径数据.txt: -------------------------------------------------------------------------------- 1 | 武大,地大,6 2 | 武大,光谷,11 3 | 武大,图书城,24 4 | 地大,光谷,4 5 | 地大,华科,8 6 | 光谷,地大,5 7 | 光谷,图书城,9 8 | 光谷,华科,7 9 | 图书城,光谷,11 10 | 华科,光谷,9 -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/mappingalgo/trajectorycompression/Point.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.mappingalgo.trajectorycompression; 2 | 3 | /** 4 | *

Title : Point

5 | *

Description : point

6 | * 7 | * @author huifer 8 | * @date 2018/10/19 9 | */ 10 | public class Point { 11 | 12 | private double id; 13 | private double x; 14 | private double y; 15 | 16 | public Point(Double id, double x, double y) { 17 | this.id = id; 18 | this.x = x; 19 | this.y = y; 20 | } 21 | 22 | @Override 23 | public String toString() { 24 | return "Point{" + 25 | "id='" + id + '\'' + 26 | ", x=" + x + 27 | ", y=" + y + 28 | '}'; 29 | } 30 | 31 | public double getId() { 32 | return id; 33 | } 34 | 35 | public void setId(double id) { 36 | this.id = id; 37 | } 38 | 39 | public double getX() { 40 | return x; 41 | } 42 | 43 | public void setX(double x) { 44 | this.x = x; 45 | } 46 | 47 | public double getY() { 48 | return y; 49 | } 50 | 51 | public void setY(double y) { 52 | this.y = y; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/mappingalgo/trajectorycompression/ReadText.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.mappingalgo.trajectorycompression; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.File; 5 | import java.io.FileInputStream; 6 | import java.io.InputStreamReader; 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | /** 11 | *

Title : ReadText

12 | *

Description : 读文件

13 | * 14 | * @author huifer 15 | * @date 2018/10/19 16 | */ 17 | public class ReadText { 18 | 19 | public static void main(String[] argv) { 20 | String filePath = "E:\\mck\\planar_algorithm\\src\\main\\java\\com\\huifer\\planar\\aset\\mappingalgo\\trajectorycompression\\read.txt"; 21 | } 22 | 23 | public List readTxtFile(String filePath) { 24 | 25 | List pointList = new ArrayList<>(); 26 | try { 27 | String encoding = "GBK"; 28 | File file = new File(filePath); 29 | //判断文件是否存在 30 | if (file.isFile() && file.exists()) { 31 | //考虑到编码格式 32 | InputStreamReader read = new InputStreamReader(new FileInputStream(file), encoding); 33 | BufferedReader bufferedReader = new BufferedReader(read); 34 | String lineTxt = null; 35 | while ((lineTxt = bufferedReader.readLine()) != null) { 36 | String[] pointStr = lineTxt.split("\t"); 37 | Point p = new Point(Double.valueOf(pointStr[0]), Double.valueOf(pointStr[1]), 38 | Double.valueOf(pointStr[2])); 39 | pointList.add(p); 40 | } 41 | read.close(); 42 | } else { 43 | System.out.println("找不到指定的文件"); 44 | } 45 | } catch (Exception e) { 46 | System.out.println("读取文件内容出错"); 47 | e.printStackTrace(); 48 | } 49 | 50 | return pointList; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/mappingalgo/zongduanmian/Zongduanmian.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.mappingalgo.zongduanmian; 2 | 3 | import com.huifer.planar.aset.mappingalgo.zongduanmian.lib.AllData; 4 | import com.huifer.planar.aset.mappingalgo.zongduanmian.lib.CrossSection; 5 | import com.huifer.planar.aset.mappingalgo.zongduanmian.lib.HeightCal; 6 | import com.huifer.planar.aset.mappingalgo.zongduanmian.lib.PointInfo; 7 | import lombok.extern.slf4j.Slf4j; 8 | 9 | /** 10 | *

Title : Zongduanmian

11 | *

Description : Zongduanmian 运行测试

12 | * 13 | * @author huifer 14 | * @date 2018/11/13 15 | */ 16 | @Slf4j 17 | public class Zongduanmian { 18 | 19 | public static void main(String[] args) { 20 | ReadHelper readHelper = new ReadHelper( 21 | "E:\\mck\\planar_algorithm\\src\\main\\java\\com\\huifer\\planar\\aset\\mappingalgo\\Zongduanmian\\断面数据.txt"); 22 | AllData allData = readHelper.getAllData(); 23 | 24 | HeightCal heightCal = new HeightCal(allData.pointInfoList); 25 | 26 | allData.verticleSection.calcVerticleSection(heightCal, allData.h0); 27 | PointInfo p1 = allData.verticleSection.kPoint.get(0); 28 | PointInfo p2 = allData.verticleSection.kPoint.get(1); 29 | PointInfo p3 = allData.verticleSection.kPoint.get(2); 30 | 31 | CrossSection c1 = new CrossSection(p1, p2, allData.verticleSection.direction1); 32 | CrossSection c2 = new CrossSection(p2, p3, allData.verticleSection.direction2); 33 | 34 | c1.calcDataForCrossSection(heightCal, allData.h0); 35 | c2.calcDataForCrossSection(heightCal, allData.h0); 36 | 37 | c1.kPoint.name = "m"; 38 | c2.kPoint.name = "n"; 39 | allData.crossSections.add(c1); 40 | allData.crossSections.add(c2); 41 | // System.out.println(allData); 42 | log.info("纵断面 = {}", allData); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/mappingalgo/zongduanmian/lib/AllData.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.mappingalgo.zongduanmian.lib; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | *

Title : AllData

8 | *

Description : 数据集

9 | * 10 | * @author huifer 11 | * @date 2018/11/13 12 | */ 13 | public class AllData { 14 | 15 | /** 16 | * 离散点集合 17 | * {@link com.huifer.planar.aset.mappingalgo.zongduanmian.lib.PointInfo} 18 | */ 19 | public List pointInfoList; 20 | 21 | /*** 22 | * 参考高程 23 | */ 24 | public double h0; 25 | 26 | /*** 27 | * 横断面集合 28 | * {@link com.huifer.planar.aset.mappingalgo.zongduanmian.lib.CrossSection} 29 | */ 30 | public List crossSections; 31 | 32 | /** 33 | * 纵断面 34 | * {@link com.huifer.planar.aset.mappingalgo.zongduanmian.lib.VerticleSection} 35 | */ 36 | public VerticleSection verticleSection; 37 | 38 | 39 | public AllData() { 40 | pointInfoList = new ArrayList<>(); 41 | crossSections = new ArrayList<>(); 42 | verticleSection = new VerticleSection(); 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return "AllData{" + 48 | "pointInfoList=" + pointInfoList + 49 | ", h0=" + h0 + 50 | ", crossSections=" + crossSections + 51 | ", verticleSection=" + verticleSection + 52 | '}'; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/mappingalgo/zongduanmian/lib/Dwh.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.mappingalgo.zongduanmian.lib; 2 | 3 | /** 4 | *

Title : Dwh

5 | *

Description : 距离\ 宽度\ 高度

6 | * 7 | * @author huifer 8 | * @date 2018/11/13 9 | */ 10 | public class Dwh { 11 | 12 | /*** 13 | * 距离 14 | */ 15 | private double distance; 16 | /** 17 | * 宽度 18 | */ 19 | private double weight; 20 | /*** 21 | * 高度 22 | */ 23 | private double height; 24 | 25 | public Dwh(double distance, double weight, double height) { 26 | this.distance = distance; 27 | this.weight = weight; 28 | this.height = height; 29 | } 30 | 31 | public Dwh() { 32 | } 33 | 34 | @Override 35 | public String toString() { 36 | return "Dwh{" + 37 | "distance=" + distance + 38 | ", weight=" + weight + 39 | ", height=" + height + 40 | '}'; 41 | } 42 | 43 | public double getDistance() { 44 | return distance; 45 | } 46 | 47 | public void setDistance(double distance) { 48 | this.distance = distance; 49 | } 50 | 51 | public double getWeight() { 52 | return weight; 53 | } 54 | 55 | public void setWeight(double weight) { 56 | this.weight = weight; 57 | } 58 | 59 | public double getHeight() { 60 | return height; 61 | } 62 | 63 | public void setHeight(double height) { 64 | this.height = height; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/mappingalgo/zongduanmian/lib/HeightCal.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.mappingalgo.zongduanmian.lib; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | *

Title : HeightCal

8 | *

Description : 高度计算工具

9 | * 10 | * @author huifer 11 | * @date 2018/11/13 12 | */ 13 | public class HeightCal { 14 | 15 | /** 16 | * 点集 17 | */ 18 | List points; 19 | /*** 20 | * dwh列表 21 | */ 22 | List dwhs; 23 | /*** 24 | * 当前点 25 | */ 26 | PointInfo p; 27 | 28 | public HeightCal(List points) { 29 | this.points = points; 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return "HeightCal{" + 35 | "points=" + points + 36 | ", dwhs=" + dwhs + 37 | ", p=" + p + 38 | '}'; 39 | } 40 | 41 | public double getHeight(PointInfo p) { 42 | this.p = p; 43 | double height = 0; 44 | dwhs = new ArrayList<>(); 45 | calcDistance(); 46 | height = calcHeight(); 47 | return height; 48 | } 49 | 50 | /*** 51 | * P 点内插高程 52 | * @return 53 | */ 54 | private double calcHeight() { 55 | double sumWeight = 0; 56 | double sumHeight = 0; 57 | for (int i = 0; i < dwhs.size(); i++) { 58 | Dwh dwh = dwhs.get(i); 59 | sumHeight += dwh.getHeight() * dwh.getWeight(); 60 | sumWeight += dwh.getWeight(); 61 | } 62 | return sumHeight / sumWeight; 63 | } 64 | 65 | 66 | /*** 67 | * 算距离 68 | * 计算p 到每一个点的距离 69 | */ 70 | private void calcDistance() { 71 | double dx = 0; 72 | double dy = 0; 73 | double dist = 0; 74 | Dwh dwh; 75 | for (int i = 0; i < points.size(); i++) { 76 | dwh = new Dwh(); 77 | PointInfo tem = points.get(i); 78 | 79 | dx = tem.xx - p.xx; 80 | dy = tem.yy - p.yy; 81 | dist = Math.sqrt(dx * dx + dy * dy); 82 | dwh.setDistance(dist); 83 | dwh.setWeight(1.0 / dist); 84 | dwh.setHeight(tem.hh); 85 | // dwh = new Dwh(dist, 1 / dist, tem.h); 86 | dwhs.add(dwh); 87 | } 88 | } 89 | 90 | 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/mappingalgo/zongduanmian/lib/PointInfo.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.mappingalgo.zongduanmian.lib; 2 | 3 | import java.util.Objects; 4 | 5 | /** 6 | *

Title : PointInfo

7 | *

Description : 离散点

8 | * 9 | * @author huifer 10 | * @date 2018/11/13 11 | */ 12 | public class PointInfo { 13 | 14 | public String name; 15 | public double xx; 16 | 17 | public double yy; 18 | public double hh; 19 | public double k; 20 | public String tag; 21 | 22 | @Override 23 | public boolean equals(Object o) { 24 | if (this == o) { 25 | return true; 26 | } 27 | if (o == null || getClass() != o.getClass()) { 28 | return false; 29 | } 30 | PointInfo pointInfo = (PointInfo) o; 31 | return Double.compare(pointInfo.xx, xx) == 0 && 32 | Double.compare(pointInfo.yy, yy) == 0 && 33 | Double.compare(pointInfo.hh, hh) == 0 && 34 | Double.compare(pointInfo.k, k) == 0 && 35 | Objects.equals(name, pointInfo.name) && 36 | Objects.equals(tag, pointInfo.tag); 37 | } 38 | 39 | @Override 40 | public String toString() { 41 | return "PointInfo{" + 42 | "name='" + name + '\'' + 43 | ", x=" + xx + 44 | ", y=" + yy + 45 | ", h=" + hh + 46 | ", k=" + k + 47 | ", tag='" + tag + '\'' + 48 | '}'; 49 | } 50 | 51 | @Override 52 | public int hashCode() { 53 | return Objects.hash(name, xx, yy, hh, k, tag); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/mappingalgo/zongduanmian/断面数据.txt: -------------------------------------------------------------------------------- 1 | H0,10.000 2 | K0,K1,K2 3 | 4 | K0,4574.012 ,3358.300 ,12.922 5 | P01,4570.355 ,3382.210 ,10.558 6 | P02,4571.827 ,3372.090 ,10.619 7 | P03,4570.907 ,3362.574 ,10.771 8 | P04,4569.494 ,3355.660 ,14.233 9 | P05,4556.682 ,3361.789 ,16.660 10 | P06,4547.554 ,3364.421 ,17.352 11 | P07,4534.086 ,3370.041 ,17.158 12 | P08,4517.549 ,3376.080 ,17.345 13 | P09,4505.572 ,3383.182 ,15.637 14 | P10,4498.562 ,3390.196 ,13.033 15 | P11,4494.457 ,3390.748 ,10.963 16 | P12,4500.501 ,3391.959 ,13.085 17 | P13,4510.753 ,3382.485 ,14.083 18 | P14,4522.092 ,3378.296 ,14.356 19 | P15,4531.567 ,3373.371 ,15.047 20 | P16,4546.386 ,3367.159 ,15.794 21 | P17,4556.219 ,3362.776 ,16.082 22 | P18,4559.558 ,3362.461 ,15.678 23 | P19,4554.746 ,3366.571 ,17.609 24 | P20,4545.254 ,3372.596 ,19.024 25 | P21,4540.860 ,3376.395 ,19.223 26 | P22,4536.141 ,3378.766 ,19.502 27 | K1,4534.227 ,3380.195 ,19.925 28 | P23,4525.945 ,3383.019 ,18.152 29 | P24,4519.592 ,3385.587 ,18.060 30 | P25,4513.249 ,3391.514 ,18.302 31 | P26,4523.724 ,3389.414 ,18.811 32 | P27,4537.846 ,3387.734 ,18.239 33 | P28,4540.773 ,3379.044 ,18.344 34 | P29,4549.894 ,3382.932 ,16.482 35 | P30,4543.390 ,3387.292 ,16.594 36 | P31,4546.992 ,3381.416 ,16.637 37 | P32,4558.964 ,3370.594 ,16.666 38 | P33,4565.741 ,3367.802 ,13.835 39 | P34,4561.203 ,3375.941 ,13.732 40 | P35,4561.762 ,3385.330 ,13.068 41 | P36,4569.250 ,3376.133 ,12.032 42 | P37,4572.318 ,3372.975 ,10.908 43 | P38,4568.279 ,3386.945 ,11.014 44 | P39,4550.913 ,3394.728 ,10.462 45 | P40,4537.754 ,3400.079 ,10.427 46 | P41,4509.525 ,3411.290 ,10.478 47 | K2,4497.844 ,3403.422 ,10.836 48 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/utils/DijkstraUtil.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.utils; 2 | 3 | import com.huifer.planar.aset.entity.MyLine; 4 | import com.huifer.planar.aset.entity.MyPoint; 5 | 6 | import java.util.ArrayList; 7 | 8 | /** 9 | *

Title : DijkstraUtil

10 | *

Description : dijkstra 邻接矩阵构造器

11 | * 12 | * @author huifer 13 | * @date 2018/12/14 14 | */ 15 | public class DijkstraUtil { 16 | 17 | 18 | /** 19 | * 构造邻接矩阵 20 | * 21 | * @param points 点集合 22 | * @param polylines 线集合 23 | * @return 邻接矩阵 24 | */ 25 | public static ArrayList> getDistances( 26 | ArrayList points, ArrayList polylines) { 27 | int n = points.size(); 28 | ArrayList> distances = new ArrayList<>(n); 29 | for (int i = 0; i < n; i++) { 30 | distances.add(new ArrayList(n)); 31 | } 32 | for (int i = 0; i < n; i++) { 33 | for (int j = 0; j < n; j++) { 34 | distances.get(i).add(100000000.0); 35 | } 36 | } 37 | for (int i = 0; i < polylines.size(); i++) { 38 | MyLine polyline = polylines.get(i); 39 | MyPoint point1 = polyline.getPoint1(); 40 | MyPoint point2 = polyline.getPoint2(); 41 | int index1 = queryIndex(points, point1); 42 | int index2 = queryIndex(points, point2); 43 | distances.get(index1).set(index2, polyline.getDistance()); 44 | distances.get(index2).set(index1, polyline.getDistance()); 45 | } 46 | 47 | return distances; 48 | } 49 | 50 | 51 | /** 52 | * 查找索引 53 | * 54 | * @param points 点集合 55 | * @param targetPoint 查询点 56 | * @return 索引值 57 | */ 58 | public static int queryIndex(ArrayList points, MyPoint targetPoint) { 59 | int index = 0; 60 | for (int i = 0; i < points.size(); i++) { 61 | MyPoint point = points.get(i); 62 | if (point == targetPoint) { 63 | index = i; 64 | } 65 | } 66 | return index; 67 | } 68 | 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/utils/Miact.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.utils; 2 | 3 | import org.locationtech.jts.geom.LineString; 4 | import org.locationtech.jts.geom.Point; 5 | 6 | import java.util.ArrayList; 7 | 8 | /** 9 | *

Title : Miact

10 | *

Description :

11 | * 12 | * @author huifer 13 | * @date 2019-03-05 14 | */ 15 | public class Miact { 16 | 17 | /** 18 | * 构造邻接矩阵 19 | * 20 | * @param points 点集合 21 | * @param polylines 线集合 22 | * @return 邻接矩阵 23 | */ 24 | public static ArrayList> getDistances( 25 | ArrayList points, ArrayList polylines) { 26 | int n = points.size(); 27 | ArrayList> distances = new ArrayList<>(n); 28 | for (int i = 0; i < n; i++) { 29 | distances.add(new ArrayList(n)); 30 | } 31 | for (int i = 0; i < n; i++) { 32 | for (int j = 0; j < n; j++) { 33 | distances.get(i).add(100000000.0); 34 | } 35 | } 36 | for (int i = 0; i < polylines.size(); i++) { 37 | LineString polyline = polylines.get(i); 38 | Point point1 = polyline.getStartPoint(); 39 | Point point2 = polyline.getEndPoint(); 40 | int index1 = queryIndex(points, point1); 41 | int index2 = queryIndex(points, point2); 42 | distances.get(index1).set(index2, polyline.getLength()); 43 | distances.get(index2).set(index1, polyline.getLength()); 44 | } 45 | return distances; 46 | } 47 | 48 | 49 | /** 50 | * 查找索引 51 | * 52 | * @param points 点集合 53 | * @param targetPoint 查询点 54 | * @return 索引值 55 | */ 56 | public static int queryIndex(ArrayList points, Point targetPoint) { 57 | int index = 0; 58 | for (int i = 0; i < points.size(); i++) { 59 | Point point = points.get(i); 60 | if (point.equals(targetPoint)) { 61 | index = i; 62 | } 63 | } 64 | return index; 65 | } 66 | 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/utils/PolygonUtils.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.utils; 2 | 3 | import org.locationtech.jts.geom.Geometry; 4 | import org.locationtech.jts.geom.GeometryFactory; 5 | import org.locationtech.jts.geom.Polygon; 6 | import org.locationtech.jts.geom.util.LineStringExtracter; 7 | import org.locationtech.jts.operation.polygonize.Polygonizer; 8 | 9 | import java.util.ArrayList; 10 | import java.util.Collection; 11 | import java.util.List; 12 | 13 | /** 14 | *

Title : PolygonUtils

15 | *

Description : polygon 工具

16 | * 17 | * @author huifer 18 | * @date 2019-02-27 19 | */ 20 | public class PolygonUtils { 21 | 22 | public static Geometry polygonize(Geometry geometry) { 23 | List lines = LineStringExtracter.getLines(geometry); 24 | Polygonizer polygonizer = new Polygonizer(); 25 | polygonizer.add(lines); 26 | Collection polys = polygonizer.getPolygons(); 27 | Polygon[] polyArray = GeometryFactory.toPolygonArray(polys); 28 | return geometry.getFactory().createGeometryCollection(polyArray); 29 | } 30 | 31 | public static Geometry splitPolygon(Geometry poly, Geometry line) { 32 | Geometry nodedLinework = poly.getBoundary().union(line); 33 | Geometry polys = polygonize(nodedLinework); 34 | 35 | // Only keep polygons which are inside the input 36 | List output = new ArrayList(); 37 | for (int i = 0; i < polys.getNumGeometries(); i++) { 38 | Polygon candpoly = (Polygon) polys.getGeometryN(i); 39 | if (poly.contains(candpoly.getInteriorPoint())) { 40 | output.add(candpoly); 41 | } 42 | } 43 | return poly.getFactory().createGeometryCollection(GeometryFactory.toGeometryArray(output)); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/utils/Project.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.utils; 2 | 3 | import org.geotools.geometry.jts.JTS; 4 | import org.geotools.referencing.CRS; 5 | import org.locationtech.jts.geom.Coordinate; 6 | import org.locationtech.jts.geom.GeometryFactory; 7 | import org.locationtech.jts.geom.Point; 8 | import org.locationtech.jts.geom.util.AffineTransformation; 9 | import org.locationtech.jts.geom.util.AffineTransformationBuilder; 10 | import org.opengis.geometry.MismatchedDimensionException; 11 | import org.opengis.referencing.FactoryException; 12 | import org.opengis.referencing.crs.CoordinateReferenceSystem; 13 | import org.opengis.referencing.operation.MathTransform; 14 | import org.opengis.referencing.operation.TransformException; 15 | 16 | /** 17 | *

Title : Project

18 | *

Description : 投影

19 | * 20 | * @author huifer 21 | * @date 2019-02-27 22 | */ 23 | public class Project { 24 | 25 | /** 26 | * 仿射转换 27 | * 28 | * @param lon 经度 29 | * @param lat 纬度 30 | */ 31 | public static void affine(double lon, double lat) { 32 | Coordinate st1 = new Coordinate(); 33 | Coordinate st2 = new Coordinate(); 34 | Coordinate st3 = new Coordinate(); 35 | 36 | Coordinate end1 = new Coordinate(); 37 | Coordinate end2 = new Coordinate(); 38 | Coordinate end3 = new Coordinate(); 39 | AffineTransformationBuilder affineTransformationBuilder = new AffineTransformationBuilder( 40 | st1, st2, st3, end1, end2, end3); 41 | AffineTransformation afm = affineTransformationBuilder.getTransformation(); 42 | 43 | Point sourcePoint = new GeometryFactory().createPoint(new Coordinate(lat, lon)); 44 | sourcePoint.apply(afm); 45 | 46 | } 47 | 48 | /*** 49 | * 投影转换 50 | * @param lon 经度 51 | * @param lat 纬度 52 | * @param epsgSource EPSG:xxx 输入坐标系 53 | * @param epsgTarget EPSG:xxx 输出坐标系 54 | * @return 55 | * @throws FactoryException 56 | * @throws MismatchedDimensionException 57 | * @throws TransformException 58 | */ 59 | public static Point projectTransform(double lon, double lat, 60 | String epsgSource, String epsgTarget) throws FactoryException, 61 | MismatchedDimensionException, TransformException { 62 | 63 | Point sourcePoint = new GeometryFactory().createPoint(new Coordinate(lat, lon)); 64 | 65 | CoordinateReferenceSystem crsSource = CRS.decode(epsgSource); 66 | CoordinateReferenceSystem crsTarget = CRS.decode(epsgTarget); 67 | MathTransform transform = CRS.findMathTransform(crsSource, crsTarget); 68 | Point pointTarget = (Point) JTS.transform(sourcePoint, transform); 69 | 70 | return pointTarget; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/utils/geo/ColorUtil.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.utils.geo; 2 | 3 | import java.awt.*; 4 | 5 | /** 6 | *

Title : ColorUtil

7 | *

Description : 颜色转换器

8 | * 9 | * @author huifer 10 | * @date 2019-01-18 11 | */ 12 | public class ColorUtil { 13 | 14 | /** 15 | * color 转换 16进制颜色字符串 16 | * 17 | * @param color 颜色 18 | * @return 16进制颜色字符串 19 | */ 20 | public static String colorToHexColor(Color color) { 21 | String r, b, g; 22 | StringBuilder hexColor = new StringBuilder(); 23 | r = Integer.toHexString(color.getRed()); 24 | g = Integer.toHexString(color.getGreen()); 25 | b = Integer.toHexString(color.getBlue()); 26 | r = r.length() == 1 ? "0" + r : r; 27 | g = g.length() == 1 ? "0" + g : g; 28 | b = b.length() == 1 ? "0" + b : b; 29 | r = r.toUpperCase(); 30 | g = g.toUpperCase(); 31 | b = b.toUpperCase(); 32 | hexColor.append("0x"); 33 | hexColor.append(r); 34 | hexColor.append(g); 35 | hexColor.append(b); 36 | return hexColor.toString(); 37 | } 38 | 39 | /** 40 | * 16进制颜色字符串 转换 color 41 | * 42 | * @param hexColor 16进制颜色字符串 43 | * @return 颜色 44 | */ 45 | public static Color hexColorToColor(String hexColor) { 46 | if (hexColor.contains("0x") || hexColor.contains("0X")) { 47 | hexColor = hexColor.substring(2); 48 | } else if (hexColor.contains("#")) { 49 | hexColor = hexColor.substring(1); 50 | } 51 | Color color = new Color(Integer.parseInt(hexColor, 16)); 52 | return color; 53 | } 54 | 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/utils/geo/GeoMapContentUtil.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.utils.geo; 2 | 3 | import org.geotools.data.simple.SimpleFeatureCollection; 4 | import org.geotools.feature.DefaultFeatureCollection; 5 | import org.geotools.feature.simple.SimpleFeatureBuilder; 6 | import org.geotools.feature.simple.SimpleFeatureTypeBuilder; 7 | import org.geotools.geometry.jts.JTSFactoryFinder; 8 | import org.geotools.map.FeatureLayer; 9 | import org.geotools.map.Layer; 10 | import org.geotools.map.MapContent; 11 | import org.geotools.styling.Style; 12 | import org.locationtech.jts.geom.Coordinate; 13 | import org.locationtech.jts.geom.GeometryFactory; 14 | import org.locationtech.jts.geom.Point; 15 | import org.opengis.feature.simple.SimpleFeature; 16 | import org.opengis.feature.simple.SimpleFeatureType; 17 | 18 | /** 19 | *

Title : GeoMapContentUtil

20 | *

Description : 地图框

21 | * 22 | * @author huifer 23 | * @date 2019-01-23 24 | */ 25 | public class GeoMapContentUtil { 26 | 27 | 28 | /** 29 | * 追加layers 30 | * 31 | * @param content mapContent 32 | * @param features 要素 33 | * @param style 样式 34 | */ 35 | public static void addLayer(MapContent content, SimpleFeatureCollection features, Style style) { 36 | Layer layer = new FeatureLayer(features, style); 37 | content.addLayer(layer); 38 | } 39 | 40 | /** 41 | * 获取地图实例 42 | */ 43 | public static MapContent getMapContent(String title) { 44 | 45 | MapContent mapContent = new MapContent(); 46 | mapContent.setTitle(title); 47 | return mapContent; 48 | } 49 | 50 | public static Layer getFlickrLayer() { 51 | SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); 52 | builder.setName("MyFeatureType"); 53 | // set crs 54 | builder.setCRS(null); 55 | // add geometry 56 | builder.add("location", Point.class); 57 | 58 | // build the type 59 | SimpleFeatureType type = builder.buildFeatureType(); 60 | 61 | // create features using the type defined 62 | SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(type); 63 | GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(); 64 | org.locationtech.jts.geom.Point point = geometryFactory.createPoint(new Coordinate(5, 5)); 65 | featureBuilder.add(point); 66 | SimpleFeature feature = featureBuilder.buildFeature("FeaturePoint"); 67 | DefaultFeatureCollection featureCollection = new DefaultFeatureCollection("internal", type); 68 | featureCollection.add(feature); // Add feature 1, 2, 3, etc 69 | 70 | Style style = GeoStyleUtil.pointStyle(null, "0xffffff", "30000", "0xffffff", "1", 5000); 71 | Layer layer = new FeatureLayer(featureCollection, style); 72 | // layer.setTitle("NewPointLayer"); 73 | return layer; 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/utils/kriging/Kpoint.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.utils.kriging; 2 | 3 | /** 4 | *

Title : Kpoint

5 | *

Description : xyz

6 | * 7 | * @author huifer 8 | * @date 2019-04-19 9 | */ 10 | public class Kpoint { 11 | 12 | 13 | private double x; 14 | private double y; 15 | private double z; 16 | 17 | public Kpoint() { 18 | } 19 | 20 | public Kpoint(double x, double y, double z) { 21 | this.x = x; 22 | this.y = y; 23 | this.z = z; 24 | } 25 | 26 | public Kpoint(double x, double y) { 27 | this.x = x; 28 | this.y = y; 29 | } 30 | 31 | public double getX() { 32 | return x; 33 | } 34 | 35 | public void setX(double x) { 36 | this.x = x; 37 | } 38 | 39 | public double getY() { 40 | return y; 41 | } 42 | 43 | public void setY(double y) { 44 | this.y = y; 45 | } 46 | 47 | public double getZ() { 48 | return z; 49 | } 50 | 51 | public void setZ(double z) { 52 | this.z = z; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/utils/kriging/ReadFile.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.utils.kriging; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.File; 5 | import java.io.FileReader; 6 | import java.io.IOException; 7 | import java.util.ArrayList; 8 | 9 | /** 10 | *

Title : ReadFile

11 | *

Description : 读文件

12 | * 13 | * @author huifer 14 | * @date 2019-04-19 15 | */ 16 | public class ReadFile { 17 | 18 | private static final String TEST_PATH = "E:\\mck\\bg\\data_status\\src\\main\\java\\com\\huifer\\data\\idw\\text.txt"; 19 | 20 | public static void main(String[] args) { 21 | ArrayList> arrayLists = readFile(); 22 | System.out.println(); 23 | } 24 | 25 | public static ArrayList> readFile() { 26 | File f = new File(TEST_PATH); 27 | BufferedReader reader = null; 28 | 29 | ArrayList> rs = null; 30 | 31 | try { 32 | 33 | reader = new BufferedReader(new FileReader(f)); 34 | 35 | String tem = null; 36 | int count = 0; 37 | rs = new ArrayList<>(); 38 | ArrayList points = null; 39 | while ((tem = reader.readLine()) != null) { 40 | String[] split = tem.split(","); 41 | points = new ArrayList(); 42 | count++; 43 | points.add(new Kpoint(Double.valueOf(split[1]), Double.valueOf(split[2]), 44 | Double.valueOf(split[3]))); 45 | rs.add(points); 46 | } 47 | reader.close(); 48 | } catch (Exception e) { 49 | e.printStackTrace(); 50 | } finally { 51 | if (reader != null) { 52 | try { 53 | reader.close(); 54 | } catch (IOException e) { 55 | e.printStackTrace(); 56 | } 57 | } 58 | } 59 | 60 | return rs; 61 | 62 | 63 | } 64 | 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/utils/polygonselect/ToceLineString.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.utils.polygonselect; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.EqualsAndHashCode; 6 | import lombok.NoArgsConstructor; 7 | import org.locationtech.jts.geom.LineString; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | *

Title : TocePoint

13 | *

Description : 面上的线段

14 | * 15 | * @author huifer 16 | * @date 2019-04-26 17 | */ 18 | @Data 19 | @NoArgsConstructor 20 | @AllArgsConstructor 21 | @EqualsAndHashCode 22 | public class ToceLineString { 23 | 24 | private String polygonID; 25 | private List lineStringList; 26 | 27 | public ToceLineString(String polygonID) { 28 | this.polygonID = polygonID; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/utils/polygonselect/TocePoint.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.utils.polygonselect; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.EqualsAndHashCode; 6 | import lombok.NoArgsConstructor; 7 | import org.locationtech.jts.geom.Point; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | *

Title : TocePoint

13 | *

Description : 面上的点

14 | * 15 | * @author huifer 16 | * @date 2019-04-26 17 | */ 18 | @Data 19 | @NoArgsConstructor 20 | @AllArgsConstructor 21 | @EqualsAndHashCode 22 | public class TocePoint { 23 | 24 | private String polygonID; 25 | private List pointList; 26 | 27 | public TocePoint(String polygonID) { 28 | this.polygonID = polygonID; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/utils/polygonselect/TocePolygon.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.utils.polygonselect; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.EqualsAndHashCode; 6 | import lombok.NoArgsConstructor; 7 | import org.locationtech.jts.geom.Geometry; 8 | 9 | /** 10 | *

Title : TocePolygon

11 | *

Description : 单个面属性

12 | * 13 | * @author huifer 14 | * @date 2019-04-26 15 | */ 16 | @Data 17 | @NoArgsConstructor 18 | @AllArgsConstructor 19 | @EqualsAndHashCode 20 | public class TocePolygon { 21 | private String id; 22 | private Geometry geom; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/utils/shptools/Shp2Wkt.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.utils.shptools; 2 | 3 | import org.geotools.data.FileDataStore; 4 | import org.geotools.data.FileDataStoreFinder; 5 | import org.geotools.data.shapefile.ShapefileDataStore; 6 | import org.geotools.data.simple.SimpleFeatureCollection; 7 | import org.geotools.data.simple.SimpleFeatureIterator; 8 | import org.geotools.data.simple.SimpleFeatureSource; 9 | import org.opengis.feature.simple.SimpleFeature; 10 | import org.opengis.filter.Filter; 11 | 12 | import java.io.File; 13 | import java.io.IOException; 14 | import java.nio.charset.Charset; 15 | 16 | /** 17 | * shp 2 wkt 18 | * 19 | * @author huifer 20 | * @date 2019年1月17日 21 | */ 22 | public class Shp2Wkt { 23 | 24 | public static void main(String[] args) { 25 | String path1 = "D:\\testdata\\2019年1月16日\\11111.shp"; 26 | SimpleFeatureCollection colls1 = readShp(path1); 27 | SimpleFeatureIterator iters = colls1.features(); 28 | while (iters.hasNext()) { 29 | SimpleFeature sf = iters.next(); 30 | System.out.println("wkt: " + sf.getAttributes()); 31 | } 32 | } 33 | 34 | public static SimpleFeatureCollection readShp(String path) { 35 | return readShp(path, null); 36 | 37 | } 38 | 39 | public static SimpleFeatureCollection readShp(String path, Filter filter) { 40 | SimpleFeatureSource featureSource = readStoreByShp(path); 41 | if (featureSource == null) { 42 | return null; 43 | } 44 | try { 45 | return filter != null ? featureSource.getFeatures(filter) : featureSource.getFeatures(); 46 | } catch (IOException e) { 47 | e.printStackTrace(); 48 | } 49 | return null; 50 | } 51 | 52 | public static SimpleFeatureSource readStoreByShp(String path) { 53 | File file = new File(path); 54 | FileDataStore store; 55 | SimpleFeatureSource featureSource = null; 56 | try { 57 | store = FileDataStoreFinder.getDataStore(file); 58 | ((ShapefileDataStore) store).setCharset(Charset.forName("UTF-8")); 59 | featureSource = store.getFeatureSource(); 60 | } catch (IOException e) { 61 | e.printStackTrace(); 62 | } 63 | return featureSource; 64 | } 65 | } 66 | 67 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/utils/shptools/polygontools/ForTest.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.utils.shptools.polygontools; 2 | 3 | 4 | import com.huifer.planar.aset.utils.shptools.polygontools.entity.LatLngEntity; 5 | import com.huifer.planar.aset.utils.shptools.polygontools.geometry.ConvexHull; 6 | import com.huifer.planar.aset.utils.shptools.polygontools.geometry.Polygon; 7 | 8 | import java.util.ArrayList; 9 | 10 | 11 | /** 12 | * ForTest 测试类 13 | * 14 | * @author huifer 15 | */ 16 | public class ForTest { 17 | 18 | /** 19 | * @param args 20 | */ 21 | public static void main(String[] args) { 22 | ConvexHull convexHull = new ConvexHull(); 23 | 24 | ArrayList list = new ArrayList(); 25 | list.add(new LatLngEntity(0.0, 1.0)); 26 | list.add(new LatLngEntity(0.0, 0.0)); 27 | list.add(new LatLngEntity(1.0, 1.0)); 28 | list.add(new LatLngEntity(2.0, 0.0)); 29 | list.add(new LatLngEntity(1.0, 2.0)); 30 | list.add(new LatLngEntity(1.0, 2.0)); 31 | try { 32 | //凸包多边形 33 | ArrayList convexHullPts = convexHull.getConvexHull(list); 34 | // for (LatLngEntity geo : convexHullPts) { 35 | // System.out.println(geo.getLng() + " , " + geo.getLat()); 36 | // } 37 | 38 | Polygon poly = new Polygon(convexHullPts); 39 | } catch (Exception ex) { 40 | ex.printStackTrace(); 41 | } 42 | 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/utils/shptools/polygontools/entity/LatLngEntity.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.utils.shptools.polygontools.entity; 2 | 3 | 4 | /** 5 | * 经纬度 6 | * 7 | * @author huifer 8 | */ 9 | public class LatLngEntity { 10 | 11 | private double lat; 12 | private double lng; 13 | 14 | public LatLngEntity(double lat, double lng) { 15 | this.lat = lat; 16 | this.lng = lng; 17 | } 18 | 19 | public LatLngEntity() { 20 | } 21 | 22 | public double getLat() { 23 | return lat; 24 | } 25 | 26 | public void setLat(double lat) { 27 | this.lat = lat; 28 | } 29 | 30 | public double getLng() { 31 | return lng; 32 | } 33 | 34 | public void setLng(double lng) { 35 | this.lng = lng; 36 | } 37 | 38 | @Override 39 | public boolean equals(Object obj) { 40 | if (this == obj) { 41 | return true; 42 | } 43 | if (!(obj instanceof LatLngEntity)) { 44 | return false; 45 | } 46 | LatLngEntity latlngInfo = (LatLngEntity) obj; 47 | return this.lat == latlngInfo.lat && 48 | this.lng == latlngInfo.lng; 49 | } 50 | 51 | @Override 52 | public int hashCode() { 53 | return (int) (this.lat * this.lng); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/utils/shptools/polygontools/geometry/Bounds.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.utils.shptools.polygontools.geometry; 2 | 3 | 4 | import com.huifer.planar.aset.utils.shptools.polygontools.entity.LatLngEntity; 5 | 6 | /** 7 | * Bounds 构建由最大和最小经纬度组成的矩形区域 8 | * 9 | * @author huifer 10 | */ 11 | public class Bounds { 12 | 13 | private LatLngEntity minlatlngEntity; 14 | private LatLngEntity maxlatlngEntity; 15 | 16 | public Bounds(LatLngEntity minlatlng, LatLngEntity maxlatlng) { 17 | minlatlngEntity = minlatlng; 18 | maxlatlngEntity = maxlatlng; 19 | } 20 | 21 | /** 22 | * 判断经纬度是否在该矩形区域 23 | */ 24 | public boolean contains(LatLngEntity latlng) { 25 | boolean status = true; 26 | if (latlng.getLat() > maxlatlngEntity.getLat() || 27 | latlng.getLng() > maxlatlngEntity.getLng() || 28 | latlng.getLat() < minlatlngEntity.getLat() || 29 | latlng.getLng() < minlatlngEntity.getLng()) { 30 | status = false; 31 | } 32 | return status; 33 | } 34 | 35 | @Override 36 | public String toString() { 37 | return "最小经纬度 : " + minlatlngEntity.getLat() + " , " + minlatlngEntity.getLng() + 38 | "最大经纬度 : " + maxlatlngEntity.getLat() + " , " + maxlatlngEntity.getLng() 39 | ; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/utils/shptools/polygontools/geometry/ComparatorLatLng.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.utils.shptools.polygontools.geometry; 2 | 3 | 4 | import com.huifer.planar.aset.utils.shptools.polygontools.entity.LatLngEntity; 5 | 6 | import java.util.Comparator; 7 | 8 | 9 | /** 10 | * LatLngEntity对象比较类,实现Comparator接口 11 | * 12 | * @author huifer 13 | */ 14 | 15 | public class ComparatorLatLng implements Comparator { 16 | 17 | @Override 18 | public int compare(Object arg0, Object arg1) { 19 | 20 | LatLngEntity latlng0 = (LatLngEntity) arg0; 21 | LatLngEntity latlng1 = (LatLngEntity) arg1; 22 | 23 | // 首先比较lat,如果lat相同,再比较lng 24 | int flag = Double.toString(latlng0.getLat()).compareTo(Double.toString(latlng1.getLat())); 25 | 26 | if (flag == 0) { 27 | return Double.toString(latlng0.getLng()).compareTo(Double.toString(latlng1.getLng())); 28 | } else { 29 | return flag; 30 | } 31 | 32 | } 33 | 34 | } 35 | 36 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/utils/shptools/triangulation/1c.txt: -------------------------------------------------------------------------------- 1 | 88001.89584 73750.60155 2 | 88000.24139 73739.96575 3 | 87997.64152 73741.85656 4 | 87991.02369 73737.83859 5 | 87983.6968 73736.42048 6 | 87978.49708 73738.54764 7 | 87976.60627 73742.80196 8 | 87977.55167 73745.63818 9 | 87992.4418 73752.49236 10 | 88006.38652 73753.67412 11 | 87998.82328 73759.81925 12 | 88002.36855 73760.29195 13 | 88006.38652 73756.27398 14 | 88012.2953 73756.27398 15 | 88009.22273 73760.5283 16 | 88004.25936 73763.83722 17 | 88001.65949 73766.43708 18 | 88000.24139 73772.58221 19 | 88007.09557 73774.70937 20 | 88012.05894 73764.30992 21 | 88016.31327 73758.87384 22 | 88020.09488 73756.27398 23 | 88021.74934 73753.91047 24 | 88027.89447 73753.67412 25 | 88029.07623 73757.45573 26 | 88025.53096 73761.001 27 | 88018.91313 73762.41911 28 | 88012.2953 73767.61883 29 | 88009.69543 73775.18207 30 | 88021.04029 73778.96369 31 | 88026.00366 73765.96438 32 | 88034.27596 73777.54558 33 | 88036.40312 73766.20073 34 | 88043.02095 73774.94572 35 | 88053.4204 73770.2187 36 | 88043.73 73757.21938 37 | 88046.09351 73738.07494 38 | 88027.89447 73739.96575 39 | 88017.96772 73731.4571 40 | 88001.65949 73736.42048 41 | 88001.89584 73750.60155 42 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/utils/shptools/triangulation/Edge2D.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.utils.shptools.triangulation; 2 | 3 | /** 4 | * 2D edge class implementation. 5 | * 6 | * @author Johannes Diemke 7 | */ 8 | public class Edge2D { 9 | 10 | public Vector2D a; 11 | public Vector2D b; 12 | 13 | /** 14 | * Constructor of the 2D edge class used to create a new edge instance from 15 | * two 2D vectors describing the edge's vertices. 16 | * 17 | * @param a The first vertex of the edge 18 | * @param b The second vertex of the edge 19 | */ 20 | public Edge2D(Vector2D a, Vector2D b) { 21 | this.a = a; 22 | this.b = b; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/utils/shptools/triangulation/EdgeDistancePack.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.utils.shptools.triangulation; 2 | 3 | /** 4 | * Edge distance pack class implementation used to describe the distance to a 5 | * given edge. 6 | * 7 | * @author Johannes Diemke 8 | */ 9 | public class EdgeDistancePack implements Comparable { 10 | 11 | public Edge2D edge; 12 | public double distance; 13 | 14 | /** 15 | * Constructor of the edge distance pack class used to create a new edge 16 | * distance pack instance from a 2D edge and a scalar value describing a 17 | * distance. 18 | * 19 | * @param edge The edge 20 | * @param distance The distance of the edge to some point 21 | */ 22 | public EdgeDistancePack(Edge2D edge, double distance) { 23 | this.edge = edge; 24 | this.distance = distance; 25 | } 26 | 27 | @Override 28 | public int compareTo(EdgeDistancePack o) { 29 | return Double.compare(this.distance, o.distance); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/utils/shptools/triangulation/FileRd.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.utils.shptools.triangulation; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.File; 5 | import java.io.FileInputStream; 6 | import java.io.InputStreamReader; 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | /** 11 | *

Title : FileRd

12 | *

Description :

13 | * 14 | * @author huifer 15 | * @date 2019-02-22 16 | */ 17 | public class FileRd { 18 | 19 | public static void main(String[] args) throws Exception { 20 | String path = "E:\\mck\\planar_algorithm\\src\\main\\java\\com\\huifer\\planar\\aset\\utils\\shptools\\triangulation\\1c.txt"; 21 | readTxtFile(path); 22 | } 23 | 24 | public static List readTxtFile(String filePath) { 25 | List pointSet = new ArrayList<>(); 26 | try { 27 | //考虑到编码格式 28 | InputStreamReader read = new InputStreamReader(new FileInputStream(new File(filePath)), "UTF-8"); 29 | BufferedReader bufferedReader = new BufferedReader(read); 30 | String lineTxt = null; 31 | while ((lineTxt = bufferedReader.readLine()) != null) { 32 | String[] pointStr = lineTxt.split("\t"); 33 | // System.out.println(pointStr[0]+"\t"+pointStr[1]); 34 | Vector2D v = new Vector2D(Double.valueOf(pointStr[0]), Double.valueOf(pointStr[1])); 35 | pointSet.add(v); 36 | } 37 | read.close(); 38 | } catch (Exception e) { 39 | e.printStackTrace(); 40 | } 41 | return pointSet; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/utils/shptools/triangulation/NotEnoughPointsException.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.utils.shptools.triangulation; 2 | 3 | /** 4 | * Exception thrown by the Delaunay triangulator when it is initialized with 5 | * less than three points. 6 | * 7 | * @author Johannes Diemke 8 | */ 9 | public class NotEnoughPointsException extends Exception { 10 | 11 | private static final long serialVersionUID = 7061712854155625067L; 12 | 13 | public NotEnoughPointsException() { 14 | } 15 | 16 | public NotEnoughPointsException(String s) { 17 | super(s); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/utils/shptools/triangulation/Triangle2DEnum.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.utils.shptools.triangulation; 2 | 3 | 4 | /*** 5 | * @author huifer 6 | */ 7 | public enum Triangle2DEnum { 8 | /** 9 | * 一条虚拟边 10 | */ 11 | T("ConvexTest"), 12 | /** 13 | * 2条虚拟边 14 | */ 15 | M("m"), 16 | /** 17 | * 3条虚拟边 18 | */ 19 | E("E"), 20 | ; 21 | private String type; 22 | 23 | Triangle2DEnum(String type) { 24 | this.type = type; 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return "Triangle2DEnum{" + 30 | "type='" + type + '\'' + 31 | '}'; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/utils/shptools/triangulation/Vector2D.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.utils.shptools.triangulation; 2 | 3 | /** 4 | * 2D vector class implementation. 5 | * 6 | * @author Johannes Diemke 7 | */ 8 | public class Vector2D { 9 | 10 | public double x; 11 | public double y; 12 | 13 | /** 14 | * Constructor of the 2D vector class used to create new vector instances. 15 | * 16 | * @param x The x coordinate of the new vector 17 | * @param y The y coordinate of the new vector 18 | */ 19 | public Vector2D(double x, double y) { 20 | this.x = x; 21 | this.y = y; 22 | } 23 | 24 | /** 25 | * Subtracts the given vector from this. 26 | * 27 | * @param vector The vector to be subtracted from this 28 | * @return A new instance holding the result of the vector subtraction 29 | */ 30 | public Vector2D sub(Vector2D vector) { 31 | return new Vector2D(this.x - vector.x, this.y - vector.y); 32 | } 33 | 34 | /** 35 | * Adds the given vector to this. 36 | * 37 | * @param vector The vector to be added to this 38 | * @return A new instance holding the result of the vector addition 39 | */ 40 | public Vector2D add(Vector2D vector) { 41 | return new Vector2D(this.x + vector.x, this.y + vector.y); 42 | } 43 | 44 | /** 45 | * Multiplies this by the given scalar. 46 | * 47 | * @param scalar The scalar to be multiplied by this 48 | * @return A new instance holding the result of the multiplication 49 | */ 50 | public Vector2D mult(double scalar) { 51 | return new Vector2D(this.x * scalar, this.y * scalar); 52 | } 53 | 54 | /** 55 | * Computes the magnitude or length of this. 56 | * 57 | * @return The magnitude of this 58 | */ 59 | public double mag() { 60 | return Math.sqrt(this.x * this.x + this.y * this.y); 61 | } 62 | 63 | /** 64 | * Computes the dot product of this and the given vector. 65 | * 66 | * @param vector The vector to be multiplied by this 67 | * @return A new instance holding the result of the multiplication 68 | */ 69 | public double dot(Vector2D vector) { 70 | return this.x * vector.x + this.y * vector.y; 71 | } 72 | 73 | /** 74 | * Computes the 2D pseudo cross product Dot(Perp(this), vector) of this and 75 | * the given vector. 76 | * 77 | * @param vector The vector to be multiplied to the perpendicular vector of 78 | * this 79 | * @return A new instance holding the result of the pseudo cross product 80 | */ 81 | public double cross(Vector2D vector) { 82 | return this.y * vector.x - this.x * vector.y; 83 | } 84 | 85 | @Override 86 | public String toString() { 87 | // return "Vector2D[" + x + ", " + y + "]"; 88 | return "POINT(" + x + " " + y + ")"; 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/utils/simplecycles/SimpleResult.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.utils.simplecycles; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.HashSet; 6 | import java.util.List; 7 | import java.util.Set; 8 | import java.util.Vector; 9 | 10 | /** 11 | *

Title : SimpleResult

12 | *

Description : 闭环搜索结果存放

13 | *

https://en.wikipedia.org/wiki/Johnson%27s_algorithm

14 | * 15 | * @author huifer 16 | * @date 2019-03-07 17 | */ 18 | @Data 19 | public class SimpleResult { 20 | 21 | /** 22 | * 当前节点的闭环 23 | */ 24 | private Set nodeOfScc = null; 25 | /** 26 | * 当前点的邻接矩阵 27 | */ 28 | private List adjList = null; 29 | /** 30 | * 当前节点索引 31 | */ 32 | private int lowesNodeIndex = -1; 33 | 34 | public SimpleResult(List adjList, int lowesNodeIndex) { 35 | this.adjList = adjList; 36 | this.lowesNodeIndex = lowesNodeIndex; 37 | this.nodeOfScc = new HashSet(); 38 | 39 | if (this.adjList != null) { 40 | for (int i = 0; i < this.adjList.size(); i++) { 41 | if (this.adjList.get(i).size() > 0) { 42 | this.nodeOfScc.add(new Integer(i)); 43 | } 44 | } 45 | } 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/utils/threepoint/SortThreePoint.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.utils.threepoint; 2 | 3 | import java.util.Stack; 4 | 5 | /** 6 | *

Title : SortThreePoint

7 | *

Description : 三点排序问题

8 | * 9 | * @author huifer 10 | * @date 2019-03-13 11 | */ 12 | public class SortThreePoint { 13 | 14 | /** 15 | * 记录总量三点一个圆 16 | */ 17 | private static int count = 0; 18 | /** 19 | * 三点一个元的结果集合 20 | */ 21 | private static Stack allStack = new Stack(); 22 | /** 23 | * 是否使用 24 | */ 25 | private static boolean[] isUsing = new boolean[10000]; 26 | 27 | public static void main(String[] args) { 28 | sortThreePoint(1, 4, 0, 3); 29 | } 30 | 31 | /** 32 | * @param minv 当前最小值 33 | * @param maxv 当前最大值 34 | * @param curnum 确认过的内容 35 | * @param maxnum 选取几个点作为一组 36 | */ 37 | public static void sortThreePoint(int minv, int maxv, int curnum, int maxnum) { 38 | if (curnum == maxnum) { 39 | count++; 40 | System.out.println(allStack); 41 | return; 42 | } 43 | for (int i = minv; i <= maxv; i++) { 44 | if (!isUsing[i]) { 45 | allStack.push(i); 46 | isUsing[i] = true; 47 | sortThreePoint(minv, maxv, curnum + 1, maxnum); 48 | allStack.pop(); 49 | isUsing[i] = false; 50 | } 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/view/MyContext.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.view; 2 | 3 | import com.huifer.planar.aset.view.base.BaseFrame; 4 | import com.huifer.planar.aset.view.base.FrameContext; 5 | import com.huifer.planar.aset.view.base.ViewHelper; 6 | 7 | import java.awt.*; 8 | import java.util.Random; 9 | 10 | /** 11 | *

Title : MyContext

12 | *

Description : 测试显示

13 | * 14 | * @author huifer 15 | * @date 2019-01-15 16 | */ 17 | public class MyContext extends FrameContext { 18 | 19 | public static void main(String[] args) { 20 | MyContext myContext = new MyContext(); 21 | BaseFrame frame = new BaseFrame(myContext); 22 | frame.run(); 23 | } 24 | 25 | 26 | @Override 27 | public void drawing(Graphics g) { 28 | 29 | Graphics2D g2d = (Graphics2D) g; 30 | ViewHelper.isRenderingHints(g2d, true); 31 | ViewHelper.setColor(g2d, ViewHelper.BLUE); 32 | ViewHelper.drawText(g2d, "aaaaaaaaaaaaaaa", 0, 50); 33 | ViewHelper.setColor(g2d, ViewHelper.TEAL); 34 | ViewHelper.strokeCircle(g2d, 10, 10, 10); 35 | 36 | ViewHelper.setColor(g2d, ViewHelper.RED); 37 | for (int i = 0; i < 2000; i++) { 38 | Random rand = new Random(); 39 | double rx = rand.nextInt(1024) + 0; 40 | double ry = rand.nextInt(768) + 0; 41 | ViewHelper.drawPoint(g2d, rx, ry); 42 | } 43 | 44 | ViewHelper.setColor(g2d, ViewHelper.AMBER); 45 | ViewHelper.drawLine(g2d, 110.2, 200, 300.3, 400.3); 46 | ViewHelper.setColor(g2d, ViewHelper.DEEPPURPLE); 47 | ViewHelper.fillCircle(g2d, 20.3, 55.5, 30); 48 | ViewHelper.setColor(g2d, ViewHelper.ORANGE); 49 | ViewHelper.strokeRectangle(g2d, 30, 20, 500, 600); 50 | ViewHelper.setColor(g2d, ViewHelper.GREEN); 51 | ViewHelper.fillRectangle(g2d, 1024 - 30, 20, 500, 600); 52 | 53 | ViewHelper.putImage(g2d, 30, 20, "C:\\Users\\wangtao\\Pictures\\go128.png"); 54 | ViewHelper.setColor(g2d, ViewHelper.LIGHTBLUE); 55 | double[] x = new double[]{100, 30, 50, 1020.8, 19.6, 555.0}; 56 | double[] y = new double[]{90.3, 55.9, 50, 55.6, 19.6, 555.0}; 57 | ViewHelper.drawPolygon(g2d, x, y); 58 | } 59 | 60 | @Override 61 | public void paintComponent(Graphics g) { 62 | drawing(g); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/view/PolygonAngleView.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.view; 2 | 3 | import com.huifer.planar.aset.algo.PolygonAngleInterface; 4 | import com.huifer.planar.aset.algo.impl.polygon.PolygonAngleCore; 5 | import com.huifer.planar.aset.algo.impl.polygon.PolygonAngleCore.PointF; 6 | import com.huifer.planar.aset.entity.PolygonAngleResult; 7 | import com.huifer.planar.aset.view.base.BaseFrame; 8 | import com.huifer.planar.aset.view.base.FrameContext; 9 | import com.huifer.planar.aset.view.base.ViewHelper; 10 | import org.locationtech.jts.awt.ShapeWriter; 11 | import org.locationtech.jts.geom.Polygon; 12 | import org.locationtech.jts.io.ParseException; 13 | 14 | import java.awt.*; 15 | import java.util.HashMap; 16 | import java.util.List; 17 | 18 | /** 19 | *

Title : PolygonAngleView

20 | *

Description :

21 | * 22 | * @author huifer 23 | * @date 2019-01-28 24 | */ 25 | public class PolygonAngleView extends FrameContext { 26 | 27 | public static void main(String[] args) { 28 | PolygonAngleView polygonAngleView = new PolygonAngleView(); 29 | BaseFrame frame = new BaseFrame(polygonAngleView); 30 | frame.run(); 31 | } 32 | 33 | @Override 34 | public void drawing(Graphics g) throws ParseException { 35 | // String wkt = "POLYGON ((350 100, 450 450, 150 400, 100 200, 350 100), (200 300, 350 350, 300 200, 200 300))"; 36 | String wkt = "POLYGON ((350 100, 450 450, 150 400, 100 200, 350 100))"; 37 | 38 | ShapeWriter sw = new ShapeWriter(); 39 | PolygonAngleInterface polygonAngleInterface = new PolygonAngleCore(); 40 | PolygonAngleResult polygonAngleResult = polygonAngleInterface.polygonWktAngle(wkt); 41 | Graphics2D g2d = (Graphics2D) g; 42 | Polygon polygon = polygonAngleResult.getPolygon(); 43 | List> polygonAngles = polygonAngleResult.getPolygonAngles(); 44 | 45 | // 绘图流程 46 | ViewHelper.setStrokeWidth(g2d, 2); 47 | ViewHelper.setColor(g2d, ViewHelper.BLUE); 48 | Shape polyShape = sw.toShape(polygon); 49 | g2d.draw(polyShape); 50 | 51 | ViewHelper.setColor(g2d, ViewHelper.GREEN); 52 | for (HashMap angle : polygonAngles) { 53 | angle.forEach( 54 | (k, v) -> { 55 | ViewHelper.drawText(g2d, v.toString(), (int) k.getX(), (int) k.getY()); 56 | } 57 | ); 58 | } 59 | } 60 | 61 | @Override 62 | public void paintComponent(Graphics g) { 63 | try { 64 | drawing(g); 65 | } catch (ParseException e) { 66 | e.printStackTrace(); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/view/base/Aframe.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.view.base; 2 | 3 | import org.locationtech.jts.io.ParseException; 4 | 5 | import java.awt.*; 6 | 7 | /** 8 | *

Title : Aframe

9 | *

Description :

10 | * 11 | * @author huifer 12 | * @date 2019-01-15 13 | */ 14 | public interface Aframe { 15 | 16 | /** 17 | * 绘图方法 18 | * 19 | * @param g Graphics 20 | * @throws ParseException 异常 21 | */ 22 | void drawing(Graphics g) throws ParseException; 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/view/base/BaseFrame.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.view.base; 2 | 3 | import javax.swing.*; 4 | import java.awt.*; 5 | 6 | /** 7 | *

Title : BaseFrame

8 | *

Description : 基础显示框架

9 | * 10 | * @author huifer 11 | * @date 2019-01-15 12 | */ 13 | public class BaseFrame extends JFrame { 14 | 15 | private FrameContext frameContext; 16 | 17 | public BaseFrame(FrameContext frameContext) { 18 | this.frameContext = frameContext; 19 | init(); 20 | } 21 | 22 | private void init() { 23 | add(frameContext); 24 | setTitle("显示框"); 25 | setSize(1024, 768); 26 | setLocationRelativeTo(null); 27 | setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 28 | } 29 | 30 | public void run() { 31 | EventQueue.invokeLater( 32 | () -> { 33 | BaseFrame ex = new BaseFrame(frameContext); 34 | ex.setVisible(true); 35 | } 36 | ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/huifer/planar/aset/view/base/FrameContext.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.view.base; 2 | 3 | import org.locationtech.jts.io.ParseException; 4 | 5 | import javax.swing.*; 6 | import java.awt.*; 7 | 8 | /** 9 | *

Title : FrameContext

10 | *

Description : 显示内容

11 | * 12 | * @author huifer 13 | * @date 2019-01-15 14 | */ 15 | public class FrameContext extends JPanel implements Aframe { 16 | 17 | @Override 18 | public void drawing(Graphics g) throws ParseException { 19 | 20 | } 21 | 22 | @Override 23 | public void paintComponent(Graphics g) { 24 | super.paintComponent(g); 25 | try { 26 | drawing(g); 27 | } catch (Exception e) { 28 | e.printStackTrace(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/resources/1.csv: -------------------------------------------------------------------------------- 1 | uuid;wkt;proportion 2 | -------------------------------------------------------------------------------- /src/main/resources/data/shp/555555.cpg: -------------------------------------------------------------------------------- 1 | UTF-8 -------------------------------------------------------------------------------- /src/main/resources/data/shp/555555.dbf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/src/main/resources/data/shp/555555.dbf -------------------------------------------------------------------------------- /src/main/resources/data/shp/555555.sbn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/src/main/resources/data/shp/555555.sbn -------------------------------------------------------------------------------- /src/main/resources/data/shp/555555.sbx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/src/main/resources/data/shp/555555.sbx -------------------------------------------------------------------------------- /src/main/resources/data/shp/555555.shp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/src/main/resources/data/shp/555555.shp -------------------------------------------------------------------------------- /src/main/resources/data/shp/555555.shp.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 20190225 5 | 15113700 6 | 1.0 7 | TRUE 8 | 9 | 10 | CalculateField 555555 split 2 VB # 13 | 14 | CalculateField 555555 split "" VB # 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/main/resources/data/shp/555555.shx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/src/main/resources/data/shp/555555.shx -------------------------------------------------------------------------------- /src/main/resources/data/shp/省范围.cpg: -------------------------------------------------------------------------------- 1 | UTF-8 -------------------------------------------------------------------------------- /src/main/resources/data/shp/省范围.dbf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/src/main/resources/data/shp/省范围.dbf -------------------------------------------------------------------------------- /src/main/resources/data/shp/省范围.prj: -------------------------------------------------------------------------------- 1 | GEOGCS["GCS_Xian_1980",DATUM["D_Xian_1980",SPHEROID["IUGG_1975",6378140.0,298.257]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]] -------------------------------------------------------------------------------- /src/main/resources/data/shp/省范围.sbn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/src/main/resources/data/shp/省范围.sbn -------------------------------------------------------------------------------- /src/main/resources/data/shp/省范围.sbx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/src/main/resources/data/shp/省范围.sbx -------------------------------------------------------------------------------- /src/main/resources/data/shp/省范围.shp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/src/main/resources/data/shp/省范围.shp -------------------------------------------------------------------------------- /src/main/resources/data/shp/省范围.shx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/src/main/resources/data/shp/省范围.shx -------------------------------------------------------------------------------- /src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n 10 | 11 | 12 | 13 | 14 | 16 | ${DEV_HOME}/debug.log 17 | 18 | 19 | %d{yyyy-MM-dd HH:mm:ss} - %msg%n 20 | 21 | 22 | 23 | 24 | ${DEV_HOME}/archived/debug.%d{yyyy-MM-dd}.%i.log 25 | 26 | 28 | 10MB 29 | 30 | 31 | 32 | 33 | 34 | 36 | ${DEV_HOME}/error.log 37 | 38 | 39 | %d{yyyy-MM-dd HH:mm:ss} - %msg%n 40 | 41 | 42 | 43 | 44 | ${DEV_HOME}/archived/error.%d{yyyy-MM-dd}.%i.log 45 | 46 | 48 | 10MB 49 | 50 | 51 | 52 | 53 | 54 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /src/main/resources/polygon_select/原始数据.dwg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/src/main/resources/polygon_select/原始数据.dwg -------------------------------------------------------------------------------- /src/main/resources/polygon_select/根据点/原始数据.dwg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/src/main/resources/polygon_select/根据点/原始数据.dwg -------------------------------------------------------------------------------- /src/main/resources/polygon_select/根据点/数据要求.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/src/main/resources/polygon_select/根据点/数据要求.txt -------------------------------------------------------------------------------- /src/main/resources/polygon_select/根据点/测试数据.cpg: -------------------------------------------------------------------------------- 1 | UTF-8 -------------------------------------------------------------------------------- /src/main/resources/polygon_select/根据点/测试数据.dbf: -------------------------------------------------------------------------------- 1 | wAIdN 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 -------------------------------------------------------------------------------- /src/main/resources/polygon_select/根据点/测试数据.sbn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/src/main/resources/polygon_select/根据点/测试数据.sbn -------------------------------------------------------------------------------- /src/main/resources/polygon_select/根据点/测试数据.sbx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/src/main/resources/polygon_select/根据点/测试数据.sbx -------------------------------------------------------------------------------- /src/main/resources/polygon_select/根据点/测试数据.shp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/src/main/resources/polygon_select/根据点/测试数据.shp -------------------------------------------------------------------------------- /src/main/resources/polygon_select/根据点/测试数据.shx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/src/main/resources/polygon_select/根据点/测试数据.shx -------------------------------------------------------------------------------- /src/main/resources/polygon_select/根据点/测试数据.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 20190426 5 | 11254200 6 | 1.0 7 | TRUE 8 | 9 | 10 | CalculateField afafaf Id [FID] VB # 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/main/resources/polygon_select/根据点/结果.cpg: -------------------------------------------------------------------------------- 1 | UTF-8 -------------------------------------------------------------------------------- /src/main/resources/polygon_select/根据点/结果.dbf: -------------------------------------------------------------------------------- 1 | wAIdN 0 1 2 3 4 11 13 14 15 17 19 20 23 24 25 28 -------------------------------------------------------------------------------- /src/main/resources/polygon_select/根据点/结果.sbn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/src/main/resources/polygon_select/根据点/结果.sbn -------------------------------------------------------------------------------- /src/main/resources/polygon_select/根据点/结果.sbx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/src/main/resources/polygon_select/根据点/结果.sbx -------------------------------------------------------------------------------- /src/main/resources/polygon_select/根据点/结果.shp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/src/main/resources/polygon_select/根据点/结果.shp -------------------------------------------------------------------------------- /src/main/resources/polygon_select/根据点/结果.shx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/src/main/resources/polygon_select/根据点/结果.shx -------------------------------------------------------------------------------- /src/main/resources/polygon_select/根据点/说明.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/src/main/resources/polygon_select/根据点/说明.png -------------------------------------------------------------------------------- /src/main/resources/polygon_select/根据线/原始数据.dwg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/src/main/resources/polygon_select/根据线/原始数据.dwg -------------------------------------------------------------------------------- /src/main/resources/polygon_select/根据线/测试数据.cpg: -------------------------------------------------------------------------------- 1 | UTF-8 -------------------------------------------------------------------------------- /src/main/resources/polygon_select/根据线/测试数据.dbf: -------------------------------------------------------------------------------- 1 | wAIdN 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 -------------------------------------------------------------------------------- /src/main/resources/polygon_select/根据线/测试数据.sbn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/src/main/resources/polygon_select/根据线/测试数据.sbn -------------------------------------------------------------------------------- /src/main/resources/polygon_select/根据线/测试数据.sbx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/src/main/resources/polygon_select/根据线/测试数据.sbx -------------------------------------------------------------------------------- /src/main/resources/polygon_select/根据线/测试数据.shp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/src/main/resources/polygon_select/根据线/测试数据.shp -------------------------------------------------------------------------------- /src/main/resources/polygon_select/根据线/测试数据.shx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/src/main/resources/polygon_select/根据线/测试数据.shx -------------------------------------------------------------------------------- /src/main/resources/polygon_select/根据线/测试数据.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 20190426 5 | 11254200 6 | 1.0 7 | TRUE 8 | 9 | 10 | CalculateField afafaf Id [FID] VB # 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/main/resources/polygon_select/测试数据.cpg: -------------------------------------------------------------------------------- 1 | UTF-8 -------------------------------------------------------------------------------- /src/main/resources/polygon_select/测试数据.dbf: -------------------------------------------------------------------------------- 1 | wAIdN 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 -------------------------------------------------------------------------------- /src/main/resources/polygon_select/测试数据.sbn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/src/main/resources/polygon_select/测试数据.sbn -------------------------------------------------------------------------------- /src/main/resources/polygon_select/测试数据.sbx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/src/main/resources/polygon_select/测试数据.sbx -------------------------------------------------------------------------------- /src/main/resources/polygon_select/测试数据.shp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/src/main/resources/polygon_select/测试数据.shp -------------------------------------------------------------------------------- /src/main/resources/polygon_select/测试数据.shx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huifer/planar_algorithm/884760e4768dc6d426c99bded29a6da45c172a0c/src/main/resources/polygon_select/测试数据.shx -------------------------------------------------------------------------------- /src/main/resources/polygon_select/测试数据.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 20190426 5 | 11254200 6 | 1.0 7 | TRUE 8 | 9 | 10 | CalculateField afafaf Id [FID] VB # 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/test/java/com/huifer/planar/aset/OT.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset; 2 | 3 | import org.locationtech.jts.geom.Geometry; 4 | import org.locationtech.jts.geom.GeometryFactory; 5 | import org.locationtech.jts.geom.Point; 6 | import org.locationtech.jts.io.WKTReader; 7 | 8 | import java.util.HashSet; 9 | import java.util.Set; 10 | 11 | /** 12 | *

Title : OT

13 | *

Description :

14 | * 15 | * @author huifer 16 | * @date 2019-03-08 17 | */ 18 | public class OT { 19 | 20 | public static void main(String[] args) throws Exception { 21 | 22 | Geometry p5 = new WKTReader() 23 | .read("POLYGON ((88066.09 73721.882, 88065.09 73721.882, 88065.09 73721.882, 88065.09 73720.882, 88065.09 73720.882, 88065.09 73720.788, 88065.09 73720.788, 88065.281 73720.942, 88065.281 73720.942, 88066.284 73721.75, 88066.284 73721.75, 88066.09 73721.882))"); 24 | 25 | Set ps = new HashSet<>(); 26 | for (int i = 0; i < p5.getCoordinates().length; i++) { 27 | ps.add(new GeometryFactory().createPoint(p5.getCoordinates()[i])); 28 | } 29 | 30 | Geometry geometry = p5.convexHull(); 31 | System.out.println(p5.getArea()); 32 | System.out.println(geometry.getArea()); 33 | 34 | System.out.println(ps.size()); 35 | System.out.println(geometry.getCoordinates().length); 36 | 37 | System.out.println(geometry); 38 | 39 | 40 | } 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/com/huifer/planar/aset/algo/KmeanPolygonSplitInterfaceTest.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo; 2 | 3 | import com.huifer.planar.aset.algo.impl.polygon.KmeanPolygonSplitCore; 4 | import org.junit.Test; 5 | 6 | public class KmeanPolygonSplitInterfaceTest { 7 | 8 | @Test 9 | public void splitPolygonWithShpTest() throws Exception { 10 | 11 | KmeanPolygonSplitInterface km = new KmeanPolygonSplitCore(); 12 | Object split = km.splitPolygonWithShp("E:\\mck\\planar_algorithm\\src\\main\\resources\\data\\shp\\555555.shp", "split"); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/com/huifer/planar/aset/algo/LineOverCoreTest.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo; 2 | 3 | 4 | import com.huifer.planar.aset.algo.impl.ovlayer.LineOverCore; 5 | import com.huifer.planar.aset.entity.MyLine; 6 | import com.huifer.planar.aset.entity.MyPoint; 7 | import com.huifer.planar.aset.entity.SortPoint; 8 | import lombok.extern.slf4j.Slf4j; 9 | import org.junit.Test; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | import java.util.Map; 14 | import java.util.function.BiConsumer; 15 | 16 | @Slf4j 17 | public class LineOverCoreTest { 18 | 19 | @Test 20 | public void simpleLineSortPointTest() { 21 | MyLine l = new MyLine(new MyPoint(10, 0), new MyPoint(10, 10)); 22 | MyPoint p1 = new MyPoint(7, 7); 23 | MyPoint p2 = new MyPoint(7, 4); 24 | MyPoint p3 = new MyPoint(12, 7); 25 | MyPoint p4 = new MyPoint(12, 4); 26 | ArrayList ps = new ArrayList<>(); 27 | ps.add(p1); 28 | ps.add(p2); 29 | ps.add(p3); 30 | ps.add(p4); 31 | LineOverCore lineOverCore = new LineOverCore(); 32 | Map> stringListMap = lineOverCore.simpleLineSortPoint(l, ps); 33 | stringListMap.forEach( 34 | new BiConsumer>() { 35 | @Override 36 | public void accept(String s, List sortPoints) { 37 | sortPoints.forEach(a -> { 38 | // System.out.println(a); 39 | 40 | log.info("{}", a); 41 | }); 42 | } 43 | } 44 | ); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/com/huifer/planar/aset/algo/PolygonAngleInterfaceTest.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo; 2 | 3 | public class PolygonAngleInterfaceTest { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/test/java/com/huifer/planar/aset/algo/PolygonCenterOfGravityInterfaceTest.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo; 2 | 3 | import com.huifer.planar.aset.algo.impl.polygon.PolygonCenterOfGravityCore; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | import org.locationtech.jts.geom.Point; 7 | import org.locationtech.jts.geom.Polygon; 8 | import org.locationtech.jts.io.WKTReader; 9 | 10 | public class PolygonCenterOfGravityInterfaceTest { 11 | 12 | private Polygon pg; 13 | private PolygonCenterOfGravityInterface polygonCenterOfGravityInterface = new PolygonCenterOfGravityCore(); 14 | 15 | @Before 16 | public void init() throws Exception { 17 | String pgwkt = "POLYGON ((87969.0159375285 73820.8504159828,87945.8039237902 73809.5760093099,87946.1355239865 73792.0011989081,87953.099128108 73779.4003914502,87969.3475377248 73775.7527892913,87995.5439532294 73778.4055908614,88006.8183599022 73790.3431979268,88006.1551595097 73802.9440053847,88002.5075573508 73814.8816124501,87992.2279512667 73823.5032175529,87980.6219443976 73823.5032175529,87969.0159375285 73820.8504159828))"; 18 | // pgwkt = "POLYGON ((35 10, 45 45, 15 40, 10 20, 35 10),(20 30, 35 35, 30 20, 20 30))"; 19 | Polygon read = (Polygon) new WKTReader().read(pgwkt); 20 | pg = read; 21 | 22 | // DelaunayTriangulationBuilder a = new DelaunayTriangulationBuilder(); 23 | // a.setSites(read); 24 | // Geometry triangles = a.getTriangles(new GeometryFactory()); 25 | // 26 | // int numGeometries = triangles.getNumGeometries(); 27 | // for (int i = 0; i < numGeometries; i++) { 28 | // Geometry geometryN = triangles.getGeometryN(i); 29 | // System.out.println(geometryN); 30 | // } 31 | // 32 | // System.out.println(); 33 | 34 | 35 | } 36 | 37 | @Test 38 | public void testClcPolygonGravitePoint() throws Exception { 39 | 40 | Point point = polygonCenterOfGravityInterface.calcGravityPointOfCovenPolygon(pg); 41 | System.out.println(point); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/com/huifer/planar/aset/algo/RailCoreTest.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo; 2 | 3 | 4 | import com.huifer.planar.aset.algo.impl.polygon.RailCore; 5 | import com.huifer.planar.aset.entity.MyLine; 6 | import com.huifer.planar.aset.entity.MyPoint; 7 | import com.huifer.planar.aset.entity.MyPolygon; 8 | import lombok.extern.slf4j.Slf4j; 9 | import org.junit.Test; 10 | 11 | import java.util.ArrayList; 12 | 13 | @Slf4j 14 | public class RailCoreTest { 15 | 16 | @Test 17 | public void Test() { 18 | MyPoint testP = new MyPoint(0.5, 0.5); 19 | 20 | MyPoint p1 = new MyPoint(0, 0); 21 | MyPoint p2 = new MyPoint(1, 0); 22 | MyPoint p3 = new MyPoint(1, 1); 23 | MyPoint p4 = new MyPoint(0, 1); 24 | 25 | MyLine l1 = new MyLine(p1, p2); 26 | MyLine l2 = new MyLine(p2, p3); 27 | MyLine l3 = new MyLine(p3, p4); 28 | 29 | ArrayList lines = new ArrayList<>(); 30 | lines.add(l1); 31 | lines.add(l2); 32 | lines.add(l3); 33 | 34 | MyPolygon pg = new MyPolygon(lines); 35 | RailInterface railInterface = new RailCore(); 36 | boolean inPolygon = railInterface.isInPolygon(testP, pg); 37 | // System.out.println(inPolygon ? "IN" : "OUT"); 38 | log.info("是否在面内 = {}", inPolygon ? "IN" : "OUT"); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/com/huifer/planar/aset/algo/impl/AverageWidthAverageLengthImplTest.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo.impl; 2 | 3 | import com.huifer.planar.aset.algo.AverageWidthAverageLength; 4 | import org.junit.Test; 5 | 6 | public class AverageWidthAverageLengthImplTest { 7 | 8 | 9 | private AverageWidthAverageLength averageWidthAverageLength = new AverageWidthAverageLengthImpl(); 10 | 11 | @Test 12 | public void calcAverageWidth() { 13 | String polygon = "POLYGON((0 0, 10 20, 20 20, 10 0, 0 0))"; 14 | double v = averageWidthAverageLength.calcAverageWidth(10, polygon); 15 | 16 | } 17 | 18 | @Test 19 | public void calcAverageLength() { 20 | String polygon = "POLYGON((0 0, 10 20, 20 20, 10 0, 0 0))"; 21 | double v = averageWidthAverageLength.calcAverageLength(10, polygon); 22 | } 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/com/huifer/planar/aset/algo/impl/MyRecatngleOverCoreTest.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo.impl; 2 | 3 | 4 | import com.huifer.planar.aset.algo.MyRectangleOver; 5 | import com.huifer.planar.aset.algo.impl.polygon.MyRecatngleOverCore; 6 | import com.huifer.planar.aset.entity.MyPoint; 7 | import com.huifer.planar.aset.entity.MyRectangle; 8 | import lombok.extern.slf4j.Slf4j; 9 | import org.junit.Test; 10 | 11 | @Slf4j 12 | public class MyRecatngleOverCoreTest { 13 | 14 | MyRectangleOver over = new MyRecatngleOverCore(); 15 | 16 | 17 | @Test 18 | public void testCalcAreaIntersectionRectangles() { 19 | MyRectangle r1 = new MyRectangle(new MyPoint(0, 0), 3, 2); 20 | MyRectangle r2 = new MyRectangle(new MyPoint(2, 0), 2, 3); 21 | double v = over.calcAreaIntersectionRectangles(r1, r2); 22 | // System.out.println(v); 23 | log.info("{}", v); 24 | assert 2 == v; 25 | r2 = new MyRectangle(new MyPoint(3, 0), 3, 2); 26 | double v1 = over.calcAreaIntersectionRectangles(r1, r2); 27 | // System.out.println(v1); 28 | log.info("{}", v1); 29 | assert 0 == v1; 30 | r2 = new MyRectangle(new MyPoint(10, 0), 1, 3); 31 | double v2 = over.calcAreaIntersectionRectangles(r1, r2); 32 | // System.out.println(v2); 33 | log.info("{}", v2); 34 | assert 0 == v2; 35 | 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/com/huifer/planar/aset/algo/impl/NearbyInterfaceImplTest.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo.impl; 2 | 3 | 4 | import com.huifer.planar.aset.algo.NearbyInterface; 5 | import org.geotools.geometry.jts.JTSFactoryFinder; 6 | import org.junit.Test; 7 | import org.locationtech.jts.geom.Coordinate; 8 | import org.locationtech.jts.geom.GeometryFactory; 9 | import org.locationtech.jts.geom.Point; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | import java.util.Random; 14 | 15 | 16 | public class NearbyInterfaceImplTest { 17 | NearbyInterface nearbyInterface = new NearbyInterfaceImpl(); 18 | GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null); 19 | 20 | @Test 21 | public void pointNearbyPolygon() { 22 | } 23 | 24 | @Test 25 | public void pointNearbyPoint() { 26 | 27 | Coordinate coordinate = new Coordinate(1, 2); 28 | 29 | Point p = new GeometryFactory().createPoint(coordinate); 30 | List list = new ArrayList<>(); 31 | for (int i = 0; i < 10; i++) { 32 | Random random = new Random(); 33 | Coordinate coordinate2 = new Coordinate(random.nextDouble(), random.nextDouble()); 34 | 35 | Point p2 = new GeometryFactory().createPoint(coordinate2); 36 | list.add(p2); 37 | 38 | } 39 | Point point = nearbyInterface.pointNearbyPoint(p, list); 40 | System.out.println("结果为" + point); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/com/huifer/planar/aset/algo/impl/PolygonAngleCoreTest.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo.impl; 2 | 3 | import com.huifer.planar.aset.algo.PolygonAngleInterface; 4 | import com.huifer.planar.aset.algo.impl.polygon.PolygonAngleCore; 5 | import com.huifer.planar.aset.entity.PolygonAngleResult; 6 | import org.junit.Test; 7 | 8 | public class PolygonAngleCoreTest { 9 | @Test 10 | public void testPolygonWktAngleMerge() throws Exception { 11 | String wkt = "POLYGON ((290.890041493776 392.188796680498,279.707468879668 191.919087136929,307.155601659751 327.126556016598,363.06846473029 170.570539419087,548.089211618257 237.665975103734,605.01867219917 407.4377593361,493.192946058091 301.711618257261,472.860995850622 232.582987551867,479.977178423236 311.877593360996,290.890041493776 392.188796680498))"; 12 | PolygonAngleInterface polygonAngleInterface = new PolygonAngleCore(); 13 | PolygonAngleResult polygonAngleResult = polygonAngleInterface.polygonWktAngleMerge(wkt, 30.0); 14 | System.out.println(polygonAngleResult.getNewPolygon()); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/test/java/com/huifer/planar/aset/algo/impl/PolygonSegmentationCoreTest.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo.impl; 2 | 3 | import org.junit.Test; 4 | import org.locationtech.jts.geom.Coordinate; 5 | import org.locationtech.jts.geom.GeometryFactory; 6 | import org.locationtech.jts.geom.Point; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | public class PolygonSegmentationCoreTest { 12 | 13 | @Test 14 | public void testSortByPoint() { 15 | List ps = new ArrayList<>(); 16 | ps.add(new GeometryFactory().createPoint(new Coordinate(0, 0))); 17 | ps.add(new GeometryFactory().createPoint(new Coordinate(1, 1))); 18 | ps.add(new GeometryFactory().createPoint(new Coordinate(3, 3))); 19 | ps.add(new GeometryFactory().createPoint(new Coordinate(2, 2))); 20 | Point point = new GeometryFactory().createPoint(new Coordinate(3, 3)); 21 | 22 | List left = new ArrayList<>(); 23 | List right = new ArrayList<>(); 24 | List result = new ArrayList<>(); 25 | int i1 = ps.indexOf(point); 26 | 27 | for (int i = 0; i < ps.size(); i++) { 28 | if (i < i1) { 29 | right.add(ps.get(i)); 30 | } 31 | if (i == i1) { 32 | result.add(ps.get(i)); 33 | } 34 | if (i > i1) { 35 | left.add(ps.get(i)); 36 | } 37 | } 38 | result.addAll(left); 39 | result.addAll(right); 40 | 41 | System.out.println(); 42 | 43 | 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/com/huifer/planar/aset/algo/impl/RemoveLineTest.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo.impl; 2 | 3 | import com.huifer.planar.aset.algo.impl.line.RemoveLine; 4 | import org.junit.Test; 5 | import org.locationtech.jts.geom.Geometry; 6 | import org.locationtech.jts.geom.Polygon; 7 | import org.locationtech.jts.io.WKTReader; 8 | 9 | public class RemoveLineTest { 10 | @Test 11 | public void tt() throws Exception { 12 | Polygon polygon1 = (Polygon) new WKTReader() 13 | .read("POLYGON ((88079.50995826721 73725.33817863464, 88079.50995826721 73723.938539505, 88076.85249519348 73722.38814735413, 88079.65061759949 73720.67353248596, 88079.50129890442 73718.87973594666, 88078.85879325867 73717.1983127594, 88080.6580028534 73717.14500236511, 88081.77146720886 73714.7630367279, 88078.27829933167 73712.19784355164, 88073.20011329651 73715.0487537384, 88068.65647697449 73720.30512428284, 88079.50995826721 73725.33817863464))"); 14 | 15 | Geometry geometry = RemoveLine.delete(polygon1, 2); 16 | // System.out.println(geometry); 17 | 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/com/huifer/planar/aset/algo/impl/VoronoiInterfaceImplTest.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo.impl; 2 | 3 | import com.huifer.planar.aset.algo.VoronoiInterface; 4 | import com.huifer.planar.aset.algo.impl.polygon.VoronoiInterfaceImpl; 5 | import com.huifer.planar.aset.utils.shptools.overlay.Operation; 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.locationtech.jts.geom.Coordinate; 9 | import org.locationtech.jts.geom.Geometry; 10 | import org.locationtech.jts.geom.Polygon; 11 | import org.locationtech.jts.io.ParseException; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | import java.util.Random; 16 | 17 | public class VoronoiInterfaceImplTest { 18 | 19 | private VoronoiInterface vo = new VoronoiInterfaceImpl(); 20 | private Operation op = new Operation(); 21 | private List coords = new ArrayList<>(); 22 | 23 | @Before 24 | public void initData() throws ParseException { 25 | int xmin = 0, xmax = 1000; 26 | int ymin = 0, ymax = 1000; 27 | Random random = new Random(); 28 | List coords = new ArrayList(); 29 | for (int i = 0; i < 600000; i++) { 30 | int x = random.nextInt(xmax) % (xmax - xmin + 1) + xmin; 31 | int y = random.nextInt(ymax) % (ymax - ymin + 1) + ymin; 32 | Coordinate coord = new Coordinate(x, y, i); 33 | coords.add(coord); 34 | } 35 | this.coords = coords; 36 | } 37 | 38 | 39 | @Test 40 | public void voronoi() { 41 | long startTime = System.currentTimeMillis(); 42 | List voronoi = vo.voronoi(coords); 43 | long endTime = System.currentTimeMillis(); 44 | System.out.println("程序运行时间:" + (endTime - startTime) + "ms"); //输出程序运行时间 45 | System.out.println(voronoi.size()); 46 | // voronoi.forEach(s -> System.out.println(s)); 47 | } 48 | 49 | @Test 50 | public void delaunay() throws ParseException { 51 | List delaunay = vo.delaunay(coords); 52 | String wkt = "POLYGON((411 80, 569 125, 675 238, 795 321, 917 416, 866 597, 600 699, 443 614, 500 483, 399 338, 411 80))"; 53 | Polygon polygon = op.createPolygonByWKT(wkt); 54 | delaunay.forEach( 55 | s -> System.out.println(s) 56 | ); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/com/huifer/planar/aset/algo/impl/concave/LineEquationTest.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo.impl.concave; 2 | 3 | import com.huifer.planar.aset.algo.impl.concave.ConcaveSplit.Radial; 4 | import org.junit.Test; 5 | import org.locationtech.jts.geom.Coordinate; 6 | import org.locationtech.jts.geom.GeometryFactory; 7 | import org.locationtech.jts.geom.Point; 8 | 9 | public class LineEquationTest { 10 | 11 | 12 | @Test 13 | public void testCalcXY() { 14 | 15 | // POINT (88066.9358577728 73719.719751358) POINT (88066.9358577728 73720.719751358) 16 | // POINT (88064.0209026337 73719.926618576) POINT (88065.280916214 73720.9421520233) 17 | // POINT (88066.9358577728 73719.719751358) POINT (88066.9358577728 73720.719751358) 18 | // POINT (88068.1958713531 73722.1269397736) POINT (88067.0298862457 73721.2430477142) 19 | // POINT (88065.0895786285 73721.8824596405) POINT (88065.0895786285 73720.8824596405) 20 | // 88063.8328418732 21 | // 73719.6257190704 22 | // 88068.1958713531 23 | // 73722.1269397736 24 | Point start = new GeometryFactory().createPoint(new Coordinate(88064.0209026337, 73719.926618576)); 25 | Point end = new GeometryFactory().createPoint(new Coordinate(88065.280916214, 73720.9421520233)); 26 | Radial radial = new Radial(start, end); 27 | // double y = radial.calcY(88064.123424185); 28 | double A = end.getY() - start.getY(); 29 | double B = start.getX() - end.getX(); 30 | double C = end.getX() * start.getY() - start.getX() * end.getY(); 31 | 32 | // 一般直线方程 : Ax + By + C = 0 33 | System.out.println(radial.getA()); 34 | System.out.println(radial.getB()); 35 | System.out.println(radial.getC()); 36 | System.out.println("======================================="); 37 | System.out.println(A); 38 | System.out.println(B); 39 | System.out.println(C); 40 | double v = radial.calcYY(88063.8328418732); 41 | System.out.println(v); 42 | 43 | } 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/com/huifer/planar/aset/algo/impl/concave/PolygonizerT.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo.impl.concave; 2 | 3 | import com.huifer.planar.aset.utils.CommonUtils; 4 | import org.junit.Test; 5 | import org.locationtech.jts.geom.Geometry; 6 | import org.locationtech.jts.geom.LineString; 7 | import org.locationtech.jts.geom.Point; 8 | import org.locationtech.jts.geom.Polygon; 9 | import org.locationtech.jts.io.WKTReader; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | *

Title : PolygonizerT

15 | *

Description :

16 | * 17 | * @author huifer 18 | * @date 2019-02-28 19 | */ 20 | public class PolygonizerT { 21 | 22 | @Test 23 | public void test() throws Exception { 24 | Geometry rs = new WKTReader() 25 | .read("POLYGON ((88075.4230267276 73722.549590726,88076.0624386539 73723.4898983432,88076.0624386539 73724.4898983432,88075.0624386539 73724.4898983432,88075.9684063663 73725.7466350986,88074.1065975894 73725.5585743381,88075.1221310367 73724.2985607578,88073.8997303714 73722.6436191989,88074.8997303714 73722.6436191989,88073.8056980838 73721.4212185336,88076.3069187869 73721.3836056186,88075.4230267276 73722.549590726))"); 26 | Geometry ls = new WKTReader() 27 | .read("LINESTRING (88073.8056980838 73725.93191244664, 88076.3069187869 73722.82854636687)"); 28 | List lineStrings = CommonUtils.polygonLineString((Polygon) rs); 29 | 30 | Geometry read = new WKTReader() 31 | .read("POLYGON((1 1,5 1,5 5,1 5,1 1),(2 2,2 3,3 3,3 2,2 2))"); 32 | 33 | Boolean clipPolygon = CommonUtils.isClipPolygon((Polygon) read); 34 | Boolean c2 = CommonUtils.isClipPolygon((Polygon) rs); 35 | System.out.println(); 36 | 37 | String splitPoint = "POINT (88075.1221310367 73724.2985607578)"; 38 | LineString lsssss = (LineString) ls; 39 | Geometry read1 = new WKTReader().read(splitPoint); 40 | Point sp = (Point) read1; 41 | 42 | List lineStrings1 = CommonUtils.lineStringSplit(lsssss, sp); 43 | lineStrings1.forEach(s -> System.out.println(s)); 44 | System.out.println(); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/com/huifer/planar/aset/algo/impl/concave/SimpleCutPolygonTest.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo.impl.concave; 2 | 3 | import com.huifer.planar.aset.algo.impl.concave.ConcaveSplit.TroughLineWithSort; 4 | import org.junit.Test; 5 | import org.locationtech.jts.geom.Polygon; 6 | import org.locationtech.jts.io.WKTReader; 7 | 8 | import java.util.List; 9 | 10 | import static com.huifer.planar.aset.algo.impl.concave.SimpleCutPolygon.simpleCutPolygonWithLine; 11 | 12 | public class SimpleCutPolygonTest { 13 | 14 | @Test 15 | public void simpleCutPolygonWithLineTest() throws Exception { 16 | 17 | Polygon pg = (Polygon) new WKTReader() 18 | .read("POLYGON ((88064.0209026337 73719.926618576,88065.280916214 73720.9421520233,88066.9358577728 73719.719751358,88066.9358577728 73720.719751358,88068.1582584381 73719.6257190704,88068.1958713531 73722.1269397736,88067.0298862457 73721.2430477142,88066.0895786285 73721.8824596405,88065.0895786285 73721.8824596405,88065.0895786285 73720.8824596405,88063.8328418732 73721.7884273529,88064.0209026337 73719.926618576))"); 19 | List splitLine = ConcaveSplit.split(pg); 20 | List polygons = simpleCutPolygonWithLine(pg, splitLine); 21 | polygons.forEach( 22 | s -> System.out.println(s) 23 | ); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/com/huifer/planar/aset/algo/impl/minrect/MaximumInnerCircleTest.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo.impl.minrect; 2 | 3 | import org.junit.Before; 4 | import org.junit.Test; 5 | import org.locationtech.jts.geom.Geometry; 6 | import org.locationtech.jts.geom.Point; 7 | import org.locationtech.jts.geom.Polygon; 8 | import org.locationtech.jts.io.WKTReader; 9 | 10 | public class MaximumInnerCircleTest { 11 | 12 | 13 | private Geometry read; 14 | 15 | @Before 16 | public void init() throws Exception { 17 | read = new WKTReader() 18 | .read("POLYGON ((88066.09 73721.882, 88065.09 73721.882, 88065.09 73721.882, 88065.09 73720.882, 88065.09 73720.882, 88065.09 73720.788, 88065.09 73720.788, 88065.281 73720.942, 88065.281 73720.942, 88066.284 73721.75, 88066.284 73721.75, 88066.09 73721.882))"); 19 | } 20 | 21 | @Test 22 | public void inCirclePolygon() { 23 | Polygon polygon = MaximumInnerCircle.inCirclePolygon((Polygon) read, 0.00001); 24 | System.out.println(polygon); 25 | } 26 | 27 | @Test 28 | public void inCirclePoint() { 29 | Point polylabel = MaximumInnerCircle.inCirclePoint((Polygon) read, 0.00001); 30 | System.out.println(polylabel); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/com/huifer/planar/aset/algo/impl/minrect/MinCircleToETest.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo.impl.minrect; 2 | 3 | import com.huifer.planar.aset.algo.impl.minrect.MinCircleToE.P; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | import org.locationtech.jts.geom.Coordinate; 7 | import org.locationtech.jts.geom.Polygon; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | public class MinCircleToETest { 13 | 14 | Coordinate p1; 15 | Coordinate p2; 16 | Coordinate p3; 17 | 18 | @Before 19 | public void init() { 20 | p1 = new Coordinate(1, 1); 21 | p2 = new Coordinate(0, 1); 22 | p3 = new Coordinate(2, 3); 23 | } 24 | 25 | @Test 26 | public void threePointCircle() { 27 | Polygon polygon = MinCircleToE.threePointCircle(p1, p2, p3); 28 | System.out.println(polygon); 29 | } 30 | 31 | 32 | @Test 33 | public void minCircle() { 34 | P p1 = new P(1, 1); 35 | P p2 = new P(0, 1); 36 | P p3 = new P(2, 3); 37 | P p4 = new P(1.3, 1.3); 38 | List

pList = new ArrayList<>(); 39 | pList.add(p1); 40 | pList.add(p2); 41 | pList.add(p3); 42 | pList.add(p4); 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/com/huifer/planar/aset/algo/impl/minrect/MinimumBoundingRectangleTest.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo.impl.minrect; 2 | 3 | import org.junit.Test; 4 | import org.locationtech.jts.geom.GeometryFactory; 5 | import org.locationtech.jts.geom.Polygon; 6 | import org.locationtech.jts.io.WKTReader; 7 | 8 | public class MinimumBoundingRectangleTest { 9 | 10 | @Test 11 | public void test() throws Exception { 12 | GeometryFactory gf = new GeometryFactory(); 13 | String wkt = "POLYGON ((87623.0828822501 73753.4143904365,87620.1073981973 73739.213216548,87629.1690996309 73730.4220136646,87641.882531493 73727.3112803367,87643.0997749692 73714.8683470248,87662.0346734872 73725.0120426595,87669.0676357939 73735.1557382941,87655.9484561064 73735.9672339449,87676.9120937514 73747.4634223308,87651.8909778525 73740.8362078495,87659.4649372597 73755.4431295634,87644.4522677204 73748.680665807,87645.5342619215 73760.7178512935,87635.2553170117 73750.9799034842,87630.5215923822 73760.3121034681,87623.0828822501 73753.4143904365))"; 14 | Polygon read = (Polygon) new WKTReader().read(wkt); 15 | Polygon polygon = MinimumBoundingRectangle.get(read, gf); 16 | 17 | System.out.println(polygon); 18 | System.out.println(polygon.getArea()); 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/com/huifer/planar/aset/algo/impl/minrect/MinimumEnclosingCoreTest.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo.impl.minrect; 2 | 3 | import com.huifer.planar.aset.algo.MinimumEnclosingInterface; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | import org.locationtech.jts.geom.Geometry; 7 | import org.locationtech.jts.geom.Polygon; 8 | import org.locationtech.jts.io.WKTReader; 9 | 10 | public class MinimumEnclosingCoreTest { 11 | 12 | private Geometry read; 13 | private MinimumEnclosingInterface m = new MinimumEnclosingCore(); 14 | 15 | @Before 16 | public void init() throws Exception { 17 | read = new WKTReader() 18 | .read("POLYGON ((35 10, 45 45, 15 40, 10 20, 35 10))"); 19 | System.out.println("原图"); 20 | System.out.println(read); 21 | } 22 | 23 | 24 | @Test 25 | public void getMinimumCircumscribedCircle() throws Exception { 26 | 27 | Polygon minimumCircumscribedCircle = m.getMinimumCircumscribedCircle((Polygon) read); 28 | System.out.println("最小外接圆"); 29 | System.out.println(minimumCircumscribedCircle); 30 | } 31 | 32 | @Test 33 | public void getMinRect() { 34 | Polygon minRect = m.getMinRect(read); 35 | System.out.println("最小矩形"); 36 | System.out.println(minRect); 37 | } 38 | 39 | 40 | @Test 41 | public void getInCirclePolygon() { 42 | Polygon inCirclePolygon = m.getInCirclePolygon((Polygon) read); 43 | System.out.println("最大内接圆"); 44 | System.out.println(inCirclePolygon); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/com/huifer/planar/aset/algo/impl/minrect/WelzlAlgoTest.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.algo.impl.minrect; 2 | 3 | import org.junit.Test; 4 | import org.locationtech.jts.geom.Coordinate; 5 | import org.locationtech.jts.geom.Geometry; 6 | import org.locationtech.jts.geom.GeometryFactory; 7 | import org.locationtech.jts.geom.Point; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | public class WelzlAlgoTest { 13 | 14 | @Test 15 | public void testOc() { 16 | List pointSet = new ArrayList<>(); 17 | pointSet.add(new GeometryFactory().createPoint(new Coordinate(6.82, 8.23))); 18 | pointSet.add(new GeometryFactory().createPoint(new Coordinate(7.37, 6.06))); 19 | pointSet.add(new GeometryFactory().createPoint(new Coordinate(8.23, 9.51))); 20 | pointSet.add(new GeometryFactory().createPoint(new Coordinate(7.61, 6.37))); 21 | pointSet.add(new GeometryFactory().createPoint(new Coordinate(9.16, 8.91))); 22 | pointSet.add(new GeometryFactory().createPoint(new Coordinate(9.35, 7.46))); 23 | pointSet.add(new GeometryFactory().createPoint(new Coordinate(7.45, 8.27))); 24 | pointSet.add(new GeometryFactory().createPoint(new Coordinate(5.43, 9.44))); 25 | pointSet.add(new GeometryFactory().createPoint(new Coordinate(5.15, 9.83))); 26 | pointSet.add(new GeometryFactory().createPoint(new Coordinate(8.15, 5.11))); 27 | pointSet.add(new GeometryFactory().createPoint(new Coordinate(9.58, 8.48))); 28 | pointSet.add(new GeometryFactory().createPoint(new Coordinate(8.6, 8.79))); 29 | pointSet.add(new GeometryFactory().createPoint(new Coordinate(8.15, 9.09))); 30 | pointSet.add(new GeometryFactory().createPoint(new Coordinate(6.66, 6.94))); 31 | pointSet.add(new GeometryFactory().createPoint(new Coordinate(5.49, 9.69))); 32 | 33 | MinCircle circle = WelzlAlgo.mec(pointSet, pointSet.size() - 1); 34 | Geometry buffer = circle.getCenter().buffer(circle.getR()); 35 | System.out.println(buffer); 36 | pointSet.forEach(s -> System.out.println(s)); 37 | 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/com/huifer/planar/aset/entity/MyLineTest.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.entity; 2 | 3 | 4 | import com.huifer.planar.aset.algo.LineOverInterface; 5 | import com.huifer.planar.aset.algo.impl.ovlayer.LineOverCore; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.junit.Test; 8 | 9 | @Slf4j 10 | public class MyLineTest { 11 | 12 | 13 | @Test 14 | public void testIntersect() { 15 | // MyPoint p1 = new MyPoint(2.44, 1.81); 16 | // MyPoint p2 = new MyPoint(2.1,1.05); 17 | // MyPoint p3 = new MyPoint(-0.2,1.72); 18 | // MyPoint p4 = new MyPoint(2.54,0.73); 19 | // 20 | // MyLine l1 = new MyLine(p1, p2); 21 | // MyLine l2 = new MyLine(p3, p4); 22 | // 23 | // boolean intresect = MyLine.isIntresect(l1, l2); 24 | // System.out.println(intresect); 25 | // MyPoint intersect = MyLine.intersect(l1, l2); 26 | // System.out.println(intersect); 27 | // MyPoint myPoint = new MyPoint(); 28 | // MyLine.getProjectivePoint(new MyPoint(0, 0), 0.5, new MyPoint(1, 1), myPoint); 29 | // System.out.println(myPoint); 30 | 31 | // MyLine l = new MyLine(new MyPoint(10, 0), new MyPoint(10, 10)); 32 | // MyPoint p1 = new MyPoint(7, 7); 33 | // MyPoint p2 = new MyPoint(7, 4); 34 | // MyPoint p3 = new MyPoint(12, 7); 35 | // MyPoint p4 = new MyPoint(12, 4); 36 | // System.out.println(l); 37 | // MyPoint projectivePoint = l.getProjectivePoint(p1); 38 | // System.out.println(projectivePoint); 39 | // 40 | LineOverInterface over = new LineOverCore(); 41 | 42 | MyLine l1 = new MyLine(new MyPoint(2, 0), new MyPoint(2, 3)); 43 | MyLine l2 = new MyLine(new MyPoint(0, 2), new MyPoint(3, 2)); 44 | MyPoint intersect = over.intersectPoint(l1, l2); 45 | // System.out.println(intersect); 46 | log.info("{}", intersect); 47 | } 48 | 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/com/huifer/planar/aset/entity/MyPointTest.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.entity; 2 | 3 | 4 | import org.junit.Test; 5 | 6 | public class MyPointTest { 7 | 8 | @Test 9 | public void testRotate() { 10 | MyPoint p = new MyPoint(1, 1); 11 | MyPoint myPoint = p.rotatePoint(new MyPoint(0, 0), 30); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/test/java/com/huifer/planar/aset/entity/PublicRadialTest.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.entity; 2 | 3 | import org.junit.Test; 4 | import org.locationtech.jts.geom.Coordinate; 5 | import org.locationtech.jts.geom.GeometryFactory; 6 | 7 | public class PublicRadialTest { 8 | 9 | @Test 10 | public void te() { 11 | PublicRadial pr1 = new PublicRadial(new GeometryFactory().createPoint(new Coordinate(0, 0)), 12 | new GeometryFactory().createPoint(new Coordinate(0, 1))); 13 | PublicRadial pr2 = new PublicRadial(new GeometryFactory().createPoint(new Coordinate(0, 3)), 14 | new GeometryFactory().createPoint(new Coordinate(1, 2))); 15 | 16 | double a1 = pr1.getA(); 17 | double b1 = pr1.getB(); 18 | double c1 = pr1.getC(); 19 | 20 | double a2 = pr2.getA(); 21 | double b2 = pr2.getB(); 22 | double c2 = pr2.getC(); 23 | double x = (c1 - b1 * c1 + b1 * c2) / (a1 * b1 - a2 * b1 - a1); 24 | double y = -(a1 * (c1 - c1 * b1 + b1 * c2) / (a1 * b1 - a2 * b1 - a1) + c1) / b1; 25 | 26 | 27 | System.out.println(y > 0); 28 | 29 | System.out.println(x); 30 | System.out.println(y); 31 | 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/com/huifer/planar/aset/mappingalgo/ConvolutionTest.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.mappingalgo; 2 | 3 | import org.junit.Test; 4 | 5 | public class ConvolutionTest { 6 | @Test 7 | public void conTest() { 8 | Convolution.main(new String[]{}); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/test/java/com/huifer/planar/aset/mappingalgo/coortrans/CoortransTest.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.mappingalgo.coortrans; 2 | 3 | import com.huifer.planar.aset.mappingalgo.coortrans.lib.*; 4 | import org.junit.Test; 5 | 6 | /** 7 | * coortrans 8 | */ 9 | public class CoortransTest { 10 | 11 | private static void printdata(AllData allData) { 12 | allData.data.stream().forEach( 13 | so -> { 14 | System.out.println(so); 15 | } 16 | ); 17 | } 18 | 19 | private static void bl2Xy(AllData allData) { 20 | // 高斯正算 21 | for (PointInfo pointInfo : allData.data) { 22 | String name = pointInfo.name; 23 | String x = Rad2Dms.rad2Str(pointInfo.b); 24 | String y = Rad2Dms.rad2Str(pointInfo.l); 25 | System.out.println(name + " | " + x + " | " + y); 26 | } 27 | } 28 | 29 | @Test 30 | public void coortransTest() { 31 | ReadHelper readHelper = new ReadHelper( 32 | "E:\\mck\\planar_algorithm\\src\\main\\java\\com\\huifer\\planar\\aset\\mappingalgo\\coortrans\\坐标数据.txt"); 33 | AllData allData = readHelper.getData(); 34 | System.out.println("============= 输入值 ============="); 35 | printdata(allData); 36 | 37 | //BLH -> XYZ 38 | // 大地测量转换为笛卡尔坐标 39 | Position position = new Position(allData.ellipsoid); 40 | for (int i = 0; i < allData.data.size(); i++) { 41 | double x, y, z; 42 | double b = allData.data.get(i).b; 43 | double l = allData.data.get(i).l; 44 | double h = allData.data.get(i).h; 45 | double[] cartesian = position.geodetic2Cartesian(b, l, h); 46 | allData.data.get(i).x = cartesian[0]; 47 | allData.data.get(i).y = cartesian[1]; 48 | allData.data.get(i).z = cartesian[2]; 49 | } 50 | System.out.println("============= 大地坐标转笛卡尔坐标系 ============="); 51 | printdata(allData); 52 | 53 | Gauss gauss = new Gauss(allData.ellipsoid, allData.l0); 54 | for (int i = 0; i < allData.data.size(); i++) { 55 | double b = allData.data.get(i).b; 56 | double l = allData.data.get(i).l; 57 | double[] xy = gauss.bl2Xy(b, l); 58 | allData.data.get(i).gsx = xy[0]; 59 | allData.data.get(i).gsy = xy[1]; 60 | } 61 | System.out.println("============= 大地坐标转高斯 ============="); 62 | printdata(allData); 63 | 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/com/huifer/planar/aset/mappingalgo/fanjuli/InverseDistanceCoreTest.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.mappingalgo.fanjuli; 2 | 3 | import org.junit.Test; 4 | 5 | import java.util.ArrayList; 6 | import java.util.HashMap; 7 | import java.util.List; 8 | 9 | /** 10 | * idw 11 | */ 12 | public class InverseDistanceCoreTest { 13 | 14 | @Test 15 | public void testIdw() { 16 | ReadHelper readHelper = new ReadHelper( 17 | "E:\\mck\\planar_algorithm\\src\\main\\java\\com\\huifer\\planar\\aset\\mappingalgo\\fanjuli\\测站坐标.txt"); 18 | List points = readHelper.getPoints(); 19 | 20 | List paramList = new ArrayList<>(); 21 | MyPoint p = new MyPoint("Q1", 4310, 3600, 0); 22 | HashMap idw = InverseDistanceCore.idw(points, p, 5); 23 | System.out.println(idw); 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/huifer/planar/aset/mappingalgo/grid/GridTest.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.mappingalgo.grid; 2 | 3 | import org.junit.Test; 4 | 5 | public class GridTest { 6 | 7 | 8 | @Test 9 | public void gridTest() { 10 | ReadHelper.main(new String[]{""}); 11 | 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/test/java/com/huifer/planar/aset/mappingalgo/sortpath/SortPathRuntTest.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.mappingalgo.sortpath; 2 | 3 | import org.junit.Test; 4 | 5 | public class SortPathRuntTest { 6 | 7 | @Test 8 | public void sortPathTest() throws Exception { 9 | SortPathRunt.main(new String[]{}); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/test/java/com/huifer/planar/aset/mappingalgo/trajectorycompression/DpLineTest.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.mappingalgo.trajectorycompression; 2 | 3 | import org.junit.Test; 4 | 5 | public class DpLineTest { 6 | @Test 7 | public void dpLine() { 8 | DpLine.main(new String[]{}); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/test/java/com/huifer/planar/aset/mappingalgo/zongduanmian/ZongduanmianTest.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.mappingalgo.zongduanmian; 2 | 3 | import org.junit.Test; 4 | 5 | public class ZongduanmianTest { 6 | 7 | @Test 8 | public void zdmTest() { 9 | Zongduanmian.main(new String[]{}); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/com/huifer/planar/aset/utils/KmeansTest.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.utils; 2 | 3 | import com.huifer.planar.aset.entity.Kmeans; 4 | import org.junit.Test; 5 | 6 | public class KmeansTest { 7 | @Test 8 | public void KmeanRunTest() { 9 | int n = 20; 10 | double[][] points = new double[n][2]; 11 | double[] a_1 = new double[]{1, 3}; 12 | double[] a_2 = new double[]{7, 7}; 13 | double[] a_3 = new double[]{4, 4}; 14 | double[] a_4 = new double[]{3, 8}; 15 | double[] a_5 = new double[]{4, 8}; 16 | double[] a_6 = new double[]{8, 6}; 17 | double[] a_7 = new double[]{8, 9}; 18 | double[] a_8 = new double[]{3, 9}; 19 | double[] a_9 = new double[]{2, 7}; 20 | double[] a_10 = new double[]{6, 5}; 21 | double[] a_11 = new double[]{7, 5}; 22 | double[] a_12 = new double[]{3, 1}; 23 | double[] a_13 = new double[]{5, 2}; 24 | double[] a_14 = new double[]{3, 3}; 25 | double[] a_15 = new double[]{8, 9}; 26 | double[] a_16 = new double[]{3, 3}; 27 | double[] a_17 = new double[]{9, 6}; 28 | double[] a_18 = new double[]{5, 2}; 29 | double[] a_19 = new double[]{6, 4}; 30 | double[] a_20 = new double[]{9, 2}; 31 | points[0] = a_1; 32 | points[1] = a_2; 33 | points[2] = a_3; 34 | points[3] = a_4; 35 | points[4] = a_5; 36 | points[5] = a_6; 37 | points[6] = a_7; 38 | points[7] = a_8; 39 | points[8] = a_9; 40 | points[9] = a_10; 41 | points[10] = a_11; 42 | points[11] = a_12; 43 | points[12] = a_13; 44 | points[13] = a_14; 45 | points[14] = a_15; 46 | points[15] = a_16; 47 | points[16] = a_17; 48 | points[17] = a_18; 49 | points[18] = a_19; 50 | points[19] = a_20; 51 | 52 | int k = 3; 53 | Kmeans kmeans = new Kmeans(points, k); 54 | 55 | double[][] centroids = kmeans.getCentroids(); 56 | System.out.println(); 57 | // int[] init = kmeans.init(); 58 | // List list1 = Arrays.stream(init).boxed().collect(Collectors.toList()); 59 | // System.out.println(list1); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/com/huifer/planar/aset/utils/PolygonUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.utils; 2 | 3 | import org.junit.Test; 4 | import org.locationtech.jts.geom.Geometry; 5 | import org.locationtech.jts.geom.GeometryFactory; 6 | import org.locationtech.jts.geom.LineString; 7 | import org.locationtech.jts.geom.Polygon; 8 | import org.locationtech.jts.io.WKTReader; 9 | 10 | public class PolygonUtilsTest { 11 | 12 | @Test 13 | public void testSplit() throws Exception { 14 | String wkt = "POLYGON ((88064.3489745457 73720.9215322899,88064.123424185 73716.9969560137,88068.4765461465 73716.0947545709,88068.950201904 73719.1396844404,88066.8074734774 73717.4931668073,88067.348794343 73720.312546316,88065.7022767099 73718.4855883943,88066.063157287 73721.7109585523,88064.9579605196 73719.4780099814,88064.3489745457 73720.9215322899))"; 15 | Geometry rs = new WKTReader().read(wkt); 16 | Polygon polygon1 = new GeometryFactory().createPolygon(rs.getCoordinates()); 17 | String li = "LINESTRING (88064.98762193692 73716.0947545709, 88072.29638054271 73721.7109585523)"; 18 | Geometry ls = new WKTReader().read(wkt); 19 | LineString lineString = new GeometryFactory().createLineString(ls.getCoordinates()); 20 | Geometry geometry = PolygonUtils.splitPolygon(polygon1, lineString); 21 | int numGeometries = geometry.getNumGeometries(); 22 | for (int i = 0; i < numGeometries; i++) { 23 | Geometry geometryN = geometry.getGeometryN(i); 24 | System.out.println(geometryN); 25 | } 26 | 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/com/huifer/planar/aset/utils/TmeanLengthTest.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.utils; 2 | 3 | import org.junit.Test; 4 | 5 | public class TmeanLengthTest { 6 | 7 | @Test 8 | public void tmeanLengthTest() throws Exception { 9 | 10 | TmeanLength.main(new String[]{}); 11 | 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/test/java/com/huifer/planar/aset/utils/geo/GeoJsonUtilTest.java: -------------------------------------------------------------------------------- 1 | package com.huifer.planar.aset.utils.geo; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.geotools.data.simple.SimpleFeatureCollection; 5 | import org.geotools.data.simple.SimpleFeatureIterator; 6 | import org.junit.Test; 7 | import org.opengis.feature.simple.SimpleFeature; 8 | import org.opengis.feature.simple.SimpleFeatureType; 9 | 10 | import java.io.IOException; 11 | 12 | @Slf4j 13 | public class GeoJsonUtilTest { 14 | 15 | 16 | @Test 17 | public void jsonTgeojson() throws IOException { 18 | String geoJsonPath = "F:\\desktop\\sheng\\sf.geojson"; 19 | SimpleFeatureCollection collection = GeoJsonUtil.readGeoJsonByFeatureJSON(geoJsonPath); 20 | SimpleFeatureIterator features = collection.features(); 21 | while (features.hasNext()) { 22 | SimpleFeature next = features.next(); 23 | SimpleFeatureType featureType = next.getFeatureType(); 24 | // System.out.println(next.getAttributes()); 25 | log.info("geojson data = {}", next.getAttributes()); 26 | } 27 | // System.out.println(collection); 28 | 29 | //language=JSON 30 | String json = "[\n" 31 | + " {\n" 32 | + " \"id\": 1,\n" 33 | + " \"x\": 1,\n" 34 | + " \"y\": 1\n" 35 | + " }, {\n" 36 | + " \"id\": 2,\n" 37 | + " \"x\": 2,\n" 38 | + " \"y\": 2\n" 39 | + "}\n" 40 | + "]"; 41 | String s = GeoJsonUtil.jsonToGeoJson(json, "x", "y", 1); 42 | // System.out.println(s); 43 | 44 | } 45 | } 46 | --------------------------------------------------------------------------------