Skip to content

Commit 9521529

Browse files
committed
Fix OGR output to make it work with KML, GPX (#4776)
1 parent 051e2aa commit 9521529

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

mapogroutput.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ static void msOGRSetPoints( OGRGeometryH hGeom, lineObj *line, int bWant2DOutput
227227
/************************************************************************/
228228

229229
static int msOGRWriteShape( layerObj *map_layer, OGRLayerH hOGRLayer,
230-
shapeObj *shape, gmlItemListObj *item_list )
230+
shapeObj *shape, gmlItemListObj *item_list,
231+
int nFirstOGRFieldIndex )
231232

232233
{
233234
OGRGeometryH hGeom = NULL;
@@ -435,7 +436,7 @@ static int msOGRWriteShape( layerObj *map_layer, OGRLayerH hOGRLayer,
435436
/* -------------------------------------------------------------------- */
436437
/* Set attributes. */
437438
/* -------------------------------------------------------------------- */
438-
out_field = 0;
439+
out_field = nFirstOGRFieldIndex;
439440
for( i = 0; i < item_list->numitems; i++ ) {
440441
gmlItemObj *item = item_list->items + i;
441442

@@ -641,6 +642,7 @@ int msOGRWriteFromQuery( mapObj *map, outputFormatObj *format, int sendheaders )
641642
const char *value;
642643
char *pszWKT;
643644
int reproject = MS_FALSE;
645+
int nFirstOGRFieldIndex = -1;
644646

645647
if( !layer->resultcache || layer->resultcache->numresults == 0 )
646648
continue;
@@ -792,6 +794,11 @@ int msOGRWriteFromQuery( mapObj *map, outputFormatObj *format, int sendheaders )
792794
msOGRCleanupDS( datasource_name );
793795
return MS_FAILURE;
794796
}
797+
798+
/* The index of the first field we create is not necessarily 0 */
799+
if( nFirstOGRFieldIndex < 0 )
800+
nFirstOGRFieldIndex = OGR_FD_GetFieldCount(
801+
OGR_L_GetLayerDefn( hOGRLayer ) ) - 1;
795802
}
796803

797804
/* -------------------------------------------------------------------- */
@@ -868,7 +875,7 @@ int msOGRWriteFromQuery( mapObj *map, outputFormatObj *format, int sendheaders )
868875

869876
if( status == MS_SUCCESS )
870877
status = msOGRWriteShape( layer, hOGRLayer, &resultshape,
871-
item_list );
878+
item_list, nFirstOGRFieldIndex );
872879

873880
if(status != MS_SUCCESS) {
874881
OGR_DS_Destroy( hDS );

msautotest

Submodule msautotest updated from 1f0ea11 to ed1a6e4

0 commit comments

Comments
 (0)