天天看點

geotrellis架構sbt轉投maven建構前言環境建構scala項目遷移geotrellis-chatta-demo代碼ETL工具金字塔模組化啟動項目代碼位址

這裡寫自定義目錄标題

  • 前言
  • 環境
  • 建構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項目

  1. 建立項目
    geotrellis架構sbt轉投maven建構前言環境建構scala項目遷移geotrellis-chatta-demo代碼ETL工具金字塔模組化啟動項目代碼位址
  2. 選擇maven
    geotrellis架構sbt轉投maven建構前言環境建構scala項目遷移geotrellis-chatta-demo代碼ETL工具金字塔模組化啟動項目代碼位址
  3. 輸入scala建構骨架(版本可再高一點,本人使用此版本無恙)
    Group id :  org.scala-tools.archetypes
    Artifact id : scala-archetype-simple
    Version : 1.2
               
    geotrellis架構sbt轉投maven建構前言環境建構scala項目遷移geotrellis-chatta-demo代碼ETL工具金字塔模組化啟動項目代碼位址
  4. 選擇使用建立的骨架
    geotrellis架構sbt轉投maven建構前言環境建構scala項目遷移geotrellis-chatta-demo代碼ETL工具金字塔模組化啟動項目代碼位址
  5. 輸入包名和項目名
    geotrellis架構sbt轉投maven建構前言環境建構scala項目遷移geotrellis-chatta-demo代碼ETL工具金字塔模組化啟動項目代碼位址
  6. 配置maven
    geotrellis架構sbt轉投maven建構前言環境建構scala項目遷移geotrellis-chatta-demo代碼ETL工具金字塔模組化啟動項目代碼位址
  7. 更改項目檔案夾名稱和路徑
    geotrellis架構sbt轉投maven建構前言環境建構scala項目遷移geotrellis-chatta-demo代碼ETL工具金字塔模組化啟動項目代碼位址
  8. 待idea完成建構後scala項目目錄結構
    geotrellis架構sbt轉投maven建構前言環境建構scala項目遷移geotrellis-chatta-demo代碼ETL工具金字塔模組化啟動項目代碼位址

遷移geotrellis-chatta-demo代碼

  1. 将代碼複制到新項目所在檔案夾中(idea會自動更新)
    geotrellis架構sbt轉投maven建構前言環境建構scala項目遷移geotrellis-chatta-demo代碼ETL工具金字塔模組化啟動項目代碼位址
  2. 複制配置檔案
    geotrellis架構sbt轉投maven建構前言環境建構scala項目遷移geotrellis-chatta-demo代碼ETL工具金字塔模組化啟動項目代碼位址
  3. 修改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>

           
  1. 修改配置檔案(路徑使用斜杠:/)
    geotrellis架構sbt轉投maven建構前言環境建構scala項目遷移geotrellis-chatta-demo代碼ETL工具金字塔模組化啟動項目代碼位址
    geotrellis架構sbt轉投maven建構前言環境建構scala項目遷移geotrellis-chatta-demo代碼ETL工具金字塔模組化啟動項目代碼位址

ETL工具金字塔模組化

  1. 規避錯誤
    geotrellis架構sbt轉投maven建構前言環境建構scala項目遷移geotrellis-chatta-demo代碼ETL工具金字塔模組化啟動項目代碼位址
    geotrellis架構sbt轉投maven建構前言環境建構scala項目遷移geotrellis-chatta-demo代碼ETL工具金字塔模組化啟動項目代碼位址
    geotrellis架構sbt轉投maven建構前言環境建構scala項目遷移geotrellis-chatta-demo代碼ETL工具金字塔模組化啟動項目代碼位址
  2. 需要金字塔模組化的tif在demo中的路徑
    geotrellis架構sbt轉投maven建構前言環境建構scala項目遷移geotrellis-chatta-demo代碼ETL工具金字塔模組化啟動項目代碼位址
  3. 修改input.json
    geotrellis架構sbt轉投maven建構前言環境建構scala項目遷移geotrellis-chatta-demo代碼ETL工具金字塔模組化啟動項目代碼位址
  4. 修改output.json
    geotrellis架構sbt轉投maven建構前言環境建構scala項目遷移geotrellis-chatta-demo代碼ETL工具金字塔模組化啟動項目代碼位址
  5. 修改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()
  }
}
           

啟動項目

geotrellis架構sbt轉投maven建構前言環境建構scala項目遷移geotrellis-chatta-demo代碼ETL工具金字塔模組化啟動項目代碼位址

檢視

geotrellis架構sbt轉投maven建構前言環境建構scala項目遷移geotrellis-chatta-demo代碼ETL工具金字塔模組化啟動項目代碼位址

代碼位址

https://gitee.com/XiaoSa12138/geotrellis-chatta-demo

繼續閱讀