学习GeoTools的Data模块的相关内容(上)-- (学习GIS【2】)

 

地理信息系统中最重要的东西莫过于就是数据了,而且我接触GeoTools的本意就是利用其处理众多标准的Gis格式文件的能力。所以首先从GeoToolsData模块着手来开始学习GeoTools

 

 Geotools_Data

 

Data模块的定义见  http://docs.codehaus.org/display/GEOTDOC/10+Data

 

The Data module is all about hoisting data (usually in the form of features) off of external services, disk files etc... into your application. This is where you can finally start putting the toolkit to work.

 

 最后一句说明了这个模块的重要性:P

 

 

 

因为Data模块的类很多,但是无外乎就是处理各种GIS文件格式(Shape,mif/mid…)。下面学习Data模块主要以处理Shapefile格式相关的部分。其他格式文件类似。

 

上面这张图来自 http://docs.codehaus.org/display/GEOTDOC/10+Data

是官方网站上学习和阐述Data模块的资料列表

 

下面就这张图的顺序记录下学习Data模块的心得。

 

Geotools_Data_List.

 

主要是下面几个类概括了整个Data模块的作用,需要特别注意:

DataStore

DataAccess

FeatureSource

FeatureStore

 

04 How to Create a DataStore or DataAccess

http://docs.codehaus.org/display/GEOTDOC/04+How+to+Create+a+DataStore+or+DataAccess

 

 

DataStoreDataAccess这两个类非常重要,要不然也不会在第一项就开始介绍了。

 

 

如果是数据是网页的话,则DataStore就是浏览器标准,各种DataStore接口实现的具体类的话就是各种类型的浏览器。通过DataStore可以访问各种数据(Shapefiles, databases tables, etc. )

 

下面是实现了DataStrore的各种“浏览器”

 

AbstractDataStore, AbstractDataStore2, AbstractFileDataStore, ArcSDEDataStore, CollectionDataStore, ContentDataStore, DB2DataStore, 

IndexedShapefileDataStore, JDBC1DataStore,JDBC2DataStore, JDBCDataStore, MemoryDataStore, PostgisDataStore, PropertyDataStore, 

ShapefileDataStore, WFS_1_0_0_DataStore, WFS_1_1_0_DataStore

 

如果我们要访问Shapefile文件格式的话,应该能猜到只要访问SahpefileDataStore就可以了:P

 

DataAccess又是什么?

 

首先DataAccess是接口,接口的目的无非就是规范所有子类的某个能力的标准,DataAccess就是规范所有子类访问数据信息和数据元信息的标准。

 

DataStore实现了DataAccess接口,实际访问各种Gis格式数据的类又实现了DataStore接口,那么这些访问各种格式数据的具体类的访问数据信息和访问数据元信息的能力就被规范了。换个意思说,就是可以在不用细节的情况,可以通过几个简单的方法一致的访问所有数据源。

 

这里放上一个使用ShapefileDataStore的完整能运行的例子

import java.io.*;

import java.net.*;

 

import org.geotools.data.*;

import org.geotools.data.shapefile.*;

import org.opengis.feature.type.*;

 

public class UseShapefileDataStore {

  public static void main(String[] args) {

    try {

      File file = new File("C://河流//hh_rivers_alber.shp");

      URI namespace = new URI("refractions");

      boolean useMemoryMapped = true;

      DataStore shapefile = new ShapefileDataStore(file.toURI().toURL(), namespace, useMemoryMapped);

      String[] typeName = shapefile.getTypeNames(); // should be "example"

      if (typeName != null && typeName.length >= 1) {

        FeatureType schema = shapefile.getSchema(typeName[0]); // should be "refractions.example"

        System.out.println("schema" + schema.getCoordinateReferenceSystem());

        FeatureSource contents = shapefile.getFeatureSource(typeName[0]);

        int count = contents.getCount(Query.ALL);

        System.out.println("Connected to " + file + " with " + count);

      }

    }

    catch (Exception ex) {

      ex.printStackTrace();

    }

  }

}

 

 

 

 

05 DataAccess and DataStore

http://docs.codehaus.org/display/GEOTDOC/05+DataAccess+and+DataStore

 

这里还是讲了DataAccessDataStore,然后列举了一些最常用的方法

interface DataAccess<T extends FeatureType, F extends Feature>{

  ServiceInfo getInfo();//返回元信息(简单的元信息)

  List<Name> getNames();//返回所有数据源的名字

  T getSchema(Name name);//Schema信息的信息

  FeatureSource<T,F> getFeatureSource(Name typeName);//下面一节会讲到FeatureSource

}

 

interface DataStore extends DataAccess<SimpleFeatureType, SimpleFeature>{

  String[] getTypeNames();

  SimpleFeatureType getSchema( String typeName );

