001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2004-2006, GeoTools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * Created on 31-dic-2004
017: */
018: package org.geotools.geometry.jts.coordinatesequence;
019:
020: import com.vividsolutions.jts.geom.CoordinateSequence;
021: import com.vividsolutions.jts.geom.impl.PackedCoordinateSequence;
022: import com.vividsolutions.jts.geom.impl.PackedCoordinateSequenceFactory;
023:
024: /**
025: * An implementation of a JTS CSBuilder which uses a PackedCoordinateSequence.
026: *
027: * @author wolf
028: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/main/src/main/java/org/geotools/geometry/jts/coordinatesequence/PackedCSBuilder.java $
029: */
030: public abstract class PackedCSBuilder implements CSBuilder {
031: int size = -1;
032:
033: int dimensions = -1;
034:
035: /**
036: * @see org.geotools.geometry.coordinatesequence.CSBuilder#getSize()
037: */
038: public int getSize() {
039: return size;
040: }
041:
042: /**
043: * @see org.geotools.geometry.coordinatesequence.CSBuilder#getDimension()
044: */
045: public int getDimension() {
046: return dimensions;
047: }
048:
049: public static class Double extends PackedCSBuilder {
050: double[] ordinates;
051:
052: PackedCoordinateSequenceFactory factory = new PackedCoordinateSequenceFactory(
053: PackedCoordinateSequenceFactory.DOUBLE);
054:
055: /**
056: * @see org.geotools.geometry.coordinatesequence.CSBuilder#start(int,
057: * int)
058: */
059: public void start(int size, int dimensions) {
060: ordinates = new double[size * dimensions];
061: this .size = size;
062: this .dimensions = dimensions;
063: }
064:
065: /**
066: * @see org.geotools.geometry.coordinatesequence.CSBuilder#end()
067: */
068: public CoordinateSequence end() {
069: CoordinateSequence cs = factory.create(ordinates,
070: dimensions);
071: ordinates = null;
072: size = -1;
073: dimensions = -1;
074: return cs;
075: }
076:
077: /**
078: * @see org.geotools.geometry.coordinatesequence.CSBuilder#setOrdinate(double,
079: * int, int)
080: */
081: public void setOrdinate(double value, int ordinateIndex,
082: int coordinateIndex) {
083: ordinates[coordinateIndex * dimensions + ordinateIndex] = value;
084: }
085:
086: /**
087: * @see org.geotools.geometry.coordinatesequence.CSBuilder#getOrdinate(int,
088: * int)
089: */
090: public double getOrdinate(int ordinateIndex, int coordinateIndex) {
091: return ordinates[coordinateIndex * dimensions
092: + ordinateIndex];
093: }
094:
095: /**
096: * @see org.geotools.geometry.coordinatesequence.CSBuilder#setOrdinate(com.vividsolutions.jts.geom.CoordinateSequence, double, int, int)
097: */
098: public void setOrdinate(CoordinateSequence sequence,
099: double value, int ordinateIndex, int coordinateIndex) {
100: PackedCoordinateSequence pcs = (PackedCoordinateSequence) sequence;
101: pcs.setOrdinate(coordinateIndex, ordinateIndex, value);
102: }
103:
104: }
105:
106: public static class Float extends PackedCSBuilder {
107: float[] ordinates;
108:
109: PackedCoordinateSequenceFactory factory = new PackedCoordinateSequenceFactory(
110: PackedCoordinateSequenceFactory.FLOAT);
111:
112: /**
113: * @see org.geotools.geometry.coordinatesequence.CSBuilder#start(int,
114: * int)
115: */
116: public void start(int size, int dimensions) {
117: ordinates = new float[size * dimensions];
118: this .size = size;
119: this .dimensions = dimensions;
120: }
121:
122: /**
123: * @see org.geotools.geometry.coordinatesequence.CSBuilder#end()
124: */
125: public CoordinateSequence end() {
126: CoordinateSequence cs = factory.create(ordinates,
127: dimensions);
128: ordinates = null;
129: size = -1;
130: dimensions = -1;
131: return cs;
132: }
133:
134: /**
135: * @see org.geotools.geometry.coordinatesequence.CSBuilder#setOrdinate(double,
136: * int, int)
137: */
138: public void setOrdinate(double value, int ordinateIndex,
139: int coordinateIndex) {
140: ordinates[coordinateIndex * dimensions + ordinateIndex] = (float) value;
141: }
142:
143: /**
144: * @see org.geotools.geometry.coordinatesequence.CSBuilder#setOrdinate(com.vividsolutions.jts.geom.CoordinateSequence, double, int, int)
145: */
146: public void setOrdinate(CoordinateSequence sequence,
147: double value, int ordinateIndex, int coordinateIndex) {
148: PackedCoordinateSequence pcs = (PackedCoordinateSequence) sequence;
149: pcs.setOrdinate(coordinateIndex, ordinateIndex, value);
150: }
151:
152: /**
153: * @see org.geotools.geometry.coordinatesequence.CSBuilder#getOrdinate(int,
154: * int)
155: */
156: public double getOrdinate(int ordinateIndex, int coordinateIndex) {
157: return ordinates[coordinateIndex * dimensions
158: + ordinateIndex];
159: }
160:
161: }
162:
163: }
|