简体   繁体   English

用JTS指向Circle

[英]Point in Circle with JTS

I have a huge set of points already loaded within a plane I need to draw a circle/ellipse starting from a given point and a radius distance in meters then check which points are inside the circle. 我已经在一个平面内加载了一大堆点,我需要从给定点开始绘制圆/椭圆,以米为单位的半径距离,然后检查圆内的哪些点。

I've already done this with a polygon with the within() method, but I can't find a way to draw a circle/ellipse without having to specify every point around the polygon. 我已经使用within()方法用多边形完成了这个,但我找不到绘制圆/椭圆的方法而不必指定多边形周围的每个点。

Is there a way to do this on JTS or do I need another java library? 有没有办法在JTS上执行此操作,还是需要其他Java库?

If I understood correctly you have the radius and the center, so you can draw a circle with JTS like this: 如果我理解正确你有半径和中心,那么你可以用这样的JTS绘制一个圆:

public static Geometry createCircle(double x, double y, final double RADIUS) {
    GeometricShapeFactory shapeFactory = new GeometricShapeFactory();
    shapeFactory.setNumPoints(32);
    shapeFactory.setCentre(new Coordinate(x, y));
    shapeFactory.setSize(RADIUS * 2);
    return shapeFactory.createCircle();
}

You can just verify that the distance from the point is less than the radius. 您可以验证距离点的距离是否小于半径。 No need to draw the circle to know which points are inside it. 无需绘制圆圈以了解其中的哪些点。 For faster run times, compare the square of the distance with the square of the radius; 为了更快的运行时间,将距离的平方与半径的平方进行比较; this saves unnecessary square root operations. 这节省了不必要的平方根操作。

For ellipses, the problem is only slightly harder, involving a quadratic form x^2 + ky^2 . 对于椭圆,问题只是稍微困难,涉及二次形式x^2 + ky^2

You can simply buffer the circle center with a positive value like so: 您可以使用正值buffer圆心,如下所示:

Point centerPoint = ...;
Polygon circle = (Polygon) centerPoint.buffer(0.1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM