@Override public void visit(Feature feature) { try { System.out.println("****************"); SimpleFeature sf = (SimpleFeature) feature; double height = getHeight(sf); System.out.println("Intersection at height " + height); FeatureCollection polygonsInRadius = Finder.featuresInRadius(surfaceFeatureSource, sf, radius); FeatureIterator<SimpleFeature> polygons = polygonsInRadius.features(); SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(viewAngleType); while (polygons.hasNext()) { SimpleFeature poly = polygons.next(); double poly_height = (Double) poly.getAttribute("Aukstis"); if (poly_height > (height + hillHeight)) { Point p = (Point) sf.getDefaultGeometry(); PointPairDistance ppd = new PointPairDistance(); EuclideanDistanceToPoint.computeDistance( (Geometry) poly.getDefaultGeometry(), p.getCoordinate(), ppd); System.out.println("View height: " + poly_height + " at distance " + ppd.getDistance()); Coordinate a = p.getCoordinate(); Coordinate b = ppd.getCoordinates()[0]; double l = 50; double C = ppd.getDistance(); Coordinate temp = b; b = a; a = temp; // http://answers.google.com/answers/threadview/id/419874.html Coordinate c = new Coordinate(b.x + (l * (a.y - b.y)) / C, b.y + (l * (b.x - a.x)) / C); Coordinate d = new Coordinate( b.x + ((-1) * l * (a.y - b.y)) / C, b.y + ((-1) * l * (b.x - a.x)) / C); Coordinate[] cords = {a, c, d, a}; LinearRing ring = gf.createLinearRing(cords); Polygon pol = gf.createPolygon(ring, null); featureBuilder.add(pol); featureBuilder.add(poly_height - height); SimpleFeature viewAngle = featureBuilder.buildFeature("Polygon." + (viewAngles.size() + 1)); viewAngles.add(viewAngle); } } } catch (Exception e) { e.printStackTrace(); } }