zoukankan      html  css  js  c++  java
  • 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) {
    				}
    			}
    		}
    	}
    }
    

      

  • 相关阅读:
    织梦后台如何生成站点地图sitemap.xml
    滚轮滚动一定距离触发导航顶部固定,且所点击的关键词,背景字体变色
    超简单横向选项卡
    后台域名重定向301
    JS检测是否是360浏览器
    《深入理解Java虚拟机》-----第2章 Java内存区域与内存溢出异常
    java基础(十七)----- 浅谈Java中的深拷贝和浅拷贝 —— 面试必问
    java基础(十六)----- equals()与hashCode()方法详解 —— 面试必问
    java基础(十五)----- Java 最全异常详解 ——Java高级开发必须懂的
    java基础(十四)-----详解匿名内部类——Java高级开发必须懂的
  • 原文地址:https://www.cnblogs.com/lilei2blog/p/7809771.html
Copyright © 2011-2022 走看看