这里写自定义目录标题
- 前言
- 环境
- 构建scala项目
- 迁移geotrellis-chatta-demo代码
- ETL工具金字塔建模
- 启动项目
- 代码地址
前言
最近一段时间在边学习边开发地理信息的分布式处理,接触到了geotrellis这个基于spark的分布式处理框架,使用scala语言编写,在这里首先学习他的demo:geotrellis-chatta-demo,这个demo以及整个geotrellis框架使用sbt构建,奈何本人愚钝,搞了几天没搞定sbt这个东西,愤而转投maven,在此记录
环境
java:JDK1.8
scala:2.11.12
maven:3.3.9
idea:2018.1.8 (需安装scala开发插件,度娘一下即可)
构建scala项目
- 新建项目
- 选择maven
- 输入scala构建骨架(版本可再高一点,本人使用此版本无恙)
Group id : org.scala-tools.archetypes Artifact id : scala-archetype-simple Version : 1.2
- 选择使用新建的骨架
- 输入包名和项目名
- 配置maven
- 更改项目文件夹名称和路径
- 待idea完成构建后scala项目目录结构
迁移geotrellis-chatta-demo代码
- 将代码复制到新项目所在文件夹中(idea会自动更新)
- 复制配置文件
- 修改pom.xml(在此展示完整的xml,改动了哪里自行比较吧)
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.geotrellis</groupId>
<artifactId>geotrellis-boot</artifactId>
<version>1.0-SNAPSHOT</version>
<inceptionYear>2019</inceptionYear>
<properties>
<scala.version>2.11.12</scala.version>
</properties>
<repositories>
<repository>
<id>scala-tools.org</id>
<name>Scala-Tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</repository>
<!-- 添加仓库位置 -->
<repository>
<id>geotools</id>
<name>geotools Repository</name>
<url>https://repo.boundlessgeo.com/main</url>
<releases>
<updatePolicy>daily</updatePolicy><!-- never,always,interval n -->
<enabled>true</enabled>
<checksumPolicy>warn</checksumPolicy><!-- fail,ignore -->
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<layout>default</layout>
</repository>
<repository>
<id>geomajas</id>
<name>geomajas Repository</name>
<url>http://maven.geomajas.org/nexus/content/groups/public/</url>
<releases>
<updatePolicy>daily</updatePolicy><!-- never,always,interval n -->
<enabled>true</enabled>
<checksumPolicy>warn</checksumPolicy><!-- fail,ignore -->
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<layout>default</layout>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>scala-tools.org</id>
<name>Scala-Tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.specs</groupId>
<artifactId>specs</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<!-- 添加依赖 -->
<dependency>
<groupId>org.locationtech.geotrellis</groupId>
<artifactId>geotrellis-spark_2.11</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.locationtech.geotrellis</groupId>
<artifactId>geotrellis-raster_2.11</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.locationtech.geotrellis</groupId>
<artifactId>geotrellis-spark-etl_2.11</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.locationtech.geotrellis</groupId>
<artifactId>geotrellis-cassandra_2.11</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_2.11</artifactId>
<version>2.4.17</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-http-core_2.11</artifactId>
<version>10.0.3</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-http_2.11</artifactId>
<version>10.0.3</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-http-spray-json_2.11</artifactId>
<version>10.0.3</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<version>2.3.0</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/scala</directory>
<excludes>
<exclude>**/*.scala</exclude>
</excludes>
</resource>
</resources>
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<scalaVersion>${scala.version}</scalaVersion>
<args>
<arg>-target:jvm-1.8</arg>
</args>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<downloadSources>true</downloadSources>
<buildcommands>
<buildcommand>ch.epfl.lamp.sdt.core.scalabuilder</buildcommand>
</buildcommands>
<additionalProjectnatures>
<projectnature>ch.epfl.lamp.sdt.core.scalanature</projectnature>
</additionalProjectnatures>
<classpathContainers>
<classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
<classpathContainer>ch.epfl.lamp.sdt.launching.SCALA_CONTAINER</classpathContainer>
</classpathContainers>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<configuration>
<scalaVersion>${scala.version}</scalaVersion>
</configuration>
</plugin>
</plugins>
</reporting>
</project>
- 修改配置文件(路径使用斜杠:/)
ETL工具金字塔建模
- 规避错误
- 需要金字塔建模的tif在demo中的路径
- 修改input.json
- 修改output.json
- 修改ChattaIngest类并启动创建
object ChattaIngest extends App {
val arg = Array[String](
"--input",
"D:\\data\\input.json",
"--output",
"D:\\data\\output.json",
"--backend-profiles",
"D:\\data\\backend-profiles.json"
);
// implicit val sc = SparkUtils.createSparkContext("GeoTrellis ETL SinglebandIngest", new SparkConf(true))
implicit val sc = SparkUtils.createLocalSparkContext("local[*]",
"GeoTrellis ETL SinglebandIngest", new SparkConf(true))
try {
Etl.ingest[ProjectedExtent, SpatialKey, Tile](arg)
} finally {
sc.stop()
}
}
启动项目
查看
代码地址
https://gitee.com/XiaoSa12138/geotrellis-chatta-demo