Revision 47432 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.geometry/org.gvsig.fmap.geometry.jts/src/main/java/org/gvsig/fmap/geom/jts/operation/fromwkt/EWKTParser.java
EWKTParser.java | ||
---|---|---|
42 | 42 |
package org.gvsig.fmap.geom.jts.operation.fromwkt; |
43 | 43 |
|
44 | 44 |
import com.vividsolutions.jts.geom.Coordinate; |
45 |
import com.vividsolutions.jts.geom.CoordinateSequence; |
|
45 | 46 |
import com.vividsolutions.jts.geom.GeometryFactory; |
46 | 47 |
import com.vividsolutions.jts.geom.PrecisionModel; |
47 | 48 |
import com.vividsolutions.jts.io.ParseException; |
... | ... | |
52 | 53 |
import java.io.StreamTokenizer; |
53 | 54 |
import java.io.StringReader; |
54 | 55 |
import java.util.ArrayList; |
56 |
import org.apache.commons.lang3.StringUtils; |
|
55 | 57 |
import org.gvsig.fmap.geom.Geometry; |
56 | 58 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
57 | 59 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
... | ... | |
713 | 715 |
if (this.hasM == null) { |
714 | 716 |
this.hasM = hasM; |
715 | 717 |
} else if (this.hasM != hasM) { |
716 |
throw new ParseException("Inkonsistent use of m-values.");
|
|
718 |
throw new ParseException("Inconsistent use of m-values.");
|
|
717 | 719 |
} |
718 | 720 |
} |
719 | 721 |
|
... | ... | |
778 | 780 |
point.setX(coordinates.x); |
779 | 781 |
point.setY(coordinates.y); |
780 | 782 |
if (subtype == Geometry.SUBTYPES.GEOM2DM) { |
781 |
point.setCoordinateAt(2, coordinates.getOrdinate(3));
|
|
783 |
point.setCoordinateAt(2, coordinates.getOrdinate(CoordinateSequence.M));
|
|
782 | 784 |
} else if (subtype == Geometry.SUBTYPES.GEOM3DM) { |
783 |
point.setCoordinateAt(2, coordinates.getOrdinate(2));
|
|
784 |
point.setCoordinateAt(3, coordinates.getOrdinate(3));
|
|
785 |
point.setCoordinateAt(2, coordinates.getOrdinate(CoordinateSequence.Z));
|
|
786 |
point.setCoordinateAt(3, coordinates.getOrdinate(CoordinateSequence.M));
|
|
785 | 787 |
} else if (subtype == Geometry.SUBTYPES.GEOM3D) { |
786 |
point.setCoordinateAt(2, coordinates.getOrdinate(2));
|
|
788 |
point.setCoordinateAt(2, coordinates.getOrdinate(CoordinateSequence.Z));
|
|
787 | 789 |
} |
788 | 790 |
} |
789 | 791 |
|
... | ... | |
871 | 873 |
* @throws IOException if an I/O error occurs |
872 | 874 |
* @throws ParseException if an unexpected token was encountered |
873 | 875 |
* @throws CreateGeometryException |
874 |
*/ |
|
875 |
private MultiPoint readMultiPointText() throws IOException, ParseException, CreateGeometryException { |
|
876 |
MCoordinate[] coords = getCoordinates(); |
|
876 |
*/ |
|
877 |
private MultiPoint readMultiPointText() throws IOException, ParseException, CreateGeometryException { |
|
878 |
String nextToken = getNextEmptyOrOpenerOrDimension(); |
|
879 |
if (nextToken.equals(Z)) { |
|
880 |
this.dimension = 3; |
|
881 |
setHasM(false); |
|
882 |
nextToken = getNextEmptyOrOpener(); |
|
883 |
} else if (nextToken.equals(M)) { |
|
884 |
this.dimension = 3; |
|
885 |
setHasM(true); |
|
886 |
nextToken = getNextEmptyOrOpener(); |
|
887 |
} else if (nextToken.equals(ZM)) { |
|
888 |
this.dimension = 4; |
|
889 |
setHasM(true); |
|
890 |
nextToken = getNextEmptyOrOpener(); |
|
891 |
} else { |
|
892 |
setHasM(false); |
|
893 |
this.dimension = 2; |
|
894 |
} |
|
895 |
|
|
877 | 896 |
int subtype = getSubtype(); |
878 | 897 |
MultiPoint multiPoint = (MultiPoint)manager.create(TYPES.MULTIPOINT, subtype); |
879 |
for (int i=0; i < coords.length; i++) |
|
880 |
{ |
|
881 |
Point point = (Point)manager.create(TYPES.POINT, subtype); |
|
882 |
fillPoint(subtype, coords[i], point); |
|
883 |
multiPoint.addPoint(point); |
|
898 |
if (nextToken.equals(EMPTY)) { |
|
899 |
return multiPoint; |
|
884 | 900 |
} |
901 |
|
|
902 |
int token = tokenizer.nextToken(); |
|
903 |
tokenizer.pushBack(); |
|
904 |
if(token == '('){ |
|
905 |
String stoken; |
|
906 |
do { |
|
907 |
Point p = readPointText(); |
|
908 |
multiPoint.addPoint(p); |
|
909 |
stoken = getNextCloserOrComma(); |
|
910 |
} while (StringUtils.equalsIgnoreCase(stoken, COMMA)); |
|
911 |
} else { |
|
912 |
String stoken; |
|
913 |
do { |
|
914 |
Coordinate coordinates = getPreciseCoordinate(); |
|
915 |
Point point = (Point) manager.create(TYPES.POINT, subtype); |
|
916 |
fillPoint(subtype, coordinates, point); |
|
917 |
multiPoint.addPoint(point); |
|
918 |
stoken = getNextCloserOrComma(); |
|
919 |
} while (StringUtils.equalsIgnoreCase(stoken, COMMA)); |
|
920 |
} |
|
885 | 921 |
return multiPoint; |
886 | 922 |
} |
887 | 923 |
|
... | ... | |
1047 | 1083 |
private MultiPolygon readMultiPolygonText() |
1048 | 1084 |
throws IOException, ParseException, CreateGeometryException { |
1049 | 1085 |
|
1050 |
// MultiPolygonM is not supported |
|
1051 |
// setHasM(false); |
|
1052 |
MultiPolygon multiPolygon = (MultiPolygon)manager.create(TYPES.MULTIPOLYGON, getSubtype()); |
|
1053 | 1086 |
|
1054 | 1087 |
String nextToken = getNextEmptyOrOpenerOrDimension(); |
1055 |
if (nextToken.equals(EMPTY)) { |
|
1056 |
return multiPolygon; |
|
1057 |
} |
|
1058 | 1088 |
if (nextToken.equals(Z)) { |
1059 | 1089 |
this.dimension = 3; |
1060 | 1090 |
setHasM(false); |
1061 | 1091 |
nextToken = getNextEmptyOrOpener(); |
1062 |
if (nextToken.equals(EMPTY)) { |
|
1063 |
return (MultiPolygon)manager.create(TYPES.MULTIPOLYGON, getSubtype()); |
|
1064 |
} |
|
1065 |
} |
|
1066 |
if (nextToken.equals(M)) { |
|
1092 |
} else if (nextToken.equals(M)) { |
|
1067 | 1093 |
this.dimension = 3; |
1068 | 1094 |
setHasM(true); |
1069 | 1095 |
nextToken = getNextEmptyOrOpener(); |
1070 |
if (nextToken.equals(EMPTY)) { |
|
1071 |
return (MultiPolygon)manager.create(TYPES.MULTIPOLYGON, getSubtype()); |
|
1072 |
} |
|
1073 |
} |
|
1074 |
if (nextToken.equals(ZM)) { |
|
1096 |
} else if (nextToken.equals(ZM)) { |
|
1075 | 1097 |
this.dimension = 4; |
1076 | 1098 |
setHasM(true); |
1077 | 1099 |
nextToken = getNextEmptyOrOpener(); |
1078 |
if (nextToken.equals(EMPTY)) {
|
|
1079 |
return (MultiPolygon)manager.create(TYPES.MULTIPOLYGON, getSubtype());
|
|
1080 |
}
|
|
1100 |
} else {
|
|
1101 |
setHasM(false);
|
|
1102 |
this.dimension = 2;
|
|
1081 | 1103 |
} |
1082 | 1104 |
|
1105 |
MultiPolygon multiPolygon = (MultiPolygon)manager.create(TYPES.MULTIPOLYGON, getSubtype()); |
|
1106 |
if (nextToken.equals(EMPTY)) { |
|
1107 |
return multiPolygon; |
|
1108 |
} |
|
1109 |
|
|
1083 | 1110 |
Polygon polygon = readPolygonText(); |
1084 | 1111 |
|
1085 | 1112 |
multiPolygon.addSurface(polygon); |
Also available in: Unified diff