Skip to content

Commit

Permalink
Support GDAL 2.0 64bit integer fields
Browse files Browse the repository at this point in the history
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 Feb 24, 2016
1 parent f0dedb6 commit 4238420
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
18 changes: 13 additions & 5 deletions mapogr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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);

Expand All @@ -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;

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 );

Expand Down
12 changes: 11 additions & 1 deletion mapogroutput.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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") )
Expand Down
5 changes: 4 additions & 1 deletion mappostgis.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
2 changes: 2 additions & 0 deletions mapwfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 4238420

Please sign in to comment.