参考网址:http://docs.geotools.org/latest/userguide/tutorial/quickstart/eclipse.html
下载安装Eclipse,并安装好Java开发环境;
打开Eclipse .ini file设置jvm环境:
1,创建maven项目:
通过创建maven项目,maven会将geotool相应的依赖开发包添加到程序中。
1,File->New->other from the menu bar
2,选择maven工程点击下一步,选择默认的maven类型,如下图所示:
使用以下参数设置maven工程:
- Group Id: org.geotools
- Artifact Id: tutorial
- Version: 0.0.1-SNAPSHOT (default)
- Package: org.geotools.tutorial
2,展示.shp文件
将jar包添加进你的工程,打开pom.xml文件,当下载jar的时候,默认使用“local repository”存储jars.
PLATFORM | LOCAL REPOSITORY |
---|---|
Windows XP: | C:\Documents and Settings\You\.m2\repository |
Windows: | C:\Users\You\.m2repository |
Linux and Mac: | ~/.m2/repository |
<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>org.geotools</groupId>
<artifactId>tutorial</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>tutorial</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<geotools.version>15-SNAPSHOT</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>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>
创建quickstart 类并在类上填上以下代码:
运行后,选择.shp文件,即可以打开.shp文件展示里面的地理数据。