/** * 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()); }
/** * Creates a Point using the given CoordinateSequence; a null or empty * CoordinateSequence will create an empty Point. */ public Point createPoint(CoordinateSequence coordinates) { return new Point(coordinates, this); }
/** * Creates a Point using the given CoordinateSequence; a null or empty * CoordinateSequence will create an empty Point. * * @param coordinates a CoordinateSequence (possibly empty), or null * @return the created Point */ public Point createPoint(CoordinateSequence coordinates) { return new Point(coordinates, this); }
@Test public void test() { Coordinate coordiates2d = new Coordinate(34.2d,34.4d); Coordinate[] coordinates = new Coordinate[1]; coordinates[0]=coordiates2d; com.vividsolutions.jts.geom.impl.PackedCoordinateSequence.Float floatSequence = new com.vividsolutions.jts.geom.impl.PackedCoordinateSequence.Float(coordinates, 2); GeometryFactory geoFactory = new GeometryFactory(new PrecisionModel(2)); Point point = new Point(floatSequence,geoFactory); point.setSRID(2); point.setSurfaceType(SurfaceType.FLAT); Geometry geometry = new com.vividsolutions.jts.geom.Point(floatSequence,geoFactory); Assert.assertTrue(point.contains(geometry)); Assert.assertTrue(point.getSurfaceType() != null); Assert.assertEquals(SurfaceType.FLAT,point.getSurfaceType()); Assert.assertEquals(2,point.getSRID()); point = new Point(coordiates2d,new PrecisionModel(2),12); Assert.assertNotNull(point); }
@Override public void setPosition(double longitude, double latitude) { Coordinate[] coordinates = new Coordinate[]{new Coordinate(longitude, latitude)}; CoordinateSequence coordSequence = new CoordinateArraySequence(coordinates); Point point = new Point(coordSequence, new GeometryFactory()); setGeometry(point); }
@Override public Point getCentroid() { Coordinate[] coordinates = new Coordinate[]{new Coordinate(machine.getLongitude(), machine.getLatitude())}; CoordinateSequence coordSequence = new CoordinateArraySequence(coordinates); return new Point(coordSequence, new GeometryFactory()); }
@Override public Point convert(final Location location) { final Coordinate coordinate = LOCATION_CONVERTER.convert(location); final CoordinateArraySequence sequence = new CoordinateArraySequence( new Coordinate[] { coordinate }); return new Point(sequence, GEOMETRY_FACTORY); } }
public static Point getPoint(double lat, double lon) { Coordinate[] coords = new Coordinate[1]; coords[0] = new Coordinate(lon, lat); CoordinateArraySequence coordArraySeq = new CoordinateArraySequence(coords); return new Point(coordArraySeq, new GeometryFactory(new PrecisionModel(), 4326)); } }
public static Point getPoint(double lat, double lon) { Coordinate[] coords = new Coordinate[1]; coords[0] = new Coordinate(lon, lat); CoordinateArraySequence coordArraySeq = new CoordinateArraySequence(coords); return new Point(coordArraySeq, new GeometryFactory(new PrecisionModel(), 4326)); } }
public static void main(String[] args){ try { //Env env = EnvBuilder.envFromArgs(args); //Configurator c = env.getConfigurator(); Point3DDistance eval = new Point3DDistance(); GeodeticCalculator calc = new GeodeticCalculator(); Coordinate beijing = new Coordinate(116, 39.9, 0); Coordinate la = new Coordinate(-118.25, 34.05, 0); Point a = new Point(beijing, new PrecisionModel(), 4326); Point b = new Point(la, new PrecisionModel(), 4326); System.out.printf("%.2f km\n", eval.calculate3DDistance(a, b, calc)/1000); }catch(Exception e){ e.printStackTrace();; } }
public static void main(String[] args){ try { //Env env = EnvBuilder.envFromArgs(args); //Configurator c = env.getConfigurator(); Point3DDistance eval = new Point3DDistance(); GeodeticCalculator calc = new GeodeticCalculator(); Coordinate beijing = new Coordinate(116, 39.9, 0); Coordinate la = new Coordinate(-118.25, 34.05, 0); Point a = new Point(beijing, new PrecisionModel(), 4326); Point b = new Point(la, new PrecisionModel(), 4326); System.out.printf("%.2f km\n", eval.calculate3DDistance(a, b, calc)/1000); }catch(Exception e){ e.printStackTrace();; } }
private static com.vividsolutions.jts.geom.Geometry createEmpty(GeometryFactory factory, String geometryType) throws JtsConversionException { if (Geometry.POINT.equals(geometryType)) { return new Point(null, factory); // do not use GeometryFactory.createPoint(null,...) as that returns null } else if (Geometry.LINEAR_RING.equals(geometryType)) { return factory.createLinearRing((com.vividsolutions.jts.geom.Coordinate[]) null); } else if (Geometry.LINE_STRING.equals(geometryType)) { return factory.createLineString((com.vividsolutions.jts.geom.Coordinate[]) null); } else if (Geometry.POLYGON.equals(geometryType)) { return factory.createPolygon(null, null); } else if (Geometry.MULTI_POINT.equals(geometryType)) { return factory.createMultiPoint((Point[]) null); } else if (Geometry.MULTI_LINE_STRING.equals(geometryType)) { return factory.createMultiLineString(null); } else if (Geometry.MULTI_POLYGON.equals(geometryType)) { return factory.createMultiPolygon(null); } else { throw new JtsConversionException("Error while converting to Geomajas: Unknown geometry type."); } }
private Geometry buildGeometry() { Coordinate[] coordinates = new Coordinate[locations.size()]; for (int i = 0; i < locations.size(); i++) { coordinates[i] = new Coordinate( locations.get(i).getLongitude(), locations.get(i).getLatitude()); } GeometryFactory factory = SPATIAL_CONTEXT.getGeometryFactory(); CoordinateSequence sequence = factory.getCoordinateSequenceFactory().create(coordinates); switch (getShapeType()) { case POINT: return new Point(sequence, factory); case LINESTRING: return new LineString(sequence, factory); case POLYGON: LinearRing shell = new LinearRing(sequence, factory); return new Polygon(shell, null, factory); default: throw new IllegalStateException("Unrecognized geometry"); } }
@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()); }
@Override public Point getCentroid() { if (getInternalGrid() == null) { LOGGER.warning("FIXME:getCentroid called while grid is null"); return null; } if (centroid == null) { Double x = getInternalGrid().getEnvelope2D().getCenterX(); Double y = getInternalGrid().getEnvelope2D().getCenterY(); centroid = new Point(new CoordinateArraySequence(new Coordinate[]{new Coordinate(x, y)}), JTSFactoryFinder.getGeometryFactory(null)); } return centroid; }
Point point = new Point(subList(gf.getCoordinateSequenceFactory(), coords, GTYPE, elemInfo, element), gf);
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; }
* (((double) t) / (n + 1)), glyphBounds .getCenterY()); Point pp = new Point(c, representativeGeom .getPrecisionModel(), representativeGeom.getSRID()); if (p.distance(pp) < mindistance)
@Test public void testChangingFeature() { placemarkGroup.add(createPlacemark("p1", new PixelPos(3, 1), new GeoPos(12, 34))); placemarkGroup.add(createPlacemark("p2", new PixelPos(5, 4), new GeoPos(16, 48))); placemarkGroup.add(createPlacemark("p3", new PixelPos(6, 2), new GeoPos(-45, 80))); assertAreEqual(placemarkGroup, pinFeatureCollection); final CoordinateArraySequence coordinates = new CoordinateArraySequence( new Coordinate[]{new Coordinate(-30, 70)}); final SimpleFeature changedFeature = placemarkGroup.get(2).getFeature(); changedFeature.setDefaultGeometry(new Point(coordinates, new GeometryFactory())); assertAreEqual(placemarkGroup, pinFeatureCollection); final SimpleFeature[] features = pinFeatureCollection.toArray(new SimpleFeature[pinFeatureCollection.size()]); assertEquals(changedFeature.getDefaultGeometry(), features[2].getDefaultGeometry()); }