/********************************************************************** * $Id$ * * Name: OGRSpatialReference_interfaz.c * Project: JGDAL. Interface java to gdal (Frank Warmerdam). * Purpose: dataset's Basic Funcions. * Author: Nacho Brodin, brodin_ign@gva.es * **********************************************************************/ /* gvSIG. Sistema de Información Geográfica de la Generalitat Valenciana * * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. * * For more information, contact: * * Generalitat Valenciana * Conselleria d'Infraestructures i Transport * Av. Blasco Ibáñez, 50 * 46010 VALENCIA * SPAIN * * +34 963862235 * gvsig@gva.es * www.gvsig.gva.es * * or * * IVER T.I. S.A * Salamanca 50 * 46005 Valencia * Spain * * +34 963163400 * dac@iver.es */ #include #include "es_gva_cit_jogr_OGRSpatialReference.h" #include "es_gva_cit_jogr_JNIBase.h" #include "gdal.h" #include "cpl_string.h" #include "ogr_api.h" #include "ogr_srs_api.h" /******************************************************************************/ // setUTM /******************************************************************************/ JNIEXPORT jint JNICALL Java_es_gva_cit_jogr_OGRSpatialReference_setUTMNat (JNIEnv *env, jobject obj, jlong cPtr, jint zona, jint norte_sur){ OGRSpatialReferenceH *hSRS = (OGRSpatialReferenceH *) 0 ; hSRS = *(OGRSpatialReferenceH **)&cPtr; if(hSRS!=NULL){ OSRSetUTM( *hSRS, zona, norte_sur ); return 1; } return -1; } /******************************************************************************/ // setWellKnownGeogCS /******************************************************************************/ JNIEXPORT jint JNICALL Java_es_gva_cit_jogr_OGRSpatialReference_setWellKnownGeogCSNat (JNIEnv *env, jobject obj, jlong cPtr, jstring cs){ OGRSpatialReferenceH *hSRS = (OGRSpatialReferenceH *) 0 ; hSRS = *(OGRSpatialReferenceH **)&cPtr; if(hSRS!=NULL){ const char *coord_sys = (*env)->GetStringUTFChars(env, cs, 0); OSRSetWellKnownGeogCS( *hSRS, coord_sys ); (*env)->ReleaseStringUTFChars(env, cs, coord_sys); return 1; } return -1; } /******************************************************************************/ // OGRSpatialReference /******************************************************************************/ JNIEXPORT jlong JNICALL Java_es_gva_cit_jogr_OGRSpatialReference_OGRSpatialReferenceNat (JNIEnv *env, jobject obj){ OGRSpatialReferenceH *hSRS; jlong jresult=0; hSRS=(OGRSpatialReferenceH*)malloc(sizeof(OGRSpatialReferenceH)); *hSRS = OSRNewSpatialReference( NULL ); *(OGRSpatialReferenceH **)&jresult = hSRS; //printf("-------->%ld\n",(long)jresult); return (long)jresult; } /******************************************************************************/ // exportToWkt /******************************************************************************/ JNIEXPORT jstring JNICALL Java_es_gva_cit_jogr_OGRSpatialReference_exportToWktNat (JNIEnv *env, jobject obj, jlong cPtr){ OGRSpatialReferenceH *hSRS = (OGRSpatialReferenceH *) 0 ; jstring wkt; char *pszSRS_WKT = NULL; hSRS = *(OGRSpatialReferenceH **)&cPtr; if(hSRS!=NULL){ OSRExportToWkt( *hSRS, &pszSRS_WKT ); if(pszSRS_WKT!=NULL){ wkt = (*env)->NewStringUTF(env, pszSRS_WKT); return wkt; } } return NULL; } /******************************************************************************/ // getUTMZone /******************************************************************************/ JNIEXPORT jint JNICALL Java_es_gva_cit_jogr_OGRSpatialReference_getUTMZoneNat (JNIEnv *env, jobject obj, jlong cPtr){ /*OGRSpatialReferenceH *hSRS = (OGRSpatialReferenceH *) 0 ; hSRS = *(OGRSpatialReferenceH **)&cPtr; if(hSRS!=NULL){ int *pH; return OSRGetUTMZone(hSRS,pH); }*/ return -1; } /******************************************************************************/ // getHemisphere /******************************************************************************/ JNIEXPORT jint JNICALL Java_es_gva_cit_jogr_OGRSpatialReference_getHemisphereNat (JNIEnv *env, jobject obj, jlong cPtr){ /*OGRSpatialReferenceH *hSRS = (OGRSpatialReferenceH *) 0 ; hSRS = *(OGRSpatialReferenceH **)&cPtr; if(hSRS!=NULL){ int pH; OSRGetUTMZone(hSRS,&pH); return *pH; }*/ return -1; } /******************************************************************************/ // OSRDestroySpatialReference /******************************************************************************/ JNIEXPORT void JNICALL Java_es_gva_cit_jogr_OGRSpatialReference_OSRDestroySpatialReferenceNat (JNIEnv *env, jobject obj, jlong cPtr){ OGRSpatialReferenceH *hSRS = (OGRSpatialReferenceH *) 0 ; hSRS = *(OGRSpatialReferenceH **)&cPtr; if(hSRS!=NULL){ OSRDestroySpatialReference(*hSRS); } } /******************************************************************************/ // setFromUserInput /******************************************************************************/ JNIEXPORT jint JNICALL Java_es_gva_cit_jogr_OGRSpatialReference_setFromUserInputNat (JNIEnv *env, jobject obj, jlong cPtr, jstring a_srs){ int ogrerr; OGRSpatialReferenceH *hSRS = (OGRSpatialReferenceH *) 0 ; const char *s; hSRS = *(OGRSpatialReferenceH **)&cPtr; s = (*env)->GetStringUTFChars(env, a_srs, 0); ogrerr = OSRSetFromUserInput(hSRS,s); (*env)->ReleaseStringUTFChars(env, a_srs, s); return ogrerr; }