244
245
return OGRERR_FAILURE;
246
FILE *fp = poDS_->GetOutputFP();
247
if( bClosedForWriting )
249
CPLError(CE_Failure, CPLE_NotSupported,
250
"Interleaved feature adding to different layers is not supported");
251
return OGRERR_FAILURE;
254
VSILFILE *fp = poDS_->GetOutputFP();
247
255
CPLAssert( NULL != fp );
249
257
// If we haven't writen any features yet, output the layer's schema
250
258
if (0 == nWroteFeatureCount_)
252
VSIFPrintf( fp, "<Schema name=\"%s\" id=\"%s\">\n", pszName_, pszName_ );
260
VSIFPrintfL( fp, "<Schema name=\"%s\" id=\"%s\">\n", pszName_, pszName_ );
253
261
OGRFeatureDefn *featureDefinition = GetLayerDefn();
254
262
for (int j=0; j < featureDefinition->GetFieldCount(); j++)
300
308
pszKMLEltName = "SimpleField";
303
VSIFPrintf( fp, "\t<%s name=\"%s\" type=\"%s\"></%s>\n",
311
VSIFPrintfL( fp, "\t<%s name=\"%s\" type=\"%s\"></%s>\n",
304
312
pszKMLEltName, fieldDefinition->GetNameRef() ,pszKMLType, pszKMLEltName );
306
VSIFPrintf( fp, "</Schema>\n" );
314
VSIFPrintfL( fp, "</Schema>\n" );
309
VSIFPrintf( fp, " <Placemark>\n" );
317
VSIFPrintfL( fp, " <Placemark>\n" );
311
319
if( poFeature->GetFID() == OGRNullFID )
312
320
poFeature->SetFID( iNextKMLId_++ );
349
357
char *pszEscaped = OGRGetXML_UTF8_EscapedString( pszRaw );
351
VSIFPrintf( fp, "\t<description>%s</description>\n", pszEscaped);
359
VSIFPrintfL( fp, "\t<description>%s</description>\n", pszEscaped);
352
360
CPLFree( pszEscaped );
357
OGRwkbGeometryType eGeomType = wkbFlatten(poFeatureDefn_->GetGeomType());
365
OGRwkbGeometryType eGeomType = wkbNone;
366
if (poFeature->GetGeometryRef() != NULL)
367
eGeomType = wkbFlatten(poFeature->GetGeometryRef()->getGeometryType());
358
368
if ( wkbPolygon == eGeomType
359
369
|| wkbMultiPolygon == eGeomType
360
370
|| wkbLineString == eGeomType
361
371
|| wkbMultiLineString == eGeomType )
373
OGRStylePen *poPen = NULL;
376
if( poFeature->GetStyleString() != NULL )
378
oSM.InitFromFeature( poFeature );
381
for(i=0; i<oSM.GetPartCount();i++)
383
OGRStyleTool *poTool = oSM.GetPart(i);
384
if (poTool && poTool->GetType() == OGRSTCPen )
386
poPen = (OGRStylePen*) poTool;
393
VSIFPrintfL( fp, "\t<Style>");
397
int bHasWidth = FALSE;
399
/* Require width to be returned in pixel */
400
poPen->SetUnit(OGRSTUPixel);
401
double fW = poPen->Width(bDefault);
406
const char* pszColor = poPen->Color(bDefault);
407
int nColorLen = CPLStrnlen(pszColor, 10);
408
if( pszColor != NULL && pszColor[0] == '#' && !bDefault && nColorLen >= 7)
410
char acColor[9] = {0};
411
/* Order of KML color is aabbggrr, whereas OGR color is #rrggbb[aa] ! */
414
acColor[0] = pszColor[7]; /* A */
415
acColor[1] = pszColor[8];
422
acColor[2] = pszColor[5]; /* B */
423
acColor[3] = pszColor[6];
424
acColor[4] = pszColor[3]; /* G */
425
acColor[5] = pszColor[4];
426
acColor[6] = pszColor[1]; /* R */
427
acColor[7] = pszColor[2];
428
VSIFPrintfL( fp, "<LineStyle><color>%s</color>", acColor);
430
VSIFPrintfL( fp, "<width>%g</width>", fW);
431
VSIFPrintfL( fp, "</LineStyle>");
434
VSIFPrintfL( fp, "<LineStyle><color>ff0000ff</color></LineStyle>");
437
VSIFPrintfL( fp, "<LineStyle><color>ff0000ff</color></LineStyle>");
363
439
//If we're dealing with a polygon, add a line style that will stand out a bit
364
VSIFPrintf( fp, " <Style><LineStyle><color>ff0000ff</color></LineStyle>");
365
VSIFPrintf( fp, " <PolyStyle><fill>0</fill></PolyStyle></Style>\n" );
440
VSIFPrintfL( fp, "<PolyStyle><fill>0</fill></PolyStyle></Style>\n" );
368
443
int bHasFoundOtherField = FALSE;