  FeatureSource<SimpleFeatureType, SimpleFeature> getFeatureSource( String typeName );

  ...

}

 

 

 

06 FeatureSource

http://docs.codehaus.org/display/GEOTDOC/06+FeatureSource

 

FeatureSource is probably the reason you came to this party; it let's you access geospatial information as Java objects.

 

这里出现了第三个非常重要的接口FeatureSource

 

FeautreSource定义了访问具体访问空间数据的标准方法,那么DataAccess中访问空间数据的能力实际上就是DataAccess具有访问FeatureSource的能力,这样它实际上也具有了访问空间数据的能力。

 

interface FeatureSource<T extends FeatureType, F extends Feature> {

  DataAccess<T, F> getDataStore()

  Envelope getBounds()

  Envelope getBounds(Query)

  int getCount(Query)

 

  FeatureCollection<T, F> getFeatures()

  FeatureCollection<T, F> getFeatures(Filter)

  FeatureCollection<T, F> getFeatures(Query)

  T getSchema()

 

  void addFeatureListener(FeatureListener)

  void removeFeatureListener(FeatureListener)

}

 

FeautreSource具有获得空间数据的边界,获得局部空间数据的边界,获得空间数据,获得过滤后的空间数据,获得查询后的空间数据。。。。的能力,具体代码见http://docs.codehaus.org/display/GEOTDOC/06+FeatureSource

 

07 FeatureStore

http://docs.codehaus.org/display/GEOTDOC/07+FeatureStore

 

FeatureStore接口具有添加,修改,删除空间数据的能力,但是首先它得具有访问空间数据的能力,访问空间数据能力是通过实现FeatureSource接口实现的

 

下面是实现了FeatureStore接口的一些具体类

AbstractFeatureLocking, AbstractFeatureStore, ArcSdeFeatureStore, ContentFeatureStore, 

DB2FeatureLocking, DB2FeatureStore, JDBCFeatureLocking, JDBCFeatureStore,PostgisFeatureLocking,

 PostgisFeatureStore, PropertyFeatureSource, ShapefileFeatureLocking, ShapefileFeatureStore, WFSFeatureStore

 

具有编辑Shapefile数据能力的类一下子就看出了,是ShapefileFeatureStore

 

添加删除修改空间数据的代码见

http://docs.codehaus.org/display/GEOTDOC/07+FeatureStore

 

ß--------------------------------有时间在这里添加一个完整的样例)

 

 

