1 /******************************************************************************
2 * $Id: osr_java.i 5106013c5d2ac51dbb5d7badae417d9bb1b1545a 2020-12-16 15:09:33 +0100 Even Rouault $
3 *
4 * Name: osr_java.i
5 * Project: GDAL SWIG Interface
6 * Purpose: Typemaps for Java bindings
7 * Author: Benjamin Collins, The MITRE Corporation
8 *
9 */
10
11 %include arrays_java.i
12 %include typemaps_java.i
13
14 #ifndef FROM_GDAL_I
15 %include java_exceptions.i
16 #endif
17
18 %pragma(java) jniclasscode=%{
19
20 static {
21 gdalJNI.isAvailable(); // force gdalJNI static initializer to run and load library
22 }
23
isAvailable()24 public static boolean isAvailable() {
25 return gdalJNI.isAvailable();
26 }
27 %}
28
29 %pragma(java) modulecode=%{
30
31 /* Uninstanciable class */
osr()32 private osr()
33 {
34 }
35 %}
36
37 %pragma(java) jniclassimports=%{
38 import org.gdal.gdal.gdalJNI;
39 %}
40
41 /*
42 * Needed to make the Constructor and getCptr 'public' and not 'protected'.
43 * There is likely a better way to do this (with javamethodmodifiers) but
44 * none worked for me.
45 */
46 %typemap(javabody) OSRSpatialReferenceShadow, OSRCoordinateTransformationShadow %{
47 private long swigCPtr;
48 protected boolean swigCMemOwn;
49
$javaclassname(long cPtr,boolean cMemoryOwn)50 public $javaclassname(long cPtr, boolean cMemoryOwn) {
51 swigCMemOwn = cMemoryOwn;
52 swigCPtr = cPtr;
53 }
54
getCPtr($javaclassname obj)55 public static long getCPtr($javaclassname obj) {
56 return (obj == null) ? 0 : obj.swigCPtr;
57 }
58 %}
59
60 %typemap(javacode) OSRSpatialReferenceShadow %{
equals(Object obj)61 public boolean equals(Object obj) {
62 boolean equal = false;
63 if (obj instanceof $javaclassname)
64 equal = ((($javaclassname)obj).swigCPtr == this.swigCPtr);
65 return equal;
66 }
67
clone()68 public Object clone()
69 {
70 return Clone();
71 }
72
hashCode()73 public int hashCode() {
74 return (int)swigCPtr;
75 }
76
toString()77 public String toString() {
78 return __str__();
79 }
80
ExportToWkt()81 public String ExportToWkt() {
82 String array[] = new String[] {null};
83 ExportToWkt(array);
84 return array[0];
85 }
86
ExportToPrettyWkt(int simplify)87 public String ExportToPrettyWkt(int simplify) {
88 String array[] = new String[] {null};
89 ExportToPrettyWkt(array, simplify);
90 return array[0];
91 }
92
ExportToPrettyWkt()93 public String ExportToPrettyWkt() {
94 String array[] = new String[] {null};
95 ExportToPrettyWkt(array);
96 return array[0];
97 }
98
ExportToProj4()99 public String ExportToProj4() {
100 String array[] = new String[] {null};
101 ExportToProj4(array);
102 return array[0];
103 }
104
ExportToXML(String dialect)105 public String ExportToXML( String dialect) {
106 String array[] = new String[] {null};
107 ExportToXML(array, dialect);
108 return array[0];
109 }
110
ExportToXML()111 public String ExportToXML() {
112 String array[] = new String[] {null};
113 ExportToXML(array);
114 return array[0];
115 }
116
ExportToMICoordSys()117 public String ExportToMICoordSys() {
118 String array[] = new String[] {null};
119 ExportToMICoordSys(array);
120 return array[0];
121 }
122
GetTOWGS84()123 public double[] GetTOWGS84()
124 {
125 double array[] = new double[7];
126 GetTOWGS84(array);
127 return array;
128 }
129
SetTOWGS84(double p1,double p2,double p3)130 public int SetTOWGS84( double p1, double p2, double p3)
131 {
132 return SetTOWGS84(p1, p2, p3, 0, 0, 0, 0);
133 }
134 %}
135
136 %typemap(javainterfaces) OSRSpatialReferenceShadow "Cloneable"
137
138 %typemap(javacode) OSRCoordinateTransformationShadow %{
TransformPoint(double x,double y,double z)139 public double[] TransformPoint(double x, double y, double z) {
140 double[] ret = new double[3];
141 TransformPoint(ret, x, y, z);
142 return ret;
143 }
144
TransformPoint(double x,double y)145 public double[] TransformPoint(double x, double y) {
146 return TransformPoint(x, y, 0);
147 }
148
149 /* New in GDAL 1.10 */
CreateCoordinateTransformation(SpatialReference src,SpatialReference dst)150 public static CoordinateTransformation CreateCoordinateTransformation(SpatialReference src, SpatialReference dst)
151 {
152 CoordinateTransformation ct = osr.CreateCoordinateTransformation(src, dst);
153 if( ct == null && osr.GetUseExceptions() )
154 throw new RuntimeException("Cannot create CoordinateTransformation: " + org.gdal.gdal.gdal.GetLastErrorMsg());
155 return ct;
156 }
157
CreateCoordinateTransformation(SpatialReference src,SpatialReference dst,CoordinateTransformationOptions options)158 public static CoordinateTransformation CreateCoordinateTransformation(SpatialReference src, SpatialReference dst, CoordinateTransformationOptions options)
159 {
160 CoordinateTransformation ct = osr.CreateCoordinateTransformation(src, dst, options);
161 if( ct == null && osr.GetUseExceptions() )
162 throw new RuntimeException("Cannot create CoordinateTransformation: " + org.gdal.gdal.gdal.GetLastErrorMsg());
163 return ct;
164 }
165 %}
166
167 /******************************************************************************
168 *
169 * Global methods
170 *
171 */
172
173 /************************************************************************/
174 /* GetWellKnownGeogCSAsWKT() */
175 /************************************************************************/
176
177 %inline %{
GetWellKnownGeogCSAsWKT(const char * name)178 retStringAndCPLFree* GetWellKnownGeogCSAsWKT( const char *name ) {
179 char* argout = NULL;
180 OGRSpatialReferenceH srs = OSRNewSpatialReference("");
181 OGRErr rcode = OSRSetWellKnownGeogCS( srs, name );
182 if( rcode == OGRERR_NONE )
183 rcode = OSRExportToWkt ( srs, &argout );
184 OSRDestroySpatialReference( srs );
185 return argout;
186 }
187 %}
188
189 /************************************************************************/
190 /* GetUserInputAsWKT() */
191 /************************************************************************/
192 %inline %{
GetUserInputAsWKT(const char * name)193 retStringAndCPLFree* GetUserInputAsWKT( const char *name ) {
194 char* argout = NULL;
195 OGRSpatialReferenceH srs = OSRNewSpatialReference("");
196 OGRErr rcode = OSRSetFromUserInput( srs, name );
197 if( rcode == OGRERR_NONE )
198 rcode = OSRExportToWkt ( srs, &argout );
199 OSRDestroySpatialReference( srs );
200 return argout;
201 }
202 %}
203