提交 c47184ef authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Combine flags into dimension system in EWKTUtils

上级 c7830320
...@@ -577,7 +577,7 @@ public final class EWKTUtils { ...@@ -577,7 +577,7 @@ public final class EWKTUtils {
* output target * output target
*/ */
public static void parseEWKT(String ewkt, Target target) { public static void parseEWKT(String ewkt, Target target) {
parseEWKT(new EWKTSource(ewkt), target, 0, false, false); parseEWKT(new EWKTSource(ewkt), target, 0, 0);
} }
/** /**
...@@ -589,12 +589,10 @@ public final class EWKTUtils { ...@@ -589,12 +589,10 @@ public final class EWKTUtils {
* output target * output target
* @param parentType * @param parentType
* type of parent geometry collection, or 0 for the root geometry * type of parent geometry collection, or 0 for the root geometry
* @param useZ * @param dimensionSystem
* parent geometry uses dimension Z * dimension system of parent geometry
* @param useM
* parent geometry uses dimension M
*/ */
private static void parseEWKT(EWKTSource source, Target target, int parentType, boolean useZ, boolean useM) { private static void parseEWKT(EWKTSource source, Target target, int parentType, int dimensionSystem) {
if (parentType == 0) { if (parentType == 0) {
target.init(source.readSRID()); target.init(source.readSRID());
} }
...@@ -602,13 +600,7 @@ public final class EWKTUtils { ...@@ -602,13 +600,7 @@ public final class EWKTUtils {
switch (parentType) { switch (parentType) {
default: { default: {
type = source.readType(); type = source.readType();
int ds = source.readDimensionSystem(); dimensionSystem = source.readDimensionSystem();
if ((ds & DIMENSION_SYSTEM_XYZ) != 0) {
useZ = true;
}
if ((ds & DIMENSION_SYSTEM_XYM) != 0) {
useM = true;
}
break; break;
} }
case MULTI_POINT: case MULTI_POINT:
...@@ -631,7 +623,7 @@ public final class EWKTUtils { ...@@ -631,7 +623,7 @@ public final class EWKTUtils {
if (empty) { if (empty) {
target.addCoordinate(Double.NaN, Double.NaN, Double.NaN, Double.NaN, 0, 1); target.addCoordinate(Double.NaN, Double.NaN, Double.NaN, Double.NaN, 0, 1);
} else { } else {
addCoordinate(source, target, useZ, useM, 0, 1); addCoordinate(source, target, dimensionSystem, 0, 1);
source.read(')'); source.read(')');
} }
break; break;
...@@ -646,7 +638,7 @@ public final class EWKTUtils { ...@@ -646,7 +638,7 @@ public final class EWKTUtils {
} else { } else {
ArrayList<double[]> coordinates = new ArrayList<>(); ArrayList<double[]> coordinates = new ArrayList<>();
do { do {
coordinates.add(readCoordinate(source, useZ, useM)); coordinates.add(readCoordinate(source, dimensionSystem));
} while (source.hasMoreCoordinates()); } while (source.hasMoreCoordinates());
int numPoints = coordinates.size(); int numPoints = coordinates.size();
if (numPoints < 0 || numPoints == 1) { if (numPoints < 0 || numPoints == 1) {
...@@ -668,10 +660,10 @@ public final class EWKTUtils { ...@@ -668,10 +660,10 @@ public final class EWKTUtils {
if (empty) { if (empty) {
target.startPolygon(0, 0); target.startPolygon(0, 0);
} else { } else {
ArrayList<double[]> outer = readRing(source, useZ, useM); ArrayList<double[]> outer = readRing(source, dimensionSystem);
ArrayList<ArrayList<double[]>> inner = new ArrayList<>(); ArrayList<ArrayList<double[]>> inner = new ArrayList<>();
while (source.hasMoreCoordinates()) { while (source.hasMoreCoordinates()) {
inner.add(readRing(source, useZ, useM)); inner.add(readRing(source, dimensionSystem));
} }
int numInner = inner.size(); int numInner = inner.size();
int size = outer.size(); int size = outer.size();
...@@ -684,7 +676,7 @@ public final class EWKTUtils { ...@@ -684,7 +676,7 @@ public final class EWKTUtils {
} }
target.startPolygon(numInner, size); target.startPolygon(numInner, size);
if (size > 0) { if (size > 0) {
addRing(outer, target, useZ, useM); addRing(outer, target);
for (int i = 0; i < numInner; i++) { for (int i = 0; i < numInner; i++) {
ArrayList<double[]> ring = inner.get(i); ArrayList<double[]> ring = inner.get(i);
size = ring.size(); size = ring.size();
...@@ -693,7 +685,7 @@ public final class EWKTUtils { ...@@ -693,7 +685,7 @@ public final class EWKTUtils {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
target.startPolygonInner(size); target.startPolygonInner(size);
addRing(ring, target, useZ, useM); addRing(ring, target);
} }
target.endNonEmptyPolygon(); target.endNonEmptyPolygon();
} }
...@@ -701,16 +693,16 @@ public final class EWKTUtils { ...@@ -701,16 +693,16 @@ public final class EWKTUtils {
break; break;
} }
case MULTI_POINT: case MULTI_POINT:
parseCollection(source, target, MULTI_POINT, parentType, useZ, useM); parseCollection(source, target, MULTI_POINT, parentType, dimensionSystem);
break; break;
case MULTI_LINE_STRING: case MULTI_LINE_STRING:
parseCollection(source, target, MULTI_LINE_STRING, parentType, useZ, useM); parseCollection(source, target, MULTI_LINE_STRING, parentType, dimensionSystem);
break; break;
case MULTI_POLYGON: case MULTI_POLYGON:
parseCollection(source, target, MULTI_POLYGON, parentType, useZ, useM); parseCollection(source, target, MULTI_POLYGON, parentType, dimensionSystem);
break; break;
case GEOMETRY_COLLECTION: case GEOMETRY_COLLECTION:
parseCollection(source, target, GEOMETRY_COLLECTION, parentType, useZ, useM); parseCollection(source, target, GEOMETRY_COLLECTION, parentType, 0);
break; break;
default: default:
throw new IllegalArgumentException(); throw new IllegalArgumentException();
...@@ -720,8 +712,8 @@ public final class EWKTUtils { ...@@ -720,8 +712,8 @@ public final class EWKTUtils {
} }
} }
private static void parseCollection(EWKTSource source, Target target, int type, int parentType, boolean useZ, private static void parseCollection(EWKTSource source, Target target, int type, int parentType,
boolean useM) { int dimensionSystem) {
if (parentType != 0 && parentType != GEOMETRY_COLLECTION) { if (parentType != 0 && parentType != GEOMETRY_COLLECTION) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
...@@ -729,7 +721,7 @@ public final class EWKTUtils { ...@@ -729,7 +721,7 @@ public final class EWKTUtils {
target.startCollection(type, 0); target.startCollection(type, 0);
} else { } else {
if (type == MULTI_POINT && source.hasCoordinate()) { if (type == MULTI_POINT && source.hasCoordinate()) {
parseMultiPointAlternative(source, target, useZ, useM); parseMultiPointAlternative(source, target, dimensionSystem);
} else { } else {
int numItems = source.getItemCount(); int numItems = source.getItemCount();
target.startCollection(type, numItems); target.startCollection(type, numItems);
...@@ -738,7 +730,7 @@ public final class EWKTUtils { ...@@ -738,7 +730,7 @@ public final class EWKTUtils {
source.read(','); source.read(',');
} }
Target innerTarget = target.startCollectionItem(i, numItems); Target innerTarget = target.startCollectionItem(i, numItems);
parseEWKT(source, innerTarget, type, useZ, useM); parseEWKT(source, innerTarget, type, dimensionSystem);
target.endCollectionItem(innerTarget, i, numItems); target.endCollectionItem(innerTarget, i, numItems);
} }
source.read(')'); source.read(')');
...@@ -747,11 +739,11 @@ public final class EWKTUtils { ...@@ -747,11 +739,11 @@ public final class EWKTUtils {
target.endCollection(type); target.endCollection(type);
} }
private static void parseMultiPointAlternative(EWKTSource source, Target target, boolean useZ, boolean useM) { private static void parseMultiPointAlternative(EWKTSource source, Target target, int dimensionSystem) {
// Special case for MULTIPOINT (1 2, 3 4) // Special case for MULTIPOINT (1 2, 3 4)
ArrayList<double[]> points = new ArrayList<>(); ArrayList<double[]> points = new ArrayList<>();
do { do {
points.add(readCoordinate(source, useZ, useM)); points.add(readCoordinate(source, dimensionSystem));
} while (source.hasMoreCoordinates()); } while (source.hasMoreCoordinates());
int numItems = points.size(); int numItems = points.size();
target.startCollection(MULTI_POINT, numItems); target.startCollection(MULTI_POINT, numItems);
...@@ -764,16 +756,16 @@ public final class EWKTUtils { ...@@ -764,16 +756,16 @@ public final class EWKTUtils {
} }
} }
private static ArrayList<double[]> readRing(EWKTSource source, boolean useZ, boolean useM) { private static ArrayList<double[]> readRing(EWKTSource source, int dimensionSystem) {
if (source.readEmpty()) { if (source.readEmpty()) {
return new ArrayList<>(0); return new ArrayList<>(0);
} }
ArrayList<double[]> result = new ArrayList<>(); ArrayList<double[]> result = new ArrayList<>();
double[] c = readCoordinate(source, useZ, useM); double[] c = readCoordinate(source, dimensionSystem);
double startX = c[X], startY = c[Y]; double startX = c[X], startY = c[Y];
result.add(c); result.add(c);
while (source.hasMoreCoordinates()) { while (source.hasMoreCoordinates()) {
result.add(readCoordinate(source, useZ, useM)); result.add(readCoordinate(source, dimensionSystem));
} }
int size = result.size(); int size = result.size();
if (size < 4) { if (size < 4) {
...@@ -791,20 +783,19 @@ public final class EWKTUtils { ...@@ -791,20 +783,19 @@ public final class EWKTUtils {
return result; return result;
} }
private static void addRing(ArrayList<double[]> ring, Target target, boolean useZ, boolean useM) { private static void addRing(ArrayList<double[]> ring, Target target) {
for (int i = 0, size = ring.size(); i < size; i++) { for (int i = 0, size = ring.size(); i < size; i++) {
double[] coordinates = ring.get(i); double[] coordinates = ring.get(i);
target.addCoordinate(coordinates[X], coordinates[Y], coordinates[Z], coordinates[M], i, size); target.addCoordinate(coordinates[X], coordinates[Y], coordinates[Z], coordinates[M], i, size);
} }
} }
private static void addCoordinate(EWKTSource source, Target target, boolean useZ, boolean useM, int index, private static void addCoordinate(EWKTSource source, Target target, int dimensionSystem, int index, int total) {
int total) {
double x = source.readCoordinate(); double x = source.readCoordinate();
double y = source.readCoordinate(); double y = source.readCoordinate();
double z = Double.NaN, m = Double.NaN; double z = Double.NaN, m = Double.NaN;
if (source.hasCoordinate()) { if (source.hasCoordinate()) {
if (!useZ && useM) { if (dimensionSystem == DIMENSION_SYSTEM_XYM) {
m = source.readCoordinate(); m = source.readCoordinate();
} else { } else {
z = source.readCoordinate(); z = source.readCoordinate();
...@@ -816,12 +807,12 @@ public final class EWKTUtils { ...@@ -816,12 +807,12 @@ public final class EWKTUtils {
target.addCoordinate(x, y, z, m, index, total); target.addCoordinate(x, y, z, m, index, total);
} }
private static double[] readCoordinate(EWKTSource source, boolean useZ, boolean useM) { private static double[] readCoordinate(EWKTSource source, int dimensionSystem) {
double x = source.readCoordinate(); double x = source.readCoordinate();
double y = source.readCoordinate(); double y = source.readCoordinate();
double z = Double.NaN, m = Double.NaN; double z = Double.NaN, m = Double.NaN;
if (source.hasCoordinate()) { if (source.hasCoordinate()) {
if (!useZ && useM) { if (dimensionSystem == DIMENSION_SYSTEM_XYM) {
m = source.readCoordinate(); m = source.readCoordinate();
} else { } else {
z = source.readCoordinate(); z = source.readCoordinate();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论