Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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