Skip to content

Instantly share code, notes, and snippets.

@reverocean
Forked from Brideau/DYLD_LIBRARY_PATH
Created February 22, 2019 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reverocean/7bd142faa2eb584e8a830a03a5e1b871 to your computer and use it in GitHub Desktop.
Save reverocean/7bd142faa2eb584e8a830a03a5e1b871 to your computer and use it in GitHub Desktop.
Install GDAL with Java bindings on macOS High Sierra
resolvers += "Boundless" at "http://repo.boundlessgeo.com/main/"
libraryDependencies += "org.gdal" % "gdal" % "2.2.1"
// These let you enter input in the terminal if running via SBT
fork in run := true
connectInput in run := true
export DYLD_LIBRARY_PATH=/usr/local/opt/gdal2/lib:$DYLD_LIBRARY_PATH
brew install osgeo/osgeo4mac/gdal2 --with-java --with-libkml --with-mdb --with-mysql --with-opencl --with-postgresql --with-swig-java
package com.whackdata
import org.gdal.ogr._
object Main extends App {
val fileName = "./src/main/resources/Canada3573.gpkg"
// Register all of the OGR drivers that are part of your GDAL installation.
ogr.RegisterAll()
// Open your file
val dataSource = ogr.OpenShared(fileName)
// Get the first layer (there is only one in the sample file).
// You can also use dataSource.GetLayerByName() if your layers are named.
val layer = dataSource.GetLayer(0)
// Load the Spatial Reference and auto-identify
val srs = layer.GetSpatialRef()
srs.AutoIdentifyEPSG
val authCode = srs.GetAuthorityCode(null)
println("EPSG: " + authCode)
}
package com.whackdata
import org.gdal.ogr._
import scala.concurrent.Future
import scala.io.StdIn
import scala.util.{Failure, Success}
import scala.concurrent.ExecutionContext.Implicits.global
object MainNonBlocking extends App {
val fileName = "./src/main/resources/hex62p5.geojson"
// Register all of the OGR drivers that are part of your GDAL installation.
ogr.RegisterAll()
def getAuthCode(fileName: String): Future[String] = Future {
val dataSource = ogr.OpenShared(fileName)
// Get the first layer (there is only one in the sample file).
// You can also use dataSource.GetLayerByName() if your layers are named.
val layer = dataSource.GetLayer(0)
// Load the Spatial Reference and auto-identify
val srs = layer.GetSpatialRef()
srs.AutoIdentifyEPSG
srs.GetAuthorityCode(null)
}
getAuthCode(fileName).onComplete{
case Success(authCode) => println("EPSG: " + authCode)
case Failure(ex) => println("Lookup Failed: " + ex.getMessage)
}
println(s"Running in background. Press Return to stop.")
StdIn.readLine()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment