这些年写过的无厘头代码(五)Springboot下使用ArcGIS Engine

GISer开发AE网上大多数见到的都是C#语言写的,闲来无事,研究一下用Java写个AE程序过程,然后用Springboot写个webapi开放出来调用。。(鸡肋,不喜勿喷(*^_^*))。

本人使用的时IDEA + ArcGIS Engine for Java (10.4) , JDK 1.8 (32位,AE环境使用32位,不易出错) ,注意要

修改操作系统环境变量Path,将32位jdk路径,ArcGIS Engine安装bin 路径添加上。(防止报no ntvinv in java.library.path 找不到arcgis)

首先用在maven创建一个Springboot工程框架。然后在Project Structure 中导入AE的jar包,

 然后在pom.xml中导入AE 包,如下:

       <dependency>
            <groupId>com.esri.arcgis</groupId>
            <artifactId>arcgis</artifactId>
            <version>10.4.1</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/src/main/resources/arcobjects.jar</systemPath>
        </dependency>

这样在Springboot 中新建实例就可以import ArcGIS的包了。

在使用时,同样需要初始化认证许可,我从C#编写的License类改造了一下放到了Springboot中。

import com.esri.arcgis.geometry.*;
import com.esri.arcgis.system.*;

public class AOUnits {
    public static void Initialize() throws Exception {
        EngineInitializer.initializeVisualBeans();

        AoInitialize aoInit = new AoInitialize();
        //具体使用什么权限得看部署环境具有的ArcGIS权限

        // initialize an ArcGIS Server license if the license is available
//        if (aoInit.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeArcServer)
//                == com.esri.arcgis.system.esriLicenseStatus.esriLicenseAvailable)
//            aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeArcServer);
        if (aoInit.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeAdvanced)
                == com.esri.arcgis.system.esriLicenseStatus.esriLicenseAvailable)
            aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeAdvanced);
        else
            throw new Exception("ESRI ArcGIS Server License is unavailable or has failed");
    }
}

在使用时调用这个方法,即可正常使用AE接口去写过程了。如下示例:

 void SaveToDatabase(List<HighConsequenceArea> HCAList) throws Exception {
       
        AOUnits.Initialize();//执行一次就行,这里只是单独拿出来做个示例

        IFeatureBuffer featureBuffer = hcaFeatureClass.createFeatureBuffer();
        IFeatureCursor pFeatCur = hcaFeatureClass.IFeatureClass_insert(true); 
 
        for (HighConsequenceArea hca : HCAList) {
            featureBuffer.setShapeByRef(hca.getHCAGeometry());
            featureBuffer.setValue(hcaFeatureClass.findField("EVENTID"), hca.getEventId());
            featureBuffer.setValue(hcaFeatureClass.findField("HCA_NUM"), hca.getHCANumber());
            featureBuffer.setValue(hcaFeatureClass.findField("PIPELINE_NAME"), hca.getPipeLineName());//名称 
            featureBuffer.setValue(hcaFeatureClass.findField("DESCRIPTION"),  
            pFeatCur.insertFeature(featureBuffer);
         }
        pFeatCur.flush();
        Cleaner.release(pFeatCur);
        Cleaner.release(featureBuffer);
        Cleaner.release(hcaFeatureClass); 
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值