我使用的是Java。
我要做的事情是:用代碼來獲得一些要素類的geometry幾何類型的詳細信息。然后再根據點的幾何 來創建一個線。
至於那些Engine的初始化代碼 就不貼了。每個AO代碼必須有的就省略了。
首先 要獲得workspace,包括shapefile的,fileGDB的,access的,SDE的。其中shapfile的workspace在下一段 打開featureClass的代碼中。
public static IWorkspace connectSDE(com.esri.arcgis.server.ServerContext context) throws com.esri.arcgis.interop.AutomationException, java.io.IOException { com.esri.arcgis.system.PropertySet propSet = new PropertySet(); propSet.setProperty("SERVER", "192.168.1.8");// pine propSet.setProperty("INSTANCE", "5151");// 9091 propSet.setProperty("DATABASE", ""); propSet.setProperty("USER", "sde"); propSet.setProperty("PASSWORD", "sde"); propSet.setProperty("VERSION", "SDE.DEFAULT"); IWorkspaceFactory pWorkspaceFactory = new SdeWorkspaceFactory(); com.esri.arcgis.geodatabase.IWorkspace ws = pWorkspaceFactory.open(propSet, 0); return ws; } public static IWorkspace connectAccess(String fileName, String AFeatureClass) throws java.net.UnknownHostException, java.io.IOException { com.esri.arcgis.datasourcesGDB.AccessWorkspaceFactory wsf = new com.esri.arcgis.datasourcesGDB.AccessWorkspaceFactory(); com.esri.arcgis.geodatabase.Workspace wspace = new com.esri.arcgis.geodatabase.Workspace(wsf.openFromFile(fileName, 0)); return wspace; } public static IWorkspace connectFileGDB(String file) throws Exception, IOException { com.esri.arcgis.datasourcesGDB.FileGDBWorkspaceFactory factory = new com.esri.arcgis.datasourcesGDB.FileGDBWorkspaceFactory(); com.esri.arcgis.geodatabase.IWorkspace workspace; try { workspace = factory.openFromFile(file, 0); return workspace; } catch (AutomationException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
然后是從workspace打開featureClass,有時候要打開的是featureDataset類型。
View Code
public static FeatureClass getFeatureClassFromAccessWorkspace(Workspace wspace, String AFeatureClassName) throws AutomationException, IOException { com.esri.arcgis.geodatabase.FeatureClass featureClass = new com.esri.arcgis.geodatabase.FeatureClass(wspace.openFeatureClass(AFeatureClassName)); return featureClass; } public static com.esri.arcgis.geodatabase.IFeatureClass getFeatureClassFromShapefile(String workspacePath, String shapefileName) throws Exception, IOException { com.esri.arcgis.datasourcesfile.ShapefileWorkspaceFactory wsf = new com.esri.arcgis.datasourcesfile.ShapefileWorkspaceFactory(); com.esri.arcgis.geodatabase.Workspace work = new com.esri.arcgis.geodatabase.Workspace(wsf.openFromFile(workspacePath, 0)); com.esri.arcgis.geodatabase.IFeatureClass featureClass = work.openFeatureClass(shapefileName); // //featureClass = new FeatureClass(workspace.openFeatureClass(name)); Boolean checkPolygonType; checkPolygonType = false; if (checkPolygonType) { if (featureClass.getShapeType() != esriGeometryType.esriGeometryPolygon) { System.out.println("The shapefile's feature class is not of type Polygon. Try another."); System.exit(1); } } return featureClass; }
如果是從fileGDB或者 SDE的workspace遍歷的話:
View Code
public static void listDTAny(String ListDatasetClassDescription, IWorkspace workspace) throws java.net.UnknownHostException, java.io.IOException { com.esri.arcgis.geodatabase.IEnumDataset enumDataset = workspace.getDatasets(esriDatasetType.esriDTAny);//esriDTFeatureDataset esriDTAny // esriDTFeatureDataset com.esri.arcgis.geodatabase.IDataset dsName = null; dsName = enumDataset.next(); System.out.println("ListDatasetClass:" + ListDatasetClassDescription); while (dsName != null) { System.out.println("Name: " + dsName.getName() + "\t\t; Type: " + getDatasetTypeDescription(dsName.getType())); dsName = enumDataset.next(); } }
是無法得到dataset下面的featureClass的。那么如何得到 數據集 下面的要素類呢?
IFeatureWorkspace fworkspace=new IFeatureWorkspaceProxy(workspace); IFeatureClass fclass = null; try { fclass = fworkspace.openFeatureClass("GPSData1"); String name=fclass.getAliasName(); System.out.println(name + ".getShapeFieldName()=" + fclass.getShapeFieldName() + " ; " + name + ".getFeatureType=" + myUtil.AOUtil.getFeatureTypeDescription(fclass.getFeatureType()) );//最后面的這個代碼是將featureType從數字轉化為對應的string的。自己寫 myUtil.AOUtil.listFeatureFromFeatureClass(fclass);//這個代碼是遍歷featureClass顯示其shape的;自己寫 } catch (Exception e) { // TODO Auto-generated catch block System.out.println("Cannot get the FeatureClass !"); //e.printStackTrace(); }
原來是要用:IFeatureWorkspace,如果直接使用IWorkspace(第一段代碼獲得的workspace)來遍歷是無法得到datasets下面的要素類的,但是使用IFeatureWorkspace可以直接打開datasets下面的要素類。要的就是這段代碼。
下面要說的是 featurelClass和feature與Geometry 都分別指的是什么:
FeatureClass指的是左側 比如states.shp這個要素類,遍歷它就是在遍歷右側的FID從0-N的每一行,這每一行就叫 feature 要素。
feature要素 中 最重要的就是shape字段(此字段也可以使其他名字),通過feature可以獲得 getshape(),獲得的是IGeometry,通過IGeometry是否是 點線面 可以分別來遍歷幾何類型來獲得其中的點了。

具體代碼還要在研究。。。
從 一個點 要素類 生成 線要素類 ,這個我還要再琢磨下。
