| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
package org.locationtech.jts.geom.impl; |
| 13 |
|
| 14 |
import java.io.Serializable; |
| 15 |
|
| 16 |
import org.locationtech.jts.geom.Coordinate; |
| 17 |
import org.locationtech.jts.geom.CoordinateSequence; |
| 18 |
import org.locationtech.jts.geom.CoordinateSequenceFactory; |
| 19 |
|
| 20 |
/** |
| 21 |
* Creates {@link CoordinateSequence}s represented as an array of {@link Coordinate}s. |
| 22 |
* |
| 23 |
* @version 1.7 |
| 24 |
*/ |
| 25 |
public final class CoordinateArraySequenceFactory |
| 26 |
implements CoordinateSequenceFactory, Serializable |
| 27 |
{ |
| 28 |
private static final long serialVersionUID = -4099577099607551657L; |
| 29 |
private static final CoordinateArraySequenceFactory instanceObject = new CoordinateArraySequenceFactory(); |
| 30 |
|
| 31 |
private CoordinateArraySequenceFactory() { |
| 32 |
} |
| 33 |
|
| 34 |
private Object readResolve() { |
| 35 |
|
| 36 |
return CoordinateArraySequenceFactory.instance(); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Returns the singleton instance of {@link CoordinateArraySequenceFactory} |
| 41 |
*/ |
| 42 |
public static CoordinateArraySequenceFactory instance() { |
| 43 |
return instanceObject; |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Returns a {@link CoordinateArraySequence} based on the given array (the array is |
| 48 |
* not copied). |
| 49 |
* |
| 50 |
* @param coordinates |
| 51 |
* the coordinates, which may not be null nor contain null |
| 52 |
* elements |
| 53 |
*/ |
| 54 |
public CoordinateSequence create(Coordinate[] coordinates) { |
| 55 |
return new CoordinateArraySequence(coordinates); |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* @see org.locationtech.jts.geom.CoordinateSequenceFactory#create(org.locationtech.jts.geom.CoordinateSequence) |
| 60 |
*/ |
| 61 |
public CoordinateSequence create(CoordinateSequence coordSeq) { |
| 62 |
return new CoordinateArraySequence(coordSeq); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* The created sequence dimension is clamped to be <= 3. |
| 67 |
* |
| 68 |
* @see org.locationtech.jts.geom.CoordinateSequenceFactory#create(int, int) |
| 69 |
* |
| 70 |
*/ |
| 71 |
public CoordinateSequence create(int size, int dimension) { |
| 72 |
if (dimension > 3) |
| 73 |
dimension = 3; |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
if (dimension < 2) |
| 78 |
dimension = 2; |
| 79 |
|
| 80 |
return new CoordinateArraySequence(size, dimension); |
| 81 |
} |
| 82 |
|
| 83 |
public CoordinateSequence create(int size, int dimension, int measures) { |
| 84 |
int spatial = dimension - measures; |
| 85 |
|
| 86 |
if (measures > 1) { |
| 87 |
measures = 1; |
| 88 |
|
| 89 |
} |
| 90 |
if ((spatial) > 3) { |
| 91 |
spatial = 3; |
| 92 |
|
| 93 |
} |
| 94 |
|
| 95 |
if (spatial < 2) |
| 96 |
spatial = 2; |
| 97 |
|
| 98 |
return new CoordinateArraySequence(size, spatial+measures, measures); |
| 99 |
} |
| 100 |
} |
| 101 |
|