• 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.

  • 相关阅读:
    JavaScript 正则表达式中的特殊字符
    framework —— throttles(访问频率控制)
    framework —— permission(权限)
    framework —— auth认证
    算法——基础知识
    算法——解迷宫
    算法
    爬虫 ==》 同步调用
    asyncio模块
    Requests模块
  • 原文地址:https://www.cnblogs.com/king1302217/p/2046950.html
Copyright © 2020-2023  润新知