maven构建geotools应用工程

前置条件

jdk1.7+eclipse+maven

POM配置

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>com.lilei.geotools</groupId>
	<artifactId>app_geotools</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<name>app_geotools</name>
	<url>http://maven.apache.org</url>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

		<geotools.version>12.0</geotools.version>
	</properties>

	<dependencies>
 
	
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>3.8.1</version>
			<scope>test</scope>
		</dependency>


	
		<dependency>
			<groupId>org.geotools</groupId>
			<artifactId>gt-shapefile</artifactId>
			<version>${geotools.version}</version>
		</dependency>
		<dependency>
			<groupId>org.geotools</groupId>
			<artifactId>gt-swing</artifactId>
			<version>${geotools.version}</version>
		</dependency>

  
	</dependencies>

	<repositories>
		<repository>
		<id>nexus2</id>
    <name>internal nexus repository2</name>
    <!-- <url>http://192.168.1.100:8081/nexus/content/groups/public/</url>-->
    <url>http://central.maven.org/maven2/</url>
		</repository>
	
		<repository>
			<id>maven2-repository.dev.java.net</id>
			<name>Java.net repository</name>
			<url>http://download.java.net/maven/2</url>
		</repository>
		<repository>
			<id>osgeo</id>
			<name>Open Source Geospatial Foundation Repository</name>
			<url>http://download.osgeo.org/webdav/geotools/</url>
		</repository>
		<repository>
			<snapshots>
				<enabled>true</enabled>
			</snapshots>
			<id>boundless</id>
			<name>Boundless Maven Repository</name>
			<url>http://repo.boundlessgeo.com/main</url>
		</repository>

			
		
	</repositories>
	
	
</project>

  

程序

package com.lilei.geotools.app_geotools;

import java.nio.charset.Charset;

import org.geotools.data.shapefile.dbf.DbaseFileHeader;
import org.geotools.data.shapefile.dbf.DbaseFileReader;
import org.geotools.data.shapefile.files.ShpFiles;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
		DbaseFileReader reader = null;
		try {
			reader = new DbaseFileReader(new ShpFiles("C:\\Users\\lilei3774\\Desktop\\wuhan\\1\\split-hanzi\\poi.shp"), false,
					Charset.forName("utf-8"));
			DbaseFileHeader header = reader.getHeader();
			int numFields = header.getNumFields();
			
			while (reader.hasNext()) {
				try {
					Object[] entry = reader.readEntry();
					for (int i = 0; i < numFields; i++) {
						String title = header.getFieldName(i);
						Object value = entry[i];
						System.out.println(title + "=" + value);
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (reader != null) {
				// �ر�
				try {
					reader.close();
				} catch (Exception e) {
				}
			}
		}
	}
}

  

posted on 2017-11-09 15:51  李雷  阅读(1790)  评论(0编辑  收藏  举报

导航