📄 ogr_srs_esri.cpp
字号:
/* Try to open the datum.csv file. *//* -------------------------------------------------------------------- */ const char *pszFilename = CSVFilename("gdal_datum.csv"); FILE * fp = VSIFOpen( pszFilename, "rb" );/* -------------------------------------------------------------------- *//* Use simple default set if we can't find the file. *//* -------------------------------------------------------------------- */ if( fp == NULL ) { papszDatumMapping = apszDefaultDatumMapping; return; }/* -------------------------------------------------------------------- *//* Figure out what fields we are interested in. *//* -------------------------------------------------------------------- */ char **papszFieldNames = CSVReadParseLine( fp ); int nDatumCodeField = CSLFindString( papszFieldNames, "DATUM_CODE" ); int nEPSGNameField = CSLFindString( papszFieldNames, "DATUM_NAME" ); int nESRINameField = CSLFindString( papszFieldNames, "ESRI_DATUM_NAME" ); CSLDestroy( papszFieldNames ); if( nDatumCodeField == -1 || nEPSGNameField == -1 || nESRINameField == -1 ) { CPLError( CE_Failure, CPLE_AppDefined, "Failed to find required field in datum.csv in InitDatumMappingTable(), using default table setup." ); papszDatumMapping = apszDefaultDatumMapping; return; } /* -------------------------------------------------------------------- *//* Read each line, adding a detail line for each. *//* -------------------------------------------------------------------- */ int nMappingCount = 0; const int nMaxDatumMappings = 1000; char **papszFields; papszDatumMapping = (char **)CPLCalloc(sizeof(char*),nMaxDatumMappings*3); for( papszFields = CSVReadParseLine( fp ); papszFields != NULL; papszFields = CSVReadParseLine( fp ) ) { int nFieldCount = CSLCount(papszFields); CPLAssert( nMappingCount+1 < nMaxDatumMappings ); if( MAX(nEPSGNameField,MAX(nDatumCodeField,nESRINameField)) < nFieldCount && nMaxDatumMappings > nMappingCount+1 ) { papszDatumMapping[nMappingCount*3+0] = CPLStrdup( papszFields[nDatumCodeField] ); papszDatumMapping[nMappingCount*3+1] = CPLStrdup( papszFields[nESRINameField] ); papszDatumMapping[nMappingCount*3+2] = CPLStrdup( papszFields[nEPSGNameField] ); OGREPSGDatumNameMassage( &(papszDatumMapping[nMappingCount*3+2]) ); nMappingCount++; } CSLDestroy( papszFields ); } VSIFClose( fp ); papszDatumMapping[nMappingCount*3+0] = NULL; papszDatumMapping[nMappingCount*3+1] = NULL; papszDatumMapping[nMappingCount*3+2] = NULL;}/************************************************************************//* OSRImportFromESRI() *//************************************************************************/OGRErr OSRImportFromESRI( OGRSpatialReferenceH hSRS, char **papszPrj ){ return ((OGRSpatialReference *) hSRS)->importFromESRI( papszPrj );}/************************************************************************//* OSR_GDV() *//* *//* Fetch a particular parameter out of the parameter list, or *//* the indicated default if it isn't available. This is a *//* helper function for importFromESRI(). *//************************************************************************/static double OSR_GDV( char **papszNV, const char * pszField, double dfDefaultValue ){ int iLine; if( papszNV == NULL || papszNV[0] == NULL ) return dfDefaultValue; if( EQUALN(pszField,"PARAM_",6) ) { int nOffset; for( iLine = 0; papszNV[iLine] != NULL && !EQUALN(papszNV[iLine],"Paramet",7); iLine++ ) {} for( nOffset=atoi(pszField+6); papszNV[iLine] != NULL && nOffset > 0; nOffset--, iLine++ ) {} if( papszNV[iLine] != NULL ) { char **papszTokens, *pszLine = papszNV[iLine]; double dfValue; int i; // Trim comments. for( i=0; pszLine[i] != '\0'; i++ ) { if( pszLine[i] == '/' && pszLine[i+1] == '*' ) pszLine[i] = '\0'; } papszTokens = CSLTokenizeString(papszNV[iLine]); if( CSLCount(papszTokens) == 3 ) { dfValue = ABS(atof(papszTokens[0])) + atof(papszTokens[1]) / 60.0 + atof(papszTokens[2]) / 3600.0; if( atof(papszTokens[0]) < 0.0 ) dfValue *= -1; } else dfValue = atof(papszTokens[0]); CSLDestroy( papszTokens ); return dfValue; } else return dfDefaultValue; } else { for( iLine = 0; papszNV[iLine] != NULL && !EQUALN(papszNV[iLine],pszField,strlen(pszField)); iLine++ ) {} if( papszNV[iLine] == NULL ) return dfDefaultValue; else return atof( papszNV[iLine] + strlen(pszField) ); }}/************************************************************************//* OSR_GDS() *//************************************************************************/static const char*OSR_GDS( char **papszNV, const char * pszField, const char *pszDefaultValue ){ int iLine; if( papszNV == NULL || papszNV[0] == NULL ) return pszDefaultValue; for( iLine = 0; papszNV[iLine] != NULL && !EQUALN(papszNV[iLine],pszField,strlen(pszField)); iLine++ ) {} if( papszNV[iLine] == NULL ) return pszDefaultValue; else { static char szResult[80]; char **papszTokens; papszTokens = CSLTokenizeString(papszNV[iLine]); if( CSLCount(papszTokens) > 1 ) strncpy( szResult, papszTokens[1], sizeof(szResult)); else strncpy( szResult, pszDefaultValue, sizeof(szResult)); CSLDestroy( papszTokens ); return szResult; }}/************************************************************************//* importFromESRI() *//************************************************************************//** * Import coordinate system from ESRI .prj format(s). * * This function will read the text loaded from an ESRI .prj file, and * translate it into an OGRSpatialReference definition. This should support * many (but by no means all) old style (Arc/Info 7.x) .prj files, as well * as the newer pseudo-OGC WKT .prj files. Note that new style .prj files * are in OGC WKT format, but require some manipulation to correct datum * names, and units on some projection parameters. This is addressed within * importFromESRI() by an automatical call to morphFromESRI(). * * Currently only GEOGRAPHIC, UTM, STATEPLANE, GREATBRITIAN_GRID, ALBERS, * EQUIDISTANT_CONIC, and TRANSVERSE (mercator) projections are supported * from old style files. * * At this time there is no equivelent exportToESRI() method. Writing old * style .prj files is not supported by OGRSpatialReference. However the * morphToESRI() and exportToWkt() methods can be used to generate output * suitable to write to new style (Arc 8) .prj files. * * This function is the equilvelent of the C function OSRImportFromESRI(). * * @param papszPrj NULL terminated list of strings containing the definition. * * @return OGRERR_NONE on success or an error code in case of failure. */OGRErr OGRSpatialReference::importFromESRI( char **papszPrj ){ if( papszPrj == NULL || papszPrj[0] == NULL ) return OGRERR_CORRUPT_DATA;/* -------------------------------------------------------------------- *//* Some newer ESRI products, like ArcPad, produce .prj files *//* with WKT in them. Check if that appears to be the case. *//* *//* ESRI uses an odd datum naming scheme, so some further *//* massaging may be required. *//* -------------------------------------------------------------------- */ if( EQUALN(papszPrj[0],"GEOGCS",6) || EQUALN(papszPrj[0],"PROJCS",6) || EQUALN(papszPrj[0],"LOCAL_CS",8) ) { char *pszWKT; OGRErr eErr; pszWKT = papszPrj[0]; eErr = importFromWkt( &pszWKT ); if( eErr == OGRERR_NONE ) eErr = morphFromESRI(); return eErr; }/* -------------------------------------------------------------------- *//* Operate on the basis of the projection name. *//* -------------------------------------------------------------------- */ const char *pszProj = OSR_GDS( papszPrj, "Projection", NULL ); if( pszProj == NULL ) { CPLDebug( "OGR_ESRI", "Can't find Projection\n" ); return OGRERR_CORRUPT_DATA; } else if( EQUAL(pszProj,"GEOGRAPHIC") ) { } else if( EQUAL(pszProj,"utm") ) { if( (int) OSR_GDV( papszPrj, "zone", 0.0 ) != 0 ) { double dfYShift = OSR_GDV( papszPrj, "Yshift", 0.0 ); SetUTM( (int) OSR_GDV( papszPrj, "zone", 0.0 ), dfYShift >= 0.0 ); } else { double dfCentralMeridian, dfRefLat; int nZone; dfCentralMeridian = OSR_GDV( papszPrj, "PARAM_1", 0.0 ); dfRefLat = OSR_GDV( papszPrj, "PARAM_2", 0.0 ); nZone = (int) ((dfCentralMeridian+183) / 6.0 + 0.0000001); SetUTM( nZone, dfRefLat >= 0.0 ); } } else if( EQUAL(pszProj,"STATEPLANE") ) { int nZone = (int) OSR_GDV( papszPrj, "zone", 0.0 ); nZone = ESRIToUSGSZone( nZone ); if( nZone != 0 ) { if( EQUAL(OSR_GDS( papszPrj, "Datum", "NAD83"),"NAD27") ) SetStatePlane( nZone, FALSE ); else SetStatePlane( nZone, TRUE ); } } else if( EQUAL(pszProj,"GREATBRITIAN_GRID") || EQUAL(pszProj,"GREATBRITAIN_GRID") ) { const char *pszWkt = "PROJCS[\"OSGB 1936 / British National Grid\",GEOGCS[\"OSGB 1936\",DATUM[\"OSGB_1936\",SPHEROID[\"Airy 1830\",6377563.396,299.3249646]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",49],PARAMETER[\"central_meridian\",-2],PARAMETER[\"scale_factor\",0.999601272],PARAMETER[\"false_easting\",400000],PARAMETER[\"false_northing\",-100000],UNIT[\"metre\",1]]"; importFromWkt( (char **) &pszWkt ); } else if( EQUAL(pszProj,"ALBERS") ) { SetACEA( OSR_GDV( papszPrj, "PARAM_1", 0.0 ), OSR_GDV( papszPrj, "PARAM_2", 0.0 ), OSR_GDV( papszPrj, "PARAM_4", 0.0 ), OSR_GDV( papszPrj, "PARAM_3", 0.0 ), OSR_GDV( papszPrj, "PARAM_5", 0.0 ), OSR_GDV( papszPrj, "PARAM_6", 0.0 ) ); } else if( EQUAL(pszProj,"LAMBERT") ) { SetLCC( OSR_GDV( papszPrj, "PARAM_1", 0.0 ), OSR_GDV( papszPrj, "PARAM_2", 0.0 ), OSR_GDV( papszPrj, "PARAM_4", 0.0 ), OSR_GDV( papszPrj, "PARAM_3", 0.0 ), OSR_GDV( papszPrj, "PARAM_5", 0.0 ), OSR_GDV( papszPrj, "PARAM_6", 0.0 ) ); } else if( EQUAL(pszProj,"EQUIDISTANT_CONIC") ) { int nStdPCount = (int) OSR_GDV( papszPrj, "PARAM_1", 0.0 );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -