Skip to content

Commit

Permalink
MITAB: add MITAB_BOUNDS_FILE to specify a file with projection bounds (
Browse files Browse the repository at this point in the history
…mapgears/mitab#3)

git-svn-id: https://svn.osgeo.org/gdal/trunk/gdal@27564 f0d54148-0727-0410-94bb-9a71ac55c965
  • Loading branch information
rouault committed Aug 5, 2014
1 parent 3366953 commit 73ef8a1
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
18 changes: 17 additions & 1 deletion ogr/ogrsf_frmts/mitab/drv_mitab.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,26 @@ <h2>Creation Issues</h2>
<li>For any other projection: BOUNDS (-30000000, -15000000) (30000000, 15000000)</li>
</ul>

<p>
Starting with GDAL 2.0, it is possible to specify a user-defined file that contain
projection definitions with bounds.
The name of this file must be specified with the MITAB_BOUNDS_FILE configuration
option.
This allows users to override the
default bounds for existing projections, and to define bounds for new projections
not listed in the hard-coded table in the driver.
The format of the file is a simple text file with one CoordSys string
per line. The CoordSys lines should follow the MIF specs, and MUST
include the optional Bounds definition at the end of the line, e.g.
<pre>
# Lambert 93 French bounds
CoordSys Earth Projection 3, 33, "m", 3, 46.5, 44, 49, 700000, 6600000 Bounds (75000, 6000000) (1275000, 7200000)
</pre>
</p>

<p>
If no coordinate system is provided when creating a layer, the projection
case is used, not geographic which can result in very low precision if
case is used, not geographic, which can result in very low precision if
the coordinates really are geographic. You can add "-a_srs WGS84" to the
<b>ogr2ogr</b> commandline during a translation to force geographic mode.
</p>
Expand Down
20 changes: 20 additions & 0 deletions ogr/ogrsf_frmts/mitab/mitab_bounds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,7 @@ static const MapInfoBoundsInfo gasBoundsList[] = {

#define TAB_EQUAL(a, b) (((a)<(b) ? ((b)-(a)) : ((a)-(b))) < 1e-6)

static char szPreviousMitabBoundsFile[2048] = { 0 };

/**********************************************************************
* MITABLookupCoordSysBounds()
Expand All @@ -1056,6 +1057,25 @@ GBool MITABLookupCoordSysBounds(TABProjInfo *psCS,
const MapInfoBoundsInfo *psList;
MapInfoBoundsInfo **ppsList;

/*-----------------------------------------------------------------
* Try to load the user defined table if not loaded yet .
*----------------------------------------------------------------*/
const char * pszMitabBoundsFile = CPLGetConfigOption("MITAB_BOUNDS_FILE", NULL);
if (pszMitabBoundsFile != NULL && pszMitabBoundsFile[0] != '\0' )
{
if( strcmp(pszMitabBoundsFile, szPreviousMitabBoundsFile) != 0)
{
CPLStrlcpy(szPreviousMitabBoundsFile, pszMitabBoundsFile,
sizeof(szPreviousMitabBoundsFile));
MITABLoadCoordSysTable(pszMitabBoundsFile);
}
}
else if ( szPreviousMitabBoundsFile[0] != '\0' )
{
MITABFreeCoordSysTable();
strcpy(szPreviousMitabBoundsFile, "");
}

/*-----------------------------------------------------------------
* Lookup table...
* Lookup external file if one was loaded, then lookup internal table.
Expand Down
2 changes: 2 additions & 0 deletions ogr/ogrsf_frmts/mitab/mitab_coordsys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,8 @@ int MITABCoordSys2TABProjInfo(const char * pszCoordSys, TABProjInfo *psProj)
psProj->adProjParams[iParam] = atof(papszNextField[0]);
papszNextField++;
}

CSLDestroy(papszFields);

return 0;
}
Expand Down
10 changes: 10 additions & 0 deletions ogr/ogrsf_frmts/mitab/mitab_ogr_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,15 @@ static CPLErr OGRTABDriverDelete( const char *pszDataSource )
return CE_None;
}

/************************************************************************/
/* OGRTABDriverUnload() */
/************************************************************************/

static void OGRTABDriverUnload(GDALDriver* poDriver)
{
MITABFreeCoordSysTable();
}

/************************************************************************/
/* RegisterOGRTAB() */
/************************************************************************/
Expand Down Expand Up @@ -230,6 +239,7 @@ void RegisterOGRTAB()
poDriver->pfnIdentify = OGRTABDriverIdentify;
poDriver->pfnCreate = OGRTABDriverCreate;
poDriver->pfnDelete = OGRTABDriverDelete;
poDriver->pfnUnloadDriver = OGRTABDriverUnload;

GetGDALDriverManager()->RegisterDriver( poDriver );
}
Expand Down

0 comments on commit 73ef8a1

Please sign in to comment.