/****************************************************************************** * $Id$ * * Name: OGRLayerAlg.cs * Project: GDAL CSharp Interface * Purpose: A sample app to demonstrate the usage of the RFC-39 functions. * Author: Tamas Szekeres, szekerest@gmail.com * ****************************************************************************** * Copyright (c) 2013, Tamas Szekeres * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. *****************************************************************************/ using System; using OSGeo.OGR; /** *

Title: OGR C# OGRLayerAlg example.

*

Description: A sample app to demonstrate the usage of the RFC-39 functions.

* @author Tamas Szekeres (szekerest@gmail.com) * @version 1.0 */ /// /// A sample app to demonstrate the usage of the RFC-39 functions. /// class OGRLayerAlg { public static void usage() { Console.WriteLine("usage: ogrlayeralg {function} {Data Source 1} {layer1} {Data Source 2} {layer2} {Result Data Source Name} {Result Layer Name} [{Options}]"); Console.WriteLine("example: ogrlayeralg Union data1.shp layer1 data.shp layer2 result.shp resultlayer SKIP_FAILURES=YES"); System.Environment.Exit(-1); } public static void Main(string[] args) { if (args.Length <= 6) usage(); Console.WriteLine(""); try { /* -------------------------------------------------------------------- */ /* Register driver(s). */ /* -------------------------------------------------------------------- */ Ogr.RegisterAll(); /* -------------------------------------------------------------------- */ /* Open data source. */ /* -------------------------------------------------------------------- */ DataSource ds1 = Ogr.Open(args[1], 0); if (ds1 == null) { Console.WriteLine("Can't open " + args[1]); System.Environment.Exit(-1); } Layer layer1 = ds1.GetLayerByName(args[2]); if (layer1 == null) { Console.WriteLine("FAILURE: Couldn't fetch layer " + args[2]); System.Environment.Exit(-1); } DataSource ds2 = Ogr.Open(args[3], 0); if (ds2 == null) { Console.WriteLine("Can't open " + args[3]); System.Environment.Exit(-1); } Layer layer2 = ds2.GetLayerByName(args[4]); if (layer2 == null) { Console.WriteLine("FAILURE: Couldn't fetch layer " + args[4]); System.Environment.Exit(-1); } /* -------------------------------------------------------------------- */ /* Get driver for creating the result ds */ /* -------------------------------------------------------------------- */ Driver drv = Ogr.GetDriverByName("ESRI Shapefile"); if (drv == null) { Console.WriteLine("Can't get driver."); System.Environment.Exit(-1); } /* -------------------------------------------------------------------- */ /* Creating the datasource */ /* -------------------------------------------------------------------- */ DataSource ds = drv.CreateDataSource( args[5], new string[] {} ); if (drv == null) { Console.WriteLine("Can't create the datasource."); System.Environment.Exit(-1); } /* -------------------------------------------------------------------- */ /* Process options */ /* -------------------------------------------------------------------- */ string[] options = null; if (args.Length > 7) { options = new string[args.Length - 7]; Array.Copy(args, 7, options, 0, args.Length - 7); } /* -------------------------------------------------------------------- */ /* Creating the layer */ /* -------------------------------------------------------------------- */ Layer layer; int i; for(i=0;i