(String srcDS, String srcSQL, String srcLyr,
String srcWhere)
| 371 | * returns a collection of read geometries. |
| 372 | */ |
| 373 | static Geometry LoadGeometry(String srcDS, String srcSQL, String srcLyr, |
| 374 | String srcWhere) { |
| 375 | |
| 376 | DataSource DS; |
| 377 | Layer lyr; |
| 378 | Feature feat; |
| 379 | Geometry geom = null; |
| 380 | |
| 381 | DS = ogr.Open(srcDS, false); |
| 382 | |
| 383 | if (DS == null) { |
| 384 | |
| 385 | return null; |
| 386 | } |
| 387 | |
| 388 | if (srcSQL != null) { |
| 389 | |
| 390 | lyr = DS.ExecuteSQL(srcSQL, null, null); |
| 391 | } else if (srcLyr != null) { |
| 392 | |
| 393 | lyr = DS.GetLayerByName(srcLyr); |
| 394 | } else { |
| 395 | |
| 396 | lyr = DS.GetLayer(0); |
| 397 | } |
| 398 | |
| 399 | if (lyr == null) { |
| 400 | |
| 401 | System.err |
| 402 | .println("Failed to identify source layer from datasource."); |
| 403 | DS.delete(); |
| 404 | return null; |
| 405 | } |
| 406 | |
| 407 | if (srcWhere != null) { |
| 408 | |
| 409 | lyr.SetAttributeFilter(srcWhere); |
| 410 | } |
| 411 | |
| 412 | while ((feat = lyr.GetNextFeature()) != null) { |
| 413 | |
| 414 | Geometry srcGeom = feat.GetGeometryRef(); |
| 415 | |
| 416 | if (srcGeom != null) { |
| 417 | |
| 418 | int srcType = srcGeom.GetGeometryType() |
| 419 | & (~ogrConstants.wkb25DBit); |
| 420 | |
| 421 | if (geom == null) { |
| 422 | |
| 423 | geom = new Geometry(ogr.wkbMultiPolygon); |
| 424 | } |
| 425 | |
| 426 | if (srcType == ogr.wkbPolygon) { |
| 427 | |
| 428 | geom.AddGeometry(srcGeom); |
| 429 | } else if (srcType == ogr.wkbMultiPolygon) { |
| 430 |
no test coverage detected