0
와 SVG로? Java 그래픽을 SVG로 내보내는 방법을 알고 있지만 symbol이있는 상자를 정의해야 geotools에서 스타일을 지정할 수 있습니다. 함수의 문제는 기호를 왼쪽 상단 (0,0)에 놓음으로써 기호의 1/4 만이 geotools에 표시되고 QGIS에서는 완벽하게 표시된다는 것입니다. 나는이JavaGraphics 누군가가 SVG에 Java 그래픽을 수출로 도와 줄 수 바틱
그리기 기능을 위해 사용되는 몇 가지 예를 게시하고
public void draw(Graphics g){
Graphics2D g2 = (Graphics2D) g;
float r = 5*_f;
// circle
crtajPodlogu(g2,new Ellipse2D.Float(_x-r,_y-r,2*r,2*r));
//point in middle
g2.fill(new Ellipse2D.Float(_x-r/5,_y-r/5,2*r/5,2*r/5));
g2.draw(new Ellipse2D.Float(_x-r/5,_y-r/5,2*r/5,2*r/5));
// vert. line
g2.draw(new Line2D.Float(_x,_y+r,_x,_y-5*r/2));
//hor. line
g2.draw(new Line2D.Float(_x,_y-2*r,_x+r,_y-2*r));
//arrow
g2.draw(new Line2D.Float(_x+r,_y-2*r,_x+r/2,_y-5*r/2));
g2.draw(new Line2D.Float(_x+r,_y-2*r,_x+r/2,_y-3*r/2));
}
변환 기능
// Get a DOMImplementation.
DOMImplementation domImpl =
GenericDOMImplementation.getDOMImplementation();
// Create an instance of org.w3c.dom.Document.
String svgNS = "http://www.w3.org/2000/svg";
Document document = domImpl.createDocument(svgNS, "svg", null);
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
String[] myStrings = new String[] {
"symbolForSvg",
};
List mylist = Arrays.asList(myStrings);
Iterator itr= mylist.iterator();
while(itr.hasNext()){
try {
Class clazz = Class.forName("key."+itr.next().toString());
java.lang.reflect.Method method = clazz.getMethod("draw", Graphics.class);
method.invoke(clazz.newInstance(), svgGenerator);
// Finally, stream out SVG to the standard output using
// UTF-8 encoding.
//boolean useCSS = true; // we want to use CSS style attributes
Writer out = null;
System.out.println(clazz.getSimpleName());
out = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream("tkey/"+clazz.getSimpleName()+".svg"), "utf-8"));
svgGenerator.stream(out, false);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException
| SecurityException | IllegalArgumentException | InvocationTargetException | UnsupportedEncodingException | FileNotFoundException | SVGGraphics2DIOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
나는이
<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.0//EN'
'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'>
<svg xmlns:xlink="http://www.w3.org/1999/xlink" style="fill-opacity:1; color-rendering:auto; color-interpolation:auto; text-rendering:auto; stroke:black; stroke-linecap:square; stroke-miterlimit:10; shape-rendering:auto; stroke-opacity:1; fill:black; stroke-dasharray:none; font-weight:normal; stroke-width:1; font-family:'Dialog'; font-style:normal; stroke-linejoin:miter; font-size:12px; stroke-dashoffset:0; image-rendering:auto;" xmlns="http://www.w3.org/2000/svg"
><!--Generated by the Batik Graphics2D SVG Generator--><defs id="genericDefs"
/><g
><g
><circle r="5" style="fill:none;" cx="0" cy="0"
/><circle r="1" style="stroke:none;" cx="0" cy="0"
/><circle r="1" style="fill:none;" cx="0" cy="0"
/><line y2="-12.5" style="fill:none;" x1="0" x2="0" y1="5"
/><line y2="-10" style="fill:none;" x1="0" x2="5" y1="-10"
/><line y2="-12.5" style="fill:none;" x1="5" x2="2.5" y1="-10"
/><line y2="-7.5" style="fill:none;" x1="5" x2="2.5" y1="-10"
/></g
></g
></svg>