Opened 14 years ago

Last modified 14 years ago

#1101 closed enhancement (fixed)

Override geom column name in ogr PostgreSQL driver

Reported by: rob@… Owned by: warmerdam
Priority: high Milestone:
Component: default Version: unspecified
Severity: minor Keywords:
Cc:

Description

Override name of geometry column when using the Postgresql driver in create 
mode. 
To invoke, supply this argument on command line: 
-lco GEOMETRY_NAME=the_geom

Patch supplied below. 

To apply patch:
cd gdal-1.3.1/ogr/ogrsf_frmts/pg/
patch ogrpgdatasource.cpp  pathtopatch/ogr_pgname.patch

-----------------------------
ogr_pgname.patch
-----------------------------
diff -aur gdal-1.3.1/ogrpgdatasource.cpp gdal-new/ogrpgdatasource.cpp
--- gdal-1.3.1/ogrpgdatasource.cpp      2006-03-01 14:43:52.000000000 -0600
+++ gdal-new/ogrpgdatasource.cpp        2006-03-01 14:33:10.000000000 -0600
@@ -541,8 +541,8 @@
     if( bHavePostGIS )
     {
         sprintf( szCommand,
-                 "SELECT DropGeometryColumn('%s','%s','wkb_geometry')",
-                 pszDBName, pszLayerName );
+                 "SELECT DropGeometryColumn('%s','%s',(SELECT 
f_geometry_column from geometry_columns where f_table_name='%s' order by 
f_geometry_column limit 1))",
+                 pszDBName, pszLayerName, pszLayerName);

         CPLDebug( "OGR_PG", "PGexec(%s)", szCommand );

@@ -698,10 +698,17 @@
     if( bHavePostGIS )
     {
         const char *pszGeometryType;
+       const char *pszGFldName;

         if( CSLFetchNameValue( papszOptions, "DIM") != NULL )
             nDimension = atoi(CSLFetchNameValue( papszOptions, "DIM"));

+       /** rgp added this **/
+        if( CSLFetchNameValue( papszOptions, "GEOMETRY_NAME") != NULL )
+            pszGFldName = CSLFetchNameValue( papszOptions, "GEOMETRY_NAME");
+       else
+           pszGFldName = "wkb_geometry";
+
         /* Sometimes there is an old cruft entry in the geometry_columns
          * table if things were not properly cleaned up before.  We make
          * an effort to clean out such cruft.
@@ -751,8 +758,8 @@
         }

         sprintf( szCommand,
-                 "select AddGeometryColumn('%s','%s','wkb_geometry',%d,'%s',%
d)",
-                 pszDBName, pszLayerName, nSRSId, pszGeometryType,
+                 "select AddGeometryColumn('%s','%s','%s',%d,'%s',%d)",
+                 pszDBName, pszLayerName, pszGFldName, nSRSId, 
pszGeometryType,
                  nDimension );

         CPLDebug( "OGR_PG", "PQexec(%s)", szCommand );

Attachments (1)

ogr_pgname.patch (1.8 KB) - added by rob@… 14 years ago.
Allow override of Postgresql geometry column name

Download all attachments as: .zip

Change History (3)

comment:1 Changed 14 years ago by rob@…

Due to cut n paste, the supplied patch appears to be malformed. Wil provide 
attachement when I get home tonight.

Changed 14 years ago by rob@…

Attachment: ogr_pgname.patch added

Allow override of Postgresql geometry column name

comment:2 Changed 14 years ago by warmerdam

Applied (with a bit of fixing for newer code), and also updated in docs.

Note: See TracTickets for help on using tickets.