利用ArcEngine类库获取ArcGIS数据
ArcGIS数据文件分为3种:shapefile,Coverage,Geodatabase。
shapefile一种基于文件方式存储GIS数据的文件格式,至少由shp,dbf,shx三个文件组成。分别存储空间,属性,2者关系。是GIS中比较通用的数据格式。
Coverage是一种矢量文件格式,几何和空间拓扑关系存储在二进制文件中,与之相关的属性数据则存放在INFO表或RDBMS中(PCArcInfo存储在DBF表中)。Coverage是对要素类组织后(featureclass)的集合,每个要素类都是一些点、线、面、annotation(文本)的集合。
Geodatabase一种基于RDBMS存储的数据格式。其有两大类:1、PersonalGeodatabase用来存储小数据量数据。存储在Access的mdb格式中。2、ArcSDEeodatabase用来存储大型数据。存储在大型数据库中,可实行并发操作,不过需要单独的用户许可。
对于ArcGIS数据文件,ESRI为JAVA语言提供了ArcEngine类库来进行ArcGIS的一切开发。对于ArcGIS3种数据文件的连接提供了统一的接口IWorkSpace,根据具体的数据有不同的实现类来实现数据文件的连接,而数据读取的方法一样,所以可以试用一个工厂模式写个工具类来统一获取3种数据。
需要导入arcobjects.jar
工厂模式连接数据统一接口:
import com.esri.arcgis.geodatabase.IFeatureClass; public interface ConnectDataSource { public IFeatureClass getDataSource(String path,String className); }
连接shape实现类:
import java.io.IOException; import com.esri.arcgis.datasourcesfile.ShapefileWorkspaceFactory; import com.esri.arcgis.geodatabase.IFeatureClass; import com.esri.arcgis.geodatabase.Workspace; import com.fjdz.inf.ConnectDataSource; public class ConnectShape implements ConnectDataSource { IFeatureClass featureClass =null; public IFeatureClass getDataSource(String path, String className) { ShapefileWorkspaceFactory shapefileWorkspaceFactory; try { shapefileWorkspaceFactory = new ShapefileWorkspaceFactory(); Workspace workspace = new Workspace(shapefileWorkspaceFactory.openFromFile(path, 0)); featureClass = workspace.openFeatureClass(className); }catch (IOException e) { e.printStackTrace(); } return featureClass; } }
连接mdb:
import java.io.IOException; import com.esri.arcgis.datasourcesGDB.AccessWorkspaceFactory; import com.esri.arcgis.geodatabase.IFeatureClass; import com.esri.arcgis.geodatabase.IFeatureWorkspace; import com.fjdz.inf.ConnectDataSource; public class ConnectAccess implements ConnectDataSource { IFeatureClass featureClass =null; public IFeatureClass getDataSource(String path, String className) { AccessWorkspaceFactory workspaceFactory; try { workspaceFactory = new AccessWorkspaceFactory(); IFeatureWorkspace workspace = (IFeatureWorkspace)workspaceFactory.openFromFile(path, 0); featureClass= workspace.openFeatureClass(className); }catch (IOException e) { e.printStackTrace(); } return featureClass; } }
数据读取类:
import java.io.IOException; import java.util.ArrayList; import java.util.List; import com.esri.arcgis.geodatabase.IFeature; import com.esri.arcgis.geodatabase.IFeatureClass; import com.esri.arcgis.geodatabase.IFeatureCursor; import com.esri.arcgis.geodatabase.IField; import com.esri.arcgis.geodatabase.IFields; import com.fjdz.bean.DataBean; import com.fjdz.enumfactory.FactoryType; import com.fjdz.inf.ConnectDataSource; import com.fjdz.inf.IQueryFactory; public class QueryFactory{ IFeatureClass featureClass = null; ConnectDataSource connectDatasource = null; public List<DataBean> Query(String type,String path,String className){ List<DataBean> datalist = new ArrayList<DataBean>(); try{ if("shape".equals(type)){ connectDatasource = new ConnectShape(); }else if("mdb".equals(type)){ connectDatasource = new ConnectAccess(); } featureClass = connectDatasource.getDataSource(path, className); IFeatureCursor cursor = featureClass.search(null, true); IFields fields = cursor.getFields(); int fieldCount = fields.getFieldCount(); IFeature feature = cursor.nextFeature(); while(feature != null){ List<String> value = new ArrayList<String>(); DataBean dataBean = new DataBean(); for (int k = 0; k < fieldCount; k++) { value.add((feature.getValue(k)).toString()); } dataBean.setList(value); } datalist.add(dataBean); feature = cursor.nextFeature(); } catch (IOException e) { e.printStackTrace(); } return datalist; }
到此ArcGIS数据获取的方法就全部介绍完。
相关推荐
xubzhlin 2020-03-05
hxok 2020-02-02
zbcaicai 2019-11-09
graseed 2016-12-20
morexyoung 2019-10-22
Guyuebingchuan 2016-12-20
xiluoenm 2010-06-30
abchywabc 2009-11-12
andyjiang 2014-05-18
hengqiaqia 2019-06-28
BUAACST 2017-09-18
jinzhentao 2013-07-15
pdw00 2019-06-25
姚强 2011-02-21
ruizhenggang 2011-02-24
xhgWanderingsoul 2018-12-17
zzwdczz 2017-05-19
adeni 2014-04-09
HendyRaw 2014-04-09