Skip to content

Commit

Permalink
MITAB: swap StdParallel1 and stdParallel2 if necessary on LCC project…
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Jul 14, 2014
1 parent 5fef72b commit d1223a0
Show file tree
Hide file tree
Showing 8 changed files with 548 additions and 16 deletions.
Binary file added autotest/ogr/data/lambert93_francais.DAT
Binary file not shown.
Empty file.
Binary file added autotest/ogr/data/lambert93_francais.MAP
Binary file not shown.
13 changes: 13 additions & 0 deletions autotest/ogr/data/lambert93_francais.TAB
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
!table
!version 300
!charset WindowsLatin1

Definition Table
Type NATIVE Charset "WindowsLatin1"
Fields 1
foo Char (10) ;
begin_metadata
"\IsReadOnly" = "FALSE"
"\MapInfo" = ""
"\MapInfo\TableID" = "5afb8cce-1842-4a1a-aafc-2a9c10687b3a"
end_metadata
36 changes: 36 additions & 0 deletions autotest/ogr/ogr_mitab.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,41 @@ def ogr_mitab_17():
return 'success'

###############################################################################
# Test EPSG:2154

def ogr_mitab_18():

if gdaltest.mapinfo_drv is None:
return 'skip'

ds = ogr.GetDriverByName('MapInfo File').CreateDataSource('/vsimem/ogr_mitab_18.tab')
sr = osr.SpatialReference()
sr.ImportFromEPSG(2154)
lyr = ds.CreateLayer('test', srs = sr)
lyr.CreateField(ogr.FieldDefn('ID', ogr.OFTInteger))
ds = None

# Test with our generated file, and with one generated by MapInfo
for filename in [ '/vsimem/ogr_mitab_18.tab', 'data/lambert93_francais.TAB' ]:
ds = ogr.Open(filename)
lyr = ds.GetLayer(0)
sr_got = lyr.GetSpatialRef()
wkt = sr_got.ExportToWkt()
if wkt.find('2154') < 0:
gdaltest.post_reason('failure')
print(sr_got)
return 'fail'
proj4 = sr_got.ExportToProj4()
if proj4.find('+proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs') != 0:
gdaltest.post_reason('failure')
print(proj4)
return 'fail'
ds = None

ogr.GetDriverByName('MapInfo File').DeleteDataSource('/vsimem/ogr_mitab_18.tab')

return 'success'
###############################################################################
#

def ogr_mitab_cleanup():
Expand Down Expand Up @@ -604,6 +639,7 @@ def ogr_mitab_cleanup():
ogr_mitab_15,
ogr_mitab_16,
ogr_mitab_17,
ogr_mitab_18,
ogr_mitab_cleanup
]

