Java Code Examples for com.vividsolutions.jts.geom.Geometry#getCoordinates()
The following examples show how to use
com.vividsolutions.jts.geom.Geometry#getCoordinates() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GamaGeometryType.java From gama with GNU General Public License v3.0 | 6 votes |
public static IShape buildSquircle(final double xRadius, final double power, final GamaPoint location) { if (xRadius <= 0) { return new GamaShape(location); } final GeometricShapeFactory factory = new GeometricShapeFactory(GeometryUtils.GEOMETRY_FACTORY); factory.setNumPoints(GamaPreferences.Displays.DISPLAY_SLICE_NUMBER.getValue()); // WARNING AD Arbitrary number. // Maybe add a // parameter and/or preference ? factory.setCentre(location); factory.setSize(xRadius); final Geometry g = factory.createSupercircle(power); if (location != null) { final Coordinate[] coordinates = g.getCoordinates(); for (int i = 0; i < coordinates.length; i++) { coordinates[i].z = location.z; } } return new GamaShape(g); }
Example 2
Source File: CGAlgorithmFunctions.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
public static Geometry segmentIntersectionDD(Geometry g1, Geometry g2) { Coordinate[] pt1 = g1.getCoordinates(); Coordinate[] pt2 = g2.getCoordinates(); // first check if there actually is an intersection RobustLineIntersector ri = new RobustLineIntersector(); ri.computeIntersection(pt1[0], pt1[1], pt2[0], pt2[1]); if (! ri.hasIntersection()) { // no intersection => return empty point return g1.getFactory().createPoint((Coordinate) null); } Coordinate intPt = CGAlgorithmsDD.intersection(pt1[0], pt1[1], pt2[0], pt2[1]); return g1.getFactory().createPoint(intPt); }
Example 3
Source File: CGAlgorithmFunctions.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
public static Geometry segmentIntersection(Geometry g1, Geometry g2) { Coordinate[] pt1 = g1.getCoordinates(); Coordinate[] pt2 = g2.getCoordinates(); RobustLineIntersector ri = new RobustLineIntersector(); ri.computeIntersection(pt1[0], pt1[1], pt2[0], pt2[1]); switch (ri.getIntersectionNum()) { case 0: // no intersection => return empty point return g1.getFactory().createPoint((Coordinate) null); case 1: // return point return g1.getFactory().createPoint(ri.getIntersection(0)); case 2: // return line return g1.getFactory().createLineString( new Coordinate[] { ri.getIntersection(0), ri.getIntersection(1) }); } return null; }
Example 4
Source File: GamaGeometryType.java From gama with GNU General Public License v3.0 | 6 votes |
public static IShape buildEllipse(final double xRadius, final double yRadius, final GamaPoint location) { if (xRadius <= 0) { if (yRadius <= 0) { return new GamaShape(location); } } final GeometricShapeFactory factory = new GeometricShapeFactory(GeometryUtils.GEOMETRY_FACTORY); factory.setNumPoints(GamaPreferences.Displays.DISPLAY_SLICE_NUMBER.getValue()); // WARNING AD Arbitrary number. // Maybe add a // parameter and/or preference ? factory.setCentre(location); factory.setWidth(xRadius); factory.setHeight(yRadius); final Geometry g = factory.createEllipse(); if (location != null) { final Coordinate[] coordinates = g.getCoordinates(); for (int i = 0; i < coordinates.length; i++) { coordinates[i].z = location.z; } } return new GamaShape(g); }
Example 5
Source File: GeometryUtils.java From gama with GNU General Public License v3.0 | 5 votes |
public static int nbCommonPoints(final Geometry p1, final Geometry p2) { try (final ICollector<Coordinate> cp = Collector.getSet()) { final List<Coordinate> coords = Arrays.asList(p1.getCoordinates()); for (final Coordinate pt : p2.getCoordinates()) { if (coords.contains(pt)) { cp.add(pt); } } return cp.size(); } }
Example 6
Source File: GeometryUtils.java From gama with GNU General Public License v3.0 | 5 votes |
private static IList<IShape> filterGeoms(final GeometryCollection geom, final Geometry clip, final double sizeTol, final boolean approxClipping) { if (geom == null) { return null; } final double elevation = getContourCoordinates(clip).averageZ(); final boolean setZ = elevation != 0.0; final IList<IShape> result = GamaListFactory.create(Types.GEOMETRY); final Geometry bufferClip = sizeTol != 0.0 ? clip.buffer(sizeTol, 5, 0) : clip; final PreparedGeometry buffered = PREPARED_GEOMETRY_FACTORY.create(bufferClip); final Envelope3D env = Envelope3D.of(buffered.getGeometry()); try { for (int i = 0; i < geom.getNumGeometries(); i++) { final Geometry gg = geom.getGeometryN(i); if (!clip.covers(gg.getCentroid())) continue; final Coordinate[] coord = gg.getCoordinates(); boolean cond = env.covers(gg.getCentroid().getCoordinate()); cond = cond && (approxClipping ? buffered.covers(gg.getCentroid()) && buffered.covers(GEOMETRY_FACTORY.createPoint(coord[0])) && buffered.covers(GEOMETRY_FACTORY.createPoint(coord[1])) && buffered.covers(GEOMETRY_FACTORY.createPoint(coord[2])) : bufferClip.covers(gg)); if (cond) { if (setZ) { final ICoordinates cc = getContourCoordinates(gg); cc.setAllZ(elevation); gg.geometryChanged(); } result.add(new GamaShape(gg)); } } } finally { env.dispose(); } /* * applyToInnerGeometries(geom, (gg) -> { final ICoordinates cc = getContourCoordinates(gg); if * (cc.isCoveredBy(env) && buffered.covers(gg)) { * * } }); */ return result; }
Example 7
Source File: GeoServiceTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
private void assertTransformedLineString(Geometry geometry) { System.out.println(geometry.toString()); Coordinate[] coordinates = geometry.getCoordinates(); Assert.assertEquals(4, coordinates.length); Assert.assertEquals(243228.2415398722, coordinates[0].x, DELTA); Assert.assertEquals(-5562212.2922869185, coordinates[0].y, DELTA); Assert.assertEquals(3571198.1691051605, coordinates[1].x, DELTA); Assert.assertEquals(-4114094.247419103, coordinates[1].y, DELTA); Assert.assertEquals(-5635610.296096718, coordinates[2].x, DELTA); Assert.assertEquals(488056.5712725008, coordinates[2].y, DELTA); Assert.assertEquals(3219427.718819718, coordinates[3].x, DELTA); Assert.assertEquals(1050557.615059331, coordinates[3].y, DELTA); }
Example 8
Source File: BrowserVisualization.java From coordination_oru with GNU General Public License v3.0 | 5 votes |
private String geometryToJSONString(String name, Geometry geom, String color, long age, boolean filled, String extraData) { String ret = "{ \"name\" : \"" + name + "\", \"color\" : \"" + color + "\", "; if (age > 0) ret += " \"age\" : " + age + ", "; ret += " \"filled\" : " + filled + ", "; if (extraData != null && !extraData.trim().equals("")) ret += " \"extraData\" : \"" + extraData + "\", "; ret += "\"coordinates\" : ["; Coordinate[] coords = geom.getCoordinates(); for (int i = 0; i < coords.length; i++) { ret += "{\"x\" : " + coords[i].x + ", \"y\" : " + coords[i].y + "}"; if (i < coords.length-1) ret += ", "; } ret += "]}"; return ret; }
Example 9
Source File: ReadFeatureApiIT.java From xyz-hub with Apache License 2.0 | 5 votes |
@Test public void testMTVResponse() throws IOException { InputStream inputStream = given() .contentType(APPLICATION_VND_MAPBOX_VECTOR_TILE) .headers(getAuthHeaders(AuthProfile.ACCESS_OWNER_1_ADMIN)) .when() .get("/spaces/x-psql-test/tile/quadkey/120203302032.mvt") .getBody().asInputStream(); ; GeometryFactory geomFactory = new GeometryFactory(); JtsMvt jtsMvt = MvtReader.loadMvt( inputStream, geomFactory, new TagKeyValueMapConverter()); JtsLayer layer = jtsMvt.getLayer("x-psql-test"); ArrayList<Geometry> geometries = (ArrayList<Geometry>) layer.getGeometries(); Geometry geom = geometries.get(0).getGeometryN(0); Object userData = geometries.get(0).getUserData(); LinkedHashMap<String,Object> t = (LinkedHashMap<String,Object>)userData; assertEquals("Commerzbank-Arena",t.get("name")); assertEquals("association football",t.get("sport")); assertEquals(51500l,t.get("capacity")); assertEquals("Eintracht Frankfurt",t.get("occupant")); assertNotNull(t.get("@ns:com:here:xyz")); Coordinate[] coordinates = geom.getCoordinates(); assertEquals(1491, coordinates[0].x, 0); assertEquals(3775, coordinates[0].y, 0); //Todo: check z after NaN fix // assertEquals("NaN", coordinates[0].z); }
Example 10
Source File: GamaGeometryType.java From gama with GNU General Public License v3.0 | 5 votes |
/** * * @param xRadius * @param heading * in decimal degrees * @param amplitude * in decimal degrees * @param filled * @param location * @return */ public static IShape buildArc(final double xRadius, final double heading, final double amplitude, final boolean filled, final GamaPoint location) { if (amplitude <= 0 || xRadius <= 0) { return new GamaShape(location); } final GeometricShapeFactory factory = new GeometricShapeFactory(GeometryUtils.GEOMETRY_FACTORY); factory.setNumPoints(GamaPreferences.Displays.DISPLAY_SLICE_NUMBER.getValue()); // WARNING AD Arbitrary number. // Maybe add a // parameter and/or preference ? factory.setCentre(location); factory.setSize(xRadius); final double ampl = Maths.checkHeading(amplitude); final double angExtent = Maths.toRad * ampl; final double startAng = Maths.toRad * Maths.checkHeading(heading - ampl / 2); Geometry g; if (filled) { g = factory.createArcPolygon(startAng, angExtent); } else { g = factory.createArc(startAng, angExtent); } if (location != null) { final Coordinate[] coordinates = g.getCoordinates(); for (int i = 0; i < coordinates.length; i++) { coordinates[i].z = location.z; } } return new GamaShape(g); }
Example 11
Source File: GeoMongoDBStorageStrategy.java From rya with Apache License 2.0 | 5 votes |
private List<List<Double>> getPoints(final Geometry geo) { final List<List<Double>> points = new ArrayList<>(); for (final Coordinate coord : geo.getCoordinates()) { points.add(getPoint(coord)); } return points; }
Example 12
Source File: CreateRandomShapeFunctions.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
public static Geometry randomPointsInTriangle(Geometry g, int nPts) { GeometryFactory geomFact = FunctionsUtil.getFactoryOrDefault(g); Coordinate[] gpts = g.getCoordinates(); Coordinate tri0 = gpts[0]; Coordinate tri1 = gpts[1]; Coordinate tri2 = gpts[2]; List pts = new ArrayList(); for (int i = 0; i < nPts; i++) { pts.add(geomFact.createPoint(randomPointInTriangle(tri0, tri1, tri2))); } return geomFact.buildGeometry(pts); }
Example 13
Source File: SpatialIndexFunctions.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
private static KdTree buildKdTree(Geometry geom, double tolerance) { final KdTree index = new KdTree(tolerance); Coordinate[] pt = geom.getCoordinates(); for (int i = 0; i < pt.length; i++) { index.insert(pt[i]); } return index; }
Example 14
Source File: VmlFeatureWriter.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
public void writeObject(Object object, GraphicsDocument document, boolean asChild) throws RenderException { try { InternalFeature feature = (InternalFeature) object; Geometry geom = feature.getGeometry(); if (feature.isClipped()) { geom = feature.getClippedGeometry(); } geom = transformer.transform(geom); if (isPointLike(feature)) { if (feature.getStyleInfo().getSymbol() != null) { SymbolInfo info = feature.getStyleInfo().getSymbol(); for (Coordinate coordinate : geom.getCoordinates()) { if (info.getRect() != null) { writeRectangle(document, coordinate, feature, info.getRect()); } else if (info.getCircle() != null) { RectInfo rectInfo = new RectInfo(); float diameter = info.getCircle().getR() * 2; rectInfo.setW(diameter); rectInfo.setH(diameter); writeRectangle(document, coordinate, feature, rectInfo); } else if (info.getImage() != null) { writeImage(document, coordinate, feature, info.getImage()); } } } } else { document.writeObject(geom, asChild); document.writeAttribute("style", "WIDTH: 100%; HEIGHT: 100%"); document.writeAttribute("coordsize", coordWidth + "," + coordHeight); document.writeAttribute("type", "#" + feature.getStyleInfo().getStyleId()); document.writeAttribute("id", feature.getId()); } } catch (TransformException e) { log.warn("could not render feature"); } }
Example 15
Source File: CGAlgorithmFunctions.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
public static int orientationIndexDD(Geometry segment, Geometry ptGeom) { if (segment.getNumPoints() != 2 || ptGeom.getNumPoints() != 1) { throw new IllegalArgumentException("A must have two points and B must have one"); } Coordinate[] segPt = segment.getCoordinates(); Coordinate p = ptGeom.getCoordinate(); int index = CGAlgorithmsDD.orientationIndex(segPt[0], segPt[1], p); return index; }
Example 16
Source File: CGAlgorithmFunctions.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
public static boolean segmentIntersects(Geometry g1, Geometry g2) { Coordinate[] pt1 = g1.getCoordinates(); Coordinate[] pt2 = g2.getCoordinates(); RobustLineIntersector ri = new RobustLineIntersector(); ri.computeIntersection(pt1[0], pt1[1], pt2[0], pt2[1]); return ri.hasIntersection(); }
Example 17
Source File: GeoServiceTransformableAreaTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
private void assertTransformedLineString(Geometry geometry) { Coordinate[] coordinates = geometry.getCoordinates(); Assert.assertEquals(5, coordinates.length); Assert.assertEquals(243228.2415398722, coordinates[0].x, DELTA); Assert.assertEquals(-5562212.2922869185, coordinates[0].y, DELTA); Assert.assertEquals(3571198.1691051605, coordinates[1].x, DELTA); Assert.assertEquals(-4114094.247419103, coordinates[1].y, DELTA); Assert.assertEquals(-1559252.030797058, coordinates[2].x, DELTA); Assert.assertEquals(4925010.054948342, coordinates[2].y, DELTA); Assert.assertEquals(-1576255.123949388, coordinates[3].x, DELTA); Assert.assertEquals(4991115.69215949, coordinates[3].y, DELTA); Assert.assertEquals(3219427.718819718, coordinates[4].x, DELTA); Assert.assertEquals(1050557.615059331, coordinates[4].y, DELTA); }
Example 18
Source File: LuceneQueryBuilder.java From Elasticsearch with Apache License 2.0 | 5 votes |
private Query getQuery(Function inner, Context context) { RefLiteralPair innerPair = new RefLiteralPair(inner); if (!innerPair.isValid()) { return null; } if (innerPair.reference().valueType().equals(DataTypes.GEO_SHAPE)) { // we have within('POINT(0 0)', shape_column) return genericFunctionFilter(inner, context); } GeoPointFieldMapper.GeoPointFieldType geoPointFieldType = getGeoPointFieldType( innerPair.reference().ident().columnIdent().fqn(), context.mapperService); Map<String, Object> geoJSON = (Map<String, Object>) innerPair.input().value(); Shape shape = GeoJSONUtils.map2Shape(geoJSON); Geometry geometry = JtsSpatialContext.GEO.getGeometryFrom(shape); IndexGeoPointFieldData fieldData = context.fieldDataService.getForField(geoPointFieldType); if (geometry.isRectangle()) { Rectangle boundingBox = shape.getBoundingBox(); return new InMemoryGeoBoundingBoxQuery( new GeoPoint(boundingBox.getMaxY(), boundingBox.getMinX()), new GeoPoint(boundingBox.getMinY(), boundingBox.getMaxX()), fieldData ); } else { Coordinate[] coordinates = geometry.getCoordinates(); GeoPoint[] points = new GeoPoint[coordinates.length]; for (int i = 0; i < coordinates.length; i++) { Coordinate coordinate = coordinates[i]; points[i] = new GeoPoint(coordinate.y, coordinate.x); } return new GeoPolygonQuery(fieldData, points); } }
Example 19
Source File: GeometryUtils.java From gama with GNU General Public License v3.0 | 4 votes |
public static GamaPoint getFirstPointOf(final IShape shape) { final Geometry g = shape.getInnerGeometry(); if (g.isEmpty()) { return null; } return (GamaPoint) g.getCoordinates()[0]; }
Example 20
Source File: GeometryUtils.java From gama with GNU General Public License v3.0 | 4 votes |
public static GamaPoint getLastPointOf(final IShape shape) { final Geometry g = shape.getInnerGeometry(); if (g.isEmpty()) { return null; } final Coordinate[] cc = g.getCoordinates(); return (GamaPoint) cc[cc.length - 1]; }