001:
002: /*
003: * The JTS Topology Suite is a collection of Java classes that
004: * implement the fundamental operations required to validate a given
005: * geo-spatial data set to a known topological specification.
006: *
007: * Copyright (C) 2001 Vivid Solutions
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
022: *
023: * For more information, contact:
024: *
025: * Vivid Solutions
026: * Suite #1A
027: * 2328 Government Street
028: * Victoria BC V8T 5G5
029: * Canada
030: *
031: * (250)385-6040
032: * www.vividsolutions.com
033: */
034: package com.vividsolutions.jts.geom;
035:
036: /**
037: * Models an OGC SFS <code>LinearRing</code>.
038: * A LinearRing is a LineString which is both closed and simple.
039: * In other words,
040: * the first and last coordinate in the ring must be equal,
041: * and the interior of the ring must not self-intersect.
042: * Either orientation of the ring is allowed.
043: *
044: * @version 1.7
045: */
046: public class LinearRing extends LineString {
047: private static final long serialVersionUID = -4261142084085851829L;
048:
049: /**
050: * Constructs a <code>LinearRing</code> with the given points.
051: *
052: *@param points points forming a closed and simple linestring, or
053: * <code>null</code> or an empty array to create the empty geometry.
054: * This array must not contain <code>null</code> elements.
055: *
056: *@param precisionModel the specification of the grid of allowable points
057: * for this <code>LinearRing</code>
058: *@param SRID the ID of the Spatial Reference System used by this
059: * <code>LinearRing</code>
060: * @deprecated Use GeometryFactory instead
061: */
062: public LinearRing(Coordinate points[],
063: PrecisionModel precisionModel, int SRID) {
064: this (points, new GeometryFactory(precisionModel, SRID));
065: validateConstruction();
066: }
067:
068: /**
069: * This method is ONLY used to avoid deprecation warnings.
070: * @param points
071: * @param factory
072: */
073: private LinearRing(Coordinate points[], GeometryFactory factory) {
074: this (factory.getCoordinateSequenceFactory().create(points),
075: factory);
076: }
077:
078: /**
079: * Constructs a <code>LinearRing</code> with the vertices
080: * specifed by the given {@link CoordinateSequence}.
081: *
082: *@param points a sequence points forming a closed and simple linestring, or
083: * <code>null</code> to create the empty geometry.
084: *
085: */
086: public LinearRing(CoordinateSequence points, GeometryFactory factory) {
087: super (points, factory);
088: validateConstruction();
089: }
090:
091: private void validateConstruction() {
092: if (!isEmpty() && !super .isClosed()) {
093: throw new IllegalArgumentException(
094: "points must form a closed linestring");
095: }
096: if (getCoordinateSequence().size() >= 1
097: && getCoordinateSequence().size() <= 3) {
098: throw new IllegalArgumentException(
099: "Number of points must be 0 or >3");
100: }
101: }
102:
103: /**
104: * Returns <code>Dimension.FALSE</code>, since by definition LinearRings do
105: * not have a boundary.
106: *
107: * @return Dimension.FALSE
108: */
109: public int getBoundaryDimension() {
110: return Dimension.FALSE;
111: }
112:
113: /**
114: * Returns <code>true</code>, since by definition LinearRings are always simple.
115: * @return <code>true</code>
116: *
117: * @see Geometry#isSimple
118: */
119: public boolean isSimple() {
120: return true;
121: }
122:
123: public String getGeometryType() {
124: return "LinearRing";
125: }
126:
127: }
|