JTS学习笔记

简介

JTS由加拿大的VividSolutions公司开发,是一个用Java语言描述的几何拓扑套件,遵循OpenGIS的Simple Feature Specification,封装了2D几何类型和非常多的空间分析操作,而且包含了不少常见的计算几何算法实现。
JTS被广泛地应用在开源GIS软件中,作为GeoTools和基于GeoTools的GeoServer和uDig的底层库。

JTS官方文档
WKT 在线查看工具

Maven 依赖

<dependency><groupId>com.vividsolutions</groupId><artifactId>jts</artifactId><version>1.13</version>
</dependency>

几何模型

Point 点

在这里插入图片描述

Coordinate coord = new Coordinate(102.6806945800781 24.999259605696068);
Point point = new GeometryFactory().createPoint( coord );

WKTReader reader = new WKTReader(new GeometryFactory());
Point point = (Point)reader.read("POINT(102.6806945800781 24.999259605696068)");

MultiPoint 多点

在这里插入图片描述

WKTReader reader = new WKTReader(new GeometryFactory());
MultiPoint mpoint = (MultiPoint)reader.read("MULTIPOINT((102.6806945800781 24.999259605696068),(102.6811065673828 24.99851282550918))");

LineString 线

在这里插入图片描述

Coordinate[] coords  = new Coordinate[]{new Coordinate(102.67990493826801, 24.999349063221004), new Coordinate(102.68184471235142, 24.9966108454865)};
LineString line = new GeometryFactory().createLineString(coords);

WKTReader reader = new WKTReader(new GeometryFactory());
LineString line = (LineString)reader.read("LINESTRING(102.67990493826801 24.999349063221004,102.68184471235142 24.9966108454865)");

MultiLineString 多线

在这里插入图片描述

GeometryFactory geometryFactory = new GeometryFactory();
Coordinate[] coords1  = new Coordinate[] {new Coordinate(102.67990493826801, 24.999349063221004), new Coordinate(102.68184471235142, 24.9966108454865)};
LineString line1 = geometryFactory.createLineString(coords1);
Coordinate[] coords2  = new Coordinate[] {new Coordinate(102.68017959647113, 24.999504642938945), new Coordinate(102.68335533194477,24.997575452644412)};
LineString line2 = geometryFactory.createLineString(coords2);
LineString[] lineStrings = new LineString[2];
lineStrings[0]= line1;
lineStrings[1] = line2;
MultiLineString ms = geometryFactory.createMultiLineString(lineStrings);

WKTReader reader = new WKTReader(new GeometryFactory());
MultiLineString line = (MultiLineString)reader.read("MULTILINESTRING((102.67990493826801 24.999349063221004,102.68184471235142 24.9966108454865),(102.68017959647113 24.999504642938945,102.68335533194477 24.997575452644412))");

Polygon 面

在这里插入图片描述

WKTReader reader = new WKTReader(new GeometryFactory());
Polygon polygon = (Polygon)reader.read("POLYGON((102.68002510070801 24.99920904358541,102.68057441790008 24.99844670247988,102.68141555759941 24.99892900051202,102.68071174621583 24.999675779831406,102.68002510070801 24.99920904358541))");

MultiPolygon 多面

在这里插入图片描述

WKTReader reader = new WKTReader(new GeometryFactory());
MultiPolygon mpolygon = (MultiPolygon) reader.read("MULTIPOLYGON(((40 10, 30 0, 40 10, 30 20, 40 10),(30 10, 30 0, 40 10, 30 20, 30 10)))");

GeometryCollection 几何集合

在这里插入图片描述

GeometryFactory geometryFactory = new GeometryFactory();
LineString line = (LineString)reader.read("LINESTRING(102.67990493826801 24.999349063221004,102.68184471235142 24.9966108454865)");
Polygon polygon = (Polygon)reader.read("POLYGON((102.68002510070801 24.99920904358541,102.68057441790008 24.99844670247988,102.68141555759941 24.99892900051202,102.68071174621583 24.999675779831406,102.68002510070801 24.99920904358541))");
Geometry g1 = geometryFactory.createGeometry(line);
Geometry g2 = geometryFactory.createGeometry(polygon);
GeometryCollection gc = geometryFactory.createGeometryCollection(new Geometry[]{g1,g2});

Circle 圆

