~ubuntu-branches/ubuntu/natty/jts/natty

« back to all changes in this revision

Viewing changes to src/com/vividsolutions/jtsexample/precision/EnhancedPrecisionOpExample.java

  • Committer: Bazaar Package Importer
  • Author(s): Wolfgang Baer
  • Date: 2005-08-07 14:12:35 UTC
  • Revision ID: james.westby@ubuntu.com-20050807141235-7hy3ll3xpq79djcb
Tags: upstream-1.6
ImportĀ upstreamĀ versionĀ 1.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
3
 * The JTS Topology Suite is a collection of Java classes that
 
4
 * implement the fundamental operations required to validate a given
 
5
 * geo-spatial data set to a known topological specification.
 
6
 *
 
7
 * Copyright (C) 2001 Vivid Solutions
 
8
 *
 
9
 * This library is free software; you can redistribute it and/or
 
10
 * modify it under the terms of the GNU Lesser General Public
 
11
 * License as published by the Free Software Foundation; either
 
12
 * version 2.1 of the License, or (at your option) any later version.
 
13
 *
 
14
 * This library is distributed in the hope that it will be useful,
 
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
17
 * Lesser General Public License for more details.
 
18
 *
 
19
 * You should have received a copy of the GNU Lesser General Public
 
20
 * License along with this library; if not, write to the Free Software
 
21
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
22
 *
 
23
 * For more information, contact:
 
24
 *
 
25
 *     Vivid Solutions
 
26
 *     Suite #1A
 
27
 *     2328 Government Street
 
28
 *     Victoria BC  V8T 5G5
 
29
 *     Canada
 
30
 *
 
31
 *     (250)385-6040
 
32
 *     www.vividsolutions.com
 
33
 */
 
34
package com.vividsolutions.jtsexample.precision;
 
35
 
 
36
import java.io.*;
 
37
import java.util.*;
 
38
import com.vividsolutions.jts.io.WKTReader;
 
39
import com.vividsolutions.jts.geom.*;
 
40
import com.vividsolutions.jts.precision.EnhancedPrecisionOp;
 
41
 
 
42
/**
 
43
 * Example of using {@link EnhancedPrecisionOp} to avoid robustness problems
 
44
 *
 
45
 * @version 1.6
 
46
 */
 
47
public class EnhancedPrecisionOpExample
 
48
{
 
49
  public static void main(String[] args) throws Exception
 
50
  {
 
51
    EnhancedPrecisionOpExample example = new EnhancedPrecisionOpExample();
 
52
    try {
 
53
      example.run();
 
54
    }
 
55
    catch (Exception ex) {
 
56
      ex.printStackTrace();
 
57
    }
 
58
  }
 
59
 
 
60
  private WKTReader reader = new WKTReader();
 
61
 
 
62
  public EnhancedPrecisionOpExample() {
 
63
  }
 
64
 
 
65
  void run()
 
66
      throws Exception
 
67
  {
 
68
    String wkt1, wkt2;
 
69
    // two geometries which cause robustness problems
 
70
    wkt1 = "POLYGON ((708653.498611049 2402311.54647056, 708708.895756966 2402203.47250014, 708280.326454234 2402089.6337791, 708247.896591321 2402252.48269854, 708367.379593851 2402324.00761653, 708248.882609455 2402253.07294874, 708249.523621829 2402244.3124463, 708261.854734465 2402182.39086576, 708262.818392579 2402183.35452387, 708653.498611049 2402311.54647056))";
 
71
    wkt2 = "POLYGON ((708258.754920656 2402197.91172757, 708257.029447455 2402206.56901508, 708652.961095455 2402312.65463437, 708657.068786251 2402304.6356364, 708258.754920656 2402197.91172757))";
 
72
    Geometry g1 = reader.read(wkt1);
 
73
    Geometry g2 = reader.read(wkt2);
 
74
 
 
75
    System.out.println("This call to intersection will throw a topology exception due to robustness problems:");
 
76
    try {
 
77
      Geometry result = g1.intersection(g2);
 
78
    }
 
79
    catch (TopologyException ex) {
 
80
      ex.printStackTrace();
 
81
    }
 
82
 
 
83
    System.out.println("Using EnhancedPrecisionOp allows the intersection to be performed with no errors:");
 
84
    Geometry result = EnhancedPrecisionOp.intersection(g1, g2);
 
85
    System.out.println(result);
 
86
  }
 
87
 
 
88
 
 
89
}