📄 ogr_srs_esri.cpp
字号:
/* -------------------------------------------------------------------- */
/* Force Unnamed to Unknown for most common locations. */
/* -------------------------------------------------------------------- */
static char *apszUnknownMapping[] = {
"Unknown", "Unnamed",
NULL, NULL
};
GetRoot()->applyRemapper( "PROJCS",
apszUnknownMapping+1, apszUnknownMapping+0, 2 );
GetRoot()->applyRemapper( "GEOGCS",
apszUnknownMapping+1, apszUnknownMapping+0, 2 );
GetRoot()->applyRemapper( "DATUM",
apszUnknownMapping+1, apszUnknownMapping+0, 2 );
GetRoot()->applyRemapper( "SPHEROID",
apszUnknownMapping+1, apszUnknownMapping+0, 2 );
GetRoot()->applyRemapper( "PRIMEM",
apszUnknownMapping+1, apszUnknownMapping+0, 2 );
/* -------------------------------------------------------------------- */
/* If the PROJCS name is unset, use the PROJECTION name in */
/* place of unknown, or unnamed. At the request of Peng Gao. */
/* -------------------------------------------------------------------- */
OGR_SRSNode *poNode;
poNode = GetAttrNode( "PROJCS" );
if( poNode != NULL )
poNode = poNode->GetChild( 0 );
if( poNode != NULL
&& ( EQUAL(poNode->GetValue(),"unnamed")
|| EQUAL(poNode->GetValue(),"unknown")
|| EQUAL(poNode->GetValue(),"") ) )
{
if( GetAttrValue( "PROJECTION", 0 ) != NULL )
poNode->SetValue( GetAttrValue( "PROJECTION", 0 ) );
}
/* -------------------------------------------------------------------- */
/* Prepare very specific PROJCS names for UTM coordinate */
/* systems. */
/* -------------------------------------------------------------------- */
int bNorth, nZone;
nZone = GetUTMZone( &bNorth );
if( nZone > 0 && pszUTMPrefix != NULL )
{
char szUTMName[128];
if( bNorth )
sprintf( szUTMName, "%s_UTM_Zone_%dN", pszUTMPrefix, nZone );
else
sprintf( szUTMName, "%s_UTM_Zone_%dS", pszUTMPrefix, nZone );
OGR_SRSNode *poProjCS = GetAttrNode( "PROJCS" );
if( poProjCS != NULL )
poProjCS->GetChild(0)->SetValue( szUTMName );
}
}
/* -------------------------------------------------------------------- */
/* Translate UNIT keywords that are misnamed, or even the wrong */
/* case. */
/* -------------------------------------------------------------------- */
GetRoot()->applyRemapper( "UNIT",
apszUnitMapping+1, apszUnitMapping, 2 );
/* -------------------------------------------------------------------- */
/* reset constants for decimal degrees to the exact string ESRI */
/* expects when encountered to ensure a matchup. */
/* -------------------------------------------------------------------- */
OGR_SRSNode *poUnit = GetAttrNode( "GEOGCS|UNIT" );
if( poUnit != NULL && poUnit->GetChildCount() >= 2
&& ABS(GetAngularUnits()-0.0174532925199433) < 0.00000000001 )
{
poUnit->GetChild(0)->SetValue("Degree");
poUnit->GetChild(1)->SetValue("0.017453292519943295");
}
/* -------------------------------------------------------------------- */
/* Make sure we reproduce US Feet exactly too. */
/* -------------------------------------------------------------------- */
poUnit = GetAttrNode( "PROJCS|UNIT" );
if( poUnit != NULL && poUnit->GetChildCount() >= 2
&& ABS(GetLinearUnits()- 0.30480060960121924) < 0.000000000000001)
{
poUnit->GetChild(0)->SetValue("Foot_US");
poUnit->GetChild(1)->SetValue("0.30480060960121924");
}
/* -------------------------------------------------------------------- */
/* Remap parameters used for Albers and Mercator. */
/* -------------------------------------------------------------------- */
pszProjection = GetAttrValue("PROJECTION");
if( pszProjection != NULL && EQUAL(pszProjection,"Albers") )
GetRoot()->applyRemapper(
"PARAMETER", apszAlbersMapping + 1, apszAlbersMapping + 0, 2 );
if( pszProjection != NULL
&& EQUAL(pszProjection,SRS_PT_EQUIDISTANT_CONIC) )
GetRoot()->applyRemapper(
"PARAMETER", apszECMapping + 1, apszECMapping + 0, 2 );
if( pszProjection != NULL && EQUAL(pszProjection,"Mercator") )
GetRoot()->applyRemapper(
"PARAMETER", apszMercatorMapping + 1, apszMercatorMapping + 0, 2 );
if( pszProjection != NULL
&& EQUALN(pszProjection,"Stereographic_",14)
&& EQUALN(pszProjection+strlen(pszProjection)-5,"_Pole",5) )
GetRoot()->applyRemapper(
"PARAMETER",
apszPolarStereographicMapping + 1,
apszPolarStereographicMapping + 0, 2 );
/* -------------------------------------------------------------------- */
/* Convert SPHEROID name to use underscores instead of spaces. */
/* -------------------------------------------------------------------- */
OGR_SRSNode *poSpheroid;
poSpheroid = GetAttrNode( "SPHEROID" );
if( poSpheroid != NULL )
poSpheroid = poSpheroid->GetChild(0);
if( poSpheroid != NULL )
{
char *pszNewValue = CPLStrdup(RemapSpheroidName(poSpheroid->GetValue()));
MorphNameToESRI( &pszNewValue );
poSpheroid->SetValue( pszNewValue );
CPLFree( pszNewValue );
}
/* -------------------------------------------------------------------- */
/* Try to insert a D_ in front of the datum name. */
/* -------------------------------------------------------------------- */
OGR_SRSNode *poDatum;
poDatum = GetAttrNode( "DATUM" );
if( poDatum != NULL )
poDatum = poDatum->GetChild(0);
if( poDatum != NULL )
{
if( !EQUALN(poDatum->GetValue(),"D_",2) )
{
char *pszNewValue;
pszNewValue = (char *) CPLMalloc(strlen(poDatum->GetValue())+3);
strcpy( pszNewValue, "D_" );
strcat( pszNewValue, poDatum->GetValue() );
poDatum->SetValue( pszNewValue );
CPLFree( pszNewValue );
}
}
return OGRERR_NONE;
}
/************************************************************************/
/* OSRMorphToESRI() */
/************************************************************************/
OGRErr OSRMorphToESRI( OGRSpatialReferenceH hSRS )
{
return ((OGRSpatialReference *) hSRS)->morphToESRI();
}
/************************************************************************/
/* morphFromESRI() */
/* */
/* modify this definition from the ESRI definition of WKT to */
/* the "Standard" definition. */
/************************************************************************/
/**
* Convert in place to ESRI WKT format.
*
* The value nodes of this coordinate system as modified in various manners
* more closely map onto the ESRI concept of WKT format. This includes
* renaming a variety of projections and arguments, and stripping out
* nodes note recognised by ESRI (like AUTHORITY and AXIS).
*
* This does the same as the C function OSRMorphFromESRI().
*
* @return OGRERR_NONE unless something goes badly wrong.
*/
OGRErr OGRSpatialReference::morphFromESRI()
{
OGRErr eErr = OGRERR_NONE;
if( GetRoot() == NULL )
return OGRERR_NONE;
/* -------------------------------------------------------------------- */
/* Translate DATUM keywords that are oddly named. */
/* -------------------------------------------------------------------- */
InitDatumMappingTable();
GetRoot()->applyRemapper( "DATUM",
papszDatumMapping+1, papszDatumMapping+2, 3 );
/* -------------------------------------------------------------------- */
/* Try to remove any D_ in front of the datum name. */
/* -------------------------------------------------------------------- */
OGR_SRSNode *poDatum;
poDatum = GetAttrNode( "DATUM" );
if( poDatum != NULL )
poDatum = poDatum->GetChild(0);
if( poDatum != NULL )
{
if( EQUALN(poDatum->GetValue(),"D_",2) )
{
char *pszNewValue = CPLStrdup( poDatum->GetValue() + 2 );
poDatum->SetValue( pszNewValue );
CPLFree( pszNewValue );
}
}
/* -------------------------------------------------------------------- */
/* Split Lambert_Conformal_Conic into 1SP or 2SP form. */
/* */
/* See bugzilla.remotesensing.org/show_bug.cgi?id=187 */
/* */
/* We decide based on whether it has 2SPs. We used to assume */
/* 1SP if it had a scale factor but that turned out to be a */
/* poor test. */
/* -------------------------------------------------------------------- */
const char *pszProjection = GetAttrValue("PROJECTION");
if( pszProjection != NULL
&& EQUAL(pszProjection,"Lambert_Conformal_Conic") )
{
if( GetProjParm( SRS_PP_STANDARD_PARALLEL_1, 1000.0 ) != 1000.0
&& GetProjParm( SRS_PP_STANDARD_PARALLEL_2, 1000.0 ) != 1000.0 )
SetNode( "PROJCS|PROJECTION",
SRS_PT_LAMBERT_CONFORMAL_CONIC_2SP );
else
SetNode( "PROJCS|PROJECTION",
SRS_PT_LAMBERT_CONFORMAL_CONIC_1SP );
}
/* -------------------------------------------------------------------- */
/* If we are remapping Hotine_Oblique_Mercator_Azimuth_Center */
/* add a rectified_grid_angle parameter - to match the azimuth */
/* I guess. */
/* -------------------------------------------------------------------- */
if( pszProjection != NULL
&& EQUAL(pszProjection,"Hotine_Oblique_Mercator_Azimuth_Center") )
{
SetProjParm( SRS_PP_RECTIFIED_GRID_ANGLE ,
GetProjParm( SRS_PP_AZIMUTH, 0.0 ) );
FixupOrdering();
}
/* -------------------------------------------------------------------- */
/* Remap Albers, Mercator and Polar Stereographic parameters. */
/* -------------------------------------------------------------------- */
if( pszProjection != NULL && EQUAL(pszProjection,"Albers") )
GetRoot()->applyRemapper(
"PARAMETER", apszAlbersMapping + 0, apszAlbersMapping + 1, 2 );
if( pszProjection != NULL
&& EQUAL(pszProjection,SRS_PT_EQUIDISTANT_CONIC) )
GetRoot()->applyRemapper(
"PARAMETER", apszECMapping + 0, apszECMapping + 1, 2 );
if( pszProjection != NULL && EQUAL(pszProjection,"Mercator") )
GetRoot()->applyRemapper(
"PARAMETER", apszMercatorMapping + 0, apszMercatorMapping + 1, 2 );
if( pszProjection != NULL
&& EQUALN(pszProjection,"Stereographic_",14)
&& EQUALN(pszProjection+strlen(pszProjection)-5,"_Pole",5) )
GetRoot()->applyRemapper(
"PARAMETER",
apszPolarStereographicMapping + 0,
apszPolarStereographicMapping + 1, 2 );
/* -------------------------------------------------------------------- */
/* Remap south and north polar stereographic to one value. */
/* -------------------------------------------------------------------- */
if( pszProjection != NULL
&& EQUALN(pszProjection,"Stereographic_",14)
&& EQUALN(pszProjection+strlen(pszProjection)-5,"_Pole",5) )
{
SetNode( "PROJCS|PROJECTION", SRS_PT_POLAR_STEREOGRAPHIC );
pszProjection = GetAttrValue("PROJECTION");
}
/* -------------------------------------------------------------------- */
/* Translate PROJECTION keywords that are misnamed. */
/* -------------------------------------------------------------------- */
GetRoot()->applyRemapper( "PROJECTION",
apszProjMapping, apszProjMapping+1, 2 );
/* -------------------------------------------------------------------- */
/* Translate DATUM keywords that are misnamed. */
/* -------------------------------------------------------------------- */
InitDatumMappingTable();
GetRoot()->applyRemapper( "DATUM",
papszDatumMapping+1, papszDatumMapping+2, 3 );
return eErr;
}
/************************************************************************/
/* OSRMorphFromESRI() */
/************************************************************************/
OGRErr OSRMorphFromESRI( OGRSpatialReferenceH hSRS )
{
return ((OGRSpatialReference *) hSRS)->morphFromESRI();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -