import org.locationtech.jts.geom.*; import org.locationtech.jts.io.*; import org.locationtech.jts.geom.Coordinate; import org.locationtech.jts.geom.GeometryFactory; import org.locationtech.jts.geom.Polygon; import org.locationtech.jts.awt.ShapeWriter; import org.locationtech.jts.awt.GeometryCollectionShape; import org.locationtech.jts.awt.ShapeReader; import com.vividsolutions.jts.util.GeometricShapeFactory; import java.awt.*; import javax.swing.*; private static Geometry createPolygon() { GeometryFactory geometryFactory = new GeometryFactory(); Coordinate[] coordinates = new Coordinate[] { new Coordinate(0, 0), new Coordinate(0, 10), new Coordinate(10, 10), new Coordinate(10, 0), new Coordinate(0, 0) }; LinearRing linearRing = geometryFactory.createLinearRing(coordinates); return geometryFactory.createPolygon(linearRing, null); } public static void main(String[] args) { GeometryFactory geometryFactory = new GeometryFactory(); Geometry polygon = createPolygon(); GeometryCollectionShape geometryCollectionShape = new GeometryCollectionShape(polygon, null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(400, 400); JPanel panel = new JPanel() { protected void paintComponent(Graphics graphics) { super.paintComponent(graphics); Graphics2D g2d = (Graphics2D) graphics; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setStroke(new BasicStroke(2)); g2d.setColor(Color.BLUE); ShapeWriter.write(g2d, geometryCollectionShape); } }; frame.add(panel); frame.setVisible(true); }


上一篇:
下一篇:
切换中文