/** * Creates a circle shape, using the JTS buffer algorithm. The method is used when there is no street found within the given traveltime, e.g. when * the pointer is placed on a field or in the woods.<br> * TODO: Note it is actually not correct to do buffer calculation in Euclidian 2D, since the resulting shape will be elliptical when projected. * * @param dropPoint the location given by the user * @param pathToStreet the path from the dropPoint to the street, used to retrieve the buffer distance * @return a Circle */ private Geometry createCirle(Coordinate dropPoint, LineString pathToStreet) { double length = pathToStreet.getLength(); GeometryFactory gf = new GeometryFactory(); Point dp = gf.createPoint(dropPoint); Geometry buffer = dp.buffer(length); return buffer; }
/** * Gets a geometry which represents the Minimum Bounding Circle. * If the input is degenerate (empty or a single unique point), * this method will return an empty geometry or a single Point geometry. * Otherwise, a Polygon will be returned which approximates the * Minimum Bounding Circle. * (Note that because the computed polygon is only an approximation, * it may not precisely contain all the input points.) * * @return a Geometry representing the Minimum Bounding Circle. */ public Geometry getCircle() { //TODO: ensure the output circle contains the extermal points. //TODO: or maybe even ensure that the returned geometry contains ALL the input points? compute(); if (centre == null) return input.getFactory().createPolygon(null, null); Point centrePoint = input.getFactory().createPoint(centre); if (radius == 0.0) return centrePoint; return centrePoint.buffer(radius); }
public Geometry buffer(double distance) { return point.buffer(distance); }
public Geometry buffer(double distance, int quadrantSegments, int endCapStyle) { return point.buffer(distance, quadrantSegments, endCapStyle); }
public Geometry buffer(double distance, int quadrantSegments) { return point.buffer(distance, quadrantSegments); }
@Override public Polygon getBuffer(double distance) { // convert to the target unit distance = converter.convert(distance); // buffer and return return (Polygon) center.buffer(distance, quadrantSegments); }
public Geometry getStandardDistanceAsCircle(List<SpatialEvent> spatialEventSet, double standardDeviation, boolean useWeight) { SpatialEvent sdtPoint = getStandardDistance(spatialEventSet, standardDeviation, useWeight); Point centerPoint = gf.createPoint(sdtPoint.getCoordinate()); // for degree in NUM.arange(0, 360): return centerPoint.buffer(sdtPoint.xVal * standardDeviation, 90, 1); }
private Geometry bufferWedge(Point centroid, double azimuth, double wedgeAngle, double innerRadius, double outerRadius) { double minRadius = Math.min(outerRadius, innerRadius); double maxRadius = Math.max(outerRadius, innerRadius); if (wedgeAngle >= 360) { Geometry buffered = centroid.buffer(maxRadius, SEG); if (minRadius > 0) { buffered = buffered.difference(centroid.buffer(minRadius, SEG)); } return buffered; } // make azimuth 0 north and positive clockwise (compass direction) azimuth = -1.0 * azimuth + 90; double fromAzimuth = azimuth - wedgeAngle * 0.5; double toAzimuth = azimuth + wedgeAngle * 0.5; return createWedgeBuffer(centroid.getCoordinate(), fromAzimuth, toAzimuth, minRadius, maxRadius); }
public Geometry getMergedBuffers() { if (this.mergedBuffers == null) { // synchronized (this) { Collection<Geometry> polygons = new ArrayList<>(); for (Stop stop : this.stops.values()) { if (getStopTimesForStop(stop.stop_id).isEmpty()) { continue; } if (stop.stop_lat > -1 && stop.stop_lat < 1 || stop.stop_lon > -1 && stop.stop_lon < 1) { continue; } Point stopPoint = gf.createPoint(new Coordinate(stop.stop_lon, stop.stop_lat)); Polygon stopBuffer = (Polygon) stopPoint.buffer(.01); polygons.add(stopBuffer); } Geometry multiGeometry = gf.buildGeometry(polygons); this.mergedBuffers = multiGeometry.union(); if (polygons.size() > 100) { this.mergedBuffers = DouglasPeuckerSimplifier.simplify(this.mergedBuffers, .001); } // } } return this.mergedBuffers; }
/** * Gets a geometry which represents the Minimum Bounding Circle. * If the input is degenerate (empty or a single unique point), * this method will return an empty geometry or a single Point geometry. * Otherwise, a Polygon will be returned which approximates the * Minimum Bounding Circle. * (Note that because the computed polygon is only an approximation, * it may not precisely contain all the input points.) * * @return a Geometry representing the Minimum Bounding Circle. */ public Geometry getCircle() { //TODO: ensure the output circle contains the extermal points. //TODO: or maybe even ensure that the returned geometry contains ALL the input points? compute(); if (centre == null) return input.getFactory().createPolygon(null, null); Point centrePoint = input.getFactory().createPoint(centre); if (radius == 0.0) return centrePoint; return centrePoint.buffer(radius); }
public CircularBinningVisitor(ReferencedEnvelope bbox, double radius) { this.diameter = radius * 2.0; columns = (int) Math.floor((bbox.getWidth() / diameter) + 0.5d); rows = (int) Math.floor((bbox.getHeight() / diameter) + 0.5d); this.columns = columns * diameter < bbox.getWidth() ? columns + 1 : columns; this.rows = rows * diameter < bbox.getHeight() ? rows + 1 : rows; // recalculate envelope : origin = lower left CoordinateReferenceSystem targetCRS = bbox.getCoordinateReferenceSystem(); ReferencedEnvelope finalBBox = new ReferencedEnvelope(targetCRS); finalBBox.init(bbox.getMinX(), bbox.getMinX() + (columns * diameter), bbox.getMinY(), bbox.getMinY() + (rows * diameter)); this.extent = finalBBox; this.minX = finalBBox.getMinX(); this.minY = finalBBox.getMinY(); this.gridValues = new Double[rows][columns]; Point center = gf.createPoint(new Coordinate(minX + radius, minY + radius)); this.binTemplate = center.buffer(radius, quadrantSegments); }
private void processLink(Link link, EmissionsByPollutant emissions, Grid<Map<Pollutant, Double>> grid) { // create a clipping area to speed up calculation time // use 5*smoothing radius as longer distances result in a weighting of effectively 0 Geometry clip = factory.createPoint(new Coordinate(link.getCoord().getX(), link.getCoord().getY())).buffer(smoothingRadius * 5); grid.getCells(clip).forEach(cell -> { double normalizationFactor = grid.getCellArea() / (Math.PI * smoothingRadius * smoothingRadius); double weight = SpatialInterpolation.calculateWeightFromLine( transformToCoordinate(link.getFromNode()), transformToCoordinate(link.getToNode()), cell.getCoordinate(), smoothingRadius); processCell(cell, emissions, weight * normalizationFactor); }); }
@Override public void handleEntity(Object bean) { Stop stop = (Stop) bean; if (_projection == null) { int zone = UTMLibrary.getUTMZoneForLongitude(stop.getLon()); _projection = new UTMProjection(zone); } XYPoint point = _projection.forward(new CoordinatePoint(stop.getLat(), stop.getLon())); Point p = _factory.createPoint(new Coordinate(point.getX(), point.getY())); Geometry geometry = p.buffer(_bufferRadiusInMeters).getEnvelope(); if (_geometry == null) _geometry = geometry; else _geometry = _geometry.union(geometry); } }
@Override public void handleEntity(Object bean) { Stop stop = (Stop) bean; if (_projection == null) { int zone = UTMLibrary.getUTMZoneForLongitude(stop.getLon()); _projection = new UTMProjection(zone); } XYPoint point = _projection.forward(new CoordinatePoint(stop.getLat(), stop.getLon())); Point p = _factory.createPoint(new Coordinate(point.getX(), point.getY())); Geometry geometry = p.buffer(_bufferRadiusInMeters).getEnvelope(); if (_geometry == null) _geometry = geometry; else _geometry = _geometry.union(geometry); } }
@Override public void handleEntity(Object bean) { Stop stop = (Stop) bean; if (_projection == null) { int zone = UTMLibrary.getUTMZoneForLongitude(stop.getLon()); _projection = new UTMProjection(zone); } XYPoint point = _projection.forward(new CoordinatePoint(stop.getLat(), stop.getLon())); Point p = _factory.createPoint(new Coordinate(point.getX(), point.getY())); Geometry geometry = p.buffer(_bufferRadiusInMeters).getEnvelope(); if (_geometry == null) _geometry = geometry; else _geometry = _geometry.union(geometry); } }
@Override public SimpleFeature next() throws NoSuchElementException { SimpleFeature feature = delegate.next(); for (Object attribute : feature.getAttributes()) { if (attribute instanceof Geometry) { Geometry geometry = (Geometry) attribute; builder.add(geometry.getCentroid().buffer(radius, quadrantSegments)); } else { builder.add(attribute); } } return builder.buildFeature(feature.getID()); } }
private void init(SimpleFeatureBuilder builder) { ListFeatureCollection result = new ListFeatureCollection(builder.getFeatureType()); String typeName = builder.getFeatureType().getTypeName(); int featureID = 1; // create circle double radius_step = radius / 5; for (int index = 0; index < 5; index++) { double buffer_radius = radius_step * (index + 1); SimpleFeature feature = builder.buildFeature(buildID(typeName, featureID++)); feature.setDefaultGeometry(center.buffer(buffer_radius, SEG).getBoundary()); feature.setAttribute(FIELDS[0], buffer_radius); result.add(feature); } // create direction for (int index = 0; index < 16; index++) { double degree = 22.5 * index; SimpleFeature feature = builder.buildFeature(buildID(typeName, featureID++)); feature.setDefaultGeometry(createLine(center, Math.toRadians(degree), radius)); feature.setAttribute(FIELDS[1], NORTH[index]); result.add(feature); } this.iter = result.features(); }
public void testExecutePoint() throws Exception { SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.setName("featureType"); tb.add("geometry", Geometry.class); tb.add("integer", Integer.class); GeometryFactory gf = new GeometryFactory(); SimpleFeatureBuilder b = new SimpleFeatureBuilder(tb.buildFeatureType()); DefaultFeatureCollection features = new DefaultFeatureCollection(null, b.getFeatureType()); for (int i = 0; i < 2; i++) { b.add(gf.createPoint(new Coordinate(i, i))); b.add(i); features.add(b.buildFeature(i + "")); } Double distance = new Double(500); BufferFeatureCollection process = new BufferFeatureCollection(); SimpleFeatureCollection output = process.execute(features, distance, null); assertEquals(2, output.size()); SimpleFeatureIterator iterator = output.features(); for (int i = 0; i < 2; i++) { Geometry expected = gf.createPoint(new Coordinate(i, i)).buffer(distance); SimpleFeature sf = iterator.next(); assertTrue(expected.equals((Geometry) sf.getDefaultGeometry())); } }
while (currentX <= bbox.getMaxX()) { Point center = gf.createPoint(new Coordinate(currentX, currentY)); Geometry geometry = center.buffer(radius, quadrantSegments);
case Circle: double radius = bounds.getWidth() / 2.0; cellGeom = gf.createPoint(bounds.centre()).buffer(radius); break;