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);
}