在这里插入图片描述

    /*** create a Circle  创建一个圆,圆心(x,y) 半径RADIUS* @param x* @param y* @param RADIUS* @return*/public Polygon createCircle(double x, double y, final double RADIUS){GeometryFactory geometryFactory = new GeometryFactory();final int SIDES = 32;//圆上面的点个数Coordinate coords[] = new Coordinate[SIDES+1];for( int i = 0; i < SIDES; i++){double angle = ((double) i / (double) SIDES) * Math.PI * 2.0;double dx = Math.cos( angle ) * RADIUS;double dy = Math.sin( angle ) * RADIUS;coords[i] = new Coordinate( (double) x + dx, (double) y + dy );}coords[SIDES] = coords[0];LinearRing ring = geometryFactory.createLinearRing( coords );Polygon polygon = geometryFactory.createPolygon( ring, null );return polygon;}

几何操作

拓扑有效性检查

WKTReader reader = new WKTReader(new GeometryFactory());
Polygon polygon = (Polygon)reader.read("POLYGON((102.68002510070801 24.99920904358541,102.68057441790008 24.99844670247988,102.68141555759941 24.99892900051202,102.68071174621583 24.999675779831406,102.68002510070801 24.99920904358541))");
boolean valid = polygon.isValid();
System.out.println("valid: " + valid);

面积计算

WKTReader reader = new WKTReader(new GeometryFactory());
Polygon polygon = (Polygon)reader.read("POLYGON((102.68002510070801 24.99920904358541,102.68057441790008 24.99844670247988,102.68141555759941 24.99892900051202,102.68071174621583 24.999675779831406,102.68002510070801 24.99920904358541))");
double area = polygon.getArea();

长度/周长计算

WKTReader reader = new WKTReader(new GeometryFactory());
LineString line = (LineString)reader.read("LINESTRING(102.67990493826801 24.999349063221004,102.68184471235142 24.9966108454865)");
double length = line.getLength();

WKTReader reader = new WKTReader(new GeometryFactory());
Polygon polygon = (Polygon)reader.read("POLYGON((102.68002510070801 24.99920904358541,102.68057441790008 24.99844670247988,102.68141555759941 24.99892900051202,102.68071174621583 24.999675779831406,102.68002510070801 24.99920904358541))");
double length = polygon.getLength();

距离计算

在这里插入图片描述

几何之间的距离

WKTReader reader = new WKTReader(new GeometryFactory());
Polygon polygon1 = (Polygon)reader.read("POLYGON((102.6797633172391 24.999400600015505,102.68005084991454 24.99904665764305,102.68069887187445 24.99930336322602,102.68021821982254 24.999626189041066,102.6797633172391 24.999400600015505))");
Polygon polygon2 = (Polygon)reader.read("POLYGON((102.68460845934166 24.99876272521388,102.68482732785922 24.998509908088764,102.68520498301947 24.998778283233165,102.68496894862618 24.998968867993526,102.68460845934166 24.99876272521388))");
double distance = polygon1.distance(polygon2); // 0.003946791560736727

几何之间的距离是否在指定范围内

WKTReader reader = new WKTReader(new GeometryFactory());
Polygon polygon1 = (Polygon)reader.read("POLYGON((102.6797633172391 24.999400600015505,102.68005084991454 24.99904665764305,102.68069887187445 24.99930336322602,102.68021821982254 24.999626189041066,102.6797633172391 24.999400600015505))");
Polygon polygon2 = (Polygon)reader.read("POLYGON((102.68460845934166 24.99876272521388,102.68482732785922 24.998509908088764,102.68520498301947 24.998778283233165,102.68496894862618 24.998968867993526,102.68460845934166 24.99876272521388))");
double distance = polygon1.distance(polygon2); // 0.003946791560736727
boolean withinDistance = polygon1.isWithinDistance(polygon2, 0.00395); // true

空间关系

contains 包含

在这里插入图片描述

WKTReader reader = new WKTReader(new GeometryFactory());
Polygon polygon1 = (Polygon)reader.read("POLYGON((102.6804885866877 24.999426853935475,102.68218803458147 24.996984242282693,102.6862392441253 24.999426853935475,102.68407630972796 25.0016204947501,102.6804885866877 24.999426853935475))");
Polygon polygon2 = (Polygon)reader.read("POLYGON((102.68181037876637 24.999302390976425,102.68265151977538 24.998088869480398,102.68426513829034 24.998866769330263,102.68316650390624 25.00009583951264,102.68181037876637 24.999302390976425))");
boolean contains = polygon1.contains(polygon2); // true

within 内含

在这里插入图片描述

WKTReader reader = new WKTReader(new GeometryFactory());
Polygon polygon1 = (Polygon)reader.read("POLYGON((102.6804885866877 24.999426853935475,102.68218803458147 24.996984242282693,102.6862392441253 24.999426853935475,102.68407630972796 25.0016204947501,102.6804885866877 24.999426853935475))");
Polygon polygon2 = (Polygon)reader.read("POLYGON((102.68181037876637 24.999302390976425,102.68265151977538 24.998088869480398,102.68426513829034 24.998866769330263,102.68316650390624 25.00009583951264,102.68181037876637 24.999302390976425))");
boolean within = polygon2.within(polygon1); // true

covers 覆盖

在这里插入图片描述

WKTReader reader = new WKTReader(new GeometryFactory());
Polygon polygon1 = (Polygon)reader.read("POLYGON((102.6804885866877 24.999426853935475,102.68218803458147 24.996984242282693,102.6862392441253 24.999426853935475,102.68407630972796 25.0016204947501,102.6804885866877 24.999426853935475))");
Polygon polygon2 = (Polygon)reader.read("POLYGON((102.68181037876637 24.999302390976425,102.68265151977538 24.998088869480398,102.68426513829034 24.998866769330263,102.68316650390624 25.00009583951264,102.68181037876637 24.999302390976425))");
boolean contains = polygon1.contains(polygon2); // true

coveredBy 被掩盖

在这里插入图片描述

WKTReader reader = new WKTReader(new GeometryFactory());
Polygon polygon1 = (Polygon)reader.read("POLYGON((102.6804885866877 24.999426853935475,102.68218803458147 24.996984242282693,102.6862392441253 24.999426853935475,102.68407630972796 25.0016204947501,102.6804885866877 24.999426853935475))");
Polygon polygon2 = (Polygon)reader.read("POLYGON((102.68181037876637 24.999302390976425,102.68265151977538 24.998088869480398,102.68426513829034 24.998866769330263,102.68316650390624 25.00009583951264,102.68181037876637 24.999302390976425))");
boolean coveredBy = polygon2.coveredBy(polygon1); // true

intersects 相交

在这里插入图片描述

WKTReader reader = new WKTReader(new GeometryFactory());
Polygon polygon1 = (Polygon)reader.read("POLYGON((102.6800594337692 24.999333506401584,102.68167304966484 24.9970931497745,102.6822910316696 24.99741987072126,102.68047142002617 24.999582432724026,102.6800594337692 24.999333506401584))");
Polygon polygon2 = (Polygon)reader.read("POLYGON((102.67961311314139 24.998508934467893,102.6800594337692 24.997871055927746,102.68199920654297 24.998897883678765,102.68134689409635 24.999566874509824,102.67961311314139 24.998508934467893))");
boolean intersects = polygon1.intersects(polygon2); // true

disjoint 脱节(不相交)

在这里插入图片描述

WKTReader reader = new WKTReader(new GeometryFactory());
Polygon polygon1 = (Polygon)reader.read("POLYGON((102.68004226658377 24.999489085070962,102.68153572134909 24.99757545240702,102.68210220310722 24.997995519624396,102.68066024858854 24.999738011078236,102.68004226658377 24.999489085070962))");
Polygon polygon2 = (Polygon)reader.read("POLYGON((102.68148422241212 25.00015807208976,102.68198204066721 24.999489085070962,102.68464279331965 25.00098263176963,102.68387031712336 25.001573822062696,102.68148422241212 25.00015807208976))");
boolean disjoint = polygon1.disjoint(polygon2); // true

crosses 交叉

在这里插入图片描述

WKTReader reader = new WKTReader(new GeometryFactory());
LineString line1 = (LineString)reader.read("LINESTRING(102.68007659964496 24.999442411573924,102.68392181344099 24.9978243822909)");
LineString line2 = (LineString)reader.read("LINESTRING(102.68076324515278 25.00000249414873,102.68273735098774 24.997310964706003)");
boolean crosses = line1.crosses(line2); // true

overlaps 重叠

在这里插入图片描述

WKTReader reader = new WKTReader(new GeometryFactory());
Polygon polygon1 = (Polygon)reader.read("POLYGON((102.67993927001955 24.99931794744367,102.6806774144643 24.99833779773074,102.68199920654297 24.999022348115815,102.6811065679067 24.99995582025325,102.67993927001955 24.99931794744367))");
Polygon polygon2 = (Polygon)reader.read("POLYGON((102.68047142002615 24.998384470460365,102.68235969517264 24.99933350628288,102.68282318167621 24.998648957631303,102.68095207240549 24.9978088238541,102.68047142002615 24.998384470460365))");
boolean overlaps = polygon1.overlaps(polygon2); // true

touches 接触

在这里插入图片描述

WKTReader reader = new WKTReader(new GeometryFactory());
Polygon polygon1 = (Polygon)reader.read("POLYGON((1 0,6 0,6 5,1 5,1 0))");
Polygon polygon2 = (Polygon)reader.read("POLYGON((6 0,6 1,7 1,7 0,6 0))");
boolean touches = polygon1.touches(polygon2); // true

equals 等于

在这里插入图片描述

WKTReader reader = new WKTReader(new GeometryFactory());
Polygon polygon1 = (Polygon)reader.read("POLYGON((102.68002510070801 24.99920904358541,102.68057441790008 24.99844670247988,102.68141555759941 24.99892900051202,102.68071174621583 24.999675779831406,102.68002510070801 24.99920904358541))");
boolean equals = polygon1.equals(polygon1); // true

relate 关系

测试两个几何体是否与 DE-9IM表达式(官方文档) 中的关系一致。
在这里插入图片描述

WKTReader reader = new WKTReader(new GeometryFactory());
Polygon polygon1 = (Polygon)reader.read("POLYGON((102.6800594337692 24.999333506401584,102.68167304966484 24.9970931497745,102.6822910316696 24.99741987072126,102.68047142002617 24.999582432724026,102.6800594337692 24.999333506401584))");
Polygon polygon2 = (Polygon)reader.read("POLYGON((102.67961311314139 24.998508934467893,102.6800594337692 24.997871055927746,102.68199920654297 24.998897883678765,102.68134689409635 24.999566874509824,102.67961311314139 24.998508934467893))");
boolean relate = polygon1.relate(polygon2, "T*T***T**"); // true

空间分析

intersection 交叉分析

在这里插入图片描述

WKTReader reader = new WKTReader(new GeometryFactory());
Polygon polygon1 = (Polygon)reader.read("POLYGON((102.67981910705566 24.999370456440957,102.68139839250942 24.99718455412153,102.68242836077113 24.997830216333284,102.68060016684466 24.999860529046316,102.67981910705566 24.999370456440957))");
Polygon polygon2 = (Polygon)reader.read("POLYGON((102.67986202239989 24.999043740680463,102.68028259355924 24.99845253791706,102.68199920732876 24.999292666996425,102.6815443044179 25.00003166473097,102.67986202239989 24.999043740680463))");
Geometry intersection = polygon1.intersection(polygon2);

在这里插入图片描述

difference 差异分析

,
在这里插入图片描述

WKTReader reader = new WKTReader(new GeometryFactory());
Polygon polygon1 = (Polygon)reader.read("POLYGON((102.67981910705566 24.999370456440957,102.68139839250942 24.99718455412153,102.68242836077113 24.997830216333284,102.68060016684466 24.999860529046316,102.67981910705566 24.999370456440957))");
Polygon polygon2 = (Polygon)reader.read("POLYGON((102.67986202239989 24.999043740680463,102.68028259355924 24.99845253791706,102.68199920732876 24.999292666996425,102.6815443044179 25.00003166473097,102.67986202239989 24.999043740680463))");
Geometry difference = polygon1.difference(polygon2);

在这里插入图片描述

union 联合分析

在这里插入图片描述

WKTReader reader = new WKTReader(new GeometryFactory());
Polygon polygon1 = (Polygon)reader.read("POLYGON((102.67981910705566 24.999370456440957,102.68139839250942 24.99718455412153,102.68242836077113 24.997830216333284,102.68060016684466 24.999860529046316,102.67981910705566 24.999370456440957))");
Polygon polygon2 = (Polygon)reader.read("POLYGON((102.67986202239989 24.999043740680463,102.68028259355924 24.99845253791706,102.68199920732876 24.999292666996425,102.6815443044179 25.00003166473097,102.67986202239989 24.999043740680463))");
Geometry union = polygon1.union(polygon2);

在这里插入图片描述

symmetric difference 对称差异分析

在这里插入图片描述

WKTReader reader = new WKTReader(new GeometryFactory());
Polygon polygon1 = (Polygon)reader.read("POLYGON((102.67981910705566 24.999370456440957,102.68139839250942 24.99718455412153,102.68242836077113 24.997830216333284,102.68060016684466 24.999860529046316,102.67981910705566 24.999370456440957))");
Polygon polygon2 = (Polygon)reader.read("POLYGON((102.67986202239989 24.999043740680463,102.68028259355924 24.99845253791706,102.68199920732876 24.999292666996425,102.6815443044179 25.00003166473097,102.67986202239989 24.999043740680463))");
Geometry symDifference = polygon1.symDifference(polygon2);

在这里插入图片描述

Buffer 缓冲区分析

在这里插入图片描述

WKTReader reader = new WKTReader(new GeometryFactory());
Polygon polygon1 = (Polygon)reader.read("POLYGON((102.67981910705566 24.999370456440957,102.68139839250942 24.99718455412153,102.68242836077113 24.997830216333284,102.68060016684466 24.999860529046316,102.67981910705566 24.999370456440957))");
Geometry buffer = polygon1.buffer(0.0005);

在这里插入图片描述

Convex hull 凸包分析

在这里插入图片描述

WKTReader reader = new WKTReader(new GeometryFactory());
MultiPoint multiPoint = (MultiPoint)reader.read("MULTIPOINT((102.6818618774414 24.999333506639005),(102.68241119463345 24.998571167492628),(102.68380165152485 24.998446703666872),(102.68666839599608 25.00062480449344),(102.68536377110284 25.00120043909439),(102.68320083670551 25.000095840462194))");
Geometry convexHull = multiPoint.convexHull();

在这里插入图片描述

精度操作

精度模型

精度模型是数值计算的核心,JTS适用于默认的双精度模型。当使用较大的值时,Java中内置的数学并不是非常精确,可以通过配置 GeometryFactoryPrecisionModel 使用不同的精度。
通过显式捕获PrecisionModel JTS中的”round-off”过程,JTS允许管理这类错误,并对工作的速度和准确性进行适当的权衡。Round-off(例如 :6.0000001)经常发生即使是双精度模型。尤其是你的工作坐标系数字很大并且离着原点很远。这里面其实也是根据需要,如果你的使用精度要求不那么高那么可以减小精度模型。

精度操作(降低精度)

精度模型常量:

  • FIXED 固定精度表示坐标有固定的小数位数,小数点的位数由比例因子的对数10决定;
  • FLOATING 浮动精度对应于标准的Java双精度浮点表示,它是基于IEEE-754标准的;
  • FLOATING_SINGLE 浮动单精度对应于标准的Java单精度浮点表示,它是基于IEEE-754标准的。
PrecisionModel precisionModel = new PrecisionModel(PrecisionModel.FLOATING_SINGLE);
WKTReader reader = new WKTReader(new GeometryFactory(precisionModel));
Polygon polygon1 = (Polygon)reader.read("POLYGON((102.67981910705566 24.999370456440957,102.68139839250942 24.99718455412153,102.68242836077113 24.997830216333284,102.68060016684466 24.999860529046316,102.67981910705566 24.999370456440957))");
Polygon polygon2 = (Polygon)reader.read("POLYGON((102.67986202239989 24.999043740680463,102.68028259355924 24.99845253791706,102.68199920732876 24.999292666996425,102.6815443044179 25.00003166473097,102.67986202239989 24.999043740680463))");
Geometry intersection = polygon1.intersection(polygon2);
System.out.println(intersection.toText());

使用 precisionModel 前:

POLYGON ((102.6804301249854 24.998524741369838, 102.67999762227275 24.99912337202302, 102.68082593508016 24.999609800656877, 102.68138303750645 24.99899110691649, 102.6804301249854 24.998524741369838))

使用 precisionModel 后:

POLYGON ((102.680428 24.998524, 102.679993 24.999123, 102.680824 24.999611, 102.681381 24.998991, 102.680428 24.998524))

几何结构

Delaunay三角剖分

从点的集合中创建三角剖分,并提取产生的三角形边缘 / 三角形作为几何图形。
在这里插入图片描述

GeometryFactory geometryFactory = new GeometryFactory();
WKTReader reader = new WKTReader(geometryFactory);
MultiPoint multiPoint = (MultiPoint)reader.read("MULTIPOINT((102.68194556236264 24.99925377243376), (102.6823854446411 24.998563388737196), (102.68381237983702 24.998495322528882), (102.68659114837645 25.000615081033544), (102.68534660339354 25.00118877085464))");DelaunayTriangulationBuilder builder = new DelaunayTriangulationBuilder();
builder.setSites(multiPoint);// 实际为GeometryCollection(组成的geometry紧密相连)
Geometry geometry = builder.getTriangles(geometryFactory);
System.out.println(geometry.toText());// 以0的距离进行缓冲(因为各多边形两两共边),生成一个多边形
// 此时则将点云构造成了多边形
Geometry buffer = geometry.buffer(0);
System.out.println(buffer.toText());

在这里插入图片描述
在这里插入图片描述

限定Delaunay三角剖分

从点的集合和线性约束中创建限定三角剖分,并提取产生的三角形边缘 / 三角形作为几何图形。
在这里插入图片描述

GeometryFactory geometryFactory = new GeometryFactory();
WKTReader reader = new WKTReader(geometryFactory);
MultiPoint multiPoint = (MultiPoint)reader.read("MULTIPOINT((102.68194556236264 24.99925377243376), (102.6823854446411 24.998563388737196), (102.68381237983702 24.998495322528882), (102.68659114837645 25.000615081033544), (102.68534660339354 25.00118877085464))");ConformingDelaunayTriangulationBuilder builder = new ConformingDelaunayTriangulationBuilder();
builder.setSites(multiPoint);// 实际为GeometryCollection(组成的geometry紧密相连)
Geometry geometry = builder.getTriangles(geometryFactory);
System.out.println(geometry.toText());// 以0的距离进行缓冲(因为各多边形两两共边),生成一个多边形
// 此时则将点云构造成了多边形
Geometry buffer = geometry.buffer(0);
System.out.println(buffer.toText());

在这里插入图片描述
在这里插入图片描述

泰森多边形图

泰森多边形(Voronoi diagram),是由荷兰气候学家A?H?Thiessen提出了一种根据离散分布的气象站的降雨量来计算平均降雨量的方法,即将所有相邻气象站连成三角形,作这些三角形各边的垂直平分线,于是每个气象站周围的若干垂直平分线便围成一个多边形。用这个多边形内所包含的一个唯一气象站的降雨强度来表示这个多边形区域内的降雨强度,并称这个多边形为泰森多边形。

从几何角度来看,两基站的分界线是两点之间连线的铅直等分线,将全平面分为两个半平面,各半平面中任何一点与本半平面内基站的间隔都要比到另一基站间隔小。当基站数量在二个以上时,全平面会划分为多个包罗一个基站的区域,区域中任何一点都与本区域内基站间隔最近,是以这些个区域可以看作是基站的覆盖区域,我们将这种由多个点将平面划分成的图称为泰森多边形,又称为Voronoi 图。

泰森多边形的特性是:

  • 每个泰森多边形内仅含有一个基站;
  • 泰森多边形区域内的点到相应基站的距离最近;
  • 位于泰森多边形边上的点到其两边的基站的距离相等。
    在这里插入图片描述
GeometryFactory geometryFactory = new GeometryFactory();
WKTReader reader = new WKTReader(geometryFactory);
MultiPoint multiPoint = (MultiPoint)reader.read("MULTIPOINT((102.68194556236264 24.99925377243376), (102.6823854446411 24.998563388737196), (102.68381237983702 24.998495322528882), (102.68659114837645 25.000615081033544), (102.68534660339354 25.00118877085464))");VoronoiDiagramBuilder builder = new VoronoiDiagramBuilder();
builder.setSites(multiPoint);Geometry geometry = builder.getDiagram(geometryFactory);
System.out.println(geometry.toText());Geometry buffer = geometry.buffer(0);
System.out.println(buffer.toText());

在这里插入图片描述
在这里插入图片描述

最小可穿过圆的直径

最小直径

最小封闭矩形

在这里插入图片描述

GeometryFactory geometryFactory = new GeometryFactory();
WKTReader reader = new WKTReader(geometryFactory);
Polygon multiPoint = (Polygon)reader.read("POLYGON((102.68198847770691 24.99927321980566,102.68244981765747 24.99862173117144,102.68380165100098 24.99857311247817,102.68649458885193 25.000624804612144,102.68589377403259 25.000935958721215,102.68534660339357 25.001091535480285,102.68315792083742 25.000012217657115,102.68198847770691 24.99927321980566))");MinimumDiameter diameter = new MinimumDiameter(multiPoint);
System.out.println(diameter.getLength());Geometry geometry = diameter.getMinimumRectangle();
System.out.println(geometry.toText());

在这里插入图片描述

最小边界圆

在这里插入图片描述

GeometryFactory geometryFactory = new GeometryFactory();
WKTReader reader = new WKTReader(geometryFactory);
Polygon multiPoint = (Polygon)reader.read("POLYGON((102.68198847770691 24.99927321980566,102.68244981765747 24.99862173117144,102.68380165100098 24.99857311247817,102.68649458885193 25.000624804612144,102.68589377403259 25.000935958721215,102.68534660339357 25.001091535480285,102.68315792083742 25.000012217657115,102.68198847770691 24.99927321980566))");MinimumBoundingCircle diameter = new MinimumBoundingCircle(multiPoint);
System.out.println(diameter.getRadius());Geometry geometry = diameter.getCircle();
System.out.println(geometry.toText());

在这里插入图片描述

度量函数

距离

在这里插入图片描述

GeometryFactory geometryFactory = new GeometryFactory();
WKTReader reader = new WKTReader(geometryFactory);Polygon multiPoint1 = (Polygon)reader.read("POLYGON((102.68017530441283 24.999487140693418,102.68065810203551 24.99887454806651,102.68160223960875 24.999312114540217,102.68085122108458 24.999924704985673,102.68017530441283 24.999487140693418))");
Polygon multiPoint2 = (Polygon)reader.read("POLYGON((102.68351197242735 25.001859692840426,102.68454194068907 25.00097485292946,102.68358707427979 25.0004692272621,102.68273949623106 25.00131517672628,102.68351197242735 25.001859692840426))");DistanceOp distance = new DistanceOp(multiPoint1, multiPoint2);
System.out.println(distance.distance());// 0.002221128437310254

豪斯多夫距离

豪斯多夫距离量度度量空间中真子集之间的距离。Hausdorff距离是另一种可以应用在边缘匹配算法的距离,它能够解决SED方法不能解决遮挡的问题。
在这里插入图片描述

GeometryFactory geometryFactory = new GeometryFactory();
WKTReader reader = new WKTReader(geometryFactory);Polygon multiPoint1 = (Polygon)reader.read("POLYGON((102.68017530441283 24.999487140693418,102.68065810203551 24.99887454806651,102.68160223960875 24.999312114540217,102.68085122108458 24.999924704985673,102.68017530441283 24.999487140693418))");
Polygon multiPoint2 = (Polygon)reader.read("POLYGON((102.68351197242735 25.001859692840426,102.68454194068907 25.00097485292946,102.68358707427979 25.0004692272621,102.68273949623106 25.00131517672628,102.68351197242735 25.001859692840426))");DiscreteHausdorffDistance distance = new DiscreteHausdorffDistance(multiPoint1, multiPoint2);
System.out.println(distance.distance());// 0.0033773571609631804

面积

在这里插入图片描述

GeometryFactory geometryFactory = new GeometryFactory();
WKTReader reader = new WKTReader(geometryFactory);Polygon multiPoint1 = (Polygon)reader.read("POLYGON((102.680025100708 24.999380180296086,102.68137693405153 24.99751322018369,102.68296480178833 24.998291123677703,102.6812481880188 25.000294202507845,102.680025100708 24.999380180296086))");
Polygon multiPoint2 = (Polygon)reader.read("POLYGON((102.68111944198608 24.99922460137013,102.68191337585448 24.99825222861996,102.68373727798462 24.998582836218347,102.68266439437866 24.999885810445036,102.68111944198608 24.99922460137013))");SimilarityMeasure similarityMeasure = new AreaSimilarityMeasure();
System.out.println(similarityMeasure.measure(multiPoint1, multiPoint2));// 0.210975468769302

豪斯多夫测度

豪斯多夫测度(Hausdorff measure)是由豪斯多夫(F.Hausdorff)提出和命名的一种测度。为了定量地描述非整数维,豪斯多夫于1919年从测量的角度引进了豪斯多夫测度。该测度是对长度、面积和体积等的推广,也是勒贝格测度的推广。
在这里插入图片描述

GeometryFactory geometryFactory = new GeometryFactory();
WKTReader reader = new WKTReader(geometryFactory);Polygon multiPoint1 = (Polygon)reader.read("POLYGON((102.68017530441283 24.999487140693418,102.68065810203551 24.99887454806651,102.68160223960875 24.999312114540217,102.68085122108458 24.999924704985673,102.68017530441283 24.999487140693418))");
Polygon multiPoint2 = (Polygon)reader.read("POLYGON((102.68351197242735 25.001859692840426,102.68454194068907 25.00097485292946,102.68358707427979 25.0004692272621,102.68273949623106 25.00131517672628,102.68351197242735 25.001859692840426))");SimilarityMeasure similarityMeasure = new HausdorffSimilarityMeasure();
System.out.println(similarityMeasure.measure(multiPoint1, multiPoint2));// 0.36149546293844836

空间算法

线段相交算法

在这里插入图片描述

Coordinate p1 = new Coordinate(102.68048644065857, 24.999477417024806);
Coordinate p2 = new Coordinate(102.68146276473998, 24.998388361268198);
Coordinate q1 = new Coordinate(102.68021821975707, 24.999030127435674);
Coordinate q2 = new Coordinate(102.68193483352661, 24.998757863410333);RobustLineIntersector intersector = new RobustLineIntersector();
intersector.computeIntersection(p1, p2, q1, q2);
System.out.println(intersector.isInteriorIntersection()); // true

计算线段排列和线段序列结点

java doc

实现线绳编码的Snap Rounding算法

java doc

确定几何体中点的拓扑位置

java doc

数学函数

角度分析

在这里插入图片描述

Angle angle = new Angle();Coordinate c1 = new Coordinate(102.68048644065857, 24.999477417024806);
Coordinate c2 = new Coordinate(102.68021821975707, 24.999030127435674);
Coordinate c3 = new Coordinate(102.68193483352661, 24.998757863410333);// 返回两个无向最小差异角度,范围 [0, 180]
double radia1 = angle.angle(c1, c2);
double radia2 = angle.angle(c2, c3);
System.out.println(angle.toDegrees(angle.diff(radia1, radia2))); // 111.93701386769487// 返回两个向量之间的最小夹角,范围[0,180]
double ang1 = angle.angleBetween(c1, c2, c3);
System.out.println(angle.toDegrees(ang1)); //68.06298613230513// 从angle到angle按什么方向旋转
// 顺时针: -1
// 逆时针: 1
System.out.println(angle.getTurn(radia1, radia2)); // 1// 判断是否是锐角
System.out.println(angle.isAcute(c1, c2, c3)); // true// 判断是否是钝角
System.out.println(angle.isObtuse(c1, c2, c3)); // false// 角度 -> 弧度的转换
System.out.println(angle.toDegrees(Math.PI)); // 180.0// 弧度 -> 角度的转换
System.out.println(angle.toRadians(180)); // 3.141592653589793

Spatial structures 空间结构

空间索引

原图形:
在这里插入图片描述
待压占测试图形:
在这里插入图片描述

四叉树

四叉树是一种空间索引结构,用于对以二维矩形为界限的项目进行有效的范围查询。几何体可以通过使用它们的包络来进行索引。任何类型的对象也可以被索引,只要它的范围可以用一个包络来表示。
这个四叉树索引为范围矩形查询提供了一个主要过滤器。各种查询方法会返回一个可能与查询矩形相交的所有项目的列表。

注意,它可能会返回事实上没有与查询矩形相交的项目。需要一个二级过滤器来测试查询矩形和每个候选项目的包络之间的实际相交。二级过滤器可以显式执行,也可以由项目的后续操作隐式提供(例如,如果索引查询之后计算了查询几何体和树形项目之间的空间谓词,则自动执行包络线交叉检查。

这个实现不需要事先指定插入的项目的范围。它将自动扩展以适应数据集的任何范围。

WKTReader reader = new WKTReader(new GeometryFactory());
Polygon polygon1 = (Polygon)reader.read("POLYGON((102.67994999885558 24.999389903972443,102.68048644065857 24.99870924477092,102.68125891685486 24.999088469648342,102.68058300018309 24.99976912674917,102.67994999885558 24.999389903972443))");
Polygon polygon2 = (Polygon)reader.read("POLYGON((102.6807117462158 24.998971785195337,102.68134474754332 24.99820360978046,102.68229961395264 24.998650902378202,102.6815378665924 24.999496864361305,102.6807117462158 24.998971785195337))");
Polygon polygon3 = (Polygon)reader.read("POLYGON((102.68196702003478 24.998670349845497,102.68261075019836 24.997950791505005,102.68352270126343 24.99851477002082,102.68287897109984 24.999321838221945,102.68196702003478 24.998670349845497))");
Polygon polygon4 = (Polygon)reader.read("POLYGON((102.6810336112976 25.000371991318303,102.6815915107727 24.999827468610945,102.68239617347716 25.000274755297553,102.68178462982178 25.000877617385797,102.6810336112976 25.000371991318303))");
Polygon polygon5 = (Polygon)reader.read("POLYGON((102.68110871315001 24.9999927704022,102.6815915107727 24.99924404874666,102.68223524093628 24.99953575902505,102.68160223960876 25.000216413648175,102.68110871315001 24.9999927704022))");
Polygon polygon6 = (Polygon)reader.read("POLYGON((102.68248200416564 25.000760934631828,102.68208503723145 24.999856639531444,102.682728767395 24.99973995580791,102.68312573432921 25.000605357454162,102.68248200416564 25.000760934631828))");
Polygon polygon7 = (Polygon)reader.read("POLYGON((102.68091559410094 24.998398085023027,102.683265209198 24.998116095820905,102.68280386924742 24.997289572017735,102.68087267875671 24.997717420327533,102.68091559410094 24.998398085023027))");Quadtree quadtree = new Quadtree();
quadtree.insert(polygon1.getEnvelopeInternal(), polygon1);
quadtree.insert(polygon2.getEnvelopeInternal(), polygon2);
quadtree.insert(polygon3.getEnvelopeInternal(), polygon3);
quadtree.insert(polygon4.getEnvelopeInternal(), polygon4);
quadtree.insert(polygon5.getEnvelopeInternal(), polygon5);
quadtree.insert(polygon6.getEnvelopeInternal(), polygon6);
quadtree.insert(polygon7.getEnvelopeInternal(), polygon7);// 点
Point q1 = (Point)reader.read("POINT(102.68122673034668 24.998563388737182)");
for (Object o : quadtree.query(q1.getEnvelopeInternal())) {Polygon polygon = (Polygon) o;if (q1.intersects(polygon)) {System.out.println(polygon.toText());}
}System.out.println("--- --- --- ---");// 线
LineString q2 = (LineString)reader.read("LINESTRING(102.68004655838013 24.999321838221945,102.68317937850951 24.997804934571022)");
for (Object o : quadtree.query(q2.getEnvelopeInternal())) {Polygon polygon = (Polygon) o;if (q2.intersects(polygon)) {System.out.println(polygon.toText());}
}System.out.println("--- --- --- ---");// 面
Polygon q3 = (Polygon)reader.read("POLYGON((102.68004655838013 24.999380180296086,102.68182754516602 24.99687144609392,102.68300771713257 24.997610458389715,102.68107652664185 24.99990525771689,102.68004655838013 24.999380180296086))");
for (Object o : quadtree.query(q3.getEnvelopeInternal())) {Polygon polygon = (Polygon) o;if (q3.intersects(polygon)) {System.out.println(polygon.toText());}
}

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

STR树

使用Sort-Tile-Recursive(STR)算法创建的纯查询R树。用于二维空间数据。
STR打包的R树实现起来很简单,并能最大限度地利用空间;也就是说,尽可能多的叶子被填充到容量。节点之间的重叠要比基本的R树少得多。然而,一旦树被建立起来(明确地或在第一次调用#query时),项目就不能被添加或删除。

请注意:

  • 向树中插入项目不是线程安全的。在一个以上的线程上进行的插入必须在外部进行同步。
  • 查询一棵树是线程安全的。

构建阶段是同步进行的,而查询是无状态的。

待压占测试图形:
在这里插入图片描述

WKTReader reader = new WKTReader(new GeometryFactory());
Polygon polygon1 = (Polygon)reader.read("POLYGON((102.67994999885558 24.999389903972443,102.68048644065857 24.99870924477092,102.68125891685486 24.999088469648342,102.68058300018309 24.99976912674917,102.67994999885558 24.999389903972443))");
Polygon polygon2 = (Polygon)reader.read("POLYGON((102.6807117462158 24.998971785195337,102.68134474754332 24.99820360978046,102.68229961395264 24.998650902378202,102.6815378665924 24.999496864361305,102.6807117462158 24.998971785195337))");
Polygon polygon3 = (Polygon)reader.read("POLYGON((102.68196702003478 24.998670349845497,102.68261075019836 24.997950791505005,102.68352270126343 24.99851477002082,102.68287897109984 24.999321838221945,102.68196702003478 24.998670349845497))");
Polygon polygon4 = (Polygon)reader.read("POLYGON((102.6810336112976 25.000371991318303,102.6815915107727 24.999827468610945,102.68239617347716 25.000274755297553,102.68178462982178 25.000877617385797,102.6810336112976 25.000371991318303))");
Polygon polygon5 = (Polygon)reader.read("POLYGON((102.68110871315001 24.9999927704022,102.6815915107727 24.99924404874666,102.68223524093628 24.99953575902505,102.68160223960876 25.000216413648175,102.68110871315001 24.9999927704022))");
Polygon polygon6 = (Polygon)reader.read("POLYGON((102.68248200416564 25.000760934631828,102.68208503723145 24.999856639531444,102.682728767395 24.99973995580791,102.68312573432921 25.000605357454162,102.68248200416564 25.000760934631828))");
Polygon polygon7 = (Polygon)reader.read("POLYGON((102.68091559410094 24.998398085023027,102.683265209198 24.998116095820905,102.68280386924742 24.997289572017735,102.68087267875671 24.997717420327533,102.68091559410094 24.998398085023027))");STRtree strTree = new STRtree();
strTree.insert(polygon1.getEnvelopeInternal(), polygon1);
strTree.insert(polygon2.getEnvelopeInternal(), polygon2);
strTree.insert(polygon3.getEnvelopeInternal(), polygon3);
strTree.insert(polygon4.getEnvelopeInternal(), polygon4);
strTree.insert(polygon5.getEnvelopeInternal(), polygon5);
strTree.insert(polygon6.getEnvelopeInternal(), polygon6);
strTree.insert(polygon7.getEnvelopeInternal(), polygon7);// 点
Point q1 = (Point)reader.read("POINT(102.68122673034668 24.998563388737182)");
for (Object o : strTree.query(q1.getEnvelopeInternal())) {Polygon polygon = (Polygon) o;if (q1.intersects(polygon)) {System.out.println(polygon.toText());}
}System.out.println("--- --- --- ---");// 线
LineString q2 = (LineString)reader.read("LINESTRING(102.68004655838013 24.999321838221945,102.68317937850951 24.997804934571022)");
for (Object o : strTree.query(q2.getEnvelopeInternal())) {Polygon polygon = (Polygon) o;if (q2.intersects(polygon)) {System.out.println(polygon.toText());}
}System.out.println("--- --- --- ---");// 面
Polygon q3 = (Polygon)reader.read("POLYGON((102.68004655838013 24.999380180296086,102.68182754516602 24.99687144609392,102.68300771713257 24.997610458389715,102.68107652664185 24.99990525771689,102.68004655838013 24.999380180296086))");
for (Object o : strTree.query(q3.getEnvelopeInternal())) {Polygon polygon = (Polygon) o;if (q3.intersects(polygon)) {System.out.println(polygon.toText());}
}

压覆图形同上!

KD树

一个2-D KD树的实现。KD树为点数据提供快速的范围搜索和快速查找。
这个实现支持检测和捕捉那些比给定距离公差更近的点。如果同一个点(在容差范围内)被插入超过一次,它就会被抢占到现有节点上。换句话说,如果一个点被插入,并且位于索引中已经存在的节点的公差范围内,那么它就会被捕捉到该节点。当一个点被卡在一个节点上时,一个新的节点不会被创建,但现有节点的计数会被增加。如果树中有多个节点在插入点的容差范围内,则会将最近的、然后是最低的节点套入。

请注意,KD树的结构取决于插入点的顺序。如果插入的点是连贯的(例如,在一个或两个维度上是单调的),那么一棵树可能会变得不平衡。一个完全平衡的树的深度只有log2(N),但一个不平衡的树可能会更深。这对查询效率有严重影响。更糟糕的是,由于递归被用于查询树,一个极深的树可能会导致StackOverflowException。解决这个问题的方法之一是在插入前随机化点的顺序(例如,通过使用Fisher-Yates洗牌)。

原图形:
在这里插入图片描述
待压占测试图形:
在这里插入图片描述

KdTree kdTree = new KdTree();
kdTree.insert(new Coordinate(102.68006801605225, 24.999321838221945));
kdTree.insert(new Coordinate(102.6806688308716, 24.998446703785575));
kdTree.insert(new Coordinate(102.68129110336305, 24.99778548696672));
kdTree.insert(new Coordinate(102.681999206543, 24.99702702799921));
kdTree.insert(new Coordinate(102.6829218864441, 24.997474324879704));
kdTree.insert(new Coordinate(102.68229961395265, 24.998291123677703));
kdTree.insert(new Coordinate(102.68161296844484, 24.99895233777569));
kdTree.insert(new Coordinate(102.68101215362549, 24.999944152251373));
kdTree.insert(new Coordinate(102.68195629119874, 25.000683146067615));
kdTree.insert(new Coordinate(102.68285751342775, 24.999827468610945));
kdTree.insert(new Coordinate(102.68347978591919, 24.998991232611843));
kdTree.insert(new Coordinate(102.68408060073854, 24.99807720070774));GeometryFactory geometryFactory = new GeometryFactory();
WKTReader reader = new WKTReader(geometryFactory);// 点 无重叠
Point q1 = (Point)reader.read("POINT(102.68122673034668 24.998563388737182)");
for (Object o : kdTree.query(q1.getEnvelopeInternal())) {KdNode node = (KdNode)o;Point point = (Point)reader.read("POINT(" + node.getX() + " " + node.getY() + ")");System.out.println(point.toText());
}System.out.println("--- --- --- ---");// 线
LineString q2 = (LineString)reader.read("LINESTRING(102.68004655838013 24.999321838221945,102.68317937850951 24.997804934571022)");
for (Object o : kdTree.query(q2.getEnvelopeInternal())) {KdNode node = (KdNode)o;Point point = (Point)reader.read("POINT(" + node.getX() + " " + node.getY() + ")");System.out.println(point.toText());
}System.out.println("--- --- --- ---");// 面
Polygon q3 = (Polygon)reader.read("POLYGON((102.68004655838013 24.999380180296086,102.68182754516602 24.99687144609392,102.68300771713257 24.997610458389715,102.68107652664185 24.99990525771689,102.68004655838013 24.999380180296086))");
for (Object o : kdTree.query(q3.getEnvelopeInternal())) {KdNode node = (KdNode)o;Point point = (Point)reader.read("POINT(" + node.getX() + " " + node.getY() + ")");System.out.println(point.toText());
}

在这里插入图片描述
在这里插入图片描述

Interval R树

包含用于实现一维区间的R树索引的包。

单调链

包含实现单调链的包。

可平面图

能在平面上画出没有相交的边的图,称为平面图(planar)。
这个类和这个包中的其他类作为一个框架,为特定的算法构建平面图。这个类必须被子类化以暴露适当的方法来构建图形。这允许控制可以被添加到图形中的图形组件(DirectedEdges、Edges和Nodes)的类型。一个使用图形框架的应用程序几乎总是为一个或多个图形组件提供子类,这些组件持有应用程序特定的数据和图形算法。

可平面图算法

在平面图上实现图算法的包。

输入/输出

WKT 导入 / 导出

GeometryFactory factory = new GeometryFactory();
// 导入
String wkt = "POLYGON((102.68004655838013 24.999380180296086,102.68182754516602 24.99687144609392,102.68300771713257 24.997610458389715,102.68107652664185 24.99990525771689,102.68004655838013 24.999380180296086))";
WKTReader reader = new WKTReader(factory);
Geometry geometry = reader.read(wkt);
System.out.println(geometry);
// 导出
WKTWriter writer = new WKTWriter(2);
String wkt2 = writer.write(geometry);
System.out.println(wkt2);

WKB 导入 / 导出

GeometryFactory factory = new GeometryFactory();
// 导入
byte[] wkb = {0, 0, 0, 0, 3, 0, 0, 0, 1, 0, 0, 0, 5, 64, 89, -85, -123, -30, 0, 0, 0, 64, 56, -1, -41, 97, 38, -92, 108, 64, 89, -85, -93, 16, 0, 0, 0, 64, 56, -1, 50, -9, -109, 74, 36, 64, 89, -85, -74, 102, 0, 0, 0, 64, 56, -1, 99, 102, 36, -18, 112, 64, 89, -85, -106, -62, 0, 0, 0, 64, 56, -1, -7, -54, 124, -2, 20, 64, 89, -85, -123, -30, 0, 0, 0, 64, 56, -1, -41, 97, 38, -92, 108};
WKBReader reader = new WKBReader(factory);
Geometry geometry = reader.read(wkb);
System.out.println(geometry);
// 导出
WKBWriter writer = new WKBWriter(2);
byte[] bytes = writer.write(geometry);
System.out.println(new String(bytes, StandardCharsets.UTF_8));

GML(V2) 导入 / 导出

GeometryFactory factory = new GeometryFactory();
// 导入
String gml = "<gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>102.68004655838013,24.999380180296086 102.68182754516602,24.99687144609392 102.68300771713257,24.997610458389715 102.68107652664185,24.99990525771689 102.68004655838013,24.999380180296086</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon>";
GMLReader reader = new GMLReader();
Geometry geometry = reader.read(gml, factory);
System.out.println(geometry);
// 导出
GMLWriter writer = new GMLWriter();
String write = writer.write(geometry);
System.out.println(write);

高精度算法

2x2双精度行列式的鲁棒性评估

执行一种算法,以稳健地计算双精度值的2x2行列式的符号。

DoubleDouble扩展精度算术

实施扩展精度的浮点数,保持106位(约30位小数)的精度。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/555194.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

填坑:Maven工程引用GeoTools依赖

这两天在做一个系统的后台&#xff0c;需要用到GeoTools做后端空间分析&#xff0c;记录一下自己遇到的问题。 项目通过Maven进行构建&#xff0c;参照文档Maven Quickstart添加GeoTools依赖和远程仓库地址。 <dependencies><dependency><groupId>org.geotoo…

墨卡托投影介绍

一、墨卡托投影 墨卡托投影&#xff0c;又称正轴等角圆柱投影&#xff0c;由荷兰地图学家墨卡托(G.Mercator)于1569年创拟。假设地球被套在一个圆柱中&#xff0c;赤道与圆柱相切&#xff0c;然后在地球中心放一盏灯&#xff0c;把球面上的图形投影到圆柱体上&#xff0c;再把…

GIS算法:可视化工具JTS TestBuilder

java、python、js都有可以引用的第三方包&#xff0c;实现GIS的空间算法。 java是jts&#xff0c;python是shapely&#xff0c;js是turf。 其中jts值得首先拥有&#xff0c;因为jts提供了一个界面工具JTS TestBuilder&#xff0c;可以在上面绘制图形&#xff0c;验证各种算法…

wkt区域围栏

API文档 http://shengshifeiyang.gitee.io/geotools-learning/ /** * 判断以x,y为坐标的点point(x,y)是否在geometry表示的Polygon中 * param x * param y * param geometry wkt格式 POLYGON((0 0, 10 0, 10 10, 0 10,0 0)) * return */ public static boolean withinGeo(doub…

oracle关联字段和序列,oracle(9) 序列和约束

序列 SEQUENCE也是数据库对象之一&#xff0c;作用&#xff1a;根据指定的规则生成一些列数字。序列通常是为某张表的主键提供值使用。主键&#xff1a;通常每张表都会有主键字段&#xff0c;该字段的值要求非空且唯一&#xff0c;使用该字段来确定表中的每一条记录。CREATE SE…

lambda表达式处理异常_lambda表达式内出现异常无法throw抛出

lambda体中有受检异常,为什么不能在lambda表达式外层try catch,只能在lambda里面try catch xxx.getUpdateList().forEach((map) ->{xxxVO vo new xxxVO();BeanUtils.populate(vo,map); // populate方法往外抛了异常list.add(vo);});因为lambda表达式本身没有处理异常的机制…

lambda处理异常四种方式

最近对接第三方呼叫系统&#xff0c;第三方SDK的所有方法里都有异常抛出&#xff0c;因为用到了lambda&#xff0c;所以异常处理还是很必要的。 本文主要用到了四种解决方案&#xff1a; 直接代码块处理自定义函数式接口&#xff0c;warp静态方法通过Either 类型包装通过Pair…

linux 历史命令快捷键,Linux历史命令及bash快捷键

本文环境 Centos71.历史命令1.1 在使用linux中熟练的使用历史命令&#xff0c;能给我很多便捷&#xff0c;下面我来总结一些常用的一些历史命令。a) 执行上一条命令,这个很重要 &#xff0c;执行上一条命令有四种方法&#xff0c;如下:[rootCentOS-7-64data]#[rootCentOS-7-64 …

linux的shell命令 a,linux shell命令大全(都是随堂笔记)

1. Tftp服务器(上传下载文件)注意&#xff1a;上传和下载文件时不能用目录表示 。因此&#xff0c;需要先cd到当前目录。注意目录权限&#xff1a;chmod 0777目录文件 8进制表示&#xff1a;Chmod的文件、目录的权限U自己 g 所属组 o其它 可加减步骤&#xff1a;安装服务器&…

异常 —— throws

1.1 异常概念 1.2 异常体系 java.lang.Throwable:类是 Java 语言中所有错误或异常的超类。 Exception:编译期异常,进行编译(写代码)java程序出现的问题 RuntimeException:运行期异常,java程序运行过程中出现的问题 异常就相当于程序得了一个小毛病(感冒,发烧),把异常处理掉,程序…

制作 小 linux 教程,【NanoPi NEO Plus2开发板试用体验】编译uboot和linux制作最小根文件系统制作刷机包---详细教程...

二、Linux命令基础1、查找文件查找a.c的文件 find -name "a.c"在当前目录搜索a字样的文件 grep "a" *-nR2、解压解压tar.gz文件 tar zxvf xxxxx.tar.gz解压tar.xz文件 先 xz -d xxx.tar.xz 将 xxx.tar.xz解压成 xxx.tar 然后&#xff0c;再用 tar xvf xx…

执行throw后 后面代码还会执行吗?

1.当我们对throw的对象进行try catch之后 public void re(int i) {if (i > 5){this.i i;}else {try {throw new Exception("数据非法&#xff01;");} catch (Exception e) {e.printStackTrace();}System.out.println("123");}结果显示&#xff1a;12…

linux怎么查看sklearn版本,Sklearn——Sklearn的介绍与安装

文章目录1.Sklearn简介2.Sklean安装2.1.pip安装2.2.conda安装1.Sklearn简介Scikit learn 也简称 sklearn, 是机器学习领域当中最知名的 python 模块之一.Sklearn 包含了很多种机器学习的方式:Classification 分类Regression 回归Clustering 非监督分类Dimensionality reduction…

一些防止 Java 代码被反编译的方法

由于Java字节码的抽象级别较高&#xff0c;因此它们较容易被反编译。本节介绍了几种常用的方法&#xff0c;用于保护Java字节码不被反编译。通常&#xff0c;这些方法不能够绝对防止程序被反编译&#xff0c;而是加大反编译的难度而已&#xff0c;因为这些方法都有自己的使用环…

linux 离线安装中文,linux离线安装及配置redis-Go语言中文社区

本文以centos7系统为例&#xff0c;介绍离线安装redis步骤一、环境准备检查服务器上是否存在gcc-c的环境&#xff0c;使用命令&#xff1a;rpm -qa | grep gcc-c如果没有该环境&#xff0c;则需要安装该环境&#xff0c;离线安装步骤为&#xff1a;1、获取相关rpm包&#xff0c…

Java学习记录 AWT绘图篇

绘制图形 Canvas画布类 Class Canvas java.lang.Object java.awt.Component java.awt.Canvas 用来 绘制图形 或 捕获用户输入的事件。绘制图形需要绘图方法实现绘制图形 方法说明paint(Graphics g)绘图repaint(Graphics g)重新绘图&#xff08;刷新 Graphics绘图类 Class Gra…

linux pmap 内存泄露,一个驱动导致的内存泄漏问题的分析过程(meminfo-pmap-slabtop-alloc_calls)...

关键词&#xff1a;sqllite、meminfo、slabinfo、alloc_calls、nand、SUnreclaim等等。下面记录一个由于驱动导致的内存泄漏问题分析过程。首先介绍问题背景&#xff0c;在一款嵌入式设备上&#xff0c;新使用sqllite库进行数据库操作&#xff0c;在操作数据(大量读写操作)一段…

Java基础--awt详解以及简单应用

GUI 图形用户界面 CLI 命令行用户接口 Java为GUI提供的对象存在java.Awt和Javax.Swing两个包中. Java当中如何完成图形化界面的制作呢? AWT:abstract Window ToolKit.需要调用本地系统实现功能.属于重量级控件.依赖于平台.跨平台性不是特别好. Javax.Swing:在AWT基础上.建立一…

Java图形化界面设计之容器(JFrame)详解

Java图形化界面设计之容器&#xff08;JFrame&#xff09;详解 Java图形化界面设计——容器&#xff08;JFrame&#xff09; 程序是为了方便用户使用的&#xff0c;因此实现图形化界面的程序编写是所有编程语言发展的必然趋势&#xff0c;在命令提示符下运行的程序可以让我们…

10个最受欢迎的JavaScript图表库

目前网上有很多用于绘制图表图形的免费JavaScript插件和图表库&#xff0c;技术学派在这里给大家推荐10个比较强大的绘制图表图形的JavaScript图表库。其中一些插件需要主流浏览器的支持&#xff0c;而另外一些经过整合后&#xff0c;也能在不同的平台和老版本的浏览器上工作。…