大学IT网 - 最懂大学生的IT学习网站! QQ资料交流群:367606806
当前位置:大学IT网 > Java技巧 > java获取shape文件面积

java获取shape文件面积

关键词:javashape面积java获取shape文件面积  阅读(709) 赞(19)

[摘要]本文主要是对java获取shape文件面积的讲解,希望对大家学习java获取shape文件面积有所帮助。

  初始化AE运行环境

  [java]

  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

  [java]

  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文件中面的面积

  [java]

  /**

  * 获取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;

  }



相关评论