📄 geo_normalize.c
字号:
case 9808: return( CT_TransvMercator_SouthOriented ); case 9809: return( CT_ObliqueStereographic ); case 9810: return( CT_PolarStereographic ); case 9811: return( CT_NewZealandMapGrid ); case 9812: return( CT_ObliqueMercator ); /* is hotine actually different? */ case 9813: return( CT_ObliqueMercator_Laborde ); case 9814: return( CT_ObliqueMercator_Rosenmund ); /* swiss */ case 9815: return( CT_ObliqueMercator ); case 9816: /* tunesia mining grid has no counterpart */ return( KvUserDefined ); } return( KvUserDefined );}/************************************************************************//* SetGTParmIds() *//* *//* This is hardcoded logic to set the GeoTIFF parmaeter *//* identifiers for all the EPSG supported projections. As the *//* trf_method.csv table grows with new projections, this code *//* will need to be updated. *//************************************************************************/static int SetGTParmIds( int nCTProjection, int *panProjParmId, int *panEPSGCodes ){ int anWorkingDummy[7]; if( panEPSGCodes == NULL ) panEPSGCodes = anWorkingDummy; if( panProjParmId == NULL ) panProjParmId = anWorkingDummy; memset( panEPSGCodes, 0, sizeof(int) * 7 ); /* psDefn->nParms = 7; */ switch( nCTProjection ) { case CT_CassiniSoldner: case CT_NewZealandMapGrid: panProjParmId[0] = ProjNatOriginLatGeoKey; panProjParmId[1] = ProjNatOriginLongGeoKey; panProjParmId[5] = ProjFalseEastingGeoKey; panProjParmId[6] = ProjFalseNorthingGeoKey; panEPSGCodes[0] = EPSGNatOriginLat; panEPSGCodes[1] = EPSGNatOriginLong; panEPSGCodes[5] = EPSGFalseEasting; panEPSGCodes[6] = EPSGFalseNorthing; return TRUE; case CT_ObliqueMercator: panProjParmId[0] = ProjCenterLatGeoKey; panProjParmId[1] = ProjCenterLongGeoKey; panProjParmId[2] = ProjAzimuthAngleGeoKey; panProjParmId[3] = ProjRectifiedGridAngleGeoKey; panProjParmId[4] = ProjScaleAtCenterGeoKey; panProjParmId[5] = ProjFalseEastingGeoKey; panProjParmId[6] = ProjFalseNorthingGeoKey; panEPSGCodes[0] = EPSGProjCenterLat; panEPSGCodes[1] = EPSGProjCenterLong; panEPSGCodes[2] = EPSGAzimuth; panEPSGCodes[3] = EPSGAngleRectifiedToSkewedGrid; panEPSGCodes[4] = EPSGInitialLineScaleFactor; panEPSGCodes[5] = EPSGProjCenterEasting; panEPSGCodes[6] = EPSGProjCenterNorthing; return TRUE; case CT_ObliqueMercator_Laborde: panProjParmId[0] = ProjCenterLatGeoKey; panProjParmId[1] = ProjCenterLongGeoKey; panProjParmId[2] = ProjAzimuthAngleGeoKey; panProjParmId[4] = ProjScaleAtCenterGeoKey; panProjParmId[5] = ProjFalseEastingGeoKey; panProjParmId[6] = ProjFalseNorthingGeoKey; panEPSGCodes[0] = EPSGProjCenterLat; panEPSGCodes[1] = EPSGProjCenterLong; panEPSGCodes[2] = EPSGAzimuth; panEPSGCodes[4] = EPSGInitialLineScaleFactor; panEPSGCodes[5] = EPSGProjCenterEasting; panEPSGCodes[6] = EPSGProjCenterNorthing; return TRUE; case CT_LambertConfConic_1SP: case CT_Mercator: case CT_ObliqueStereographic: case CT_PolarStereographic: case CT_TransverseMercator: case CT_TransvMercator_SouthOriented: panProjParmId[0] = ProjNatOriginLatGeoKey; panProjParmId[1] = ProjNatOriginLongGeoKey; panProjParmId[4] = ProjScaleAtNatOriginGeoKey; panProjParmId[5] = ProjFalseEastingGeoKey; panProjParmId[6] = ProjFalseNorthingGeoKey; panEPSGCodes[0] = EPSGNatOriginLat; panEPSGCodes[1] = EPSGNatOriginLong; panEPSGCodes[4] = EPSGNatOriginScaleFactor; panEPSGCodes[5] = EPSGFalseEasting; panEPSGCodes[6] = EPSGFalseNorthing; return TRUE; case CT_LambertConfConic_2SP: panProjParmId[0] = ProjFalseOriginLatGeoKey; panProjParmId[1] = ProjFalseOriginLongGeoKey; panProjParmId[2] = ProjStdParallel1GeoKey; panProjParmId[3] = ProjStdParallel2GeoKey; panProjParmId[5] = ProjFalseEastingGeoKey; panProjParmId[6] = ProjFalseNorthingGeoKey; panEPSGCodes[0] = EPSGFalseOriginLat; panEPSGCodes[1] = EPSGFalseOriginLong; panEPSGCodes[2] = EPSGStdParallel1Lat; panEPSGCodes[3] = EPSGStdParallel2Lat; panEPSGCodes[5] = EPSGFalseOriginEasting; panEPSGCodes[6] = EPSGFalseOriginNorthing; return TRUE; case CT_SwissObliqueCylindrical: panProjParmId[0] = ProjCenterLatGeoKey; panProjParmId[1] = ProjCenterLongGeoKey; panProjParmId[5] = ProjFalseEastingGeoKey; panProjParmId[6] = ProjFalseNorthingGeoKey; /* EPSG codes? */ return TRUE; default: return( FALSE ); }}/************************************************************************//* GTIFGetProjTRFInfo() *//* *//* Transform a PROJECTION_TRF_CODE into a projection method, *//* and a set of parameters. The parameters identify will *//* depend on the returned method, but they will all have been *//* normalized into degrees and meters. *//************************************************************************/int GTIFGetProjTRFInfo( /* COORD_OP_CODE from coordinate_operation.csv */ int nProjTRFCode, char **ppszProjTRFName, short * pnProjMethod, double * padfProjParms ){ int nProjMethod, i, anEPSGCodes[7]; double adfProjParms[7]; char szTRFCode[16]; int nCTProjMethod; char *pszFilename = CPLStrdup(CSVFilename("projop_wparm.csv"));/* -------------------------------------------------------------------- *//* Get the proj method. If this fails to return a meaningful *//* number, then the whole function fails. *//* -------------------------------------------------------------------- */ sprintf( szTRFCode, "%d", nProjTRFCode ); nProjMethod = atoi( CSVGetField( pszFilename, "COORD_OP_CODE", szTRFCode, CC_Integer, "COORD_OP_METHOD_CODE" ) ); if( nProjMethod == 0 ) { CPLFree( pszFilename ); return FALSE; }/* -------------------------------------------------------------------- *//* Initialize a definition of what EPSG codes need to be loaded *//* into what fields in adfProjParms. *//* -------------------------------------------------------------------- */ nCTProjMethod = EPSGProjMethodToCTProjMethod( nProjMethod ); SetGTParmIds( nCTProjMethod, NULL, anEPSGCodes );/* -------------------------------------------------------------------- *//* Get the parameters for this projection. For the time being *//* I am assuming the first four parameters are angles, the *//* fifth is unitless (normally scale), and the remainder are *//* linear measures. This works fine for the existing *//* projections, but is a pretty fragile approach. *//* -------------------------------------------------------------------- */ for( i = 0; i < 7; i++ ) { char szParamUOMID[32], szParamValueID[32], szParamCodeID[32]; const char *pszValue; int nUOM; int nEPSGCode = anEPSGCodes[i]; int iEPSG; /* Establish default */ if( nEPSGCode == EPSGAngleRectifiedToSkewedGrid ) adfProjParms[i] = 90.0; else if( nEPSGCode == EPSGNatOriginScaleFactor || nEPSGCode == EPSGInitialLineScaleFactor || nEPSGCode == EPSGPseudoStdParallelScaleFactor ) adfProjParms[i] = 1.0; else adfProjParms[i] = 0.0; /* If there is no parameter, skip */ if( nEPSGCode == 0 ) continue; /* Find the matching parameter */ for( iEPSG = 0; iEPSG < 7; iEPSG++ ) { sprintf( szParamCodeID, "PARAMETER_CODE_%d", iEPSG+1 ); if( atoi(CSVGetField( pszFilename, "COORD_OP_CODE", szTRFCode, CC_Integer, szParamCodeID )) == nEPSGCode ) break; } /* not found, accept the default */ if( iEPSG == 7 ) continue; /* Get the value, and UOM */ sprintf( szParamUOMID, "PARAMETER_UOM_%d", iEPSG+1 ); sprintf( szParamValueID, "PARAMETER_VALUE_%d", iEPSG+1 ); nUOM = atoi(CSVGetField( pszFilename, "COORD_OP_CODE", szTRFCode, CC_Integer, szParamUOMID )); pszValue = CSVGetField( pszFilename, "COORD_OP_CODE", szTRFCode, CC_Integer, szParamValueID ); /* Transform according to the UOM */ if( nUOM >= 9100 && nUOM < 9200 ) adfProjParms[i] = GTIFAngleStringToDD( pszValue, nUOM ); else if( nUOM > 9000 && nUOM < 9100 ) { double dfInMeters; if( !GTIFGetUOMLengthInfo( nUOM, NULL, &dfInMeters ) ) dfInMeters = 1.0; adfProjParms[i] = atof(pszValue) * dfInMeters; } else adfProjParms[i] = atof(pszValue); }/* -------------------------------------------------------------------- *//* Get the name, if requested. *//* -------------------------------------------------------------------- */ if( ppszProjTRFName != NULL ) { *ppszProjTRFName = CPLStrdup(CSVGetField( pszFilename, "COORD_OP_CODE", szTRFCode, CC_Integer, "COORD_OP_NAME" )); } /* -------------------------------------------------------------------- *//* Transfer requested data into passed variables. *//* -------------------------------------------------------------------- */ if( pnProjMethod != NULL ) *pnProjMethod = (short) nProjMethod; if( padfProjParms != NULL ) { for( i = 0; i < 7; i++ ) padfProjParms[i] = adfProjParms[i]; } CPLFree( pszFilename ); return TRUE;}/************************************************************************//* GTIFFetchProjParms() *//* *//* Fetch the projection parameters for a particular projection *//* from a GeoTIFF file, and fill the GTIFDefn structure out *//* with them. *//************************************************************************/static void GTIFFetchProjParms( GTIF * psGTIF, GTIFDefn * psDefn ){ double dfNatOriginLong = 0.0, dfNatOriginLat = 0.0, dfRectGridAngle = 0.0; double dfFalseEasting = 0.0, dfFalseNorthing = 0.0, dfNatOriginScale = 1.0; double dfStdParallel1 = 0.0, dfStdParallel2 = 0.0, dfAzimuth = 0.0;/* -------------------------------------------------------------------- *//* Get the false easting, and northing if available. *//* -------------------------------------------------------------------- */ if( !GTIFKeyGet(psGTIF, ProjFalseEastingGeoKey, &dfFalseEasting, 0, 1) && !GTIFKeyGet(psGTIF, ProjCenterEastingGeoKey, &dfFalseEasting, 0, 1) && !GTIFKeyGet(psGTIF, ProjFalseOriginEastingGeoKey, &dfFalseEasting, 0, 1) ) dfFalseEasting = 0.0; if( !GTIFKeyGet(psGTIF, ProjFalseNorthingGeoKey, &dfFalseNorthing,0,1) && !GTIFKeyGet(psGTIF, ProjCenterNorthingGeoKey, &dfFalseNorthing, 0, 1) && !GTIFKeyGet(psGTIF, ProjFalseOriginNorthingGeoKey, &dfFalseNorthing, 0, 1) ) dfFalseNorthing = 0.0; switch( psDefn->CTProjection ) {/* -------------------------------------------------------------------- */ case CT_Stereographic:/* -------------------------------------------------------------------- */ if( GTIFKeyGet(psGTIF, ProjNatOriginLongGeoKey, &dfNatOriginLong, 0, 1 ) == 0 && GTIFKeyGet(psGTIF, ProjFalseOriginLongGeoKey, &dfNatOriginLong, 0, 1 ) == 0 && GTIFKeyGet(psGTIF, ProjCenterLongGeoKey, &dfNatOriginLong, 0, 1 ) == 0 ) dfNatOriginLong = 0.0; if( GTIFKeyGet(psGTIF, ProjNatOriginLatGeoKey,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -