`
marsprj
  • 浏览: 65084 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

GeoTools读取Shape File

    博客分类:
  • GIS
阅读更多
package com.test.geotools.shp;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;

import org.geotools.data.FeatureSource;
import org.geotools.data.shapefile.ShapefileDataStore;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.FeatureIterator;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;

import com.vividsolutions.jts.geom.Geometry;


public class shptest {

	public static void main(String[] argv){
		
		String strShpPath = "D:\\data\\country.shp";
		File file = new File(strShpPath);
		ShapefileDataStore shpDataStore = null;
		try{
			shpDataStore = new ShapefileDataStore(file.toURL());
			String typeName = shpDataStore.getTypeNames()[0];
			FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = null;
			featureSource = (FeatureSource<SimpleFeatureType, SimpleFeature>)shpDataStore.getFeatureSource(typeName);
			FeatureCollection<SimpleFeatureType, SimpleFeature> result = featureSource.getFeatures();
			
			FeatureIterator<SimpleFeature> itertor = result.features();
			while(itertor.hasNext()){
				SimpleFeature feature = itertor.next();
				Geometry geometry = (Geometry)feature.getDefaultGeometry();				
				System.out.println(geometry.toText());
			}
			itertor.close();
		}
		catch(MalformedURLException e){
			e.printStackTrace();
		}
		catch(IOException e){
			e.printStackTrace();
		}
	}
}
分享到:
评论
1 楼 蔽目聆雨 2016-04-08  
geometry.getCoordinates()获得三维

相关推荐

Global site tag (gtag.js) - Google Analytics