com.vividsolutions.jtsexample.geom.ConstructionExample Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jts Show documentation
Show all versions of jts Show documentation
The JTS Topology Suite is an API for modelling and
manipulating 2-dimensional linear geometry. It provides
numerous geometric predicates and functions. JTS
conforms to the Simple Features Specification for
SQL published by the Open GIS Consortium.
package com.vividsolutions.jtsexample.geom;
import com.vividsolutions.jts.geom.*;
/**
* Examples of constructing Geometries programmatically.
*
* The Best Practice moral here is:
*
* Use the GeometryFactory to construct Geometries whenever possible.
*
* This has several advantages:
*
* - Simplifies your code
*
- allows you to take advantage of convenience methods provided by GeometryFactory
*
- Insulates your code from changes in the signature of JTS constructors
*
*
* @version 1.7
*/
public class ConstructionExample
{
public static void main(String[] args)
throws Exception
{
// create a factory using default values (e.g. floating precision)
GeometryFactory fact = new GeometryFactory();
Point p1 = fact.createPoint(new Coordinate(0,0));
System.out.println(p1);
Point p2 = fact.createPoint(new Coordinate(1,1));
System.out.println(p2);
MultiPoint mpt = fact.createMultiPoint(new Coordinate[] { new Coordinate(0,0), new Coordinate(1,1) } );
System.out.println(mpt);
}
}