Java Code Examples for com.vividsolutions.jts.geom.GeometryFactory#createPolygon()
The following examples show how to use
com.vividsolutions.jts.geom.GeometryFactory#createPolygon() .
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: TestReedsSheppCarPlannerSmoothGeometry.java From coordination_oru with GNU General Public License v3.0 | 6 votes |
public static void main(String[] args) { ReedsSheppCarPlanner rsp = new ReedsSheppCarPlanner(); Coordinate footprint1 = new Coordinate(-2.0,0.5); Coordinate footprint2 = new Coordinate(2.0,0.5); Coordinate footprint3 = new Coordinate(2.0,-0.5); Coordinate footprint4 = new Coordinate(-2.0,-0.5); rsp.setRadius(0.5); rsp.setFootprint(footprint1,footprint2,footprint3,footprint4); JTSDrawingPanel panel = JTSDrawingPanel.makeEmpty("debug"); GeometryFactory gf = new GeometryFactory(); Polygon footprint = gf.createPolygon(new Coordinate[] {footprint1,footprint2,footprint3,footprint4,footprint1}); Polygon smoothedFootprint = gf.createPolygon(rsp.getCollisionCircleCenters()); System.out.println("Smoothing went from " + footprint.getCoordinates().length + " to " + smoothedFootprint.getCoordinates().length + " points"); panel.addGeometry("orig", footprint, true, true, true, "#00FF00"); panel.addGeometry("smooth", smoothedFootprint, false, false, true, "#FF0000"); for (int i = 0; i < smoothedFootprint.getCoordinates().length; i++) { double delta = 0.1; Coordinate p1 = new Coordinate(smoothedFootprint.getCoordinates()[i].x,smoothedFootprint.getCoordinates()[i].y); Coordinate p2 = new Coordinate(smoothedFootprint.getCoordinates()[i].x+delta,smoothedFootprint.getCoordinates()[i].y+delta); Coordinate p3 = new Coordinate(smoothedFootprint.getCoordinates()[i].x-delta,smoothedFootprint.getCoordinates()[i].y+delta); panel.addGeometry("_cp"+i, gf.createPolygon(new Coordinate[] {p1,p2,p3,p1}), false, false, false, "#000000"); } }
Example 2
Source File: AbstractTrajectoryEnvelopeCoordinator.java From coordination_oru with GNU General Public License v3.0 | 6 votes |
/** * Generate obstacles representing the placement(s) of a given robot in given poses. * @param robotID The ID of the robot whose footprint should be used. * @param obstaclePoses The poses of the footprint. * @return A {@link Geometry} that has the shape of the given robot's footprint, placed in each of the the given {@link Pose}s. */ public Geometry[] makeObstacles(int robotID, Pose ... obstaclePoses) { ArrayList<Geometry> ret = new ArrayList<Geometry>(); for (Pose p : obstaclePoses) { GeometryFactory gf = new GeometryFactory(); Coordinate[] footprint = this.getFootprint(robotID); Coordinate[] newFoot = new Coordinate[footprint.length+1]; for (int j = 0; j < footprint.length; j++) { newFoot[j] = footprint[j]; } newFoot[footprint.length] = footprint[0]; Geometry obstacle = gf.createPolygon(newFoot); AffineTransformation at = new AffineTransformation(); at.rotate(p.getTheta()); at.translate(p.getX(), p.getY()); obstacle = at.transform(obstacle); ret.add(obstacle); metaCSPLogger.fine("Made obstacle for Robot" + robotID + " in pose " + p); } return ret.toArray(new Geometry[ret.size()]); }
Example 3
Source File: PathEditor.java From coordination_oru with GNU General Public License v3.0 | 6 votes |
private Geometry makeObstacle(Pose p) { GeometryFactory gf = new GeometryFactory(); Geometry geom = null; if (obstacleFootprint == null) { geom = gf.createPolygon(new Coordinate[] { new Coordinate(0.0,0.0), new Coordinate(0.0,OBSTACLE_SIZE), new Coordinate(OBSTACLE_SIZE,OBSTACLE_SIZE), new Coordinate(OBSTACLE_SIZE,0.0), new Coordinate(0.0,0.0) }); } else { geom = gf.createPolygon(obstacleFootprint); } AffineTransformation at = new AffineTransformation(); at.rotate(p.getTheta()); at.translate(p.getX(), p.getY()); Geometry transGeom = at.transform(geom); Pose center = new Pose(p.getX(), p.getY(), p.getTheta()); obstacles.add(transGeom); obstacleCenters.add(center); return transGeom; }
Example 4
Source File: BrowserVisualization.java From coordination_oru with GNU General Public License v3.0 | 6 votes |
private Geometry createArrow(Pose pose, double length, double size) { GeometryFactory gf = new GeometryFactory(); double aux = 1.8; double aux1 = 0.8; double aux2 = 0.3; double theta = pose.getTheta(); Coordinate[] coords = new Coordinate[8]; coords[0] = new Coordinate(0.0,-aux2); coords[1] = new Coordinate(length-aux,-aux2); coords[2] = new Coordinate(length-aux,-aux1); coords[3] = new Coordinate(length,0.0); coords[4] = new Coordinate(length-aux,aux1); coords[5] = new Coordinate(length-aux,aux2); coords[6] = new Coordinate(0.0,aux2); coords[7] = new Coordinate(0.0,-aux2); Polygon arrow = gf.createPolygon(coords); AffineTransformation at = new AffineTransformation(); at.scale(size, size); at.rotate(theta); at.translate(pose.getX(), pose.getY()); Geometry ret = at.transform(arrow); return ret; }
Example 5
Source File: HoleRemover.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
public Polygon getResult() { GeometryFactory gf = poly.getFactory(); Polygon shell = gf.createPolygon((LinearRing) poly.getExteriorRing()); List holes = new ArrayList(); for (int i = 0; i < poly.getNumInteriorRing(); i++) { LinearRing hole = (LinearRing) poly.getInteriorRingN(i); if (! isRemoved.value(hole)) { holes.add(hole); } } // all holes valid, so return original if (holes.size() == poly.getNumInteriorRing()) return poly; // return new polygon with covered holes only Polygon result = gf.createPolygon((LinearRing) poly.getExteriorRing(), GeometryFactory.toLinearRingArray(holes)); return result; }
Example 6
Source File: InvalidHoleRemover.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
public Polygon getResult() { GeometryFactory gf = poly.getFactory(); Polygon shell = gf.createPolygon((LinearRing) poly.getExteriorRing()); PreparedGeometry shellPrep = PreparedGeometryFactory.prepare(shell); List holes = new ArrayList(); for (int i = 0; i < poly.getNumInteriorRing(); i++) { LinearRing hole = (LinearRing) poly.getInteriorRingN(i); if (shellPrep.covers(hole)) { holes.add(hole); } } // all holes valid, so return original if (holes.size() == poly.getNumInteriorRing()) return poly; // return new polygon with covered holes only Polygon result = gf.createPolygon((LinearRing) poly.getExteriorRing(), GeometryFactory.toLinearRingArray(holes)); return result; }
Example 7
Source File: CustomBeanLayerTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
@Before public void setupBeans() throws LayerException { GeometryFactory factory = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING), 4329); LinearRing shell = factory.createLinearRing(new Coordinate[] { new Coordinate(0, 0), new Coordinate(1, 0), new Coordinate(1, 1), new Coordinate(0, 1), new Coordinate(0, 0), }); Polygon p = factory.createPolygon(shell, null); MultiPolygon expected = factory.createMultiPolygon(new Polygon[] { p }); CustomBean cb = new CustomBean(); cb.setId(1); cb.setGeometry(expected); cb.setName("testbean"); layer.saveOrUpdate(cb); }
Example 8
Source File: SimpleRoadMapPlanner.java From coordination_oru with GNU General Public License v3.0 | 5 votes |
private Geometry makeObstacle(Pose pose) { GeometryFactory gf = new GeometryFactory(); Coordinate[] newFoot = new Coordinate[this.footprintCoords.length+1]; for (int j = 0; j < this.footprintCoords.length; j++) { newFoot[j] = this.footprintCoords[j]; } newFoot[this.footprintCoords.length] = this.footprintCoords[0]; Geometry obstacle = gf.createPolygon(newFoot); AffineTransformation at = new AffineTransformation(); at.rotate(pose.getTheta()); at.translate(pose.getX(), pose.getY()); return at.transform(obstacle); }
Example 9
Source File: StyleConverterServiceImpl.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
private Geometry toSimpleGeometry(GeometryFactory factory, AbstractGeometryInfo geom) throws LayerException { Geometry geometry = null; if (geom instanceof PointTypeInfo) { PointTypeInfo point = (PointTypeInfo) geom; if (point.ifCoord()) { geometry = factory.createPoint(getCoordinates(Collections.singletonList(point.getCoord()))[0]); } else if (point.ifCoordinates()) { geometry = factory.createPoint(getCoordinates(point.getCoordinates())[0]); } } else if (geom instanceof LineStringTypeInfo) { LineStringTypeInfo linestring = (LineStringTypeInfo) geom; if (linestring.ifCoordList()) { geometry = factory.createLineString(getCoordinates(linestring.getCoordList())); } else if (linestring.ifCoordinates()) { geometry = factory.createLineString(getCoordinates(linestring.getCoordinates())); } } else if (geom instanceof PolygonTypeInfo) { PolygonTypeInfo polygon = (PolygonTypeInfo) geom; OuterBoundaryIsInfo outer = polygon.getOuterBoundaryIs(); LinearRing shell = toLinearRing(factory, outer.getLinearRing()); if (polygon.getInnerBoundaryIList() == null) { geometry = factory.createPolygon(shell, null); } else { LinearRing[] holes = new LinearRing[polygon.getInnerBoundaryIList().size()]; int i = 0; for (InnerBoundaryIsInfo inner : polygon.getInnerBoundaryIList()) { holes[i++] = toLinearRing(factory, inner.getLinearRing()); } geometry = factory.createPolygon(shell, holes); } } return geometry; }
Example 10
Source File: QuadEdgeTriangle.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
public static Geometry toPolygon(QuadEdge[] e) { Coordinate[] ringPts = new Coordinate[] { e[0].orig().getCoordinate(), e[1].orig().getCoordinate(), e[2].orig().getCoordinate(), e[0].orig().getCoordinate() }; GeometryFactory fact = new GeometryFactory(); LinearRing ring = fact.createLinearRing(ringPts); Polygon tri = fact.createPolygon(ring, null); return tri; }
Example 11
Source File: QuadEdgeTriangle.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
public static Geometry toPolygon(Vertex[] v) { Coordinate[] ringPts = new Coordinate[] { v[0].getCoordinate(), v[1].getCoordinate(), v[2].getCoordinate(), v[0].getCoordinate() }; GeometryFactory fact = new GeometryFactory(); LinearRing ring = fact.createLinearRing(ringPts); Polygon tri = fact.createPolygon(ring, null); return tri; }
Example 12
Source File: GeoJsonReader.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
private Geometry createPolygon(Map<String, Object> geometryMap, GeometryFactory geometryFactory) throws ParseException { Geometry result = null; try { @SuppressWarnings("unchecked") List<List<List<Number>>> ringsList = (List<List<List<Number>>>) geometryMap .get(GeoJsonConstants.NAME_COORDINATES); List<CoordinateSequence> rings = new ArrayList<CoordinateSequence>(); for (List<List<Number>> coordinates : ringsList) { rings.add(createCoordinateSequence(coordinates)); } if (rings.isEmpty()) { throw new IllegalArgumentException("Polygon specified with no rings."); } LinearRing outer = geometryFactory.createLinearRing(rings.get(0)); LinearRing[] inner = null; if (rings.size() > 1) { inner = new LinearRing[rings.size() - 1]; for (int i = 1; i < rings.size(); i++) { inner[i - 1] = geometryFactory.createLinearRing(rings.get(i)); } } result = geometryFactory.createPolygon(outer, inner); } catch (RuntimeException e) { throw new ParseException("Could not parse Polygon from GeoJson string.", e); } return result; }
Example 13
Source File: CopyStrategyTest.java From jaxb2-basics with BSD 2-Clause "Simplified" License | 5 votes |
public void testPolygon() { final GeometryFactory geometryFactory = new GeometryFactory(); final Polygon polygon = geometryFactory.createPolygon( geometryFactory.createLinearRing(new Coordinate[] { new Coordinate(0, 0, 0), new Coordinate(1, 1, 0), new Coordinate(1, 0, 0), new Coordinate(0, 1, 0), new Coordinate(0, 0, 0) }), null); polygon.clone(); new JAXBCopyStrategy().copy(null, polygon); }
Example 14
Source File: TestFactory.java From TomboloDigitalConnector with MIT License | 5 votes |
/** * Returns a square geometry * @param lowerLeftXOffset x-coordinate of lower left corner * @param lowerLeftYOffset y-coordinate of lower left corner * @param edgeSize the edge size of the square * @return A square geometry with left corner at lowerLeftXOffset, lowerLeftYOffset */ public static Geometry makeSquareGeometry(Double lowerLeftXOffset, Double lowerLeftYOffset, Double edgeSize){ GeometryFactory geometryFactory = new GeometryFactory(); Coordinate[] corners = { new Coordinate(lowerLeftXOffset, lowerLeftYOffset), new Coordinate(lowerLeftXOffset, lowerLeftYOffset+edgeSize), new Coordinate(lowerLeftXOffset+edgeSize, lowerLeftYOffset+edgeSize), new Coordinate(lowerLeftXOffset+edgeSize, lowerLeftYOffset), new Coordinate(lowerLeftXOffset, lowerLeftYOffset) }; Geometry square = geometryFactory.createPolygon(corners); square.setSRID(Subject.SRID); return square; }
Example 15
Source File: SearchByLocationCommandTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
@Test public void intersect50percentOverlapExactly() throws Exception { // prepare command SearchByLocationRequest request = new SearchByLocationRequest(); request.setCrs("EPSG:4326"); request.setQueryType(SearchByLocationRequest.QUERY_INTERSECTS); request.setSearchType(SearchByLocationRequest.SEARCH_ALL_LAYERS); request.setRatio(0.5f); request.setLayerIds(new String[] {LAYER_ID}); // create a rectangle that overlaps 50 % GeometryFactory factory = new GeometryFactory(); LinearRing half1 = factory.createLinearRing(new Coordinate[] {new Coordinate(0, 0), new Coordinate(1, 0), new Coordinate(1, 0.5), new Coordinate(0, 0.5), new Coordinate(0, 0)}); Polygon polygon = factory.createPolygon(half1, null); request.setLocation(converter.toDto(polygon)); // execute SearchByLocationResponse response = (SearchByLocationResponse) dispatcher.execute( SearchByLocationRequest.COMMAND, request, null, "en"); // test Assert.assertFalse(response.isError()); List<Feature> features = response.getFeatureMap().get(LAYER_ID); Assert.assertNotNull(features); List<String> actual = new ArrayList<String>(); for (Feature feature : features) { actual.add(feature.getLabel()); } List<String> expected = new ArrayList<String>(); expected.add("Country 1"); Assert.assertEquals(expected, actual); }
Example 16
Source File: JTSDrawingPanelVisualization.java From coordination_oru with GNU General Public License v3.0 | 5 votes |
public void setMinimumVisibleFrame(double minX, double minY, double maxX, double maxY) { GeometryFactory gf = new GeometryFactory(); Geometry frame = gf.createPolygon(new Coordinate[] { new Coordinate(minX,minY), new Coordinate(minX,maxY), new Coordinate(maxX,maxY), new Coordinate(maxX,minY), new Coordinate(minX,minY) }); panel.removeGeometry("_frame"); panel.addGeometry("_frame", frame, true, false, true, "#000000"); panel.setPermanent("_frame"); }
Example 17
Source File: AbstractMotionPlanner.java From coordination_oru with GNU General Public License v3.0 | 5 votes |
private Geometry getFootprintAsGeometry() { GeometryFactory gf = new GeometryFactory(); Coordinate[] newFoot = new Coordinate[footprintCoords.length+1]; for (int j = 0; j < footprintCoords.length; j++) { newFoot[j] = footprintCoords[j]; } newFoot[footprintCoords.length] = footprintCoords[0]; Geometry foot = gf.createPolygon(newFoot); return foot; }
Example 18
Source File: GeoJsonReader.java From jts with GNU Lesser General Public License v2.1 | 4 votes |
private Geometry createMultiPolygon(Map<String, Object> geometryMap, GeometryFactory geometryFactory) throws ParseException { Geometry result = null; try { @SuppressWarnings("unchecked") List<List<List<List<Number>>>> polygonsList = (List<List<List<List<Number>>>>) geometryMap .get(GeoJsonConstants.NAME_COORDINATES); Polygon[] polygons = new Polygon[polygonsList.size()]; int p = 0; for (List<List<List<Number>>> ringsList : polygonsList) { List<CoordinateSequence> rings = new ArrayList<CoordinateSequence>(); for (List<List<Number>> coordinates : ringsList) { rings.add(createCoordinateSequence(coordinates)); } if (rings.isEmpty()) { continue; } LinearRing outer = geometryFactory.createLinearRing(rings.get(0)); LinearRing[] inner = null; if (rings.size() > 1) { inner = new LinearRing[rings.size() - 1]; for (int i = 1; i < rings.size(); i++) { inner[i - 1] = geometryFactory.createLinearRing(rings.get(i)); } } polygons[p] = geometryFactory.createPolygon(outer, inner); ++p; } result = geometryFactory.createMultiPolygon(polygons); } catch (RuntimeException e) { throw new ParseException( "Could not parse MultiPolygon from GeoJson string.", e); } return result; }
Example 19
Source File: QuadEdgeTriangle.java From jts with GNU Lesser General Public License v2.1 | 4 votes |
public Polygon getGeometry(GeometryFactory fact) { LinearRing ring = fact.createLinearRing(getCoordinates()); Polygon tri = fact.createPolygon(ring, null); return tri; }
Example 20
Source File: SimpleDemo.java From jts with GNU Lesser General Public License v2.1 | 2 votes |
private Geometry demonstrateGeometryAndWktWriter() { GeometryFactory gf = new GeometryFactory(); WKTWriter wkt2 = new WKTWriter(); WKTWriter wkt3 = new WKTWriter(3); Coordinate c1 = new Coordinate(1234234.233442, 2234234.234234, 3323424.2342342); Point p = gf.createPoint(c1); sLogger.info("Point WKT: " + wkt2.write(p)); sLogger.info("Point WKT3: " + wkt3.write(p)); Coordinate c2 = new Coordinate(4234234.233442, 5234223.234234, 5323424.2342342); Coordinate[] c3 = new Coordinate[] { c1, c2 }; MultiPoint mp = gf.createMultiPoint(c3); sLogger.info("Point WKT: " + wkt2.write(mp)); sLogger.info("Point WKT3: " + wkt3.write(mp)); LineString ls = gf.createLineString(c3); sLogger.info("Point WKT: " + wkt2.write(ls)); sLogger.info("Point WKT3: " + wkt3.write(ls)); MultiLineString mls = gf.createMultiLineString(new LineString[] { ls, ls }); sLogger.info("Point WKT: " + wkt2.write(mls)); sLogger.info("Point WKT3: " + wkt3.write(mls)); Coordinate c4 = new Coordinate(6234234.233442, 8234234.234234, 9323424.2342342); Coordinate[] c5 = new Coordinate[] { c1, c2, c4, c1 }; Polygon poly = gf.createPolygon(c5); sLogger.info("Point WKT: " + wkt2.write(poly)); sLogger.info("Point WKT3: " + wkt3.write(poly)); MultiPolygon mpoly = gf .createMultiPolygon(new Polygon[] { poly, poly }); sLogger.info("Point WKT: " + wkt2.write(mpoly)); sLogger.info("Point WKT3: " + wkt3.write(mpoly)); GeometryCollection gc = gf.createGeometryCollection(new Geometry[] { p, mp, ls, mls, poly, mpoly }); sLogger.info("Point WKT: " + wkt2.write(gc)); sLogger.info("Point WKT3: " + wkt3.write(gc)); return gc; }