GeoTools Read Shape File

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();
                }
        }
}
分类:Java 时间:2010-03-18 人气:601
分享到:
blog comments powered by Disqus

相关文章

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.291 (s). 12 q(s)