⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 importsvg.java.svn-base

📁 aresde 空间数据开发 例子
💻 SVN-BASE
📖 第 1 页 / 共 3 页
字号:
		FeatureCursor fc=new FeatureCursor(line.insert(true));
		IFeatureBuffer fb=line.createFeatureBuffer();
		Iterator<String> busid=BusLayer.keySet().iterator();
		int index_svgid=fb.getFields().findField("SVGID");
		String svgid=null;
		while(busid.hasNext()){
			svgid=busid.next();
			fb.setShapeByRef(getBusLine(BusLayer.get(svgid)));
			fb.setValue(index_svgid, svgid);
			fc.insertFeature(fb);
		}
		fc.flush();
	}
	
	
	private IPolyline getBusLine(HashMap<Double,IPoint> coordinate) throws Exception{
		IPolyline busline=new Polyline();
		IPolyline p=new Polyline();
		IPointCollection igc=(IPointCollection)p;
		ArrayList<Double> xlist=new ArrayList<Double>();
		
		xlist.addAll(coordinate.keySet());
		//System.out.println(coordinate.keySet().iterator());
		/*Object[] xArray=xlist.toArray();
		Arrays.sort(xArray);
		for(int i=0;i<xArray.length;i++){
			igc.addPoint(coordinate.get((Double)xArray[i]), null, null);
			//log.info(coordinate.get((Double)xArray[i]).getX());
		}*/
		Double[] xArray=new Double[xlist.size()];
		xArray=xlist.toArray(xArray);
		for(Double xArray_i : xArray){
			igc.addPoint(coordinate.get(xArray_i), null, null);
		}
		busline=(IPolyline)igc;
		return busline;
	}
	
	/***
	 * 处理BBreaker,Disconnector,Compensator,PT
	 * 
	 * */
	private void paseBDCP(XPath path,String tagType) throws Exception{
		IGeometryDefEdit igde=new GeometryDef();
		igde.setGeometryType(com.esri.arcgis.geometry.esriGeometryType.esriGeometryPoint);
		igde.setSpatialReferenceByRef(isr);
		//设置列集合
		IFieldsEdit pFieldsEdit = new Fields();
		//设置列
	    IFieldEdit pFieldEdit = new Field();
	    IFieldEdit shp = new Field();
	    IFieldEdit svgid=new Field();
	    IFeatureClass ifc=null;
	    
	    //加入基本字段
	    pFieldEdit.setName("ObjectID");
	    pFieldEdit.setType(com.esri.arcgis.geodatabase.esriFieldType.esriFieldTypeOID);

	    shp.setName("SHP");
	    shp.setType(com.esri.arcgis.geodatabase.esriFieldType.esriFieldTypeGeometry);
	    shp.setGeometryDefByRef(igde);
	    
	    svgid.setName("SVGID");
	    svgid.setType(com.esri.arcgis.geodatabase.esriFieldType.esriFieldTypeInteger);
	    
	    pFieldsEdit.addField(pFieldEdit);
	    pFieldsEdit.addField(shp);
	    pFieldsEdit.addField(svgid);
	    
	    if(tagType==this.Breaker_Layer){
	    	// 加入开关特有属性
			
		    ifc=createFeatureClass(this.Breaker_Layer,pFieldsEdit);
		    log.info("创建开关层:"+this.Breaker_Layer);
	    	
	    }else if(tagType==this.Disconnector_Layer){
	    	//加入刀闸层特有属性
	    	
	    	ifc=createFeatureClass(this.Disconnector_Layer,pFieldsEdit);
	    	 log.info("创建刀闸层:"+this.Disconnector_Layer);
	    }else if(tagType==this.Compensator_Layer){
	    	ifc=createFeatureClass(this.Compensator_Layer,pFieldsEdit);
	    	log.info("创建电容层:"+this.Compensator_Layer);
	    }else if(tagType==this.PT_Layer){
	    	ifc=createFeatureClass(this.PT_Layer,pFieldsEdit);
	    	log.info("创建PT层:"+this.PT_Layer);
	    }else if(tagType==this.Transformer3_Layer){
	    	ifc=createFeatureClass("TF3",pFieldsEdit);
	    	log.info("创建三卷变层:TF3");
	    	
	    }
	    FeatureClass geopoint=new FeatureClass(ifc);
		FeatureCursor fc=new FeatureCursor(geopoint.insert(true));
		IFeatureBuffer fb=geopoint.createFeatureBuffer();
		Iterator<Element> it=path.selectNodes(root).iterator();
		Element e=null;
		//SVGID字段序列
		int index_svgid=fb.getFields().findField("SVGID");
		while(it.hasNext()){
			e=it.next();
			fb.setShapeByRef(paseUse(e));
			fb.setValue(index_svgid, e.getParentElement().getAttributeValue("id"));
			//log.info("导入SVG图中母线,ID:"+e.getParentElement().getAttributeValue("id"));
			fc.insertFeature(fb);
		}
		fc.flush();
	}
	
	/**
	 * 将传入的path值转为IPolyline
	 * @param path &lt;path&gt;标签的 d属性
	 *
	 * */
	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(String cdnt_i : cdnt){
			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)*t, height-point.get(i)*t);
			}else{
				pt.putCoords(point.get(i)*t, height-point.get(i+1)*t);
			}
			igc.addPoint(pt, null, null);
		}
		
		p=(IPolyline)igc;
		return p;
	}
	
	/**
	 * 将传入的use元素传为IPoint
	 * @param use &lt;use&gt;元素
	 * */
	private IPoint paseUse(Element use) throws Exception{
		IPoint p=new Point();
		p.setX(Double.parseDouble(use.getAttributeValue("x"))*t);
		p.setY(height-Double.parseDouble(use.getAttributeValue("y"))*t);
		//log.info("x : "+p.getX()+"  y : "+p.getY());
		return p;
	}
	
	/**
	 * 处理变压器
	 * @param path 变压器元素XPath
	 * @param tagType 主变类型:三卷变,4.两卷变,5
	 * */
	private void paseTransformer(XPath path,String tagType) throws Exception{
		IGeometryDefEdit igde=new GeometryDef();
		igde.setGeometryType(com.esri.arcgis.geometry.esriGeometryType.esriGeometryPoint);
		igde.setSpatialReferenceByRef(isr);
		//设置列集合
		IFieldsEdit pFieldsEdit = new Fields();
		//设置列
	    IFieldEdit pFieldEdit = new Field();
	    IFieldEdit shp = new Field();
	    IFieldEdit svgid=new Field();
	    IFieldEdit transsvgid=new Field();
	    IFeatureClass ifc=null;
	    
	    //加入基本字段
	    pFieldEdit.setName("ObjectID");
	    pFieldEdit.setType(com.esri.arcgis.geodatabase.esriFieldType.esriFieldTypeOID);

	    shp.setName("SHP");
	    shp.setType(com.esri.arcgis.geodatabase.esriFieldType.esriFieldTypeGeometry);
	    shp.setGeometryDefByRef(igde);
	    
	    svgid.setName("SVGID");
	    svgid.setType(com.esri.arcgis.geodatabase.esriFieldType.esriFieldTypeInteger);
	    
	    transsvgid.setName("TRANSSVGID");
	    transsvgid.setType(com.esri.arcgis.geodatabase.esriFieldType.esriFieldTypeInteger);
	    
	    pFieldsEdit.addField(pFieldEdit);
	    pFieldsEdit.addField(shp);
	    pFieldsEdit.addField(svgid);
	    pFieldsEdit.addField(transsvgid);
	    
	    if(tagType==this.Transformer3_Layer){
	    	ifc=createFeatureClass(this.Transformer3_Layer,pFieldsEdit);
	    	log.info("创建三卷变层:"+this.Transformer3_Layer);
	    	
	    }else if(tagType==this.Transformer2_Layer){
	    	ifc=createFeatureClass(this.Transformer2_Layer,pFieldsEdit);
	    	log.info("创建两卷变层:"+this.Transformer2_Layer);
	    }
	    
	    FeatureClass geopoint=new FeatureClass(ifc);
		FeatureCursor fc=new FeatureCursor(geopoint.insert(true));
		IFeatureBuffer fb=geopoint.createFeatureBuffer();
		Iterator<Element> it=path.selectNodes(root).iterator();
		//Element e=(Element)path.selectSingleNode(root);
		Element e=null;
		//SVGID字段序列
		int index_svgid=fb.getFields().findField("SVGID");
		int index_transsvgid=fb.getFields().findField("TRANSSVGID");
		while(it.hasNext()){
			e=it.next();
			
			fb.setShapeByRef(paseUse(e));
			fb.setValue(index_svgid, e.getParentElement().getAttributeValue("id"));
			fb.setValue(index_transsvgid, e.getParentElement().getParentElement().getAttributeValue("id"));
			//log.info("导入SVG图中母线,ID:"+e.getParentElement().getAttributeValue("id"));
			fc.insertFeature(fb);
			fc.flush();
		}
		
		fc.flush();
		
	}
	
	/**
	 * 处理注记
	 * */
	private void paseTextLayer(XPath path) throws Exception{
		IFeatureClass ifc=null;
		IFieldsEdit pFieldsEdit = new Fields();
		//设置列
	    IFieldEdit svgid = new Field();
	    svgid.setName("SVGID");
	    svgid.setType(com.esri.arcgis.geodatabase.esriFieldType.esriFieldTypeInteger);
	    pFieldsEdit.addField(svgid);

		log.info("创建注记层"+this.Text_Layer);
	    ifc=this.createAnnotationClass(this.Text_Layer, pFieldsEdit);
	    IFDOGraphicsLayerFactory fdo=new FDOGraphicsLayerFactory();
		
		IFDOGraphicsLayer layer=(IFDOGraphicsLayer)fdo.openGraphicsLayer(ifw, ifc.getFeatureDataset(), this.Text_Layer);
		layer.beginAddElements();
		
		
        
        Iterator<Element> it=path.selectNodes(root).iterator();
        
        Element e=null;
        ElementCollection ec=new ElementCollection();
        while(it.hasNext()){
        	e=it.next();
        	ec.add(paseText(e),1);
        }
        layer.doAddElements(ec, 0);
        
	}
	
	/**
	 * 处理&lt;text&gt;元素
	 * @param e &lt;text&gt;元素
	 * */
	private IElement paseText(Element e) throws Exception{
		ITextElement text=new TextElement();
		IElement em=(IElement)text;
		text.setScaleText(true);
		text.setText(e.getText().replaceAll("\n", ""));
		StdFont font = new StdFont();
		font.setName(e.getAttributeValue("font-family"));
		TextSymbol textSymbol = new TextSymbol();
		textSymbol.setFont(font);
		IFillSymbol fill=new SimpleFillSymbol();
		ILineSymbol outline=new CartographicLineSymbol();
		fill.setColor(paseRGB(e.getAttributeValue("fill")));
		outline.setColor(paseRGB(e.getAttributeValue("stroke")));
		outline.setWidth(0.5);
		fill.setOutline(outline);
		
		textSymbol.setSize(Double.valueOf(e.getAttributeValue("font-size")));
		textSymbol.setFillSymbolByRef(fill);
		if("tb".equals(e.getAttributeValue("writing-mode"))){
			textSymbol.setAngle(270);
		}
		//设置左对齐
		textSymbol.setHorizontalAlignment(
				com.esri.arcgis.display.esriTextHorizontalAlignment.esriTHALeft
				);
		text.setSymbol(textSymbol);
		
		
		em.setGeometry(paseUse(e));
		
		return em;
	}
	
	/**
	 * 传入颜色属性值rgb(int,int,int),返回RgbColor对象
	 * */
	private RgbColor paseRGB(String fill) throws Exception{
		RgbColor color=new RgbColor();
		String[] colorArray=fill.substring(fill.indexOf("(")+1,fill.indexOf(")")).split(",");
		if(colorArray!=null){
			color.setRed(Integer.valueOf(colorArray[0]));
			color.setGreen(Integer.valueOf(colorArray[1]));
			color.setBlue(Integer.valueOf(colorArray[2]));
		}
		return color;
	}
	
	/**
	 * 处理连接线
	 * @param path 连接线的XPath
	 * */
	private void paseLinkLayer(XPath path) throws Exception{
		IGeometryDefEdit igde=new GeometryDef();
		igde.setGeometryType(com.esri.arcgis.geometry.esriGeometryType.esriGeometryPolyline);
		igde.setSpatialReferenceByRef(isr);
		//设置列集合
		IFieldsEdit pFieldsEdit = new Fields();
		//设置列
	    IFieldEdit pFieldEdit = new Field();
	    IFieldEdit shp = new Field();
	    IFieldEdit svgid=new Field();
	    IFeatureClass ifc=null;
	    
	    //加入基本字段
	    pFieldEdit.setName("ObjectID");
	    pFieldEdit.setType(com.esri.arcgis.geodatabase.esriFieldType.esriFieldTypeOID);

	    shp.setName("SHP");
	    shp.setType(com.esri.arcgis.geodatabase.esriFieldType.esriFieldTypeGeometry);
	    shp.setGeometryDefByRef(igde);
	    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -