コード例 #1
0
ファイル: gt_citation.cpp プロジェクト: 0004c/node-gdal
OGRBoolean CheckCitationKeyForStatePlaneUTM(GTIF* hGTIF, GTIFDefn* psDefn, OGRSpatialReference* poSRS, OGRBoolean* pLinearUnitIsSet)
{
    if( !hGTIF || !psDefn || !poSRS )
        return FALSE;

/* -------------------------------------------------------------------- */
/*      For ESRI builds we are interested in maximizing PE              */
/*      compatability, but generally we prefer to use EPSG              */
/*      definitions of the coordinate system if PCS is defined.         */
/* -------------------------------------------------------------------- */
#if !defined(ESRI_BUILD)
    if( psDefn->PCS != KvUserDefined )
        return FALSE;
#endif

    char  szCTString[512];
    szCTString[0] = '\0';

    /* Check units */
    char units[32];
    units[0] = '\0';

    OGRBoolean hasUnits = FALSE;
    if( GTIFKeyGet( hGTIF, GTCitationGeoKey, szCTString, 0, sizeof(szCTString) ) )
    {
        CPLString osLCCT = szCTString;

        osLCCT.tolower();

        if( strstr(osLCCT,"us") && strstr(osLCCT,"survey")
            && (strstr(osLCCT,"feet") || strstr(osLCCT,"foot")) )
            strcpy(units, "us_survey_feet");
        else if(strstr(osLCCT, "linear_feet")  
                || strstr(osLCCT, "linear_foot") 
                || strstr(osLCCT, "international"))
            strcpy(units, "international_feet");
        else if( strstr(osLCCT,"meter") )
            strcpy(units, "meters");

        if (strlen(units) > 0)
            hasUnits = TRUE;

        if( strstr( szCTString, "Projection Name = ") && strstr( szCTString, "_StatePlane_"))
        {
            const char *pStr = strstr( szCTString, "Projection Name = ") + strlen("Projection Name = ");
            const char* pReturn = strchr( pStr, '\n');
            char CSName[128];
            strncpy(CSName, pStr, pReturn-pStr);
            CSName[pReturn-pStr] = '\0';
            if( poSRS->ImportFromESRIStatePlaneWKT(0, NULL, NULL, 32767, CSName) == OGRERR_NONE )
            {
                // for some erdas citation keys, the state plane CS name is incomplete, the unit check is necessary.
                OGRBoolean done = FALSE;
                if (hasUnits)
                {
                    OGR_SRSNode *poUnit = poSRS->GetAttrNode( "PROJCS|UNIT" );
      
                    if( poUnit != NULL && poUnit->GetChildCount() >= 2 )
                    {
                        CPLString unitName = poUnit->GetChild(0)->GetValue();
                        unitName.tolower();

                        if (strstr(units, "us_survey_feet"))
                        {              
                            if (strstr(unitName, "us_survey_feet") || strstr(unitName, "foot_us") )
                                done = TRUE;
                        }
                        else if (strstr(units, "international_feet"))
                        {
                            if (strstr(unitName, "feet") || strstr(unitName, "foot"))
                                done = TRUE;
                        }
                        else if (strstr(units, "meters"))
                        {
                            if (strstr(unitName, "meter") )
                                done = TRUE;
                        }
                    }
                }
                if (done)
                    return TRUE;
            }
        }
    }
    if( !hasUnits )
    {
        char	*pszUnitsName = NULL;
        GTIFGetUOMLengthInfo( psDefn->UOMLength, &pszUnitsName, NULL );
        if( pszUnitsName && strlen(pszUnitsName) > 0 )
        {
            CPLString osLCCT = pszUnitsName;
            GTIFFreeMemory( pszUnitsName );
            osLCCT.tolower();

            if( strstr(osLCCT, "us") && strstr(osLCCT, "survey")
                && (strstr(osLCCT, "feet") || strstr(osLCCT, "foot")))
                strcpy(units, "us_survey_feet");
            else if(strstr(osLCCT, "feet") || strstr(osLCCT, "foot"))
                strcpy(units, "international_feet");
            else if(strstr(osLCCT, "meter"))
                strcpy(units, "meters");
            hasUnits = TRUE;
        }
    }

    if (strlen(units) == 0)
        strcpy(units, "meters");

    /* check PCSCitationGeoKey if it exists */
    szCTString[0] = '\0';
    if( hGTIF && GTIFKeyGet( hGTIF, PCSCitationGeoKey, szCTString, 0, sizeof(szCTString)) )  
    {
        /* For tif created by LEICA(ERDAS), ESRI state plane pe string was used and */
        /* the state plane zone is given in PCSCitation. Therefore try Esri pe string first. */
        SetCitationToSRS(hGTIF, szCTString, strlen(szCTString), PCSCitationGeoKey, poSRS, pLinearUnitIsSet);
        const char *pcsName = poSRS->GetAttrValue("PROJCS");
        const char *pStr = NULL;
        if( (pcsName && (pStr = strstr(pcsName, "State Plane Zone ")) != NULL)
            || (pStr = strstr(szCTString, "State Plane Zone ")) != NULL )
        {
            pStr += strlen("State Plane Zone ");
            int statePlaneZone = abs(atoi(pStr));
            char nad[32];
            strcpy(nad, "HARN");
            if( strstr(szCTString, "NAD83") || strstr(szCTString, "NAD = 83") )
                strcpy(nad, "NAD83");
            else if( strstr(szCTString, "NAD27") || strstr(szCTString, "NAD = 27") )
                strcpy(nad, "NAD27");
            if( poSRS->ImportFromESRIStatePlaneWKT(statePlaneZone, (const char*)nad, (const char*)units, psDefn->PCS) == OGRERR_NONE )
                return TRUE;
        }
        else if( pcsName && (pStr = strstr(pcsName, "UTM Zone ")) != NULL )
            CheckUTM( psDefn, szCTString );
    }

    /* check state plane again to see if a pe string is available */
    if( psDefn->PCS != KvUserDefined )
    {
        if( poSRS->ImportFromESRIStatePlaneWKT(0, NULL, (const char*)units, psDefn->PCS) == OGRERR_NONE )
            return TRUE;
    }

    return FALSE;
}