diff options
| author | Martin Desruisseaux <martin.desruisseaux@geomatys.fr> | 2011-09-01 17:25:48 +0000 |
|---|---|---|
| committer | Martin Desruisseaux <martin.desruisseaux@geomatys.fr> | 2011-09-01 17:25:48 +0000 |
| commit | 8d26bb7e1130d5d44777087324c34635eb1f2a0a (patch) | |
| tree | 8db496911b235bccb4c92c07f1ec8c72db6f6c29 /jniwrap | |
| parent | bcada9c0400f2c18c999b2e1e5bda824942e89f2 (diff) | |
| download | PROJ-8d26bb7e1130d5d44777087324c34635eb1f2a0a.tar.gz PROJ-8d26bb7e1130d5d44777087324c34635eb1f2a0a.zip | |
Updated the Ant build file for JNI bindings, the jniwrap/README and the ChangeLog.
git-svn-id: http://svn.osgeo.org/metacrs/proj/trunk@2094 4e78687f-474d-0410-85f9-8d5e500ac6b2
Diffstat (limited to 'jniwrap')
| -rw-r--r-- | jniwrap/README | 154 | ||||
| -rw-r--r-- | jniwrap/build.xml | 152 |
2 files changed, 96 insertions, 210 deletions
diff --git a/jniwrap/README b/jniwrap/README index 0c5818e8..a7f4efc5 100644 --- a/jniwrap/README +++ b/jniwrap/README @@ -19,7 +19,7 @@ What is "Proj.4 wrapper": ------------- "Proj.4 wrapper" is a small library of Java classes that wrap a few Proj.4 functions by -using the Java Native Interface (JNI). +using the Java Native Interface (JNI). The main Java class is org.proj4.PJ. Compilation: @@ -86,138 +86,34 @@ The whole job is done by the proj4, so there are just a couple of functions that be used. The best way is to see everything through an example. -In the following example we read projection informations and data from a file -and then transform the data and query the information. +In the following example we create two Coordinate System and transform 3 points. +The Coordinate System and the points are hard-coded for simplicity. Of course, +real applications would read them from a file or other data source. ________________________________________________________________________________ -First step: -create a text file, let's say test.txt, with the following in it: -srcProj: +proj=latlong +datum=WGS84 -destProj: +init=epsg:32632 -rows: 1 -46 11 194.0 - - -This contains info about a source and destination projection, the number of data -triplets and then the data (in this case just one point) - - -________________________________________________________________________________ -Step two: -create a test code. Simply copy the following into a file called Main.java. The -code is commented to see what we are doing: - - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.LinkedHashMap; - -import org.proj4.Proj4; -import org.proj4.ProjectionData; - - -public class Main -{ - - public static void main(String[] args) throws IOException - { - // print out the usage if no argument was given - if (args.length < 1) - { - System.out.println(); - System.out.println("Usage: Proj datafile"); - System.out.println(); - System.exit(0); +import org.proj4.*; +import java.util.Arrays; + + +/** + * Converts coordinates from EPSG:32632 (WGS 84 / UTM zone 32N) to WGS84, + * then prints the result to the standard output stream. + */ +public class Main { + public static void main(String[] args) throws PJException { + PJ sourcePJ = new PJ("+init=epsg:32632"); // (x,y) axis order + PJ targetPJ = new PJ("+proj=latlong +datum=WGS84"); // (λ,φ) axis order + double[] coordinates = { + 500000, 0, // First coordinate + 400000, 100000, // Second coordinate + 600000, -100000 // Third coordinate + }; + sourcePJ.transform(targetPJ, 2, coordinates, 0, 3); + System.out.println(Arrays.toString(coordinates)); } - - // now the input file is going to be read - BufferedReader br = new BufferedReader(new InputStreamReader( - new FileInputStream(new File(args[0])))); - LinkedHashMap mapHeader = new LinkedHashMap(); - // read the header - String line = null; - for (int i = 0; i < 3; i++) - { - if ((line = br.readLine()) != null) - { - String[] header = line.split(":", 2); - if (header.length <= 2) - { - mapHeader.put(header[0].trim(), header[1].trim()); - } - else - { - System.out.println("Wrong file format"); - System.exit(0); - } - } - } - // with what you see above, the header was read - - // now I can define the number of rows of data triplets - int rows = new Integer((String) mapHeader.get("rows")).intValue(); - - double[][] testCoord = new double[rows][2]; - double[] testValues = new double[rows]; - System.out.println("Source coordinates and values:"); - - // start reading the data - for (int i = 0; i < rows; i++) - { - if ((line = br.readLine()) != null) - { - String[] values = line.split(" +"); - if (values.length == 3) - { - testCoord[i][0] = new Double(values[0].trim()).doubleValue(); - testCoord[i][1] = new Double(values[1].trim()).doubleValue(); - testValues[i] = new Double(values[2].trim()).doubleValue(); - System.out.println("x = " + testCoord[i][0] + " y = " - + testCoord[i][1] + " z = " + testValues[i]); - } - else - { - System.out.println("Wrong file format or empty line found"); - } - } - } - - // create the dataset - // this is necessary to be able to transform - ProjectionData dataTP = new ProjectionData(testCoord, testValues); - - // here we go with the instantiation of the proj4 object - Proj4 testProjection = new Proj4((String) mapHeader.get("srcProj"), - (String) mapHeader.get("destProj")); - - // the instantiation of the proj4 object instantiated also the projection - // objects for source and destination projection - // therefore we can already print the projection infos: - testProjection.printSrcProjInfo(); - testProjection.printDestProjInfo(); - - // and transform, passing as parameter the created dataset: - testProjection.transform(dataTP, 1, 1); - - // if we need the parameters as Hashmap for a later use: - LinkedHashMap testMap = testProjection.getSrcProjInfo(); - - // and let us print them to screen to see them - System.out.println(); - System.out.println("Proj as a Hashmap"); - System.out.println("******************************************************"); - System.out.println(testMap.toString()); - - } - } - - ________________________________________________________________________________ -Step three + compile the Main code: we assume that proj was compiled with the right flag to support jproj. Therefore we have a library called jproj.jar. @@ -227,6 +123,6 @@ javac -classpath <path to the jar library>/jproj.jar Main.java and execute the created test case with: -java -cp .:<path to the jar library>/jproj.jar -Djava.library.path=<path to the libproj, if needed> Main test.txt +java -cp .:<path to the jar library>/jproj.jar -Djava.library.path=<path to the libproj, if needed> Main That's it, enjoy! diff --git a/jniwrap/build.xml b/jniwrap/build.xml index 3032a52f..2888a1ec 100644 --- a/jniwrap/build.xml +++ b/jniwrap/build.xml @@ -1,98 +1,88 @@ <?xml version="1.0"?> <project name="jproj" default="compile" basedir="."> - <!-- ******************************************* --> - <!-- set the variables --> - <!-- ******************************************* --> - <property name="src" value="org/proj4"/> - <property name="build" value="classes"/> - <property name="libs" value="libs"/> + <!-- ******************************************* --> + <!-- Set the variables --> + <!-- ******************************************* --> + <property name="src" value="org/proj4"/> + <property name="srcProj" value="../src"/> + <property name="build" value="classes"/> + <property name="libs" value="libs"/> - <!-- ******************************************* --> - <!-- start everything (default target) --> - <!-- ******************************************* --> - <target name="compile" depends="start, do_javac, jar_it"> + <!-- ******************************************* --> + <!-- Start everything (default target) --> + <!-- ******************************************* --> + <target name="compile" depends="start, do_javac, jar_it"> <echo>Compilation finished...</echo> - </target> + </target> - <!-- ******************************************* --> - <!-- create some begin stuff --> - <!-- ******************************************* --> - <target name="start"> - <echo>Start compilation...</echo> - <!-- <splash imageurl="./etc/images/logo.jpg" showduration="5000"/> --> + <!-- ******************************************* --> + <!-- Create some begin stuff --> + <!-- ******************************************* --> + <target name="start"> <echo>Creating folder structure...</echo> <mkdir dir="${build}"/> <mkdir dir="${libs}"/> - </target> + </target> - <!-- ******************************************* --> - <!-- execute javac compilation --> - <!-- ******************************************* --> - <target name="do_javac" depends="start"> - <echo>Compiling the java code...</echo> - <javac srcdir="${src}" destdir="${build}" debug="on"> - </javac> - </target> + <!-- ******************************************* --> + <!-- Execute javac compilation --> + <!-- ******************************************* --> + <target name="do_javac" depends="start"> + <echo>Compiling the java code...</echo> + <javac srcdir="${src}" destdir="${build}" encoding="UTF-8" source="1.5" target="1.5" includeAntRuntime="false"/> + </target> + <!-- ******************************************* --> + <!-- Execute javah for JNI headers --> + <!-- ******************************************* --> + <!-- Needed if new native methods are added. --> + <!-- Header file is created only if the old --> + <!-- proj/src/org_proj4_PJ.h file is deleted --> + <!-- before to run this task. --> + <!-- ******************************************* --> + <target name="do_javah" depends="do_javac"> + <echo>Creating jni headers...</echo> + <javah classpath="${build}" class="org.proj4.PJ" destdir="${srcProj}"/> + </target> + <!-- ******************************************* --> + <!-- Do the C part compilation through make --> + <!-- ******************************************* --> + <target name="do_make" depends="do_javah"> + <echo>Compiling libraries...</echo> + <exec dir=".." executable="make"/> + </target> - <!-- ******************************************* --> - <!-- execute javah for JNI headers --> - <!-- ******************************************* --> - <!-- needed if new native methods are added --> - <!-- ******************************************* --> - <target name="do_javah" depends="do_javac"> - <echo>Creating jni headers...</echo> - <exec dir="${build}" executable="javah" os="Linux"> - <arg line="-jni -d ../native org.proj4.PJ"/> - </exec> - </target> + <!-- ******************************************* --> + <!-- Create binary package distribution --> + <!-- ******************************************* --> + <target name="jar_it"> + <jar destfile="${libs}/jproj.jar" basedir="${build}/"> + <manifest> + <attribute name="Built-By" value="Proj.4"/> + </manifest> + </jar> + </target> - <!-- ******************************************* --> - <!-- do the C part compilation through make --> - <!-- ******************************************* --> - <target name="do_make" depends="do_javah"> - <echo>Compiling libraries ...</echo> - <exec dir="." executable="make" os="Linux"> - <arg line=""/> - </exec> - </target> + <!-- ****************************************************** --> + <!-- Execute doxygen help file and source file creation --> + <!-- ****************************************************** --> + <target name="do_make_help" depends="start"> + <echo>Creating help files...</echo> + <exec dir="." executable="doxygen"> + <arg line="doxygen.cfg"/> + </exec> + </target> - <!-- ******************************************* --> - <!-- create binary package distribution with ant --> - <!-- ******************************************* --> - - <!-- this is not working properly by now --> - <target name="jar_it"> - <delete file="${libs}/jproj.jar"/> - <jar destfile="${libs}/jproj.jar" basedir="${build}/"> - <manifest> - <attribute name="Built-By" value="the jgrass idealists"/> - </manifest> - </jar> - <delete dir="${build}"/> - </target> - - <!-- ****************************************************** --> - <!-- execute doxygen help file and source file creation --> - <!-- ****************************************************** --> - <target name="do_make_help" depends="start"> - <echo>Creating help files...</echo> - <exec dir="." executable="doxygen"> - <arg line="doxygen.cfg"/> - </exec> - </target> - - <!-- ******************************************* --> - <!-- clean up everything --> - <!-- ******************************************* --> - <target name="clean"> - <echo>Cleaning up...</echo> - <delete dir="${build}"/> - <delete dir="${libs}"/> - <delete dir="docs"/> - </target> + <!-- ******************************************* --> + <!-- Clean up everything --> + <!-- ******************************************* --> + <target name="clean"> + <echo>Cleaning up...</echo> + <delete dir="${build}"/> + <delete dir="${libs}"/> + <delete dir="docs"/> + </target> </project> - |
