String pszSourceSRSDef = null;
SpatialReference poOutputSRS = null;
SpatialReference poSourceSRS = null;
String pszNewLayerName = null;
String pszWHERE = null;
Geometry poSpatialFilter = null;
String pszSelect;
Vector papszSelFields = null;
String pszSQLStatement = null;
int eGType = -2;
GeomOperation eGeomOp = GeomOperation.NONE;
double dfGeomOpParam = 0;
Vector papszFieldTypesToString = new Vector();
boolean bDisplayProgress = false;
ProgressCallback pfnProgress = null;
boolean bClipSrc = false;
Geometry poClipSrc = null;
String pszClipSrcDS = null;
String pszClipSrcSQL = null;
String pszClipSrcLayer = null;
String pszClipSrcWhere = null;
Geometry poClipDst = null;
String pszClipDstDS = null;
String pszClipDstSQL = null;
String pszClipDstLayer = null;
String pszClipDstWhere = null;
String pszSrcEncoding = null;
String pszDstEncoding = null;
boolean bExplodeCollections = false;
String pszZField = null;
ogr.DontUseExceptions();
/* -------------------------------------------------------------------- */
/* Register format(s). */
/* -------------------------------------------------------------------- */
if( ogr.GetDriverCount() == 0 )
ogr.RegisterAll();
/* -------------------------------------------------------------------- */
/* Processing command line arguments. */
/* -------------------------------------------------------------------- */
args = ogr.GeneralCmdLineProcessor( args );
if( args.length < 2 )
{
Usage();
System.exit( -1 );
}
for( int iArg = 0; iArg < args.length; iArg++ )
{
if( args[iArg].equalsIgnoreCase("-f") && iArg < args.length-1 )
{
pszFormat = args[++iArg];
}
else if( args[iArg].equalsIgnoreCase("-dsco") && iArg < args.length-1 )
{
papszDSCO.addElement(args[++iArg] );
}
else if( args[iArg].equalsIgnoreCase("-lco") && iArg < args.length-1 )
{
papszLCO.addElement(args[++iArg] );
}
else if( args[iArg].equalsIgnoreCase("-preserve_fid") )
{
bPreserveFID = true;
}
else if( args[iArg].length() >= 5 && args[iArg].substring(0, 5).equalsIgnoreCase("-skip") )
{
bSkipFailures = true;
nGroupTransactions = 1; /* #2409 */
}
else if( args[iArg].equalsIgnoreCase("-append") )
{
bAppend = true;
bUpdate = true;
}
else if( args[iArg].equalsIgnoreCase("-overwrite") )
{
bOverwrite = true;
bUpdate = true;
}
else if( args[iArg].equalsIgnoreCase("-update") )
{
bUpdate = true;
}
else if( args[iArg].equalsIgnoreCase("-fid") && args[iArg+1] != null )
{
nFIDToFetch = Integer.parseInt(args[++iArg]);
}
else if( args[iArg].equalsIgnoreCase("-sql") && args[iArg+1] != null )
{
pszSQLStatement = args[++iArg];
}
else if( args[iArg].equalsIgnoreCase("-nln") && iArg < args.length-1 )
{
pszNewLayerName = args[++iArg];
}
else if( args[iArg].equalsIgnoreCase("-nlt") && iArg < args.length-1 )
{
if( args[iArg+1].equalsIgnoreCase("NONE") )
eGType = ogr.wkbNone;
else if( args[iArg+1].equalsIgnoreCase("GEOMETRY") )
eGType = ogr.wkbUnknown;
else if( args[iArg+1].equalsIgnoreCase("POINT") )
eGType = ogr.wkbPoint;
else if( args[iArg+1].equalsIgnoreCase("LINESTRING") )
eGType = ogr.wkbLineString;
else if( args[iArg+1].equalsIgnoreCase("POLYGON") )
eGType = ogr.wkbPolygon;
else if( args[iArg+1].equalsIgnoreCase("GEOMETRYCOLLECTION") )
eGType = ogr.wkbGeometryCollection;
else if( args[iArg+1].equalsIgnoreCase("MULTIPOINT") )
eGType = ogr.wkbMultiPoint;
else if( args[iArg+1].equalsIgnoreCase("MULTILINESTRING") )
eGType = ogr.wkbMultiLineString;
else if( args[iArg+1].equalsIgnoreCase("MULTIPOLYGON") )
eGType = ogr.wkbMultiPolygon;
else if( args[iArg+1].equalsIgnoreCase("GEOMETRY25D") )
eGType = ogr.wkbUnknown | ogr.wkb25DBit;
else if( args[iArg+1].equalsIgnoreCase("POINT25D") )
eGType = ogr.wkbPoint25D;
else if( args[iArg+1].equalsIgnoreCase("LINESTRING25D") )
eGType = ogr.wkbLineString25D;
else if( args[iArg+1].equalsIgnoreCase("POLYGON25D") )
eGType = ogr.wkbPolygon25D;
else if( args[iArg+1].equalsIgnoreCase("GEOMETRYCOLLECTION25D") )
eGType = ogr.wkbGeometryCollection25D;
else if( args[iArg+1].equalsIgnoreCase("MULTIPOINT25D") )
eGType = ogr.wkbMultiPoint25D;
else if( args[iArg+1].equalsIgnoreCase("MULTILINESTRING25D") )
eGType = ogr.wkbMultiLineString25D;
else if( args[iArg+1].equalsIgnoreCase("MULTIPOLYGON25D") )
eGType = ogr.wkbMultiPolygon25D;
else
{
System.err.println("-nlt " + args[iArg+1] + ": type not recognised.");
System.exit( 1 );
}
iArg++;
}
else if( (args[iArg].equalsIgnoreCase("-tg") ||
args[iArg].equalsIgnoreCase("-gt")) && iArg < args.length-1 )
{
nGroupTransactions = Integer.parseInt(args[++iArg]);
}
else if( args[iArg].equalsIgnoreCase("-s_srs") && iArg < args.length-1 )
{
pszSourceSRSDef = args[++iArg];
}
else if( args[iArg].equalsIgnoreCase("-a_srs") && iArg < args.length-1 )
{
pszOutputSRSDef = args[++iArg];
}
else if( args[iArg].equalsIgnoreCase("-t_srs") && iArg < args.length-1 )
{
pszOutputSRSDef = args[++iArg];
bTransform = true;
}
else if (args[iArg].equalsIgnoreCase("-spat") && iArg + 4 < args.length)
{
Geometry oRing = new Geometry(ogrConstants.wkbLinearRing);
double xmin = new Double(args[++iArg]).doubleValue();
double ymin = new Double(args[++iArg]).doubleValue();
double xmax = new Double(args[++iArg]).doubleValue();
double ymax = new Double(args[++iArg]).doubleValue();
oRing.AddPoint(xmin, ymin);
oRing.AddPoint(xmin, ymax);
oRing.AddPoint(xmax, ymax);
oRing.AddPoint(xmax, ymin);
oRing.AddPoint(xmin, ymin);
poSpatialFilter = new Geometry(ogrConstants.wkbPolygon);
poSpatialFilter.AddGeometry(oRing);
}
else if( args[iArg].equalsIgnoreCase("-where") && args[iArg+1] != null )
{
pszWHERE = args[++iArg];
}
else if( args[iArg].equalsIgnoreCase("-select") && args[iArg+1] != null)
{
pszSelect = args[++iArg];
StringTokenizer tokenizer = new StringTokenizer(pszSelect, " ,");
papszSelFields = new Vector();
while(tokenizer.hasMoreElements())
papszSelFields.addElement(tokenizer.nextToken());
}
else if( args[iArg].equalsIgnoreCase("-simplify") && iArg < args.length-1 )
{
eGeomOp = GeomOperation.SIMPLIFY_PRESERVE_TOPOLOGY;
dfGeomOpParam = new Double(args[++iArg]).doubleValue();
}
else if( args[iArg].equalsIgnoreCase("-segmentize") && iArg < args.length-1 )
{
eGeomOp = GeomOperation.SEGMENTIZE;
dfGeomOpParam = new Double(args[++iArg]).doubleValue();
}
else if( args[iArg].equalsIgnoreCase("-fieldTypeToString") && iArg < args.length-1 )
{
StringTokenizer tokenizer = new StringTokenizer(args[++iArg], " ,");
while(tokenizer.hasMoreElements())
{
String token = (String)tokenizer.nextToken();
if (token.equalsIgnoreCase("Integer") ||
token.equalsIgnoreCase("Real") ||
token.equalsIgnoreCase("String") ||
token.equalsIgnoreCase("Date") ||
token.equalsIgnoreCase("Time") ||
token.equalsIgnoreCase("DateTime") ||
token.equalsIgnoreCase("Binary") ||
token.equalsIgnoreCase("IntegerList") ||
token.equalsIgnoreCase("RealList") ||
token.equalsIgnoreCase("StringList"))
{
papszFieldTypesToString.addElement(token);
}
else if (token.equalsIgnoreCase("All"))
{
papszFieldTypesToString = null;
papszFieldTypesToString.addElement("All");
break;
}
else
{
System.err.println("Unhandled type for fieldtypeasstring option : " + token);
Usage();
}
}
}
else if( args[iArg].equalsIgnoreCase("-progress") )
{
bDisplayProgress = true;
}
/*else if( args[iArg].equalsIgnoreCase("-wrapdateline") )
{
bWrapDateline = true;
}
*/
else if( args[iArg].equalsIgnoreCase("-clipsrc") && iArg < args.length-1 )
{
bClipSrc = true;
if ( IsNumber(args[iArg+1]) && iArg < args.length - 4 )
{
Geometry oRing = new Geometry(ogrConstants.wkbLinearRing);
double xmin = new Double(args[++iArg]).doubleValue();
double ymin = new Double(args[++iArg]).doubleValue();
double xmax = new Double(args[++iArg]).doubleValue();
double ymax = new Double(args[++iArg]).doubleValue();
oRing.AddPoint(xmin, ymin);
oRing.AddPoint(xmin, ymax);
oRing.AddPoint(xmax, ymax);
oRing.AddPoint(xmax, ymin);
oRing.AddPoint(xmin, ymin);
poClipSrc = new Geometry(ogrConstants.wkbPolygon);
poClipSrc.AddGeometry(oRing);
}
else if( (args[iArg+1].length() >= 7 && args[iArg+1].substring(0, 7).equalsIgnoreCase("POLYGON") ) ||
(args[iArg+1].length() >= 12 && args[iArg+1].substring(0, 12).equalsIgnoreCase("MULTIPOLYGON") ) )
{
poClipSrc = Geometry.CreateFromWkt(args[iArg+1]);
if (poClipSrc == null)
{
System.err.print("FAILURE: Invalid geometry. Must be a valid POLYGON or MULTIPOLYGON WKT\n\n");
Usage();
}
iArg ++;
}
else if (args[iArg+1].equalsIgnoreCase("spat_extent") )
{
iArg ++;
}
else
{
pszClipSrcDS = args[iArg+1];
iArg ++;
}
}
else if( args[iArg].equalsIgnoreCase("-clipsrcsql") && iArg < args.length-1 )
{
pszClipSrcSQL = args[iArg+1];
iArg ++;
}
else if( args[iArg].equalsIgnoreCase("-clipsrclayer") && iArg < args.length-1 )
{
pszClipSrcLayer = args[iArg+1];
iArg ++;
}
else if( args[iArg].equalsIgnoreCase("-clipsrcwhere") && iArg < args.length-1 )
{
pszClipSrcWhere = args[iArg+1];
iArg ++;
}
else if( args[iArg].equalsIgnoreCase("-clipdst") && iArg < args.length-1 )
{
if ( IsNumber(args[iArg+1]) && iArg < args.length - 4 )
{
Geometry oRing = new Geometry(ogrConstants.wkbLinearRing);
double xmin = new Double(args[++iArg]).doubleValue();
double ymin = new Double(args[++iArg]).doubleValue();
double xmax = new Double(args[++iArg]).doubleValue();
double ymax = new Double(args[++iArg]).doubleValue();
oRing.AddPoint(xmin, ymin);
oRing.AddPoint(xmin, ymax);
oRing.AddPoint(xmax, ymax);
oRing.AddPoint(xmax, ymin);
oRing.AddPoint(xmin, ymin);
poClipDst = new Geometry(ogrConstants.wkbPolygon);
poClipDst.AddGeometry(oRing);
}
else if( (args[iArg+1].length() >= 7 && args[iArg+1].substring(0, 7).equalsIgnoreCase("POLYGON") ) ||
(args[iArg+1].length() >= 12 && args[iArg+1].substring(0, 12).equalsIgnoreCase("MULTIPOLYGON") ) )
{