OGRLayer * OGRGMLDataSource::CreateLayer( const char * pszLayerName, OGRSpatialReference *poSRS, OGRwkbGeometryType eType, char ** papszOptions ) { /* -------------------------------------------------------------------- */ /* Verify we are in update mode. */ /* -------------------------------------------------------------------- */ if( fpOutput == NULL ) { CPLError( CE_Failure, CPLE_NoWriteAccess, "Data source %s opened for read access.\n" "New layer %s cannot be created.\n", pszName, pszLayerName ); return NULL; } /* -------------------------------------------------------------------- */ /* Ensure name is safe as an element name. */ /* -------------------------------------------------------------------- */ char *pszCleanLayerName = CPLStrdup( pszLayerName ); CPLCleanXMLElementName( pszCleanLayerName ); if( strcmp(pszCleanLayerName,pszLayerName) != 0 ) { CPLError( CE_Warning, CPLE_AppDefined, "Layer name '%s' adjusted to '%s' for XML validity.", pszLayerName, pszCleanLayerName ); } /* -------------------------------------------------------------------- */ /* Create the layer object. */ /* -------------------------------------------------------------------- */ OGRGMLLayer *poLayer; poLayer = new OGRGMLLayer( pszCleanLayerName, poSRS, TRUE, eType, this ); CPLFree( pszCleanLayerName ); /* -------------------------------------------------------------------- */ /* Add layer to data source layer list. */ /* -------------------------------------------------------------------- */ papoLayers = (OGRGMLLayer **) CPLRealloc( papoLayers, sizeof(OGRGMLLayer *) * (nLayers+1) ); papoLayers[nLayers++] = poLayer; return poLayer; }
OGRErr OGRGMLLayer::CreateField( OGRFieldDefn *poField, int bApproxOK ) { if( !bWriter || iNextGMLId != 0 ) return OGRERR_FAILURE; /* -------------------------------------------------------------------- */ /* Enforce XML naming semantics on element name. */ /* -------------------------------------------------------------------- */ OGRFieldDefn oCleanCopy( poField ); char *pszName = CPLStrdup( poField->GetNameRef() ); CPLCleanXMLElementName( pszName ); if( strcmp(pszName,poField->GetNameRef()) != 0 ) { if( !bApproxOK ) { CPLFree( pszName ); CPLError( CE_Failure, CPLE_AppDefined, "Unable to create field with name '%s', it would not\n" "be valid as an XML element name.", poField->GetNameRef() ); return OGRERR_FAILURE; } oCleanCopy.SetName( pszName ); CPLError( CE_Warning, CPLE_AppDefined, "Field name '%s' adjusted to '%s' to be a valid\n" "XML element name.", poField->GetNameRef(), pszName ); } CPLFree( pszName ); poFeatureDefn->AddFieldDefn( &oCleanCopy ); return OGRERR_NONE; }
OGRLayer * OGRKMLDataSource::ICreateLayer( const char * pszLayerName, OGRSpatialReference *poSRS, OGRwkbGeometryType eType, CPL_UNUSED char ** papszOptions ) { CPLAssert( NULL != pszLayerName); /* -------------------------------------------------------------------- */ /* Verify we are in update mode. */ /* -------------------------------------------------------------------- */ if( fpOutput_ == NULL ) { CPLError( CE_Failure, CPLE_NoWriteAccess, "Data source %s opened for read access.\n" "New layer %s cannot be created.\n", pszName_, pszLayerName ); return NULL; } /* -------------------------------------------------------------------- */ /* Close the previous layer (if there is one open) */ /* -------------------------------------------------------------------- */ if (GetLayerCount() > 0) { if( nLayers_ == 1 && papoLayers_[0]->nWroteFeatureCount_ == 0 ) { VSIFPrintfL( fpOutput_, "<Folder><name>%s</name>\n", papoLayers_[0]->GetName() ); } VSIFPrintfL( fpOutput_, "</Folder>\n"); ((OGRKMLLayer*)GetLayer(GetLayerCount()-1))->SetClosedForWriting(); } /* -------------------------------------------------------------------- */ /* Ensure name is safe as an element name. */ /* -------------------------------------------------------------------- */ char *pszCleanLayerName = CPLStrdup( pszLayerName ); CPLCleanXMLElementName( pszCleanLayerName ); if( strcmp(pszCleanLayerName, pszLayerName) != 0 ) { CPLError( CE_Warning, CPLE_AppDefined, "Layer name '%s' adjusted to '%s' for XML validity.", pszLayerName, pszCleanLayerName ); } if (GetLayerCount() > 0) { VSIFPrintfL( fpOutput_, "<Folder><name>%s</name>\n", pszCleanLayerName); } /* -------------------------------------------------------------------- */ /* Create the layer object. */ /* -------------------------------------------------------------------- */ OGRKMLLayer *poLayer; poLayer = new OGRKMLLayer( pszCleanLayerName, poSRS, TRUE, eType, this ); CPLFree( pszCleanLayerName ); /* -------------------------------------------------------------------- */ /* Add layer to data source layer list. */ /* -------------------------------------------------------------------- */ papoLayers_ = (OGRKMLLayer **) CPLRealloc( papoLayers_, sizeof(OGRKMLLayer *) * (nLayers_+1) ); papoLayers_[nLayers_++] = poLayer; return poLayer; }