Expand Down
7 changes: 4 additions & 3 deletions gdal/ogr/ogrsf_frmts/mitab/mitab_bounds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
* bounds lookups
*----------------------------------------------------------------*/
static MapInfoBoundsInfo **gpapsExtBoundsList = NULL;
static MapInfoBoundsInfo gasBoundsList[] = {
static const MapInfoBoundsInfo gasBoundsList[] = {
{{1, 0xff, 0xff, {0,0,0,0,0,0}, 0,0,0,0, {0,0,0,0,0}}, -1000, -1000, 1000, 1000}, /* Lat/Lon */

{{2, 29, 0, {-85.5,13,0,0,0,0}, 0,0,0,0, {0,0,0,0,0}}, -18500.7190263237, -4067.43878447928, 30025.7571082958, 4067.43878447928},
Expand Down Expand Up @@ -1053,7 +1053,8 @@ GBool MITABLookupCoordSysBounds(TABProjInfo *psCS,
double &dXMax, double &dYMax)
{
GBool bFound = FALSE;
MapInfoBoundsInfo *psList, **ppsList;
const MapInfoBoundsInfo *psList;
MapInfoBoundsInfo **ppsList;

/*-----------------------------------------------------------------
* Lookup table...
Expand Down Expand Up @@ -1100,7 +1101,7 @@ GBool MITABLookupCoordSysBounds(TABProjInfo *psCS,
psList = gasBoundsList;
for( ; !bFound && psList->sProj.nProjId!=0xff; psList++)
{
TABProjInfo *p = &(psList->sProj);
const TABProjInfo *p = &(psList->sProj);

if (p->nProjId == psCS->nProjId &&
(p->nUnitsId == 0xff || p->nUnitsId == psCS->nUnitsId) &&
Expand Down
48 changes: 43 additions & 5 deletions gdal/ogr/ogrsf_frmts/mitab/mitab_coordsys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@
#include "mitab.h"
#include "mitab_utils.h"

extern MapInfoDatumInfo asDatumInfoList[];
extern MapInfoSpheroidInfo asSpheroidInfoList[];
extern const MapInfoDatumInfo asDatumInfoList[];
extern const MapInfoSpheroidInfo asSpheroidInfoList[];

/************************************************************************/
/* GetMIFParm() */
Expand Down Expand Up @@ -650,6 +650,17 @@ OGRSpatialReference *MITABCoordSys2SpatialRef( const char * pszCoordSys )
GetMIFParm( papszNextField, 5, 0.0 )); // dfFalseNorthing
break;

/*--------------------------------------------------------------
* Equidistant Cylindrical / Equirectangular
*-------------------------------------------------------------*/
case 33:
poSR->SetEquirectangular(
GetMIFParm( papszNextField, 1, 0.0 ),
GetMIFParm( papszNextField, 0, 0.0 ),
GetMIFParm( papszNextField, 2, 0.0 ),
GetMIFParm( papszNextField, 3, 0.0 ) );
break;

default:
break;
}
Expand Down Expand Up @@ -683,7 +694,7 @@ OGRSpatialReference *MITABCoordSys2SpatialRef( const char * pszCoordSys )
/* Find the datum, and collect it's parameters if possible. */
/* -------------------------------------------------------------------- */
int iDatum;
MapInfoDatumInfo *psDatumInfo = NULL;
const MapInfoDatumInfo *psDatumInfo = NULL;

for( iDatum = 0; asDatumInfoList[iDatum].nMapInfoDatumID != -1; iDatum++ )
{
Expand Down Expand Up @@ -786,7 +797,9 @@ OGRSpatialReference *MITABCoordSys2SpatialRef( const char * pszCoordSys )
CPLAtof(SRS_UA_DEGREE_CONV) );

poSR->SetTOWGS84( adfDatumParm[0], adfDatumParm[1], adfDatumParm[2],
-adfDatumParm[3], -adfDatumParm[4], -adfDatumParm[5],
adfDatumParm[3] == 0.0 ? 0.0 : -adfDatumParm[3],
adfDatumParm[4] == 0.0 ? 0.0 : -adfDatumParm[4],
adfDatumParm[5] == 0.0 ? 0.0 : -adfDatumParm[5],
adfDatumParm[6] );

/*-----------------------------------------------------------------
Expand All @@ -798,6 +811,21 @@ OGRSpatialReference *MITABCoordSys2SpatialRef( const char * pszCoordSys )
poSR->SetNode( "PROJCS", "WGS 84 / Pseudo-Mercator" );
poSR->SetExtension( "PROJCS", "PROJ4", "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs" );
}

/*-----------------------------------------------------------------
* Special case for France Lambert-93
*----------------------------------------------------------------*/
if( nBaseProjection == 3
&& nDatum == 33
&& nEllipsoid == 0
&& poSR->GetProjParm(SRS_PP_CENTRAL_MERIDIAN,0.0) == 3.0
&& poSR->GetProjParm(SRS_PP_LATITUDE_OF_ORIGIN,0.0) == 46.5 )
{
poSR->SetNode( "PROJCS", "RGF93 / Lambert-93" );
poSR->SetNode( "PROJCS|GEOGCS", "RGF93");
poSR->SetNode( "PROJCS|GEOGCS|DATUM", "Reseau_Geodesique_Francais_1993");
}

/* -------------------------------------------------------------------- */
/* Report on translation. */
/* -------------------------------------------------------------------- */
Expand Down Expand Up @@ -1139,6 +1167,16 @@ char *MITABSpatialRef2CoordSys( OGRSpatialReference * poSR )
nParmCount = 6;
}

else if( EQUAL(pszProjection,SRS_PT_EQUIRECTANGULAR) )
{
nProjection = 33;
parms[0] = poSR->GetProjParm(SRS_PP_CENTRAL_MERIDIAN,0.0);
parms[1] = poSR->GetProjParm(SRS_PP_LATITUDE_OF_ORIGIN,0.0);
parms[2] = poSR->GetProjParm(SRS_PP_FALSE_EASTING,0.0);
parms[3] = poSR->GetProjParm(SRS_PP_FALSE_NORTHING,0.0);
nParmCount = 4;
}

/* ==============================================================
* Translate Datum and Ellipsoid
* ============================================================== */
Expand Down Expand Up @@ -1507,7 +1545,7 @@ int MITABCoordSys2TABProjInfo(const char * pszCoordSys, TABProjInfo *psProj)
* Find the datum, and collect it's parameters if possible.
*----------------------------------------------------------------*/
int iDatum;
MapInfoDatumInfo *psDatumInfo = NULL;
const MapInfoDatumInfo *psDatumInfo = NULL;

for(iDatum=0; asDatumInfoList[iDatum].nMapInfoDatumID != -1; iDatum++)
{
Expand Down
Loading

0 comments on commit d1223a0

Please sign in to comment.