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

📄 importsvg.java.svn-base

📁 aresde 空间数据开发 例子
💻 SVN-BASE
📖 第 1 页 / 共 3 页
字号:
	    svgid.setName("SVGID");
	    svgid.setType(com.esri.arcgis.geodatabase.esriFieldType.esriFieldTypeInteger);
	    
	    pFieldsEdit.addField(pFieldEdit);
	    pFieldsEdit.addField(shp);
	    pFieldsEdit.addField(svgid);

	    log.info("创建连接线层:"+this.Link_Layer);
	    ifc=createFeatureClass(this.Link_Layer,pFieldsEdit);
	    
	    FeatureClass line=new FeatureClass(ifc);
		FeatureCursor fc=new FeatureCursor(line.insert(true));
		IFeatureBuffer fb=line.createFeatureBuffer();
		int index_svgid=fb.getFields().findField("SVGID");
		/*Iterator<Element> it=path.selectNodes(root).iterator();
		Element e=null;
		//SVGID字段序列
		while(it.hasNext()){
			e=it.next();
			fb.setShapeByRef(link(e));
			fb.setValue(index_svgid, e.getAttributeValue("id"));
			//log.info("导入SVG图中母线,ID:"+e.getParentElement().getAttributeValue("id"));
			fc.insertFeature(fb);
		}*/
		List<Element> list=path.selectNodes(root);
		for(Element list_i : list){
			fb.setShapeByRef(link(list_i));
			fb.setValue(index_svgid, list_i.getAttributeValue("id"));
			//log.info("导入SVG图中母线,ID:"+e.getParentElement().getAttributeValue("id"));
			fc.insertFeature(fb);
		}
		fc.flush();
	}
	
	/**
	 * 把连接线延伸到连接目标的点上
	 * @param g: &lt;Link_Layer&gt;下的&lt;g&gt;标签
	 * */
	private IPolyline link(Element g) throws Exception{
		IPolyline p=pasePath(g.getChild("path", ns_svg).getAttributeValue("d"));
		IPolyline p2=pasePath(g.getChild("path", ns_svg).getAttributeValue("d"));
		Element psr=g.getChild("metadata",ns_svg).getChild("PSR_Link",ns_cge);
		attr.clear();
		
		/*Iterator<Attribute> it=psr.getAttributes().iterator();
		while(it.hasNext()){
			Attribute at=it.next();
			if(at.getName().matches("Pin\\dInfoVect\\dLinkObjId")){
				//例:101000924_0 取 _ 前的ID号
				attr.add(at.getValue().split("_")[0]);
			}
		}*/
		List<Attribute> list=psr.getAttributes();
		
		for(Attribute list_i : list){
			if(list_i.getName().matches("Pin\\dInfoVect\\dLinkObjId")){
				//例:101000924_0 取 _ 前的ID号
				attr.add(list_i.getValue().split("_")[0]);
			}
		}
		
		ipoint=findDevice(attr.iterator(),g);
		
		IPointCollection igc=(IPointCollection)p;
		IPointCollection igc2=(IPointCollection)p2;
		
		//log.info("连接设备数:"+ipoint.size());
		if(ipoint.size()==2){
			igc.addPoint(ipoint.get(0), 0, null);
			igc.addPoint(ipoint.get(1), null, null);
			
			igc2.addPoint(ipoint.get(1), 0, null);
			igc2.addPoint(ipoint.get(0), null, null);
		}else if(ipoint.size()==1){
			igc.addPoint(ipoint.get(0), 0, null);
			igc2.addPoint(ipoint.get(0), null, null);
		}
		
		if(ipoint.size()>0){
		p=(IPolyline)igc;
		p2=(IPolyline)igc2;
		if(p.getLength()>p2.getLength()){
			/*igc2=(IPointCollection)p2;
			igc2.removePoints(1, 1);
			if(ipoint.size()==2){
				igc2.removePoints(igc2.getPointCount()-2, 1);
			}
			p2=(IPolyline)igc2;*/
			p=p2;
		}/*else{
			igc=(IPointCollection)p;
			igc.removePoints(1, 1);
			if(ipoint.size()==2){
				igc.removePoints(igc.getPointCount()-2, 1);
			}
			p=(IPolyline)igc;
		}*/
		}
		//p.
		return p;
	}
	
	/**
	 * 查找连接线连接的设备
	 * @param it 连接对象的ID
	 * @param g 连接线&lt;Link_Layer&gt;下的&lt;g&gt;标签
	 * */
	private ArrayList<IPoint> findDevice(Iterator<String> it,Element g) throws Exception{
		ipoint.clear();
		String xpath="";
		while(it.hasNext()){
			String id=it.next();
			xpath=path_id.replaceFirst(":id", id);
			//log.info(xpath);
			path=XPath.newInstance(xpath);
			//带有设备id的<g>标签
			Element e=(Element)path.selectSingleNode(root);
			if(e!=null){
				//记录连接到母线上的节点
				if("Bus_Layer".equals(e.getParentElement().getAttributeValue("id"))){
					IPoint end=compare(g,getBusPoint(e).getY());
					BusLayer.get(e.getAttributeValue("id")).put(end.getX(),end);
					//System.out.println(e.getAttributeValue("id")+" 添加点");
				}
				
				xpath="descendant::*[local-name()='use' and namespace-uri()='http://www.w3.org/2000/svg']";
				path=XPath.newInstance(xpath);
				//点层设备
				if(!LineLayer.contains(e.getParentElement().getAttributeValue("id"))){
					//log.info(out.outputString((Element)path.selectSingleNode(e)));
					IPoint p=paseUse((Element)path.selectSingleNode(e));
					ipoint.add(p);
				}
			}
		}
		return ipoint;
	}
	
	/**
	 * 记录连接线与母线的交点
	 *@param g 连接线&lt;Link_Layer&gt;下的&lt;g&gt;标签
	 *@param y 母线的<b>y</b>坐标
	 * */
	private IPoint compare(Element g,double y)throws Exception{
		IPoint p=new Point();
		
		IPolyline line=pasePath(g.getChild("path", this.ns_svg).getAttributeValue("d"));
		//判断连接线两端点,y值与母线y相等的说明连接在母线上
		if(line.getFromPoint().getY()==y){
			p.putCoords(line.getFromPoint().getX(),line.getFromPoint().getY());
			//System.out.println("起点");
		}else if(line.getToPoint().getY()==y){
			p.putCoords(line.getToPoint().getX(),line.getToPoint().getY());
			//System.out.println("终点");
		}
		return p;
	}
	
	/**
	 * 取得母线上一端点的坐标
	 * @param e 母线path的父元素&lt;g&gt;
	 * */
	private IPoint getBusPoint(Element e)throws Exception{
		IPoint p=new Point();
		
		Element pth=e.getChild("path", this.ns_svg);
		String[] cdnt=pth.getAttributeValue("d").split(" ");
		
		point.clear();
		
		/*for(int i=0;i<cdnt.length;i++){
			if(!cdnt[i].matches("\\D")){
				point.add(new Double(cdnt[i]));
			}
		}*/
		for(String cdnt_i : cdnt){
			if(!cdnt_i.matches("\\D")){
				point.add(new Double(cdnt_i));
			}
		}
		
		p.putCoords(point.get(0)*t, height-point.get(1)*t);
		return p;
	}
	
	
	/**
	 * 创建FeatureClass
	 * @param name FeaturClass名称
	 * @param fields 字段
	 * */
	private IFeatureClass createFeatureClass(String name,IFieldsEdit fields) throws Exception{
		if(ifd==null){
			ifd = ifw.openFeatureDataset(dsname);
		}
		UID id=new UID();
	    id.setValue("esriGeoDatabase.Feature");
	    String fieldName="";
    	//log.info("字段名称:---");
	    for(int i=0;i<fields.getFieldCount();i++){
	    //log.info(fields.getField(i).getName());
	    	if(fields.getField(i).getType()==com.esri.arcgis.geodatabase.esriFieldType.esriFieldTypeGeometry){
	    		fieldName=fields.getField(i).getName();
	    	}
	    }
    	//log.info(ifd.getName());
	    return ifd.createFeatureClass(name, fields, id, null,
				com.esri.arcgis.geodatabase.esriFeatureType.esriFTSimple, fieldName, "");
	}
	
	/**
	 * 创建注记层
	 * @param name 注记层名称
	 * @param fields 自定义字段
	 * */
	private IFeatureClass createAnnotationClass(String name,IFieldsEdit fields) throws Exception{
		//数值范围
		GraphicsLayerScale referenceScale = new GraphicsLayerScale();
		//单位
        referenceScale.setUnits(esriUnits.esriMeters);
        //比例 1: ***
        //referenceScale.setReferenceScale(89410);
        referenceScale.setReferenceScale(30000);
        
        //样式集合
        SymbolCollection symbolCollection = new SymbolCollection();
        //字体样式
        TextSymbol textSymbol = new TextSymbol();
        //颜色参数
        RgbColor color=new RgbColor();
        color.setRed(0);
        color.setGreen(0);
        color.setBlue(0);
        //设置参数
        StdFont font = new StdFont();
        font.setName("SimSun");
        font.setBold(true);
       
        //设置字体
        textSymbol.setFont(font);
       //字体大小不是通过IFont对象设置
        textSymbol.setSize(8);
        //字体颜色
        textSymbol.setColor(color);
        //对齐
        textSymbol.setHorizontalAlignment(com.esri.arcgis.display.esriTextHorizontalAlignment.esriTHALeft);
        
        symbolCollection.setSymbolByRef(0, textSymbol);
        
        //IFeatureClass linkfeatureClass=ifw.openFeatureClass(this.Link_Layer);
        IFeatureWorkspaceAnno annotationWorkspace = new IFeatureWorkspaceAnnoProxy(ifw);
        //设置与关联图层的关系
        LabelEngineLayerProperties annotationProperties = new LabelEngineLayerProperties();
        annotationProperties.setFeatureLinked(true);
        annotationProperties.setAddUnplacedToGraphicsContainer(false);
        annotationProperties.setCreateUnplacedElements(true);
        annotationProperties.setDisplayAnnotation(true);
        annotationProperties.setUseOutput(true);

        AnnotationFeatureClassDescription annotationFeatureClassDescription = new AnnotationFeatureClassDescription();
        //annotationFeatureClassDescription.
        //annotationProperties.setAnnotationMaximumScale(arg0);
        //annotationProperties.setAnnotationMinimumScale(arg0);
        //AnnotationJScriptEngine annotationExpressionEngine = new AnnotationJScriptEngine();
        AnnotationVBScriptEngine annotationExpressionEngine = new AnnotationVBScriptEngine();
        annotationProperties.setExpressionParserByRef(annotationExpressionEngine);
        // just show the first field for now, until I get this working
        annotationProperties.setExpression("[objectid]");
        annotationProperties.setIsExpressionSimple(true);
        annotationProperties.setOffset(0.0);
        annotationProperties.setSymbolID(0);
        annotationProperties.setSymbolByRef(textSymbol);
        annotationProperties.setReferenceScale(referenceScale.getReferenceScale());
        annotationProperties.setUnits(referenceScale.getUnits());
        annotationProperties.setScaleRatio(1.0);

        AnnotateLayerPropertiesCollection annotateLayerPropertiesCollection = new AnnotateLayerPropertiesCollection();
        annotateLayerPropertiesCollection.add(annotationProperties);
        IFieldsEdit pFieldsEdit=new Fields(annotationFeatureClassDescription.getRequiredFields());
        for(int i=0;i<pFieldsEdit.getFieldCount();i++){
        	if(pFieldsEdit.getField(i).getType()==com.esri.arcgis.geodatabase.esriFieldType.esriFieldTypeGeometry){
        		IFieldEdit ife=(IFieldEdit)pFieldsEdit.getField(i);
        		IGeometryDefEdit igde=(IGeometryDefEdit)ife.getGeometryDef();
        		igde.setSpatialReferenceByRef(isr);
        		ife.setGeometryDefByRef(igde);
        	}
        }
        for(int i=0;i<fields.getFieldCount();i++){
        	pFieldsEdit.addField(fields.getField(i));
        }
        return annotationWorkspace.createAnnotationClass(
				name,
				pFieldsEdit,
				annotationFeatureClassDescription.getInstanceCLSID(),
				annotationFeatureClassDescription.getClassExtensionCLSID(),
				annotationFeatureClassDescription.getShapeFieldName(),
				"",
				ifw.openFeatureDataset(dsname),
				//linkfeatureClass,
				null,//null,
				annotateLayerPropertiesCollection,
				referenceScale,
				symbolCollection,
				true);
        
	}
	
	/**
	 * 创建FeatureDataset
	 * @param name FeatureDataset名称
	 * */
	private void createDataset() throws Exception{
		ifd=ifw.createFeatureDataset(dsname, isr);
	}
	
	public static void main(String[] args) throws Exception{
		EngineInitializer.initializeEngine();
		final AoInitialize aoInit =new AoInitialize();
		try{
			aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB);
			
			new ImportSVG().pase();
			
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			aoInit.shutdown();
		}

	}

}

⌨️ 快捷键说明

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