天天看点

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

继续阅读