jts-geometry를 AWT 형태로 어떻게 변환 할 수 있습니까?
문제
변환 할 수 있습니까? com.vividsolutions.jts.geom.Geometry
(또는 그것의 서브 클래스)를 구현하는 클래스로 java.awt.Shape
? 그 목표를 달성하기 위해 어떤 라이브러리 또는 방법을 사용할 수 있습니까?
해결책
에 따르면:
http://lists.jump-project.org/pipermail/jts-devel/2007-may/001954.html
수업이 있습니다 :
com.vividsolutions.jump.workbench.ui.renderer.java2D.Java2DConverter
어느 것이 할 수 있습니까?
다른 팁
또한 살펴보십시오 Shapewriter JTS 라이브러리에서 제공합니다. 다음 코드를 사용하여 JTS 지오메트리 객체를 AWT 모양으로 변환했습니다.
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Shape;
import javax.swing.JFrame;
import javax.swing.JPanel;
import com.vividsolutions.jts.awt.ShapeWriter;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.LineString;
import com.vividsolutions.jts.geom.Polygon;
public class Paint extends JPanel{
public void paint(Graphics g) {
Coordinate[] coords = new Coordinate[] {new Coordinate(400, 0), new Coordinate(200, 200), new Coordinate(400, 400), new Coordinate(600, 200), new Coordinate(400, 0) };
Polygon polygon = new GeometryFactory().createPolygon(coords);
LineString ls = new GeometryFactory().createLineString(new Coordinate[] {new Coordinate(20, 20), new Coordinate(200, 20)});
ShapeWriter sw = new ShapeWriter();
Shape polyShape = sw.toShape(polygon);
Shape linShape = sw.toShape(ls);
((Graphics2D) g).draw(polyShape);
((Graphics2D) g).draw(linShape);
}
public static void main(String[] args) {
JFrame f = new JFrame();
f.getContentPane().add(new Paint());
f.setSize(700, 700);
f.setVisible(true);
}
}
편집 : 결과는이 이미지처럼 보입니다
제휴하지 않습니다 StackOverflow