📄 geo_normalize.c
字号:
/* Get the PM offset. *//* -------------------------------------------------------------------- */ if( pdfOffset != NULL ) { *pdfOffset = GTIFAngleStringToDD( CSVGetField( pszFilename, "PRIME_MERIDIAN_CODE", szSearchKey, CC_Integer, "GREENWICH_LONGITUDE" ), nUOMAngle ); } /* -------------------------------------------------------------------- *//* Get the name, if requested. *//* -------------------------------------------------------------------- */ if( ppszName != NULL ) *ppszName = CPLStrdup( CSVGetField( pszFilename, "PRIME_MERIDIAN_CODE", szSearchKey, CC_Integer, "PRIME_MERIDIAN_NAME" )); return( TRUE );}/************************************************************************//* GTIFGetDatumInfo() *//* *//* Fetch the ellipsoid, and name for a datum. *//************************************************************************/int GTIFGetDatumInfo( int nDatumCode, char ** ppszName, short * pnEllipsoid ){ char szSearchKey[24]; int nEllipsoid; const char *pszFilename = CSVFilename( "datum.csv" ); FILE *fp;/* -------------------------------------------------------------------- *//* If we can't find datum.csv then gdal_datum.csv is an *//* acceptable fallback. Mostly this is for GDAL. *//* -------------------------------------------------------------------- */ if( (fp = VSIFOpen(pszFilename,"r")) == NULL ) pszFilename = CSVFilename( "gdal_datum.csv" ); else VSIFClose( fp );/* -------------------------------------------------------------------- *//* Search the database for the corresponding datum code. *//* -------------------------------------------------------------------- */ sprintf( szSearchKey, "%d", nDatumCode ); nEllipsoid = atoi(CSVGetField( pszFilename, "DATUM_CODE", szSearchKey, CC_Integer, "ELLIPSOID_CODE" ) ); if( pnEllipsoid != NULL ) *pnEllipsoid = (short) nEllipsoid; /* -------------------------------------------------------------------- *//* Handle a few built-in datums. *//* -------------------------------------------------------------------- */ if( nEllipsoid < 1 ) { const char *pszName = NULL; if( nDatumCode == Datum_North_American_Datum_1927 ) { nEllipsoid = Ellipse_Clarke_1866; pszName = "North American Datum 1927"; } else if( nDatumCode == Datum_North_American_Datum_1983 ) { nEllipsoid = Ellipse_GRS_1980; pszName = "North American Datum 1983"; } else if( nDatumCode == Datum_WGS84 ) { nEllipsoid = Ellipse_WGS_84; pszName = "World Geodetic System 1984"; } else if( nDatumCode == Datum_WGS72 ) { nEllipsoid = 7043; /* WGS7 */ pszName = "World Geodetic System 1972"; } else return FALSE; if( pnEllipsoid != NULL ) *pnEllipsoid = (short) nEllipsoid; if( ppszName != NULL ) *ppszName = CPLStrdup( pszName ); return TRUE; }/* -------------------------------------------------------------------- *//* Get the name, if requested. *//* -------------------------------------------------------------------- */ if( ppszName != NULL ) *ppszName = CPLStrdup(CSVGetField( pszFilename, "DATUM_CODE", szSearchKey, CC_Integer, "DATUM_NAME" )); return( TRUE );}/************************************************************************//* GTIFGetUOMLengthInfo() *//* *//* Note: This function should eventually also know how to *//* lookup length aliases in the UOM_LE_ALIAS table. *//************************************************************************/int GTIFGetUOMLengthInfo( int nUOMLengthCode, char **ppszUOMName, double * pdfInMeters ){ char **papszUnitsRecord; char szSearchKey[24]; int iNameField; const char *pszFilename;/* -------------------------------------------------------------------- *//* We short cut meter to save work in the most common case. *//* -------------------------------------------------------------------- */ if( nUOMLengthCode == 9001 ) { if( ppszUOMName != NULL ) *ppszUOMName = CPLStrdup( "metre" ); if( pdfInMeters != NULL ) *pdfInMeters = 1.0; return TRUE; }/* -------------------------------------------------------------------- *//* Search the units database for this unit. If we don't find *//* it return failure. *//* -------------------------------------------------------------------- */ pszFilename = CSVFilename( "unit_of_measure.csv" ); sprintf( szSearchKey, "%d", nUOMLengthCode ); papszUnitsRecord = CSVScanFileByName( pszFilename, "UOM_CODE", szSearchKey, CC_Integer ); if( papszUnitsRecord == NULL ) return FALSE;/* -------------------------------------------------------------------- *//* Get the name, if requested. *//* -------------------------------------------------------------------- */ if( ppszUOMName != NULL ) { iNameField = CSVGetFileFieldId( pszFilename, "UNIT_OF_MEAS_NAME" ); *ppszUOMName = CPLStrdup( CSLGetField(papszUnitsRecord, iNameField) ); } /* -------------------------------------------------------------------- *//* Get the A and B factor fields, and create the multiplicative *//* factor. *//* -------------------------------------------------------------------- */ if( pdfInMeters != NULL ) { int iBFactorField, iCFactorField; iBFactorField = CSVGetFileFieldId( pszFilename, "FACTOR_B" ); iCFactorField = CSVGetFileFieldId( pszFilename, "FACTOR_C" ); if( atof(CSLGetField(papszUnitsRecord, iCFactorField)) > 0.0 ) *pdfInMeters = atof(CSLGetField(papszUnitsRecord, iBFactorField)) / atof(CSLGetField(papszUnitsRecord, iCFactorField)); else *pdfInMeters = 0.0; } return( TRUE );}/************************************************************************//* GTIFGetUOMAngleInfo() *//************************************************************************/int GTIFGetUOMAngleInfo( 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. *//* -------------------------------------------------------------------- */ if( pszUOMName != NULL ) { double dfFactorB, dfFactorC, dfInRadians; dfFactorB = atof(CSVGetField( pszFilename, "UOM_CODE", szSearchKey, CC_Integer, "FACTOR_B" )); dfFactorC = atof(CSVGetField( pszFilename, "UOM_CODE", szSearchKey, CC_Integer, "FACTOR_C" )); if( dfFactorC != 0.0 ) { dfInRadians = (dfFactorB / dfFactorC); dfInDegrees = dfInRadians * 180.0 / PI; } /* We do a special override of some of the DMS formats name */ if( nUOMAngleCode == 9102 || nUOMAngleCode == 9107 || nUOMAngleCode == 9108 || nUOMAngleCode == 9110 || nUOMAngleCode == 9122 ) { dfInDegrees = 1.0; pszUOMName = "degree"; } }/* -------------------------------------------------------------------- *//* Otherwise handle a few well known units directly. *//* -------------------------------------------------------------------- */ else { switch( nUOMAngleCode ) { case 9101: pszUOMName = "radian"; dfInDegrees = 180.0 / PI; break; case 9102: case 9107: case 9108: case 9110: pszUOMName = "degree"; dfInDegrees = 1.0; break; case 9103: pszUOMName = "arc-minute"; dfInDegrees = 1 / 60.0; break; case 9104: pszUOMName = "arc-second"; dfInDegrees = 1 / 3600.0; break; case 9105: pszUOMName = "grad"; dfInDegrees = 180.0 / 200.0; break; case 9106: pszUOMName = "gon"; dfInDegrees = 180.0 / 200.0; break; case 9109: pszUOMName = "microradian"; dfInDegrees = 180.0 / (PI * 1000000.0); break; default: return FALSE; } }/* -------------------------------------------------------------------- *//* Return to caller. *//* -------------------------------------------------------------------- */ if( ppszUOMName != NULL ) { if( pszUOMName != NULL ) *ppszUOMName = CPLStrdup( pszUOMName ); else *ppszUOMName = NULL; } if( pdfInDegrees != NULL ) *pdfInDegrees = dfInDegrees; return( TRUE );}/************************************************************************//* EPSGProjMethodToCTProjMethod() *//* *//* Convert between the EPSG enumeration for projection methods, *//* and the GeoTIFF CT codes. *//************************************************************************/static int EPSGProjMethodToCTProjMethod( int nEPSG ){ /* see trf_method.csv for list of EPSG codes */ switch( nEPSG ) { case 9801: return( CT_LambertConfConic_1SP ); case 9802: return( CT_LambertConfConic_2SP ); case 9803: return( CT_LambertConfConic_2SP ); /* Belgian variant not supported */ case 9804: return( CT_Mercator ); /* 1SP and 2SP not differentiated */ case 9805: return( CT_Mercator ); /* 1SP and 2SP not differentiated */ case 9806: return( CT_CassiniSoldner ); case 9807: return( CT_TransverseMercator );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -