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 人气:689
分享到:
blog comments powered by Disqus

相关文章

  • java to get the main information page of the three: html to tree (rpm) 2010-12-04

    1. Required Documents param.txt: storing the path need to extract information page TestPage: need to extract the information stored pages Out.txt: page content output 2. Test program package test; import java.io.*; import Source.*; // Extract the mai

  • Java import. Export Excel 2010-08-09

    Current B / S model has become a mainstream application development, and in the business office systems, often have customers like this requirement: You should report directly with our Excel to open (the telecommunications system, the banking system)

  • java to get the main information pages of the two: auxiliary operations (transfer) 2010-12-04

    1. Stack operation package Source; import java.util.LinkedList; // Use List defines a stack public class Stack { // Construct method public Stack() { list = new LinkedList(); isEmpty = true; } // Into the stack public void push(Object node) { list.ad

  • java to get the main information page two: auxiliary operation (transfer) 2010-12-04

    1 stack operation package Source; import java.util.LinkedList; // List the definition of a stack public class Stack { // Construction method public Stack() { list = new LinkedList(); isEmpty = true; } // In stack public void push(Object node) { list.

  • JAVA Shape file created. And add a line in the file 2011-10-10

    import java.io.File; import java.io.IOException; import com.esri.arcgis.datasourcesfile.ShapefileWorkspaceFactory; import com.esri.arcgis.geodatabase.FeatureClass; import com.esri.arcgis.geodatabase.Field; import com.esri.arcgis.geodatabase.Fields; i

  • oem error "java.lang.Exception: IOException in send -" 2010-04-26

    oracle 10g R2 EM management console login, header error as follows: "Java.lang.Exception: IOException in sending Request:: Connection refused: connect" Handled as follows: 1. Stop emagent: [Oracle @ rac1] $ export ORACLE_SID = rac1 [Oracle @ rac

  • String the string to extract a certain type of 2010-10-24

    Old code, the first Tieshanglai, to be finishing import java.io.UnsupportedEncodingException; import java.util.HashMap; import java.util.Map; import java.util.Set; public class StringHandler { public static final int CH_STR = 1; public static final i

  • java oracle clob string large string storage 2011-05-03

    In the past few days to the database updates in a large string, busy for several days finally a good way to try out, and now come to share under: public class ClobTest { static String url = "jdbc:oracle:thin:@10.12.10.18:1521:orcl"; static Strin

  • 编写高质量代码改善java程序的151个建议--[52-57]String !about Strin 2014-07-05

    原创地址: http://www.cnblogs.com/Alandre/ (泥沙砖瓦浆木匠),需要转载的,保留下! Thanks Although the world is full of suffering , it is full also of the overcoming of it. -Hellen Keller 相信自己看得懂就看得懂了,相信自己能写下去,我就开始写了.其实也简单-泥沙砖瓦浆木匠 Written In The Font Three pieces[52-3]: 52.

  • String.getBytes() String编码转换 2015-01-26

    在Java中,String的getBytes()方法是得到一个操作系统默认的编码格式的字节数组.这个表示在不通OS下,返回的东西不一样! String.getBytes(String decode)方法会根据指定的decode编码返回某字符串在该编码下的byte数组表示,如 byte[] b_gbk = "中".getBytes("GBK"); byte[] b_utf8 = "中".getBytes("UTF-8"); by

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

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

CodeWeblog.com 版权所有 闽ICP备15018612号

processed in 0.036 (s). 13 q(s)