public static Polygon homothetie(Polygon geom, double x0, double y0, double scale) { GeometryFactory gf = new GeometryFactory(); // le contour externe Coordinate[] coord = geom.getExteriorRing().getCoordinates(); Coordinate[] coord_ = new Coordinate[coord.length]; for (int i = 0; i < coord.length; i++) { coord_[i] = new Coordinate(x0 + scale * (coord[i].x - x0), y0 + scale * (coord[i].y - y0)); } LinearRing lr = gf.createLinearRing(new CoordinateArraySequence(coord_)); // les trous LinearRing[] trous = new LinearRing[geom.getNumInteriorRing()]; for (int j = 0; j < geom.getNumInteriorRing(); j++) { Coordinate[] hole_coord = geom.getInteriorRingN(j).getCoordinates(); Coordinate[] hole_coord_ = new Coordinate[hole_coord.length]; for (int i = 0; i < hole_coord.length; i++) { hole_coord_[i] = new Coordinate(x0 + scale * (hole_coord[i].x - x0), y0 + scale * (hole_coord[i].y - y0)); } trous[j] = gf.createLinearRing(new CoordinateArraySequence(hole_coord_)); } return gf.createPolygon(lr, trous); }
/** * <p>createCompoundLineString.</p> * * @param factory a {@link com.vividsolutions.jts.geom.GeometryFactory} object. * @param segments a {@link com.vividsolutions.jts.geom.LineString} object. * @return a {@link nl.pdok.gml3.impl.geometry.extended.CompoundLineString} object. */ public static CompoundLineString createCompoundLineString(GeometryFactory factory, LineString... segments) { List<Coordinate> coordinates = new ArrayList<Coordinate>(); for(int i=0; i<segments.length; i++) { LineString segment = segments[i]; Coordinate[] coordinateArray = segment.getCoordinates(); if(i != segments.length-1) { int lengtWithoutLastElement = coordinateArray.length-1; Coordinate[] coordinateArray2 = new Coordinate[lengtWithoutLastElement]; System.arraycopy(coordinateArray, 0, coordinateArray2, 0, lengtWithoutLastElement); coordinates.addAll(Arrays.asList(coordinateArray2)); } else { coordinates.addAll(Arrays.asList(coordinateArray)); } } CoordinateSequence coordinateSequence = new CoordinateArraySequence( coordinates.toArray(new Coordinate[]{})); CompoundLineString curveLineString = new CompoundLineString(coordinateSequence, factory, segments); return curveLineString; }
private LinearRing translateLinearRingType(LinearRingType ring) throws GeometryException { if (ring.getPosList() == null) { throw new DeprecatedGeometrySpecificationException("Geen post list voor ring gespecificeerd"); } CoordinateArraySequence sequence = gmlToPointConvertor.translateOrdinates(ring.getPosList()); int length = sequence.size(); Coordinate firstCoordinate = length == 0 ? null : sequence.getCoordinate(0); if (length < NUMBER_OF_COORDINATES_NEEDED_FOR_RING) { throw new InvalidGeometryException(GeometryValidationErrorType.TOO_FEW_POINTS, firstCoordinate); } if (!isClosed(sequence)) { throw new InvalidGeometryException(GeometryValidationErrorType.RING_NOT_CLOSED, firstCoordinate); } return geometryFactory.createLinearRing(sequence); }
private CoordinateArraySequence getCoordinatesForArc(ArcType arc) throws GeometryException { if(arc.getPosList() != null) { return gmlToPointConvertor.translateOrdinates(arc.getPosList()); } else if(arc.getPosOrPointPropertyOrPointRep() != null && arc.getPosOrPointPropertyOrPointRep().size() > 0) { List<Double> values = new ArrayList<Double>(); Iterator<JAXBElement<?>> iterator = arc.getPosOrPointPropertyOrPointRep().iterator(); while(iterator.hasNext()) { Object value = iterator.next().getValue(); if(value instanceof DirectPositionType) { DirectPositionType position = (DirectPositionType) value; values.addAll(position.getValue()); } else { throw new DeprecatedGeometrySpecificationException( "Geen poslist voor arc binnen curve gespecificeerd"); } } return gmlToPointConvertor.translateOrdinates(values, 2); // could be 3 too? } else { throw new DeprecatedGeometrySpecificationException("Geen poslist voor arc binnen curve gespecificeerd"); } }
/** * <p>translateOrdinates.</p> * * @param coordinates a {@link java.util.List} object. * @param dimension a {@link int}. * @return a {@link com.vividsolutions.jts.geom.impl.CoordinateArraySequence} object. * @throws nl.pdok.gml3.exceptions.InvalidGeometryException if any. * @throws nl.pdok.gml3.exceptions.CoordinateMaxScaleExceededException if any. */ public CoordinateArraySequence translateOrdinates(List<Double> coordinates, int dimension) throws InvalidGeometryException, CoordinateMaxScaleExceededException { if (coordinates == null || coordinates.size() < dimension) { throw new InvalidGeometryException(GeometryValidationErrorType.EMPTY_GEOMETRY, null); } if(coordinates.size()%dimension != 0) { throw new InvalidGeometryException(GeometryValidationErrorType.INVALID_COORDINATE, null); } CoordinateArraySequence sequence = new CoordinateArraySequence(coordinates.size() / dimension); int i = 0; for (Double ordinate : coordinates) { BigDecimal bd = new BigDecimal(ordinate); int ordinateIndex = i % dimension; int index = (i / dimension); sequence.setOrdinate(index, ordinateIndex, bd.doubleValue()); i++; } return sequence; }
/** * <p>convertPoint.</p> * * @param point a {@link net.opengis.gml.v_3_1_1.PointType} object. * @return a {@link com.vividsolutions.jts.geom.Point} object. * @throws nl.pdok.gml3.exceptions.GeometryException if any. */ public Point convertPoint(PointType point) throws GeometryException { DirectPositionType pos = point.getPos(); int dimension = pos.getSrsDimension() != null ? pos.getSrsDimension().intValue() : pos.getValue().size(); if(point.getPos() == null) { throw new DeprecatedGeometrySpecificationException( "Geen post list voor ring gespecificeerd"); } List<Double> values = pos.getValue(); if(values.size() != dimension) { throw new InvalidGeometryException(GeometryValidationErrorType.POINT_INVALID_NUMBER_OF_ORDINATES, null); } CoordinateArraySequence sequence = translateOrdinates(values, dimension); return geometryFactory.createPoint(sequence); }
/** * <p>translateOrdinates.</p> * * @param ordinates a {@link java.util.List} object. * @param dimension a {@link int}. * @return a {@link com.vividsolutions.jts.geom.impl.CoordinateArraySequence} object. * @throws nl.pdok.gml3.exceptions.InvalidGeometryException if any. * @throws nl.pdok.gml3.exceptions.CoordinateMaxScaleExceededException if any. */ public CoordinateArraySequence translateOrdinates(List<Double> ordinates, int dimension) throws InvalidGeometryException, CoordinateMaxScaleExceededException { if (ordinates == null || ordinates.size() < dimension) { throw new InvalidGeometryException(GeometryValidationErrorType.EMPTY_GEOMETRY, null); } if (ordinates.size()%dimension != 0) { throw new InvalidGeometryException(GeometryValidationErrorType.INVALID_COORDINATE, createCoordinateFromFirstTwoOrdinates(ordinates)); } CoordinateArraySequence sequence = new CoordinateArraySequence(ordinates.size() / dimension); int i = 0; for (Double ordinate : ordinates) { BigDecimal bd = new BigDecimal(ordinate); int ordinateIndex = i % dimension; int index = (i / dimension); sequence.setOrdinate(index, ordinateIndex, bd.doubleValue()); i++; } return sequence; }
/** * <p>convertPoint.</p> * * @param point a {@link net.opengis.gml.v_3_2_1.PointType} object. * @return a {@link com.vividsolutions.jts.geom.Point} object. * @throws nl.pdok.gml3.exceptions.GeometryException if any. */ public Point convertPoint(PointType point) throws GeometryException { DirectPositionType pos = point.getPos(); List<Double> values = pos.getValue(); int dimension = pos.getSrsDimension() != null ? pos.getSrsDimension().intValue() : values.size(); if (point.getPos() == null) { throw new DeprecatedGeometrySpecificationException( "Geen post list voor ring gespecificeerd"); } if (values.size() != dimension) { throw new InvalidGeometryException(GeometryValidationErrorType.POINT_INVALID_NUMBER_OF_ORDINATES, null); } CoordinateArraySequence sequence = translateOrdinates(values, dimension); return geometryFactory.createPoint(sequence); }
public double calculate(Polygon polygon, Coordinate coordinate, double precisionKilometers, GeometryFactory geometryFactory) { Point point = new Point(new CoordinateArraySequence(new Coordinate[]{coordinate}), geometryFactory); if (polygon.contains(point)) { // todo distance to border? well if that should be the case then factor this method out of this class! return 0; } double smallestDistance = Double.MAX_VALUE; Coordinate[] coordinates = polygon.getCoordinates(); for (int i = 1; i < coordinates.length; i++) { for (Coordinate interpolated : new LineInterpolation().interpolate(precisionKilometers, coordinates[i - 1], coordinates[i])) { double distance = calculate(interpolated, coordinate); if (distance < smallestDistance) { smallestDistance = distance; } } } return smallestDistance; }
/** * Converts geometry from lat/lon (EPSG:4326)) to Spherical Mercator * (EPSG:3857) * * @param geometry the geometry to convert * @return the geometry transformed to EPSG:3857 */ public Geometry lngLatToMeters(Geometry geometry) { GeometryTransformer transformer = new GeometryTransformer() { @Override protected CoordinateSequence transformCoordinates(CoordinateSequence coords, Geometry parent) { Coordinate[] newCoords = new Coordinate[coords.size()]; for (int i = 0; i < coords.size(); ++i) { Coordinate coord = coords.getCoordinate(i); newCoords[i] = lngLatToMeters(coord); } return new CoordinateArraySequence(newCoords); } }; Geometry result = transformer.transform(geometry); return result; }
/** * Converts geometry from Spherical Mercator * (EPSG:3857) to lat/lon (EPSG:4326)) * * @param geometry the geometry to convert * @return the geometry transformed to EPSG:4326 */ public Geometry metersToLngLat(Geometry geometry) { GeometryTransformer transformer = new GeometryTransformer() { @Override protected CoordinateSequence transformCoordinates(CoordinateSequence coords, Geometry parent) { Coordinate[] newCoords = new Coordinate[coords.size()]; for (int i = 0; i < coords.size(); ++i) { Coordinate coord = coords.getCoordinate(i); newCoords[i] = metersToLngLat(coord); } return new CoordinateArraySequence(newCoords); } }; Geometry result = transformer.transform(geometry); return result; }
/** * Transform into GeometryCollection. * * @param geom input geometry * @return a geometry collection */ private static GeometryCollection transformIntoPointGeometryCollection(Geometry geom) { UniqueCoordinateArrayFilter filter = new UniqueCoordinateArrayFilter(); geom.apply(filter); Coordinate[] coord = filter.getCoordinates(); Geometry[] geometries = new Geometry[coord.length]; for (int i = 0; i < coord.length; i++) { Coordinate[] c = new Coordinate[]{coord[i]}; CoordinateArraySequence cs = new CoordinateArraySequence(c); geometries[i] = new Point(cs, geom.getFactory()); } return new GeometryCollection(geometries, geom.getFactory()); }
/** * Transform into GeometryCollection. * * @param geom input geometry * @return a geometry collection */ private static GeometryCollection transformIntoPointGeometryCollection(GeometryCollection gc) { UniqueCoordinateArrayFilter filter = new UniqueCoordinateArrayFilter(); gc.apply(filter); Coordinate[] coord = filter.getCoordinates(); Geometry[] geometries = new Geometry[coord.length]; for (int i = 0; i < coord.length; i++) { Coordinate[] c = new Coordinate[]{coord[i]}; CoordinateArraySequence cs = new CoordinateArraySequence(c); geometries[i] = new Point(cs, gc.getFactory()); } return new GeometryCollection(geometries, gc.getFactory()); }
/** * Transform into GeometryCollection. * * @param geom * input geometry * @return * a geometry collection */ private static GeometryCollection transformIntoPointGeometryCollection(Geometry geom) { UniqueCoordinateArrayFilter filter = new UniqueCoordinateArrayFilter(); geom.apply(filter); Coordinate[] coord = filter.getCoordinates(); Geometry[] geometries = new Geometry[coord.length]; for (int i = 0 ; i < coord.length ; i++) { Coordinate[] c = new Coordinate[] { coord[i] }; CoordinateArraySequence cs = new CoordinateArraySequence(c); geometries[i] = new Point(cs, geom.getFactory()); } return new GeometryCollection(geometries, geom.getFactory()); }
/** * Transform into GeometryCollection. * * @param gc * input geometry * @return * a geometry collection */ private static GeometryCollection transformIntoPointGeometryCollection(GeometryCollection gc) { UniqueCoordinateArrayFilter filter = new UniqueCoordinateArrayFilter(); gc.apply(filter); Coordinate[] coord = filter.getCoordinates(); Geometry[] geometries = new Geometry[coord.length]; for (int i = 0 ; i < coord.length ; i++) { Coordinate[] c = new Coordinate[] { coord[i] }; CoordinateArraySequence cs = new CoordinateArraySequence(c); geometries[i] = new Point(cs, gc.getFactory()); } return new GeometryCollection(geometries, gc.getFactory()); }
/** * Checks if the computed value for isInCircle is correct, using * double-double precision arithmetic. * * @param a a vertex of the triangle * @param b a vertex of the triangle * @param c a vertex of the triangle * @param p the point to test */ private static void checkRobustInCircle(Coordinate a, Coordinate b, Coordinate c, Coordinate p) { boolean nonRobustInCircle = isInCircleNonRobust(a, b, c, p); boolean isInCircleDD = TrianglePredicate.isInCircleDDSlow(a, b, c, p); boolean isInCircleCC = TrianglePredicate.isInCircleCC(a, b, c, p); Coordinate circumCentre = Triangle.circumcentre(a, b, c); System.out.println("p radius diff a = " + Math.abs(p.distance(circumCentre) - a.distance(circumCentre)) / a.distance(circumCentre)); if (nonRobustInCircle != isInCircleDD || nonRobustInCircle != isInCircleCC) { System.out.println("inCircle robustness failure (double result = " + nonRobustInCircle + ", DD result = " + isInCircleDD + ", CC result = " + isInCircleCC + ")"); System.out.println(WKTWriter.toLineString(new CoordinateArraySequence( new Coordinate[] { a, b, c, p }))); System.out.println("Circumcentre = " + WKTWriter.toPoint(circumCentre) + " radius = " + a.distance(circumCentre)); System.out.println("p radius diff a = " + Math.abs(p.distance(circumCentre) / a.distance(circumCentre) - 1)); System.out.println("p radius diff b = " + Math.abs(p.distance(circumCentre) / b.distance(circumCentre) - 1)); System.out.println("p radius diff c = " + Math.abs(p.distance(circumCentre) / c.distance(circumCentre) - 1)); System.out.println(); } }
public static Polygon affinite(Polygon geom, Coordinate c, double angle, double coef) { // pivote le polygone Polygon rot = CommonAlgorithms.rotation(geom, c, -1.0 * angle); GeometryFactory gf = new GeometryFactory(); // le contour externe Coordinate[] coord = rot.getExteriorRing().getCoordinates(); Coordinate[] coord_ = new Coordinate[coord.length]; for (int i = 0; i < coord.length; i++) { coord_[i] = new Coordinate(c.x + coef * (coord[i].x - c.x), coord[i].y); } LinearRing lr = new LinearRing(new CoordinateArraySequence(coord_), gf); // les trous LinearRing[] trous = new LinearRing[rot.getNumInteriorRing()]; for (int j = 0; j < rot.getNumInteriorRing(); j++) { Coordinate[] hole_coord = rot.getInteriorRingN(j).getCoordinates(); Coordinate[] hole_coord_ = new Coordinate[hole_coord.length]; for (int i = 0; i < hole_coord.length; i++) { hole_coord_[i] = new Coordinate(c.x + coef * (hole_coord[i].x - c.x), coord[i].y); } trous[j] = new LinearRing(new CoordinateArraySequence(hole_coord_), gf); } return CommonAlgorithms.rotation(new Polygon(lr, trous, gf), c, angle); }
/** * <p>createRing.</p> * * @param factory a {@link com.vividsolutions.jts.geom.GeometryFactory} object. * @param segments a {@link com.vividsolutions.jts.geom.LineString} object. * @return a {@link nl.pdok.gml3.impl.geometry.extended.Ring} object. */ public static Ring createRing(GeometryFactory factory, LineString... segments) { Set<Coordinate> coordinates = new LinkedHashSet<>(); for (LineString segment : segments) { coordinates.addAll(Arrays.asList(segment.getCoordinates())); } List<Coordinate> coordsWithoutDuplicates = new ArrayList<>(coordinates); coordsWithoutDuplicates.add(coordsWithoutDuplicates.get(0)); CoordinateSequence coordinateSequence = new CoordinateArraySequence(coordsWithoutDuplicates.toArray(new Coordinate[] {})); return new Ring(coordinateSequence, factory, segments); }
/** * <p>densify.</p> * * @param coordinates an array of {@link com.vividsolutions.jts.geom.Coordinate} objects. * @param factory a {@link com.vividsolutions.jts.geom.GeometryFactory} object. * @return a {@link com.vividsolutions.jts.geom.CoordinateSequence} object. */ public static CoordinateSequence densify(Coordinate[] coordinates, GeometryFactory factory) { double tolerance = ExtendedGeometryFactory.DEFAULT_MAXIMUM_ARC_APPROXIMATION_ERROR; if(factory instanceof ExtendedGeometryFactory) { tolerance = ((ExtendedGeometryFactory) factory).getMaximumArcApproximationError(); } LineString ls = factory.createLineString(coordinates); Envelope envelope = ls.getEnvelopeInternal(); // bbox bepalen double threshold = tolerance * 3; if(envelope.getHeight() <= threshold || envelope.getWidth() <= threshold) { // do nothing with small arc, to prevent floating point shizzle return new CoordinateArraySequence(coordinates); } // make sure the original coordinates are not changed Coordinate[] orderedCoordinates = orderCoordinates(coordinates, factory); Coordinate[] result = SmallCircle.linearizeArc( orderedCoordinates[0].x, orderedCoordinates[0].y, orderedCoordinates[1].x, orderedCoordinates[1].y, orderedCoordinates[2].x, orderedCoordinates[2].y, tolerance); CoordinateSequence out = new CoordinateArraySequence(result); // if the points were reversed, the densified line needs to be reversed again if(!orderedCoordinates[0].equals(coordinates[0])) { CoordinateSequences.reverse(out); } return out; }
/** * <p>translateCurveTypeToSegments.</p> * * @param curve a {@link net.opengis.gml.v_3_1_1.CurveType} object. * @return a {@link java.util.List} object. * @throws nl.pdok.gml3.exceptions.GeometryException if any. */ public List<LineString> translateCurveTypeToSegments(CurveType curve) throws GeometryException { List<LineString> list = new ArrayList<LineString>(); CurveSegmentArrayPropertyType array = curve.getSegments(); valideerSegmentArray(array); int size = array.getCurveSegment().size(); for (int i = 0; i < size; i++) { AbstractCurveSegmentType curveProperty = array.getCurveSegment().get(i).getValue(); if (curveProperty instanceof LineStringSegmentType) { LineStringSegmentType line = (LineStringSegmentType) curveProperty; if (line.getPosList() == null) { throw new DeprecatedGeometrySpecificationException( "Geen poslist voor linestringsegment binnen curve gespecificeerd"); } CoordinateArraySequence sequence = gmlToPointConvertor.translateOrdinates(line.getPosList()); LineString lineString = new LineString(sequence, geometryFactory); list.add(lineString); } else if (curveProperty instanceof ArcType && !(curveProperty instanceof CircleType)) { ArcType arc = (ArcType) curveProperty; list.add(translateArc(arc)); } else { throw new UnsupportedGeometrySpecificationException( "Only arc and linestring are supported within a Curve segment"); } } return list; }
private ArcLineString translateArc(ArcType arc) throws GeometryException { if (CurveInterpolationType.CIRCULAR_ARC_3_POINTS != ArcStringType.INTERPOLATION) { throw new UnsupportedGeometrySpecificationException( "Het arc attribuut interpolation moet circularArc3Points zijn"); } CoordinateArraySequence sequence = getCoordinatesForArc(arc); validateArcHasThreeCoordinates(sequence); validateArcIsNotAStraightLine(sequence); return new ArcLineString(sequence, geometryFactory); }
private void validateArcIsNotAStraightLine(CoordinateArraySequence sequence) throws GeometryException { if(CGAlgorithms.isOnLine(sequence.getCoordinate(1), new Coordinate[]{sequence.getCoordinate(0), sequence.getCoordinate(2)})) { throw new InvalidGeometryException(GeometryValidationErrorType.ARC_IS_A_STRAIGHT_LINE, sequence.getCoordinate(1), "arc should not be a straight line"); } }
private boolean isClosed(CoordinateArraySequence sequence) { int length = sequence.size(); if (length < NUMBER_OF_COORDINATES_NEEDED_FOR_RING) { return false; } return sequence.getCoordinate(0).equals2D(sequence.getCoordinate(length - 1)); }
private LineString convertLineString(LineStringType lineStringType) throws GeometryException { if (lineStringType.getPosList() == null) { throw new DeprecatedGeometrySpecificationException("Geen poslist voor lineString gespecificeerd"); } int dimension = lineStringType.getSrsDimension() != null ? lineStringType.getSrsDimension().intValue() : 2; List<Double> posList = lineStringType.getPosList().getValue(); if(posList.size() < NUMBER_OF_ORDINATES_NEEDED_FOR_LINE_PER_DIMENSION * dimension) { throw new InvalidGeometryException(GeometryValidationErrorType.TOO_FEW_POINTS, null); } CoordinateArraySequence sequence = gmlToPointConvertor.translateOrdinates(lineStringType.getPosList()); return new LineString(sequence, geometryFactory); }
/** * <p>translateCurveTypeToSegments.</p> * * @param curve a {@link net.opengis.gml.v_3_2_1.CurveType} object. * @return a {@link java.util.List} object. * @throws nl.pdok.gml3.exceptions.GeometryException if any. */ public List<LineString> translateCurveTypeToSegments(CurveType curve) throws GeometryException { List<LineString> list = new ArrayList<>(); CurveSegmentArrayPropertyType array = curve.getSegments(); valideerSegmentArray(array); int size = array.getAbstractCurveSegment().size(); for (int i = 0; i < size; i++) { AbstractCurveSegmentType curveProperty = array.getAbstractCurveSegment().get(i).getValue(); if (curveProperty instanceof LineStringSegmentType) { LineStringSegmentType line = (LineStringSegmentType) curveProperty; if (line.getPosList() == null) { throw new DeprecatedGeometrySpecificationException( "Geen poslist voor linestringsegment binnen curve gespecificeerd"); } CoordinateArraySequence sequence = gmlToPointConvertor.translateOrdinates(line.getPosList()); LineString lineString = new LineString(sequence, geometryFactory); list.add(lineString); } else if (curveProperty instanceof ArcType && !(curveProperty instanceof CircleType)) { ArcType arc = (ArcType) curveProperty; list.add(translateArc(arc)); } else { throw new UnsupportedGeometrySpecificationException( "Only arc and linestring are supported within a Curve segment"); } } return list; }
private CoordinateArraySequence getCoordinatesForArc(ArcType arc) throws GeometryException { if (arc.getPosList() != null) { return gmlToPointConvertor.translateOrdinates(arc.getPosList()); } else if (arc.getPosOrPointPropertyOrPointRep() != null && arc.getPosOrPointPropertyOrPointRep().size() > 0) { List<Double> values = new ArrayList<>(); Iterator<JAXBElement<?>> iterator = arc.getPosOrPointPropertyOrPointRep().iterator(); while (iterator.hasNext()) { Object value = iterator.next().getValue(); if (value instanceof DirectPositionType) { DirectPositionType position = (DirectPositionType) value; values.addAll(position.getValue()); } else { throw new DeprecatedGeometrySpecificationException( "Geen poslist voor arc binnen curve gespecificeerd"); } } DirectPositionListType newDirectPositionList = new DirectPositionListType(); newDirectPositionList.withValue(values); newDirectPositionList.setSrsDimension(arc.getPosList().getSrsDimension()); newDirectPositionList.setSrsName(arc.getPosList().getSrsName()); return gmlToPointConvertor.translateOrdinates(newDirectPositionList); } else { throw new DeprecatedGeometrySpecificationException("Geen poslist voor arc binnen curve gespecificeerd"); } }
private void validateArcIsNotAStraightLine(CoordinateArraySequence sequence) throws GeometryException { if (CGAlgorithms.isOnLine(sequence.getCoordinate(1), new Coordinate[]{sequence.getCoordinate(0), sequence.getCoordinate(2)})) { throw new InvalidGeometryException(GeometryValidationErrorType.ARC_IS_A_STRAIGHT_LINE, sequence.getCoordinate(1), "arc should not be a straight line"); } }
private LineString convertLineString(LineStringType lineStringType) throws GeometryException { if (lineStringType.getPosList() == null) { throw new DeprecatedGeometrySpecificationException("Geen poslist voor lineString gespecificeerd"); } List<Double> posList = lineStringType.getPosList().getValue(); if (posList.size() < NUMBER_OF_ORDINATES_NEEDED_FOR_LINE) { throw new InvalidGeometryException(GeometryValidationErrorType.TOO_FEW_POINTS, null); } CoordinateArraySequence sequence = gmlToPointConvertor.translateOrdinates(lineStringType.getPosList()); return new LineString(sequence, geometryFactory); }
private List<ContextRegistrationResponse> geolocate(List<ContextRegistrationResponse> crrl, OperationScope opScope, EntityId entityId, ArrayList<String> attributeList) { // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. ObjectMapper objectMapper = new ObjectMapper(); //instantiate registration filter RegisterResultFilter regFilter = new RegisterResultFilter(); ContextRegistrationResponse crr = new ContextRegistrationResponse(); LinkedHashMap shapeHMap = (LinkedHashMap) opScope.getScopeValue(); Shape ngsiShape = objectMapper.convertValue(shapeHMap, Shape.class); final GeometryFactory gf = new GeometryFactory(); Polygon polygon = ngsiShape.getPolygon(); if (!(polygon == null)) { final ArrayList<Coordinate> points = new ArrayList<>(); int polygonPoints = polygon.getVertices().size(); for (int i = 0; i < polygonPoints; i++) { int lat = Integer.getInteger(polygon.getVertices().get(i).getLatitude()); int lon = Integer.getInteger(polygon.getVertices().get(i).getLongitude()); points.add(new Coordinate(lat, lon)); } Geometry shape = gf.createPolygon(new LinearRing(new CoordinateArraySequence(points.toArray( new Coordinate[points.size()])), gf), null); } return crrl; }
protected LinearRing simplify(LinearRing linearRing){ CoordinateSequence coordinateSequence = linearRing.getCoordinateSequence(); Coordinate lastCoord = coordinateSequence.getCoordinate(0); simplifiedCoords.add(lastCoord); for (int i = 1; i < coordinateSequence.size()-1; i++){ Coordinate coord = coordinateSequence.getCoordinate(i); double xDist = (lastCoord.x - coord.x); double yDist = (lastCoord.y - coord.y); double distSq = xDist*xDist + yDist*yDist; if (distSq < minDistSq){ //skip this point }else{ simplifiedCoords.add(coord); lastCoord = coord; } } // if (simplifiedCoords.size() < 2){ // return null; // } if (simplifiedCoords.size() >= 3){ // don't check the first and last coords as they're meant to be the exact same point. simplifiedCoords.add(simplifiedCoords.get(0)); CoordinateArraySequence newCoordinateSequence = new CoordinateArraySequence(simplifiedCoords.toArray(new Coordinate[simplifiedCoords.size()])); simplifiedCoords.clear(); return new LinearRing(newCoordinateSequence, geometryFactory); }else{ simplifiedCoords.clear(); return linearRing; } }
public static ICoordinates getContourCoordinates(final Polygon g) { if (g.isEmpty()) return ICoordinates.EMPTY; if(g.getExteriorRing().getCoordinateSequence() instanceof CoordinateArraySequence) { return GEOMETRY_FACTORY.getCoordinateSequenceFactory().create(g.getExteriorRing().getCoordinates()); } return (ICoordinates) g.getExteriorRing().getCoordinateSequence(); }
public LandCell(int x, int y){ super( new CoordinateArraySequence(new Coordinate[]{ new Coordinate(x, y) }), GEOM_FACTORY ); this.x = x; this.y = y; }
public RoadNode(Coordinate coord, int type){ super( new CoordinateArraySequence(new Coordinate[]{ coord }), new GeometryFactory() ); if(type == MARKET) distFromMarket = 0; else distFromMarket = -1; edges = new LinkedList<RoadEdge>(); }
/** * Checks if the computed value for isInCircle is correct, using * double-double precision arithmetic. * * @param a a vertex of the triangle * @param b a vertex of the triangle * @param c a vertex of the triangle * @param p the point to test */ private static void checkRobustInCircle(Coordinate a, Coordinate b, Coordinate c, Coordinate p) { boolean nonRobustInCircle = isInCircleNonRobust(a, b, c, p); boolean isInCircleDD = TrianglePredicate.isInCircleDDSlow(a, b, c, p); boolean isInCircleCC = TrianglePredicate.isInCircleCC(a, b, c, p); Coordinate circumCentre = Triangle.circumcentre(a, b, c); System.out.println("p radius diff a = " + Math.abs(p.distance(circumCentre) - a.distance(circumCentre)) / a.distance(circumCentre)); if (nonRobustInCircle != isInCircleDD || nonRobustInCircle != isInCircleCC) { System.out.println("inCircle robustness failure (double result = " + nonRobustInCircle + ", DD result = " + isInCircleDD + ", CC result = " + isInCircleCC + ")"); System.out.println(WKTWriter.toLineString(new CoordinateArraySequence( new Coordinate[]{a, b, c, p}))); System.out.println("Circumcentre = " + WKTWriter.toPoint(circumCentre) + " radius = " + a.distance(circumCentre)); System.out.println("p radius diff a = " + Math.abs(p.distance(circumCentre) / a.distance(circumCentre) - 1)); System.out.println("p radius diff b = " + Math.abs(p.distance(circumCentre) / b.distance(circumCentre) - 1)); System.out.println("p radius diff c = " + Math.abs(p.distance(circumCentre) / c.distance(circumCentre) - 1)); System.out.println(); } }
/** * Checks if the computed value for isInCircle is correct, using * double-double precision arithmetic. * * @param a a vertex of the triangle * @param b a vertex of the triangle * @param c a vertex of the triangle * @param p the point to test */ private static void checkRobustInCircle(Coordinate a, Coordinate b, Coordinate c, Coordinate p) { boolean nonRobustInCircle = isInCircle(a, b, c, p); boolean isInCircleDD = TriPredicate.isInCircleDD(a, b, c, p); boolean isInCircleCC = TriPredicate.isInCircleCC(a, b, c, p); Coordinate circumCentre = Triangle.circumcentre(a, b, c); System.out.println("p radius diff a = " + Math.abs(p.distance(circumCentre) - a.distance(circumCentre)) / a.distance(circumCentre)); if (nonRobustInCircle != isInCircleDD || nonRobustInCircle != isInCircleCC) { System.out.println("inCircle robustness failure (double result = " + nonRobustInCircle + ", DD result = " + isInCircleDD + ", CC result = " + isInCircleCC + ")"); System.out.println(WKTWriter.toLineString(new CoordinateArraySequence( new Coordinate[] { a, b, c, p }))); System.out.println("Circumcentre = " + WKTWriter.toPoint(circumCentre) + " radius = " + a.distance(circumCentre)); System.out.println("p radius diff a = " + Math.abs(p.distance(circumCentre)/a.distance(circumCentre) - 1)); System.out.println("p radius diff b = " + Math.abs(p.distance(circumCentre)/b.distance(circumCentre) - 1)); System.out.println("p radius diff c = " + Math.abs(p.distance(circumCentre)/c.distance(circumCentre) - 1)); System.out.println(); } }
@Override public void setGeometry(Geometry geometry) { Point point = (Point) geometry; final Point2D.Double sceneCoords = new Point2D.Double(point.getX(), point.getY()); Point2D.Double modelCoords = new Point2D.Double(); Coordinate coordinate; try { sceneTransformProvider.getSceneToModelTransform().transform(sceneCoords, modelCoords); coordinate = new Coordinate(modelCoords.getX(), modelCoords.getY()); } catch (TransformException e) { coordinate = new Coordinate(Double.NaN, Double.NaN); } this.geometry = new Point(new CoordinateArraySequence(new Coordinate[]{coordinate}), point.getFactory()); }
/** * Checks if the computed value for isInCircle is correct, using * double-double precision arithmetic. * * @param a a vertex of the triangle * @param b a vertex of the triangle * @param c a vertex of the triangle * @param p the point to test */ private static void checkRobustInCircle(Coordinate a, Coordinate b, Coordinate c, Coordinate p) { boolean nonRobustInCircle = isInCircleNonRobust(a, b, c, p); boolean isInCircleDD = TrianglePredicate.isInCircleDDSlow(a, b, c, p); boolean isInCircleCC = TrianglePredicate.isInCircleCC(a, b, c, p); Coordinate circumCentre = Triangle.circumcentre(a, b, c); System.out.println("p radius diff a = " + Math.abs(p.distance(circumCentre) - a.distance(circumCentre)) / a.distance(circumCentre)); if (nonRobustInCircle != isInCircleDD || nonRobustInCircle != isInCircleCC) { System.out.println("inCircle robustness failure (double result = " + nonRobustInCircle + ", DD result = " + isInCircleDD + ", CC result = " + isInCircleCC + ")"); System.out.println(WKTWriter.toLineString(new CoordinateArraySequence( new Coordinate[] { a, b, c, p }))); System.out.println("Circumcentre = " + WKTWriter.toPoint(circumCentre) + " radius = " + a.distance(circumCentre)); System.out.println("p radius diff a = " + Math.abs(p.distance(circumCentre)/a.distance(circumCentre) - 1)); System.out.println("p radius diff b = " + Math.abs(p.distance(circumCentre)/b.distance(circumCentre) - 1)); System.out.println("p radius diff c = " + Math.abs(p.distance(circumCentre)/c.distance(circumCentre) - 1)); System.out.println(); } }