[Gdal-dev] OGR and support for older PostGIS DBs?
Frank Warmerdam
fwarmerdam at gmail.com
Wed Aug 3 09:22:26 EDT 2005
On 8/1/05, Markus Neteler <neteler at itc.it> wrote:
> Hi,
>
> I was trying the current OGR (today) against an older
> PostGIS database (based on libpostgis.so.0.7 and PostgreSQL V7.3.3):
....
> I am not sure what's wrong... AFAIK I didn't touch the PG DB for a long
> while. Is backward compatibility supported? Otherwise I'll have to upgrade
> my PG database.
>
> This patch cured at least the BOX3D problem:
> --- ogr/ogrsf_frmts/pg/ogrpgtablelayer.cpp 20 Jul 2005 01:45:30 -0000 1.29
> +++ ogr/ogrsf_frmts/pg/ogrpgtablelayer.cpp 1 Aug 2005 17:18:19 -0000
> @@ -1282,7 +1282,7 @@
> szVals[strstr(ptr,")") - ptr] = '\0';
>
> char ** papszTokens = CSLTokenizeString2(szVals," ,",CSLT_HONOURSTRINGS);
> - if ( CSLCount(papszTokens) != 4 )
> + if ( CSLCount(papszTokens) != 6 )
> {
> CPLError(CE_Failure, CPLE_IllegalArg, "Bad extent representation: '%s'", pszBox);
> CSLDestroy(papszTokens);
>
>
> Help is appreciated,
Markus,
Sorry about this. I asked Andrey and Oleg to look into this yesterday,
but I believe Andrey is travelling today. I am commiting the following
patch which I think should support the BOX3D if it is returned by
the Extent() operator. I am not sure if this is a postgis version issue or
not, but it is my intention to continue supporting earlier versions of
PostGIS for a year or two at least.
diff -u -b -r1.29 ogrpgtablelayer.cpp
--- ogrpgtablelayer.cpp 20 Jul 2005 01:45:30 -0000 1.29
+++ ogrpgtablelayer.cpp 3 Aug 2005 13:18:49 -0000
@@ -1282,9 +1282,11 @@
szVals[strstr(ptr,")") - ptr] = '\0';
char ** papszTokens = CSLTokenizeString2(szVals," ,",CSLT_HONOUR
STRINGS);
- if ( CSLCount(papszTokens) != 4 )
+ if ( CSLCount(papszTokens) != 4
+ && CSLCount(papszTokens) != 6 )
{
- CPLError(CE_Failure, CPLE_IllegalArg, "Bad extent repres
entation: '%s'", pszBox);
+ CPLError(CE_Failure, CPLE_IllegalArg,
+ "Bad extent representation: '%s'", pszBox);
CSLDestroy(papszTokens);
PQclear(hResult);
return OGRERR_FAILURE;
@@ -1292,8 +1294,21 @@
psExtent->MinX = CPLScanDouble(papszTokens[0],strlen(papszTokens
[0]),"C");
psExtent->MinY = CPLScanDouble(papszTokens[1],strlen(papszTokens
[1]),"C");
- psExtent->MaxX = CPLScanDouble(papszTokens[2],strlen(papszTokens
[2]),"C");
- psExtent->MaxY = CPLScanDouble(papszTokens[3],strlen(papszTokens
[3]),"C");
+
+ if( CSLCount( papszTokens ) == 4 ) // BOX2D
+ {
+ psExtent->MaxX = CPLScanDouble(papszTokens[2],
+ strlen(papszTokens[2]),"C");
+ psExtent->MaxY = CPLScanDouble(papszTokens[3],
+ strlen(papszTokens[3]),"C");
+ }
+ else // BOX3D
+ {
+ psExtent->MaxX = CPLScanDouble(papszTokens[3],
+ strlen(papszTokens[4]),"C");
+ psExtent->MaxY = CPLScanDouble(papszTokens[4],
+ strlen(papszTokens[5]),"C");
+ }
CSLDestroy(papszTokens);
Note my change differs from yours in that it correctly extract
the extents in the case of a BOX3D and in that it continues
to support the 2D version of the box.
Andrey / Oleg, perhaps you guys could verify the changed
code makes sense in all circumstances.
Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush | Geospatial Programmer for Rent
More information about the Gdal-dev
mailing list