ArcGIS 10 Engine 我今天的研究战果

我使用的是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是否是 点线面 可以分别来遍历几何类型来获得其中的点了。

具体代码还要在研究。。。

从 一个点 要素类 生成 线要素类 ,这个我还要再琢磨下。

原文地址:https://www.cnblogs.com/ayanmw/p/2514600.html