Permalink
Browse files

Support GDAL 2.0 64bit integer fields

Now that http://trac.osgeo.org/gdal/wiki/rfc31_ogr_64 has been
committed in GDAL trunk 2.0dev, OFTInteger64 can be return as a
field type.
So :
- when reading OGR layer, support mapping OFTInteger64 to a new "Long" datatype
- when reading PostGIS layer, map INT8 columns to "Long" datatype
- in mapwfs, map "Long" to xs:long
- in OGR output code, map "Long" to OFTInteger64, if GDAL 2.0, or
  OFTReal otherwise

OGR_F_GetFID() in GDAL 2.0 returns a 64 bit integer. We just fix
warnings by casting to int, but if a 64bit FID was really returned,
we might have issues.
  • Loading branch information...
rouault authored and tbonfort committed Jan 30, 2015
1 parent f0dedb6 commit 4238420939197f9a7412dcb9667613028e1a2847
Showing with 30 additions and 7 deletions.
  1. +13 −5 mapogr.cpp
  2. +11 −1 mapogroutput.c
  3. +4 −1 mappostgis.c
  4. +2 −0 mapwfs.c
View
@@ -1714,6 +1714,14 @@ msOGRPassThroughFieldDefinitions( layerObj *layer, msOGRFileInfo *psInfo )
sprintf( gml_width, "%d", OGR_Fld_GetWidth( hField) );
break;
+#if GDAL_VERSION_MAJOR >= 2
+ case OFTInteger64:
+ gml_type = "Long";
+ if( OGR_Fld_GetWidth( hField) > 0 )
+ sprintf( gml_width, "%d", OGR_Fld_GetWidth( hField) );
+ break;
+#endif
+
case OFTReal:
gml_type = "Real";
if( OGR_Fld_GetWidth( hField) > 0 )
@@ -1897,8 +1905,8 @@ msOGRFileNextShape(layerObj *layer, shapeObj *shape,
break; // Shape is ready to be returned!
if (layer->debug >= MS_DEBUGLEVEL_VVV)
- msDebug("msOGRFileNextShape: Rejecting feature (shapeid = %ld, tileid=%d) of incompatible type for this layer (feature wkbType %d, layer type %d)\n",
- OGR_F_GetFID( hFeature ), psInfo->nTileId,
+ msDebug("msOGRFileNextShape: Rejecting feature (shapeid = " CPL_FRMT_GIB ", tileid=%d) of incompatible type for this layer (feature wkbType %d, layer type %d)\n",
+ (GIntBig)OGR_F_GetFID( hFeature ), psInfo->nTileId,
OGR_F_GetGeometryRef( hFeature )==NULL ? wkbFlatten(wkbUnknown):wkbFlatten( OGR_G_GetGeometryType( OGR_F_GetGeometryRef( hFeature ) ) ),
layer->type);
@@ -1914,7 +1922,7 @@ msOGRFileNextShape(layerObj *layer, shapeObj *shape,
shape->type = MS_SHAPE_NULL;
}
- shape->index = OGR_F_GetFID( hFeature );;
+ shape->index = (int)OGR_F_GetFID( hFeature ); // FIXME? GetFID() is a 64bit integer in GDAL 2.0
shape->resultindex = psInfo->last_record_index_read;
shape->tileindex = psInfo->nTileId;
@@ -2029,7 +2037,7 @@ msOGRFileGetShape(layerObj *layer, shapeObj *shape, long record,
shape->index = record;
shape->resultindex = -1;
} else {
- shape->index = OGR_F_GetFID( hFeature );
+ shape->index = (int)OGR_F_GetFID( hFeature ); // FIXME? GetFID() is a 64bit integer in GDAL 2.0
shape->resultindex = record;
}
@@ -2111,7 +2119,7 @@ int msOGRFileReadTile( layerObj *layer, msOGRFileInfo *psInfo,
connection = msStrdup( OGR_F_GetFieldAsString( hFeature,
layer->tileitemindex ));
- nFeatureId = OGR_F_GetFID( hFeature );
+ nFeatureId = (int)OGR_F_GetFID( hFeature ); // FIXME? GetFID() is a 64bit integer in GDAL 2.0
OGR_F_Destroy( hFeature );
View
@@ -497,7 +497,11 @@ static int msOGRWriteShape( layerObj *map_layer, OGRLayerH hOGRLayer,
if( shape->values[i][0] == '\0' ) {
OGRFieldDefnH hFieldDefn = OGR_FD_GetFieldDefn(hLayerDefn, out_field);
OGRFieldType eFieldType = OGR_Fld_GetType(hFieldDefn);
- if( eFieldType == OFTInteger || eFieldType == OFTReal )
+ if( eFieldType == OFTInteger || eFieldType == OFTReal
+#if GDAL_VERSION_MAJOR >= 2
+ || eFieldType == OFTInteger64
+#endif
+ )
{
out_field++;
continue;
@@ -987,6 +991,12 @@ int msOGRWriteFromQuery( mapObj *map, outputFormatObj *format, int sendheaders )
eType = OFTString;
else if( EQUAL(item->type,"Integer") )
eType = OFTInteger;
+ else if( EQUAL(item->type,"Long") )
+#if GDAL_VERSION_MAJOR >= 2
+ eType = OFTInteger64;
+#else
+ eType = OFTReal;
+#endif
else if( EQUAL(item->type,"Real") )
eType = OFTReal;
else if( EQUAL(item->type,"Character") )
View
@@ -3020,9 +3020,12 @@ msPostGISPassThroughFieldDefinitions( layerObj *layer,
gml_type = "Integer";
sprintf( gml_width, "%d", 5 );
- } else if( oid == INT4OID || oid == INT8OID ) {
+ } else if( oid == INT4OID ) {
gml_type = "Integer";
+ } else if( oid == INT8OID ) {
+ gml_type = "Long";
+
} else if( oid == FLOAT4OID || oid == FLOAT8OID ) {
gml_type = "Real";
View
@@ -1025,6 +1025,8 @@ static const char* msWFSMapServTypeToXMLType(const char* type)
/* Note : xs:int and xs:integer differ */
else if ( EQUAL(type,"int") )
element_type = "int";
+ if( strcasecmp(type,"Long") == 0 ) /* 64bit integer */
+ element_type = "long";
else if( EQUAL(type,"Real") ||
EQUAL(type,"double") /* just in case someone provided the xsd type directly */ )
element_type = "double";

0 comments on commit 4238420

Please sign in to comment.