org.geotools org.geotools.arcsde org.geotools.arcsde.data org.geotools.arcsde.data.versioning org.geotools.arcsde.data.view org.geotools.arcsde.filter org.geotools.arcsde.gce org.geotools.arcsde.gce.band org.geotools.arcsde.gce.imageio org.geotools.arcsde.gce.producer org.geotools.arcsde.pool org.geotools.axis org.geotools.brewer.color org.geotools.coverage org.geotools.coverage.grid org.geotools.coverage.grid.io org.geotools.coverage.grid.io.imageio org.geotools.coverage.io org.geotools.coverage.processing org.geotools.coverage.processing.operation org.geotools.data org.geotools.data.collection org.geotools.data.crs org.geotools.data.db2 org.geotools.data.db2.filter org.geotools.data.dir org.geotools.data.gml org.geotools.data.gpx org.geotools.data.gpx.temporal org.geotools.data.h2 org.geotools.data.jdbc org.geotools.data.jdbc.attributeio org.geotools.data.jdbc.datasource org.geotools.data.jdbc.fidmapper org.geotools.data.jdbc.referencing org.geotools.data.memory org.geotools.data.mif org.geotools.data.mysql org.geotools.data.oracle org.geotools.data.oracle.attributeio org.geotools.data.oracle.referencing org.geotools.data.oracle.sdo org.geotools.data.ows org.geotools.data.postgis org.geotools.data.postgis.attributeio org.geotools.data.postgis.collection org.geotools.data.postgis.fidmapper org.geotools.data.postgis.referencing org.geotools.data.property org.geotools.data.shapefile org.geotools.data.shapefile.dbf org.geotools.data.shapefile.indexed org.geotools.data.shapefile.indexed.attribute org.geotools.data.shapefile.prj org.geotools.data.shapefile.shp org.geotools.data.shapefile.shp.xml org.geotools.data.store org.geotools.data.tiger org.geotools.data.view org.geotools.data.vpf org.geotools.data.vpf.exc org.geotools.data.vpf.file org.geotools.data.vpf.ifc org.geotools.data.vpf.io org.geotools.data.vpf.readers org.geotools.data.vpf.util org.geotools.data.wfs org.geotools.data.wms org.geotools.data.wms.request org.geotools.data.wms.response org.geotools.data.wms.xml org.geotools.demo org.geotools.demo.data org.geotools.demo.example org.geotools.demo.features org.geotools.demo.geometry org.geotools.demo.introduction org.geotools.demo.jts org.geotools.demo.libraryJTS org.geotools.demo.main org.geotools.demo.mappane org.geotools.demo.metadata.example org.geotools.demo.postgis org.geotools.demo.swing org.geotools.demo.swing.process org.geotools.demo.widgets org.geotools.demo.xml org.geotools.display.canvas org.geotools.display.canvas.map org.geotools.display.event org.geotools.display.geom org.geotools.display.style org.geotools.factory org.geotools.feature org.geotools.feature.collection org.geotools.feature.simple org.geotools.feature.type org.geotools.feature.visitor org.geotools.filter org.geotools.filter.capability org.geotools.filter.expression org.geotools.filter.function org.geotools.filter.function.math org.geotools.filter.identity org.geotools.filter.parser org.geotools.filter.spatial org.geotools.filter.text.cql2 org.geotools.filter.text.txt org.geotools.filter.v1_0 org.geotools.filter.v1_0.capabilities org.geotools.filter.v1_1 org.geotools.filter.v1_1.capabilities org.geotools.filter.visitor org.geotools.gce.arcgrid org.geotools.gce.geotiff org.geotools.gce.geotiff.crs_adapters org.geotools.gce.geotiff.IIOMetadataAdpaters org.geotools.gce.geotiff.IIOMetadataAdpaters.utils org.geotools.gce.geotiff.IIOMetadataAdpaters.utils.codes org.geotools.gce.gtopo30 org.geotools.gce.image org.geotools.gce.imagemosaic org.geotools.gce.imagepyramid org.geotools.geometry org.geotools.geometry.array org.geotools.geometry.coordinatesequence org.geotools.geometry.iso org.geotools.geometry.iso.aggregate org.geotools.geometry.iso.complex org.geotools.geometry.iso.coordinate org.geotools.geometry.iso.index org.geotools.geometry.iso.index.quadtree org.geotools.geometry.iso.io org.geotools.geometry.iso.io.wkt org.geotools.geometry.iso.operation org.geotools.geometry.iso.operation.overlay org.geotools.geometry.iso.operation.relate org.geotools.geometry.iso.primitive org.geotools.geometry.iso.root org.geotools.geometry.iso.topograph2D org.geotools.geometry.iso.topograph2D.index org.geotools.geometry.iso.topograph2D.util org.geotools.geometry.iso.util org.geotools.geometry.iso.util.algorithm2D org.geotools.geometry.iso.util.algorithmND org.geotools.geometry.iso.util.elem2D org.geotools.geometry.iso.util.interpolation org.geotools.geometry.iso.util.topology org.geotools.geometry.jts org.geotools.geometry.jts.coordinatesequence org.geotools.geometry.jts.spatialschema org.geotools.geometry.jts.spatialschema.geometry org.geotools.geometry.jts.spatialschema.geometry.aggregate org.geotools.geometry.jts.spatialschema.geometry.complex org.geotools.geometry.jts.spatialschema.geometry.geometry org.geotools.geometry.jts.spatialschema.geometry.primitive org.geotools.geometry.text org.geotools.gml org.geotools.gml.producer org.geotools.gml2 org.geotools.gml2.bindings org.geotools.gml3 org.geotools.gml3.bindings org.geotools.gml3.bindings.smil org.geotools.gml3.smil org.geotools.gpx org.geotools.gpx.bean org.geotools.gpx.binding org.geotools.graph.build org.geotools.graph.build.basic org.geotools.graph.build.feature org.geotools.graph.build.line org.geotools.graph.build.opt org.geotools.graph.build.polygon org.geotools.graph.io org.geotools.graph.io.standard org.geotools.graph.path org.geotools.graph.structure org.geotools.graph.structure.basic org.geotools.graph.structure.line org.geotools.graph.structure.opt org.geotools.graph.traverse org.geotools.graph.traverse.basic org.geotools.graph.traverse.standard org.geotools.graph.util org.geotools.graph.util.delaunay org.geotools.graph.util.geom org.geotools.graph.util.graph org.geotools.gui.headless org.geotools.gui.swing org.geotools.gui.swing.contexttree org.geotools.gui.swing.contexttree.column org.geotools.gui.swing.contexttree.node org.geotools.gui.swing.contexttree.popup org.geotools.gui.swing.contexttree.renderer org.geotools.gui.swing.crschooser org.geotools.gui.swing.datachooser org.geotools.gui.swing.datachooser.model org.geotools.gui.swing.demo org.geotools.gui.swing.event org.geotools.gui.swing.filter org.geotools.gui.swing.icon org.geotools.gui.swing.image org.geotools.gui.swing.map.map2d org.geotools.gui.swing.map.map2d.control org.geotools.gui.swing.map.map2d.decoration org.geotools.gui.swing.map.map2d.event org.geotools.gui.swing.map.map2d.handler org.geotools.gui.swing.map.map2d.listener org.geotools.gui.swing.map.map2d.strategy org.geotools.gui.swing.misc org.geotools.gui.swing.misc.filter org.geotools.gui.swing.misc.Render org.geotools.gui.swing.process org.geotools.gui.swing.propertyedit org.geotools.gui.swing.propertyedit.filterproperty org.geotools.gui.swing.propertyedit.model org.geotools.gui.swing.propertyedit.styleproperty org.geotools.gui.swing.referencing org.geotools.gui.swing.style org.geotools.gui.swing.style.sld org.geotools.gui.swing.table org.geotools.gui.swing.tree org.geotools.image org.geotools.image.io org.geotools.image.io.metadata org.geotools.image.io.mosaic org.geotools.image.io.netcdf org.geotools.image.io.stream org.geotools.image.io.text org.geotools.image.jai org.geotools.image.palette org.geotools.index org.geotools.index.quadtree org.geotools.index.quadtree.fs org.geotools.index.rtree org.geotools.index.rtree.cachefs org.geotools.index.rtree.database org.geotools.index.rtree.database.mysql org.geotools.index.rtree.fs org.geotools.index.rtree.memory org.geotools.io org.geotools.jdbc org.geotools.kml org.geotools.kml.bindings org.geotools.legend org.geotools.map org.geotools.map.event org.geotools.math org.geotools.measure org.geotools.metadata org.geotools.metadata.iso org.geotools.metadata.iso.citation org.geotools.metadata.iso.constraint org.geotools.metadata.iso.content org.geotools.metadata.iso.distribution org.geotools.metadata.iso.extent org.geotools.metadata.iso.identification org.geotools.metadata.iso.lineage org.geotools.metadata.iso.maintenance org.geotools.metadata.iso.quality org.geotools.metadata.iso.spatial org.geotools.metadata.sql org.geotools.nature org.geotools.openoffice org.geotools.ows org.geotools.ows.bindings org.geotools.ows.v1_1 org.geotools.parameter org.geotools.process org.geotools.process.impl org.geotools.process.literal org.geotools.referencing org.geotools.referencing.crs org.geotools.referencing.cs org.geotools.referencing.datum org.geotools.referencing.example org.geotools.referencing.factory org.geotools.referencing.factory.epsg org.geotools.referencing.factory.wms org.geotools.referencing.operation org.geotools.referencing.operation.builder org.geotools.referencing.operation.matrix org.geotools.referencing.operation.projection org.geotools.referencing.operation.transform org.geotools.referencing.piecewise org.geotools.referencing.wkt org.geotools.renderer org.geotools.renderer.i18n org.geotools.renderer.lite org.geotools.renderer.lite.gridcoverage2d org.geotools.renderer.shape org.geotools.renderer.shape.shapehandler.jts org.geotools.renderer.shape.shapehandler.simple org.geotools.renderer.style org.geotools.repository org.geotools.repository.adaptable org.geotools.repository.defaults org.geotools.repository.postgis org.geotools.repository.property org.geotools.repository.shapefile org.geotools.repository.styling org.geotools.repository.wfs org.geotools.repository.wms org.geotools.sld org.geotools.sld.bindings org.geotools.styling org.geotools.styling.visitor org.geotools.svg org.geotools.test org.geotools.text org.geotools.text.filter org.geotools.util org.geotools.util.logging org.geotools.utils org.geotools.utils.coveragetiler org.geotools.utils.imagemosaic org.geotools.utils.imageoverviews org.geotools.utils.imagepyramid org.geotools.utils.progress org.geotools.validation org.geotools.validation.attributes org.geotools.validation.dto org.geotools.validation.network org.geotools.validation.relate org.geotools.validation.spatial org.geotools.validation.xml org.geotools.wfs org.geotools.wfs.bindings org.geotools.wfs.protocol org.geotools.wfs.v_1_0_0.data org.geotools.wfs.v_1_1_0.data org.geotools.xlink org.geotools.xml org.geotools.xml.filter org.geotools.xml.gml org.geotools.xml.handlers org.geotools.xml.handlers.xsi org.geotools.xml.impl org.geotools.xml.impl.jxpath org.geotools.xml.schema org.geotools.xml.schema.impl org.geotools.xml.styling org.geotools.xml.test org.geotools.xml.transform org.geotools.xml.wfs org.geotools.xml.xLink org.geotools.xml.xsi org.geotools.xs org.geotools.xs.bindings org.geotools.xs.facets
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值