01: package com.vividsolutions.jtsexample.geom;
02:
03: import com.vividsolutions.jts.geom.*;
04:
05: /**
06: * Examples of constructing Geometries programmatically.
07: * <p>
08: * The Best Practice moral here is:
09: * <quote>
10: * Use the GeometryFactory to construct Geometries whenever possible.
11: * </quote>
12: * This has several advantages:
13: * <ol>
14: * <li>Simplifies your code
15: * <li>allows you to take advantage of convenience methods provided by GeometryFactory
16: * <li>Insulates your code from changes in the signature of JTS constructors
17: * </ol>
18: *
19: * @version 1.7
20: */
21: public class ConstructionExample {
22:
23: public static void main(String[] args) throws Exception {
24: // create a factory using default values (e.g. floating precision)
25: GeometryFactory fact = new GeometryFactory();
26:
27: Point p1 = fact.createPoint(new Coordinate(0, 0));
28: System.out.println(p1);
29:
30: Point p2 = fact.createPoint(new Coordinate(1, 1));
31: System.out.println(p1);
32:
33: MultiPoint mpt = fact.createMultiPoint(new Coordinate[] {
34: new Coordinate(0, 0), new Coordinate(1, 1) });
35: System.out.println(mpt);
36:
37: }
38: }
|