這裡寫自定義目錄标題
- 前言
- 環境
- 建構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