zoukankan      html  css  js  c++  java
  • JAVA+ArcEngine开发(二):java arcengine连接sde示例代码

         1)首先建立一个ArcGis Engine Project:EngineProject

         2)在工程文件上新建一个类DataImport

    读取sde dataset
    import java.io.IOException;
    import javax.swing.JFrame;
    import com.esri.arcgis.system.AoInitialize;
    import com.esri.arcgis.system.EngineInitializer;
    import com.esri.arcgis.datasourcesGDB.SdeWorkspaceFactory;
    import com.esri.arcgis.geodatabase.*;
    import com.esri.arcgis.system.*;


    public class DataImport {
        
        
    public static void main(String[] args) 
        {
            getSDETable();
        }
        
        
    public static void getSDETable() {
            
    try {
            
                initializeArcGISLicenses();
                
                
                SdeWorkspaceFactory sdeFact 
    = new SdeWorkspaceFactory();

                
    // Create a PropertySet object that will contain all of the
                
    // SDE connection parameters
                PropertySet propSet = new PropertySet();

                
    // Populate the property set with the connection parameters
                propSet.setProperty("SERVER""192.168.2.24");
                propSet.setProperty(
    "INSTANCE""5151");
                propSet.setProperty(
    "DATABASE""testsde");
                propSet.setProperty(
    "USER""sde");
                propSet.setProperty(
    "PASSWORD""wt");
                propSet.setProperty(
    "VERSION""sde.DEFAULT");

                
    // Open the ArcSDE workspace using the connection PropertySet
                Workspace ws = new Workspace(sdeFact.open(propSet, 0));

                
    // Get the collection of dataset names in the database and display their names
                IEnumDatasetName dsNames = ws
                        .getDatasetNames(esriDatasetType.esriDTAny);

                IDatasetName name 
    = dsNames.next();
                
    while (name != null) {
                    System.out.println(name.getName());
                    name 
    = dsNames.next();
                }
            } 
    catch (IOException e) {
                e.printStackTrace();
            }
        }
        
        
    static void initializeArcGISLicenses() {
            
    try {
                EngineInitializer.initializeEngine();
                com.esri.arcgis.system.AoInitialize ao 
    = new com.esri.arcgis.system.AoInitialize();
                
    if (ao.isProductCodeAvailable(com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeEngine) == com.esri.arcgis.system.esriLicenseStatus.esriLicenseAvailable)
                    ao.initialize(com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeEngine);
            } 
    catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

        3)在DataImport上右键,run as java application,运行这个类

        4)在console界面下就可以看见数据库服务器sde下的所有dataset名称

    备注:initializeArcGISLicenses() 用于初始化engine的licence,如果不加的话,会提示错误:Could not load native libraries. ArcGIS/bin should be added to the system PATH environment variable.

  • 相关阅读:
    题解+补题
    信息安全导论期末复习
    Codeforces Round #104 (Div.2)
    中国计量大学现代科技学院第四届“中竞杯”程序设计校赛(同步赛)
    第一章练习-1
    【练习】购物车程序
    【转】Python中设置输出文字的颜色
    字符串,列表,元组,字典间的互相转换
    【转】Python Enhancement Proposal #8【PEP8】
    【转】pycharm的一些快捷键
  • 原文地址:https://www.cnblogs.com/king1302217/p/2046950.html
Copyright © 2011-2022 走看看