bDisplayProgress = false;
}
else
{
nCountLayerFeatures = poResultSet.GetFeatureCount();
pfnProgress = new TermProgressCallback();
}
}
/* -------------------------------------------------------------------- */
/* Special case to improve user experience when translating into */
/* single file shapefile and source has only one layer, and that */
/* the layer name isn't specified */
/* -------------------------------------------------------------------- */
if (poDriver.GetName().equalsIgnoreCase("ESRI Shapefile") &&
pszNewLayerName == null)
{
File f = new File(pszDestDataSource);
if (f.exists() && f.listFiles() == null)
{
pszNewLayerName = f.getName();
int posPoint = pszNewLayerName.lastIndexOf('.');
if (posPoint != -1)
pszNewLayerName = pszNewLayerName.substring(0, posPoint);
}
}
if( !TranslateLayer( poDS, poResultSet, poODS, papszLCO,
pszNewLayerName, bTransform, poOutputSRS,
poSourceSRS, papszSelFields, bAppend, eGType,
bOverwrite, eGeomOp, dfGeomOpParam, papszFieldTypesToString,
nCountLayerFeatures, poClipSrc, poClipDst, bExplodeCollections,
pszZField, pszWHERE, pfnProgress ))
{
System.err.println(
"Terminating translation prematurely after failed\n" +
"translation from sql statement." );
System.exit( 1 );
}
poDS.ReleaseResultSet( poResultSet );
}
}
else
{
int nLayerCount = 0;
Layer[] papoLayers = null;
/* -------------------------------------------------------------------- */
/* Process each data source layer. */
/* -------------------------------------------------------------------- */
if ( papszLayers.size() == 0)
{
nLayerCount = poDS.GetLayerCount();
papoLayers = new Layer[nLayerCount];
for( int iLayer = 0;
iLayer < nLayerCount;
iLayer++ )
{
Layer poLayer = poDS.GetLayer(iLayer);
if( poLayer == null )
{
System.err.println("FAILURE: Couldn't fetch advertised layer " + iLayer + "!");
System.exit( 1 );
}
papoLayers[iLayer] = poLayer;
}
}
/* -------------------------------------------------------------------- */
/* Process specified data source layers. */
/* -------------------------------------------------------------------- */
else
{
nLayerCount = papszLayers.size();
papoLayers = new Layer[nLayerCount];
for( int iLayer = 0;
iLayer < papszLayers.size();
iLayer++ )
{
Layer poLayer = poDS.GetLayerByName((String)papszLayers.get(iLayer));
if( poLayer == null )
{
System.err.println("FAILURE: Couldn't fetch advertised layer " + (String)papszLayers.get(iLayer) + "!");
System.exit( 1 );
}
papoLayers[iLayer] = poLayer;
}
}
/* -------------------------------------------------------------------- */
/* Special case to improve user experience when translating into */
/* single file shapefile and source has only one layer, and that */
/* the layer name isn't specified */
/* -------------------------------------------------------------------- */
if (poDriver.GetName().equalsIgnoreCase("ESRI Shapefile") &&
nLayerCount == 1 && pszNewLayerName == null)
{
File f = new File(pszDestDataSource);
if (f.exists() && f.listFiles() == null)
{
pszNewLayerName = f.getName();
int posPoint = pszNewLayerName.lastIndexOf('.');
if (posPoint != -1)
pszNewLayerName = pszNewLayerName.substring(0, posPoint);
}
}
long[] panLayerCountFeatures = new long[nLayerCount];
long nCountLayersFeatures = 0;
long nAccCountFeatures = 0;
/* First pass to apply filters and count all features if necessary */
for( int iLayer = 0;
iLayer < nLayerCount;
iLayer++ )
{
Layer poLayer = papoLayers[iLayer];
if( pszWHERE != null )
{
if( poLayer.SetAttributeFilter( pszWHERE ) != ogr.OGRERR_NONE )
{
System.err.println("FAILURE: SetAttributeFilter(" + pszWHERE + ") failed.");
if (!bSkipFailures)
System.exit( 1 );
}
}
if( poSpatialFilter != null )
poLayer.SetSpatialFilter( poSpatialFilter );
if (bDisplayProgress)
{
if (!poLayer.TestCapability(ogr.OLCFastFeatureCount))
{
System.err.println("Progress turned off as fast feature count is not available.");
bDisplayProgress = false;
}
else
{
panLayerCountFeatures[iLayer] = poLayer.GetFeatureCount();
nCountLayersFeatures += panLayerCountFeatures[iLayer];
}
}
}
/* Second pass to do the real job */
for( int iLayer = 0;
iLayer < nLayerCount;
iLayer++ )
{
Layer poLayer = papoLayers[iLayer];
if (bDisplayProgress)
{
pfnProgress = new GDALScaledProgress(
nAccCountFeatures * 1.0 / nCountLayersFeatures,
(nAccCountFeatures + panLayerCountFeatures[iLayer]) * 1.0 / nCountLayersFeatures,
new TermProgressCallback());
}
nAccCountFeatures += panLayerCountFeatures[iLayer];
if( !TranslateLayer( poDS, poLayer, poODS, papszLCO,