📄 testimport.java.svn-base
字号:
package test;
import java.io.File;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import org.jdom.Attribute;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.Namespace;
import org.jdom.input.SAXBuilder;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
import org.jdom.xpath.XPath;
import com.esri.arcgis.datasourcesGDB.SdeWorkspaceFactory;
import com.esri.arcgis.geodatabase.FeatureClass;
import com.esri.arcgis.geodatabase.FeatureCursor;
import com.esri.arcgis.geodatabase.IFeatureBuffer;
import com.esri.arcgis.geodatabase.IFeatureWorkspace;
import com.esri.arcgis.geometry.IPoint;
import com.esri.arcgis.geometry.IPointCollection;
import com.esri.arcgis.geometry.IPolyline;
import com.esri.arcgis.geometry.Point;
import com.esri.arcgis.geometry.Polyline;
import com.esri.arcgis.system.AoInitialize;
import com.esri.arcgis.system.EngineInitializer;
import com.esri.arcgis.system.PropertySet;
import com.esri.arcgis.system.esriLicenseProductCode;
import junit.framework.TestCase;
public class TestImport extends TestCase {
AoInitialize aoInit;
public static final String filename="src/test/ZJ_温州_瓯海变.fac.svg";
Namespace ns_svg=Namespace.getNamespace("", "http://www.w3.org/2000/svg");
private final Namespace ns_cge=Namespace.getNamespace("cge", "http://www.cim.com");
Document doc=null;
SAXBuilder builder =new SAXBuilder();
Element root=null;
XPath path;
IFeatureWorkspace ifw;
ArrayList<Double> point=new ArrayList<Double>();
ArrayList<String> attr=new ArrayList<String>();
XMLOutputter out;
Format format = Format.getCompactFormat();
protected void setUp() throws Exception {
/*EngineInitializer.initializeEngine();
aoInit =new AoInitialize();
aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB);
PropertySet propSet = new PropertySet();
//连接参数
propSet.setProperty("SERVER", "10.158.164.220");
propSet.setProperty("INSTANCE", "5151");
//propSet.setProperty("DATABASE", "sde");
propSet.setProperty("USER", "sde");
propSet.setProperty("PASSWORD", "sde");
propSet.setProperty("VERSION", "SDE.DEFAULT");
SdeWorkspaceFactory swf=new SdeWorkspaceFactory();
ifw=(IFeatureWorkspace)swf.open(propSet, 0);*/
format.setEncoding("gb2312"); //设置xml文件的字符为gb2312
format.setIndent(" "); //缩进
out=new XMLOutputter(format);
}
protected void tearDown() throws Exception {
//aoInit.shutdown();
}
public void testImp() throws Exception{
doc=builder.build(new File(filename));
root=doc.getRootElement();//取得根元素
//path=XPath.newInstance("*[local-name()='g' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g' and @id='101000924' and namespace-uri()='http://www.w3.org/2000/svg']");
//path=XPath.newInstance("*[local-name()='g' and @id='Disconnector_Layer' and namespace-uri()='http://www.w3.org/2000/svg']");
path=XPath.newInstance("*[local-name()='g' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g' and @id='100001829' and namespace-uri()='http://www.w3.org/2000/svg']");
//Element paths=(Element)path.selectSingleNode(root);
//System.out.println(out.outputString(paths));
//System.out.println(path.);
//path=XPath.newInstance("*[(*[local-name()='g' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='use' and namespace-uri()='http://www.w3.org/2000/svg']) or (*[local-name()='g' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='use' and namespace-uri()='http://www.w3.org/2000/svg'])]");
//path=XPath.newInstance("*[ or (*[local-name()='g' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='use' and namespace-uri()='http://www.w3.org/2000/svg'])]");
//path=XPath.newInstance("descendant::*[local-name()='g' and namespace-uri()='http://www.w3.org/2000/svg' and @id='1030015860']/*[local-name()='metadata' and namespace-uri='http://www.w3.org/2000/svg']/*[local-name()='PSR_Ref' and namespace-uri()='http://www.cim.com']");
path=XPath.newInstance("descendant::*[local-name()='g' and namespace-uri()='http://www.w3.org/2000/svg' and @id='1030015860']/*[local-name()='metadata']/*[local-name()='PSR_Ref' and namespace-uri()='http://www.cim.com']");
//path=XPath.newInstance("*[local-name()='g' and @id='Link_Layer' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g' and namespace-uri()='http://www.w3.org/2000/svg']");
//Element g=(Element)path.selectSingleNode(root);
//System.out.println(g);
//System.out.println(g.getAttributes());
//path=XPath.newInstance("descendant::*[local-name()='use' and namespace-uri()='http://www.w3.org/2000/svg']");
//path=XPath.newInstance("*[local-name()='use' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='use' and namespace-uri()='http://www.w3.org/2000/svg']");
//Element use=(Element)path.selectSingleNode(g);
//System.out.print(out.outputString(use));
List<Element> paths=path.selectNodes(root);
Iterator<Element> it=paths.iterator();
Element e=it.next();
System.out.println(out.outputString(e));
/*path=XPath.newInstance("*[local-name()='metadata']/*[local-name()='PSR_Ref' and namespace-uri()='http://www.cim.com']");
e=(Element)path.selectSingleNode(e);
System.out.println(e);*/
//System.out.println(it.next());
/*FeatureClass line=new FeatureClass(ifw.openFeatureClass("t2"));
FeatureCursor fc=new FeatureCursor(line.insert(true));
//得到一个缓冲,所有写操作都在缓冲中执行
IFeatureBuffer fb=line.createFeatureBuffer();*/
/*if(it.hasNext()){
fb.setShapeByRef(pasePath(it.next().getAttribute("d").getValue()));
fc.insertFeature(fb);
Element e=it.next();
Element psr=e.getChild("metadata",ns_svg).getChild("PSR_Link",ns_cge);
//List psr=e.getChild("metadata",ns_svg).getChildren();
System.out.println(psr);
Iterator<Attribute> t=psr.getAttributes().iterator();
attr.clear();
while(t.hasNext()){
Attribute at=t.next();
System.out.println(at.getName());
if(at.getName().matches("Pin\\dInfoVect\\dLinkObjId")){
System.out.println("matched:"+at.getName());
attr.add(at.getValue());
}
}
}*/
//fc.flush();
}
private IPolyline pasePath(String path) throws Exception{
String[] cdnt=path.split(" ");
point.clear();
IPolyline p=new Polyline();
IPointCollection igc=(IPointCollection)p;
for(int i=0;i<cdnt.length;i++){
if(!cdnt[i].matches("\\D")){
//System.out.println(new Double(cdnt[i]));
point.add(new Double(cdnt[i]));
}
}
for(int i=0;i<point.size();i+=2){
IPoint pt=new Point();
if(i==point.size()){
pt.putCoords(point.get(i), 1160-point.get(i));
}else{
pt.putCoords(point.get(i), 1160-point.get(i+1));
}
igc.addPoint(pt, null, null);
}
p=(IPolyline)igc;
return p;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -