我做过一点点AE for java的开发,最早也做过Mo for java的开发, 所以想再这儿和大家探讨一下ESRI for java方面的开发 先贴一个AE for java that is Edit 类 回头贴 网络分析的模型(路径分析,服务区分析等)代码 回家休息五一,回来慢慢介绍详细 /* * EditLayer.java * * Created on 2006年11月1日, 上午9:44 * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ package com.hltsoft.mfsoft.wzglsoft.dataOption; /** * @author new */ import java.awt.HeadlessException; import java.io.IOException; import java.util.Vector; import javax.swing.JOptionPane; import com.esri.arcgis.carto.IActiveView; import com.esri.arcgis.carto.IActiveViewProxy; import com.esri.arcgis.carto.IFeatureLayer; import com.esri.arcgis.carto.IFeatureLayerProxy; import com.esri.arcgis.carto.IFeatureSelection; import com.esri.arcgis.carto.IFeatureSelectionProxy; import com.esri.arcgis.carto.ILayer; import com.esri.arcgis.carto.IMap; import com.esri.arcgis.carto.esriViewDrawPhase; import com.esri.arcgis.display.IDisplayFeedback; import com.esri.arcgis.display.ILineMovePointFeedback; import com.esri.arcgis.display.ILineMovePointFeedbackProxy; import com.esri.arcgis.display.IMovePointFeedback; import com.esri.arcgis.display.IMovePointFeedbackProxy; import com.esri.arcgis.display.INewLineFeedback; import com.esri.arcgis.display.INewLineFeedbackProxy; import com.esri.arcgis.display.INewMultiPointFeedback; import com.esri.arcgis.display.INewMultiPointFeedbackProxy; import com.esri.arcgis.display.INewPolygonFeedback; import com.esri.arcgis.display.INewPolygonFeedbackProxy; import com.esri.arcgis.display.IPolygonMovePointFeedback; import com.esri.arcgis.display.IPolygonMovePointFeedbackProxy; import com.esri.arcgis.display.LineMovePointFeedback; import com.esri.arcgis.display.MovePointFeedback; import com.esri.arcgis.display.NewLineFeedback; import com.esri.arcgis.display.NewMultiPointFeedback; import com.esri.arcgis.display.NewPolygonFeedback; import com.esri.arcgis.display.PolygonMovePointFeedback; import com.esri.arcgis.geodatabase.ICursor; import com.esri.arcgis.geodatabase.IDataset; import com.esri.arcgis.geodatabase.IDatasetProxy; import com.esri.arcgis.geodatabase.IEnumFeature; import com.esri.arcgis.geodatabase.IEnumFeatureProxy; import com.esri.arcgis.geodatabase.IFeature; import com.esri.arcgis.geodatabase.IFeatureClass; import com.esri.arcgis.geodatabase.IFeatureCursor; import com.esri.arcgis.geodatabase.IFeatureCursorProxy; import com.esri.arcgis.geodatabase.IObjectClass; import com.esri.arcgis.geodatabase.IQueryFilter; import com.esri.arcgis.geodatabase.IQueryFilterProxy; import com.esri.arcgis.geodatabase.ISelectionSet; import com.esri.arcgis.geodatabase.ISpatialFilter; import com.esri.arcgis.geodatabase.IWorkspaceEdit; import com.esri.arcgis.geodatabase.IWorkspaceEditProxy; import com.esri.arcgis.geodatabase.QueryFilter; import com.esri.arcgis.geodatabase.SpatialFilter; import com.esri.arcgis.geodatabase.esriSpatialRelEnum; import com.esri.arcgis.geometry.IGeometry; import com.esri.arcgis.geometry.IGeometryCollection; import com.esri.arcgis.geometry.IGeometryCollectionProxy; import com.esri.arcgis.geometry.IGeometryProxy; import com.esri.arcgis.geometry.IHitTest; import com.esri.arcgis.geometry.IHitTestProxy; import com.esri.arcgis.geometry.IPath; import com.esri.arcgis.geometry.IPathProxy; import com.esri.arcgis.geometry.IPoint; import com.esri.arcgis.geometry.IPointCollection; import com.esri.arcgis.geometry.IPointCollectionProxy; import com.esri.arcgis.geometry.IPointProxy; import com.esri.arcgis.geometry.IPolygon; import com.esri.arcgis.geometry.IPolygonProxy; import com.esri.arcgis.geometry.IPolyline; import com.esri.arcgis.geometry.IPolylineProxy; import com.esri.arcgis.geometry.ITopologicalOperator; import com.esri.arcgis.geometry.ITopologicalOperatorProxy; import com.esri.arcgis.geometry.Multipoint; import com.esri.arcgis.geometry.Point; import com.esri.arcgis.geometry.esriGeometryHitPartType; import com.esri.arcgis.geometry.esriGeometryType; import com.esri.arcgis.system.esriDrawPhase; public class EditLayer { private ILayer m_pCurrentLayer; private IMap m_pMap; private IFeature m_pEditFeature; private IPoint m_pPoint; private boolean vertexHit; private IDisplayFeedback m_pFeedback; private boolean m_bInUse=false; private IPointCollection m_pPointCollection; private Vector EditFeatures; /** Creates a new instance of EditLayer */ public EditLayer() { EditFeatures = new Vector(); } public EditLayer(IMap map,ILayer layer) { m_pMap=map; m_pCurrentLayer=layer; EditFeatures = new Vector(); } public void setMap(IMap map) { m_pMap=map; } public void setLayer(ILayer layer) { m_pCurrentLayer=layer; } public IMap getMap() { return m_pMap; } public ILayer getLayer() { return m_pCurrentLayer; } public Vector getFeatures(){ return EditFeatures; } public void StartEditing() { IWorkspaceEdit pWorkspaceEdit; IFeatureLayer pFeatureLayer; IDataset pDataset; try { if(m_pCurrentLayer==null) { JOptionPane.showMessageDialog(null,"没有选择要编辑的层!","错误提示",JOptionPane.ERROR_MESSAGE); return; } pFeatureLayer=new IFeatureLayerProxy(m_pCurrentLayer); if(pFeatureLayer==null) { JOptionPane.showMessageDialog(null,"该层不可编辑!","错误提示",JOptionPane.ERROR_MESSAGE); return; } pDataset=new IDatasetProxy(pFeatureLayer.getFeatureClass()); if(pDataset==null) { JOptionPane.showMessageDialog(null,"该层没有合适的地理集!","错误提示",JOptionPane.ERROR_MESSAGE); return; } pWorkspaceEdit=new IWorkspaceEditProxy(pDataset.getWorkspace()); if(!pWorkspaceEdit.isBeingEdited()) { pWorkspaceEdit.startEditing(true); pWorkspaceEdit.enableUndoRedo(); System.out.println("Start Editing..."); return; } else { JOptionPane.showMessageDialog(null,"该地理空间不允许编辑!","错误提示",JOptionPane.ERROR_MESSAGE); return; } } catch(HeadlessException ex) { ex.printStackTrace(); } catch(IOException ex) { ex.printStackTrace(); } } public void StopEditing() { IWorkspaceEdit pWorkspaceEdit; IFeatureLayer pFeatureLayer; IDataset pDataset; IActiveView pActiveView; boolean bHasEdits[]={false}; boolean bSave=true; try { if(m_pCurrentLayer==null) { JOptionPane.showMessageDialog(null,"","",JOptionPane.ERROR_MESSAGE); return; } pFeatureLayer=new IFeatureLayerProxy(m_pCurrentLayer); if(pFeatureLayer==null) { JOptionPane.showMessageDialog(null,"","",JOptionPane.ERROR_MESSAGE); return; } pDataset=new IDatasetProxy(pFeatureLayer.getFeatureClass()); if(pDataset==null) { JOptionPane.showMessageDialog(null,"","",JOptionPane.ERROR_MESSAGE); return; } pWorkspaceEdit=new IWorkspaceEditProxy(pDataset.getWorkspace()); if(pWorkspaceEdit.isBeingEdited()) { pWorkspaceEdit.hasEdits(bHasEdits); if(bHasEdits[0]==true) { } if(bSave) { // int i=JOptionPane.showConfirmDialog(new JFrame(),"确认保存吗?","询问",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE); // if(i==JOptionPane.YES_OPTION) // { pWorkspaceEdit.stopEditing(true); m_pMap.clearSelection(); pActiveView=new IActiveViewProxy(m_pMap); pActiveView.refresh(); return; //} } else { JOptionPane.showMessageDialog(null,"取消了保存!","提示",JOptionPane.ERROR_MESSAGE); return; } } } catch(HeadlessException ex) { ex.printStackTrace(); } catch(IOException ex) { ex.printStackTrace(); } } public boolean isEditstate() { IWorkspaceEdit pWorkspaceEdit; IFeatureLayer pFeatureLayer; IDataset pDataset; try { if(m_pCurrentLayer==null) { JOptionPane.showMessageDialog(null,"","",JOptionPane.ERROR_MESSAGE); return false; } pFeatureLayer=new IFeatureLayerProxy(m_pCurrentLayer); if(pFeatureLayer==null) { JOptionPane.showMessageDialog(null,"","",JOptionPane.ERROR_MESSAGE); return false; } pDataset=new IDatasetProxy(pFeatureLayer.getFeatureClass().getFeatureDataset()); if(pDataset==null) { JOptionPane.showMessageDialog(null,"","",JOptionPane.ERROR_MESSAGE); return false; } pWorkspaceEdit=new IWorkspaceEditProxy(pDataset.getWorkspace()); if(pWorkspaceEdit.isBeingEdited()) { return true; } } catch(HeadlessException ex) { ex.printStackTrace(); } catch(IOException ex) { ex.printStackTrace(); } return false; } |