001: /*
002: * The JTS Topology Suite is a collection of Java classes that
003: * implement the fundamental operations required to validate a given
004: * geo-spatial data set to a known topological specification.
005: *
006: * Copyright (C) 2001 Vivid Solutions
007: *
008: * This library is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Lesser General Public
010: * License as published by the Free Software Foundation; either
011: * version 2.1 of the License, or (at your option) any later version.
012: *
013: * This library is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public
019: * License along with this library; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
021: *
022: * For more information, contact:
023: *
024: * Vivid Solutions
025: * Suite #1A
026: * 2328 Government Street
027: * Victoria BC V8T 5G5
028: * Canada
029: *
030: * (250)385-6040
031: * www.vividsolutions.com
032: */
033: package com.vividsolutions.jts.generator;
034:
035: import com.vividsolutions.jts.geom.*;
036:
037: /**
038: * This class illustrates the basic functionality and configuration options for generating spatial data.
039: *
040: * @author David Zwiers, Vivid Solutions.
041: */
042: public abstract class GeometryGenerator {
043: protected int dimensions = 2;
044: protected GeometryFactory geometryFactory; // includes srid
045: protected Envelope boundingBox;
046:
047: /**
048: * @return A Geometry which uses some or all of the Bounding Box specified.
049: */
050: public abstract Geometry create();
051:
052: /**
053: * @see GridGenerator
054: * @return A new GridGenerator
055: */
056: public static GridGenerator createGridGenerator() {
057: return new GridGenerator();
058: }
059:
060: /**
061: * @see PointGenerator
062: * @return A new PointGenerator
063: */
064: public static PointGenerator createPointGenerator() {
065: return new PointGenerator();
066: }
067:
068: /**
069: * @see LineStringGenerator
070: * @return A new LineStringGenerator
071: */
072: public static LineStringGenerator createLineStringGenerator() {
073: LineStringGenerator lsg = new LineStringGenerator();
074: lsg.setGenerationAlgorithm(LineStringGenerator.ARC);
075: lsg.setNumberPoints(10);
076: return lsg;
077: }
078:
079: /**
080: * @see PolygonGenerator
081: * @return A new PolygonGenerator
082: */
083: public static PolygonGenerator createPolygonGenerator() {
084: PolygonGenerator pg = new PolygonGenerator();
085: pg.setGenerationAlgorithm(PolygonGenerator.ARC);
086: pg.setNumberPoints(10);
087: pg.setNumberHoles(8);
088: return pg;
089: }
090:
091: /**
092: * @see PointGenerator
093: * @see MultiGenerator
094: * @return A new MultiGenerator
095: */
096: public static MultiGenerator createMultiPointGenerator() {
097: MultiGenerator mg = new MultiGenerator(createPointGenerator());
098: mg.setNumberGeometries(4);
099: return mg;
100: }
101:
102: /**
103: * @see LineStringGenerator
104: * @see MultiGenerator
105: * @return A new PointGenerator
106: */
107: public static MultiGenerator createMultiLineStringGenerator() {
108: MultiGenerator mg = new MultiGenerator(
109: createLineStringGenerator());
110: mg.setNumberGeometries(4);
111: return mg;
112: }
113:
114: /**
115: * @see PolygonGenerator
116: * @see MultiGenerator
117: * @return A new PointGenerator
118: */
119: public static MultiGenerator createMultiPolygonGenerator() {
120: MultiGenerator mg = new MultiGenerator(createPolygonGenerator());
121: mg.setNumberGeometries(4);
122: return mg;
123: }
124:
125: /**
126: * @return Returns the boundingBox.
127: */
128: public Envelope getBoundingBox() {
129: return boundingBox;
130: }
131:
132: /**
133: * @param boundingBox The boundingBox to set.
134: */
135: public void setBoundingBox(Envelope boundingBox) {
136: this .boundingBox = boundingBox;
137: }
138:
139: /**
140: * @return Returns the dimensions.
141: */
142: public int getDimensions() {
143: return dimensions;
144: }
145:
146: /**
147: * @param dimensions The dimensions to set.
148: */
149: public void setDimensions(int dimensions) {
150: this .dimensions = dimensions;
151: throw new RuntimeException(
152: "Dimensions other than 2 are not yet supported");
153: }
154:
155: /**
156: * @return Returns the geometryFactory.
157: */
158: public GeometryFactory getGeometryFactory() {
159: return geometryFactory;
160: }
161:
162: /**
163: * @param geometryFactory The geometryFactory to set.
164: */
165: public void setGeometryFactory(GeometryFactory geometryFactory) {
166: this.geometryFactory = geometryFactory;
167: }
168:
169: }
|