概述
初始化AE运行环境
public static void initializeAE() {
EngineInitializer.initializeEngine();
try {
AoInitialize aoInit = new AoInitialize();
try {
if (aoInit.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeEngine) == esriLicenseStatus.esriLicenseAvailable)
aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);
else if (aoInit.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeArcView) == esriLicenseStatus.esriLicenseAvailable)
aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeArcView);
else {
System.err.println("请检查,没有ArcGISLicenses.");
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
}获取featureclass
public static FeatureClass getFeatureClassByShpfileWorkspaceFactory(String path, String name) throws IOException {
FeatureClass featureClass = null;
try {
ShapefileWorkspaceFactory shapefileWorkspaceFactory = new ShapefileWorkspaceFactory();
Workspace workspace = new Workspace(shapefileWorkspaceFactory.openFromFile(path, 0));
featureClass = new FeatureClass(workspace.openFeatureClass(name));
} catch (IOException e) {
throw e;
}
return featureClass;
}
计算shape文件中面的面积
/**
* 获取shape文件面类型的面积
* @param featureClass
* @param type
* @return
*/
public Double getShapeArea (FeatureClass featureClass, String type) {
Double allArea = 0d;
try {
IQueryFilter pQueryFilter = new QueryFilter();
int featureCount = featureClass.featureCount(pQueryFilter);
if(type.equals("polygon")){
for (int i = 0; i < featureCount; i++) {
IGeometry ig = featureClass.getFeature(i).getShape();
Polygon polygon = (Polygon) ig;
polygon.getArea();
}
}
} catch (AutomationException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
com.esri.arcgis.system.EngineInitializer.release(featureClass);
}
return allArea;
}
最后
以上就是忧心路灯为你收集整理的java 读取shape文件夹,java获取shape文件面积的全部内容,希望文章能够帮你解决java 读取shape文件夹,java获取shape文件面积所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复