ogr_fromepsg.cpp
来自「用于读取TAB、MIF、SHP文件的类」· C++ 代码 · 共 1,725 行 · 第 1/5 页
CPP
1,725 行
/****************************************************************************** * $Id: ogr_fromepsg.cpp,v 1.43 2006/04/21 04:12:29 fwarmerdam Exp $ * * Project: OpenGIS Simple Features Reference Implementation * Purpose: Generate an OGRSpatialReference object based on an EPSG * PROJCS, or GEOGCS code. * Author: Frank Warmerdam, warmerdam@pobox.com * ****************************************************************************** * Copyright (c) 2000, Frank Warmerdam * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. ****************************************************************************** * * $Log: ogr_fromepsg.cpp,v $ * Revision 1.43 2006/04/21 04:12:29 fwarmerdam * Removed debugging printf. * * Revision 1.42 2006/04/21 04:10:07 fwarmerdam * added deprecated PCS name if it is deprecated * * Revision 1.41 2006/03/01 03:12:51 fwarmerdam * added method 9823 (Equirectangular/Plate Caree/Equidistant Cylindrical * * Revision 1.40 2005/12/06 06:41:18 fwarmerdam * added slightly questionable translation for method 9829 (PS Variant B * * Revision 1.39 2005/04/06 00:02:05 fwarmerdam * various osr and oct functions now stdcall * * Revision 1.38 2004/09/10 21:02:41 fwarmerdam * added note about 9814 * * Revision 1.37 2004/05/26 19:53:17 warmerda * Fixed poor NULL checking in auto-identify. * * Revision 1.36 2004/05/10 17:05:14 warmerda * added AutoIdentifyEPSG() * * Revision 1.35 2004/05/04 17:54:06 warmerda * keep longitudes greenwich relative * * Revision 1.34 2004/04/28 00:27:58 warmerda * Added Albers Conic Area Area translation (method=9822). * * Revision 1.33 2004/04/24 15:47:19 warmerda * Added uom 9122 improvements. * * Revision 1.32 2004/03/04 18:04:45 warmerda * added importFromDict() support * * Revision 1.31 2003/11/20 19:41:15 warmerda * added logic to set EPSG authority info if read from PROJ.4 * * Revision 1.30 2003/11/19 20:40:58 warmerda * Add support for faking EPSG coordinate systems from PROJ.4 definitions * * Revision 1.29 2003/06/23 14:48:42 warmerda * make OGREPSTDatumNameMassage() public * * Revision 1.28 2003/05/30 18:35:15 warmerda * fixed stateplane.csv error msg and clear() before SetLocalCS call * * Revision 1.27 2003/05/30 17:48:57 warmerda * Set GEOGCS|UNIT AUTHORITY information. * * Revision 1.26 2003/05/30 15:39:53 warmerda * Added override units capability for SetStatePlane() * * Revision 1.25 2003/05/20 19:03:24 warmerda * suggest GDAL_DATA in error message * * Revision 1.24 2003/05/20 18:43:31 warmerda * added error reporting * * Revision 1.23 2003/02/14 22:15:04 warmerda * expand tabs * * Revision 1.22 2003/02/14 16:29:02 warmerda * Added LAEA support * * Revision 1.21 2003/02/06 04:53:53 warmerda * fixed handling of empty fields to avoid emitting debug warning * * Revision 1.20 2003/02/05 17:14:11 warmerda * work around a bug in EPSG 6.2.2 with scale factor units for PCS 2935/2936 * * Revision 1.19 2003/01/08 18:23:45 warmerda * ensure order is fixed up * * Revision 1.18 2002/12/16 17:06:32 warmerda * ensure that prime meridian offsets are applied to angular proj parms * * Revision 1.17 2002/12/14 22:59:14 warmerda * added Krovak in ESRI compatible way * * Revision 1.16 2002/12/13 06:35:45 warmerda * fixed rotatin sign in TOWGS84 from method 9607 * * Revision 1.15 2002/12/02 00:07:50 warmerda * set angular units properly in GEOGCS * * Revision 1.14 2002/11/30 15:45:07 warmerda * be careful about how UOM codes are linear * * Revision 1.13 2002/11/29 20:49:10 warmerda * fixed GetTRFInfo filename corruption * * Revision 1.12 2002/11/28 15:59:58 warmerda * rewritten to use EPSG 6.2.2 tables * * Revision 1.11 2001/08/23 13:20:07 warmerda * fixed serious bug in translating LCC projections from EPSG to WKT * * Revision 1.10 2001/07/18 05:03:05 warmerda * added CPL_CVSID * * Revision 1.9 2001/03/15 03:19:23 warmerda * added polyconic (9818) support * * Revision 1.8 2001/03/14 21:33:46 warmerda * treaat 9717 (Lambert Near Conformal) like LCC1SP * * Revision 1.7 2001/01/19 21:10:46 warmerda * replaced tabs * * Revision 1.6 2000/12/07 03:46:04 danmo * Made papszDatumEquiv[] const * * Revision 1.5 2000/10/23 13:01:59 warmerda * Fixed OSRSetStatePlane * * Revision 1.4 2000/10/20 04:19:38 warmerda * added setstateplane * * Revision 1.3 2000/03/20 22:39:08 warmerda * Added C function. * * Revision 1.2 2000/03/20 14:59:05 warmerda * fixed semi major axis check * * Revision 1.1 2000/03/16 19:04:14 warmerda * New * */#include "ogr_spatialref.h"#include "cpl_csv.h"CPL_CVSID("$Id: ogr_fromepsg.cpp,v 1.43 2006/04/21 04:12:29 fwarmerdam Exp $");#ifndef PI# define PI 3.14159265358979323846#endifstatic const char *papszDatumEquiv[] ={ "Militar_Geographische_Institut", "Militar_Geographische_Institute", "World_Geodetic_System_1984", "WGS_1984", "WGS_72_Transit_Broadcast_Ephemeris", "WGS_1972_Transit_Broadcast_Ephemeris", "World_Geodetic_System_1972", "WGS_1972", "European_Terrestrial_Reference_System_89", "European_Reference_System_1989", NULL};/************************************************************************//* OGREPSGDatumNameMassage() *//* *//* Massage an EPSG datum name into WMT format. Also transform *//* specific exception cases into WKT versions. *//************************************************************************/void OGREPSGDatumNameMassage( char ** ppszDatum ){ int i, j; char *pszDatum = *ppszDatum;/* -------------------------------------------------------------------- *//* Translate non-alphanumeric values to underscores. *//* -------------------------------------------------------------------- */ for( i = 0; pszDatum[i] != '\0'; i++ ) { if( !(pszDatum[i] >= 'A' && pszDatum[i] <= 'Z') && !(pszDatum[i] >= 'a' && pszDatum[i] <= 'z') && !(pszDatum[i] >= '0' && pszDatum[i] <= '9') ) { pszDatum[i] = '_'; } }/* -------------------------------------------------------------------- *//* Remove repeated and trailing underscores. *//* -------------------------------------------------------------------- */ for( i = 1, j = 0; pszDatum[i] != '\0'; i++ ) { if( pszDatum[j] == '_' && pszDatum[i] == '_' ) continue; pszDatum[++j] = pszDatum[i]; } if( pszDatum[j] == '_' ) pszDatum[j] = '\0'; else pszDatum[j+1] = '\0'; /* -------------------------------------------------------------------- *//* Search for datum equivelences. Specific massaged names get *//* mapped to OpenGIS specified names. *//* -------------------------------------------------------------------- */ for( i = 0; papszDatumEquiv[i] != NULL; i += 2 ) { if( EQUAL(*ppszDatum,papszDatumEquiv[i]) ) { CPLFree( *ppszDatum ); *ppszDatum = CPLStrdup( papszDatumEquiv[i+1] ); break; } }}/************************************************************************//* EPSGAngleStringToDD() *//* *//* Convert an angle in the specified units to decimal degrees. *//************************************************************************/static doubleEPSGAngleStringToDD( const char * pszAngle, int nUOMAngle ){ double dfAngle; if( nUOMAngle == 9110 ) /* DDD.MMSSsss */ { char *pszDecimal; dfAngle = ABS(atoi(pszAngle)); pszDecimal = (char *) strchr(pszAngle,'.'); if( pszDecimal != NULL && strlen(pszDecimal) > 1 ) { char szMinutes[3]; char szSeconds[64]; szMinutes[0] = pszDecimal[1]; if( pszDecimal[2] >= '0' && pszDecimal[2] <= '9' ) szMinutes[1] = pszDecimal[2]; else szMinutes[1] = '0'; szMinutes[2] = '\0'; dfAngle += atoi(szMinutes) / 60.0; if( strlen(pszDecimal) > 3 ) { szSeconds[0] = pszDecimal[3]; if( pszDecimal[4] >= '0' && pszDecimal[4] <= '9' ) { szSeconds[1] = pszDecimal[4]; szSeconds[2] = '.'; strcpy( szSeconds+3, pszDecimal + 5 ); } else { szSeconds[1] = '0'; szSeconds[2] = '\0'; } dfAngle += atof(szSeconds) / 3600.0; } } if( pszAngle[0] == '-' ) dfAngle *= -1; } else if( nUOMAngle == 9105 || nUOMAngle == 9106 ) /* grad */ { dfAngle = 180 * (atof(pszAngle ) / 200); } else if( nUOMAngle == 9101 ) /* radians */ { dfAngle = 180 * (atof(pszAngle ) / PI); } else if( nUOMAngle == 9103 ) /* arc-minute */ { dfAngle = atof(pszAngle) / 60; } else if( nUOMAngle == 9104 ) /* arc-second */ { dfAngle = atof(pszAngle) / 3600; } else /* decimal degrees ... some cases missing but seeminly never used */ { CPLAssert( nUOMAngle == 9102 || nUOMAngle == 0 ); dfAngle = atof(pszAngle ); } return( dfAngle );}/************************************************************************//* EPSGGetUOMAngleInfo() *//************************************************************************/int EPSGGetUOMAngleInfo( int nUOMAngleCode, char **ppszUOMName, double * pdfInDegrees ){ const char *pszUOMName = NULL; double dfInDegrees = 1.0; const char *pszFilename = CSVFilename( "unit_of_measure.csv" ); char szSearchKey[24]; sprintf( szSearchKey, "%d", nUOMAngleCode ); pszUOMName = CSVGetField( pszFilename, "UOM_CODE", szSearchKey, CC_Integer, "UNIT_OF_MEAS_NAME" );/* -------------------------------------------------------------------- *//* If the file is found, read from there. Note that FactorC is *//* an empty field for any of the DMS style formats, and in this *//* case we really want to return the default InDegrees value *//* (1.0) from above. */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?