Skip to content

Instantly share code, notes, and snippets.

@Brideau
Last active April 27, 2020 14:03
Show Gist options
  • Save Brideau/b96aa05d719fb764d38bb9d75b48aa9d to your computer and use it in GitHub Desktop.
Save Brideau/b96aa05d719fb764d38bb9d75b48aa9d 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()
}
@jfacoustic
Copy link

I'm getting error: invalid option: --with-java

@utahemre
Copy link

Try with "with-swig-java" option

@jasbeern
Copy link

Tried with-swig-java option.
Error: invalid option: --with-swig-java

@rooby
Copy link

rooby commented Apr 27, 2020

FYI it seems like you cannot do this via homebrew anymore as there are no such options available (e.g. with-swig-java).
So far I haven't found a way other than building from source.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment