Skip to content

Commit 607dc66

Browse files
committed
Move PDAL java from PDAL repo
0 parents  commit 607dc66

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+4794
-0
lines changed

.gitignore

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Operating System Files
2+
3+
# *.DS_Store
4+
Thumbs.db
5+
6+
# Build Files
7+
8+
bin
9+
target
10+
build/
11+
.gradle
12+
13+
# Eclipse Project Files
14+
15+
.classpath
16+
.project
17+
.settings
18+
19+
# IntelliJ IDEA Files
20+
21+
*.iml
22+
*.ipr
23+
*.iws
24+
*.idea
25+
26+
# Spring Bootstrap artifacts
27+
28+
dependency-reduced-pom.xml
29+
README.html
30+
31+
# Sublime files
32+
33+
*.sublime-workspace
34+
35+
# Test data files #
36+
37+
java/data
38+
39+
# Compiled libs #
40+
41+
java/*.dylib
42+
java/*.so
43+
java/*dll

LICENSE.txt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
Unless otherwise indicated, all files in the PDAL distribution are
2+
3+
Copyright (c) 2017, Hobu, Inc. ([email protected])
4+
5+
and are released under the terms of the BSD open source license.
6+
7+
This file contains the license terms of all files within PDAL.
8+
9+
10+
Overall PDAL license (BSD)
11+
===========================
12+
13+
Copyright (c) 2017, Hobu, Inc. ([email protected])
14+
15+
All rights reserved.
16+
17+
Redistribution and use in source and binary forms, with or without
18+
modification, are permitted provided that the following
19+
conditions are met:
20+
21+
* Redistributions of source code must retain the above copyright
22+
notice, this list of conditions and the following disclaimer.
23+
* Redistributions in binary form must reproduce the above copyright
24+
notice, this list of conditions and the following disclaimer in
25+
the documentation and/or other materials provided
26+
with the distribution.
27+
* Neither the name of Hobu, Inc. or Flaxen Consulting LLC nor the
28+
names of its contributors may be used to endorse or promote
29+
products derived from this software without specific prior
30+
written permission.
31+
32+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
35+
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
36+
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
37+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
38+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
39+
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
40+
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
41+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
42+
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
43+
OF SUCH DAMAGE.
44+
45+
46+

README.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# PDAL Java bindings
2+
3+
[![Join the chat at https://gitter.im/PDAL/PDAL](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/PDAL/PDAL?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4+
5+
Java bindings to use PDAL on JVM (supports PDAL >= 1.4).
6+
7+
## Using PDAL JNI with SBT
8+
9+
```scala
10+
// pdal is published to maven central, but you can use following repos in addition
11+
resolvers ++= Seq(
12+
Resolver.sonatypeRepo("releases"),
13+
Resolver.sonatypeRepo("snapshots") // for snaphots
14+
)
15+
16+
libraryDependencies ++= Seq(
17+
"io.pdal" %% "pdal" % "1.6.0"
18+
)
19+
```
20+
21+
It's required to have native JNI binary in `java.library.path`:
22+
23+
```scala
24+
// Mac OS X example with manual JNI installation
25+
// Though it's strongly recommended to use WITH_PDAL_JNI during PDAL build
26+
// cp -f native/target/resource_managed/main/native/x86_64-darwin/libpdaljni.1.4.dylib /usr/local/lib/libpdaljni.1.4.dylib
27+
// place built binary into /usr/local/lib, and pass java.library.path to your JVM
28+
javaOptions += "-Djava.library.path=/usr/local/lib"
29+
```
30+
31+
## PDAL-Scala
32+
33+
Scala API to build pipeline expressions instead of writing a raw JSON.
34+
35+
```scala
36+
libraryDependencies ++= Seq(
37+
"io.pdal" %% "pdal-scala" % "1.6.0"
38+
)
39+
```
40+
41+
Scala API covers PDAL 1.6.0 but is compatible with PDAL >= 1.4, to use any custom DSL
42+
that is not covered by the current Scala API you can use `RawExpr` type to build `Pipeline
43+
Expression`.
44+
45+
### Code examples
46+
47+
```scala
48+
// To construct the expected json
49+
val expected =
50+
"""
51+
|{
52+
| "pipeline" : [
53+
| {
54+
| "filename" : "/path/to/las",
55+
| "type" : "readers.las"
56+
| },
57+
| {
58+
| "type" : "filters.crop"
59+
| },
60+
| {
61+
| "filename" : "/path/to/new/las",
62+
| "type" : "writers.las"
63+
| }
64+
| ]
65+
|}
66+
""".stripMargin
67+
68+
// The same, but using scala DSL
69+
val pc: PipelineConstructor = LasRead("/path/to/las") ~ CropFilter() ~ LasWrite("/path/to/new/las")
70+
71+
// The same, but using RawExpr, to support not implemented PDAL Pipeline API features
72+
// RawExpr accepts a circe.Json type, which can be a json object of any desired complexity
73+
val pcWithRawExpr = LasRead("/path/to/las") ~ RawExpr(Map("type" -> "filters.crop").asJson) ~ LasWrite("/path/to/new/las")
74+
```
75+
76+
## How to compile
77+
78+
Development purposes (including binaries):
79+
1. Install PDAL (using brew / package managers (unix) / build from sources / etc) _without_ `-DWITH_PDAL_JNI=ON` flag
80+
2. Build native libs `./sbt native/nativeCompile` (optionally, binaries would be built during tests run)
81+
3. Run `./sbt core/test` to run PDAL tests
82+
83+
Only Java development purposes:
84+
1. Provide `$LD_LIBRARY_PATH` or `$DYLD_LIBRARY_PATH`
85+
2. If you don't want to provide global variable you can pass `-Djava.library.path=<path>` into sbt:
86+
`./sbt -Djava.library.path=<path>`
87+
3. Set `PDAL_DEPEND_ON_NATIVE=false` (to disable `native` project build)
88+
4. Run `PDAL_DEPEND_ON_NATIVE=false ./sbt`
89+
90+
Finally the possible command to launch and build PDAL JNI bindings could be:
91+
92+
```bash
93+
# Including binaries build
94+
# WARN: PDAL should be built without `-DWITH_PDAL_JNI=ON` flag
95+
./sbt
96+
```
97+
98+
```bash
99+
# Java side development without binaries build
100+
# WARN: PDAL should be built with `-DWITH_PDAL_JNI=ON` flag
101+
PDAL_DEPEND_ON_NATIVE=false ./sbt -Djava.library.path=<path>
102+
```
103+
104+
### Possible issues and solutions
105+
106+
1. In case of not installed as global PDAL change [this](./java/native/src/CMakeLists.txt#L25) line to:
107+
108+
```cmake
109+
set(CMAKE_CXX_FLAGS "$ENV{PDAL_LD_FLAGS} $ENV{PDAL_CXX_FLAGS} -std=c++11")
110+
```
111+
In this case sbt launch would be the following:
112+
113+
```bash
114+
PDAL_LD_FLAGS=`pdal-config --libs` PDAL_CXX_FLAGS=`pdal-config --includes` ./sbt
115+
```
116+
117+
2. Sometimes can happen a bad dynamic linking issue (somehow spoiled environment),
118+
the quick workaround would be to replace [this](./java/native/src/CMakeLists.txt#L25) line to:
119+
120+
```cmake
121+
set(CMAKE_CXX_FLAGS "-L<path to dynamic libs> -std=c++11")
122+
```

build.sbt

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name := "pdal-jni"
2+
3+
lazy val commonSettings = Seq(
4+
version := "1.7.0" + Environment.versionSuffix,
5+
scalaVersion := "2.11.11",
6+
crossScalaVersions := Seq("2.12.4", "2.11.11"),
7+
organization := "io.pdal",
8+
description := "PDAL JNI bindings",
9+
licenses := Seq("BSD" -> url("https://github.com/PDAL/PDAL/blob/master/LICENSE.txt")),
10+
homepage := Some(url("http://www.pdal.io")),
11+
publishMavenStyle := true,
12+
pomIncludeRepository := { _ => false },
13+
scalacOptions ++= Seq(
14+
"-deprecation",
15+
"-unchecked",
16+
"-language:implicitConversions",
17+
"-language:reflectiveCalls",
18+
"-language:higherKinds",
19+
"-language:postfixOps",
20+
"-language:existentials",
21+
"-feature"
22+
),
23+
test in assembly := {},
24+
shellPrompt := { s => Project.extract(s).currentProject.id + " > " },
25+
commands ++= Seq(
26+
Commands.processJavastyleCommand("publish"),
27+
Commands.processJavastyleCommand("publishSigned")
28+
),
29+
publishArtifact in Test := false,
30+
publishTo := {
31+
val nexus = "https://oss.sonatype.org/"
32+
if (isSnapshot.value)
33+
Some("snapshots" at nexus + "content/repositories/snapshots")
34+
else
35+
Some("releases" at nexus + "service/local/staging/deploy/maven2")
36+
},
37+
pomExtra := (
38+
<scm>
39+
<url>git@github.com:PDAL/PDAL.git</url>
40+
<connection>scm:git:git@github.com:PDAL/PDAL.git</connection>
41+
</scm>
42+
<developers>
43+
<developer>
44+
<id>pomadchin</id>
45+
<name>Grigory Pomadchin</name>
46+
<url>http://github.com/pomadchin/</url>
47+
</developer>
48+
</developers>
49+
)
50+
)
51+
52+
lazy val root = (project in file("."))
53+
.settings(commonSettings: _*)
54+
.aggregate(`core-scala`, core, native)
55+
56+
lazy val `core-scala` = project
57+
.settings(commonSettings: _*)
58+
.settings(name := "pdal-scala")
59+
.settings(target in javah := (sourceDirectory in nativeCompile in native).value / "include")
60+
.settings(libraryDependencies ++= Seq(
61+
Dependencies.circeCore,
62+
Dependencies.circeGeneric,
63+
Dependencies.circeGenericExtras,
64+
Dependencies.circeParser,
65+
Dependencies.jtsCore,
66+
Dependencies.scalaTest % Test
67+
))
68+
.settings(headerLicense := Some(HeaderLicense.ALv2("2017", "Azavea")))
69+
.settings(licenses := Seq("Apache-2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0.html")))
70+
.dependsOn(core)
71+
72+
lazy val core = project
73+
.settings(commonSettings: _*)
74+
.settings(name := "pdal")
75+
.settings(target in javah := (sourceDirectory in nativeCompile in native).value / "include")
76+
.settings(libraryDependencies += Dependencies.scalaTest % Test)
77+
.dependsOn(Environment.dependOnNative(native % Runtime): _*)
78+
79+
lazy val native = project
80+
.settings(sourceDirectory in nativeCompile := sourceDirectory.value)
81+
.enablePlugins(JniNative)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2017 Azavea
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.pdal.pipeline
18+
19+
import scala.util.Try
20+
21+
trait ExprType {
22+
val `type`: String
23+
lazy val name = s"${`type`}.${this.getClass.getName.split("\\$").last}"
24+
25+
override def toString = name
26+
}
27+
28+
object ExprType {
29+
def fromName(name: String): ExprType =
30+
Try(FilterTypes.fromName(name))
31+
.getOrElse(Try(ReaderTypes.fromName(name))
32+
.getOrElse(Try(WriterTypes.fromName(name))
33+
.getOrElse(throw new Exception(s"ExprType $name is not supported."))))
34+
}

0 commit comments

Comments
 (0)