Revision 29097 branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/operation/fromwkb/WKBParser2.java
WKBParser2.java | ||
---|---|---|
32 | 32 |
import java.nio.ByteBuffer; |
33 | 33 |
import java.nio.ByteOrder; |
34 | 34 |
|
35 |
import org.geotools.xml.gml.GMLComplexTypes.MultiGeometryPropertyType; |
|
35 | 36 |
import org.gvsig.fmap.geom.Geometry; |
36 | 37 |
import org.gvsig.fmap.geom.GeometryLocator; |
37 | 38 |
import org.gvsig.fmap.geom.GeometryManager; |
39 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
|
40 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
|
41 |
import org.gvsig.fmap.geom.aggregate.Aggregate; |
|
42 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
|
43 |
import org.gvsig.fmap.geom.aggregate.MultiPrimitive; |
|
38 | 44 |
import org.gvsig.fmap.geom.aggregate.impl.BaseMultiPrimitive; |
39 | 45 |
import org.gvsig.fmap.geom.aggregate.impl.BaseMultiPrimitive2D; |
40 |
import org.gvsig.fmap.geom.aggregate.impl.MultiPoint2D; |
|
46 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
47 |
import org.gvsig.fmap.geom.primitive.Curve; |
|
41 | 48 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
49 |
import org.gvsig.fmap.geom.primitive.Primitive; |
|
50 |
import org.gvsig.fmap.geom.primitive.Surface; |
|
42 | 51 |
import org.gvsig.fmap.geom.primitive.impl.Curve2D; |
43 | 52 |
import org.gvsig.fmap.geom.primitive.impl.Point2D; |
44 | 53 |
import org.gvsig.fmap.geom.primitive.impl.Point2DZ; |
... | ... | |
71 | 80 |
* |
72 | 81 |
* Is synchronized to protect offset counter. (Unfortunately, Java does not |
73 | 82 |
* have neither call by reference nor multiple return values.) |
83 |
* @throws CreateGeometryException |
|
74 | 84 |
*/ |
75 |
public synchronized Geometry parse(byte[] value) { |
|
85 |
public synchronized Geometry parse(byte[] value) throws CreateGeometryException {
|
|
76 | 86 |
// BinaryByteGetter bytes = new ByteGetter.BinaryByteGetter(value); |
77 | 87 |
ByteBuffer buf = ByteBuffer.wrap(value); |
78 | 88 |
return parseGeometry(buf); |
... | ... | |
101 | 111 |
} |
102 | 112 |
|
103 | 113 |
|
104 |
/** Parse a geometry starting at offset. */ |
|
105 |
protected Geometry parseGeometry(ByteBuffer data) { |
|
114 |
/** Parse a geometry starting at offset. |
|
115 |
* @throws CreateGeometryException */ |
|
116 |
protected Geometry parseGeometry(ByteBuffer data) throws CreateGeometryException { |
|
106 | 117 |
byte endian = data.get(); //skip and test endian flag |
107 | 118 |
if (endian == 1) |
108 | 119 |
{ |
... | ... | |
179 | 190 |
return result; |
180 | 191 |
} |
181 | 192 |
|
182 |
/** Parse an Array of "full" Geometries */ |
|
183 |
private void parseGeometryArray(ByteBuffer data, Geometry[] container) { |
|
193 |
/** Parse an Array of "full" Geometries |
|
194 |
* @throws CreateGeometryException */ |
|
195 |
private void parseGeometryArray(ByteBuffer data, Geometry[] container) throws CreateGeometryException { |
|
184 | 196 |
for (int i = 0; i < container.length; i++) { |
185 | 197 |
container[i] = parseGeometry(data); |
186 | 198 |
} |
... | ... | |
202 | 214 |
return result; |
203 | 215 |
} |
204 | 216 |
|
205 |
private MultiPoint2D parseMultiPoint(ByteBuffer data) { |
|
206 |
Point2D[] points = new Point2D[data.getInt()]; |
|
217 |
private MultiPoint parseMultiPoint(ByteBuffer data) throws CreateGeometryException { |
|
218 |
MultiPoint multipoint = (MultiPoint) geomManager.create(TYPES.MULTIPOINT, SUBTYPES.GEOM2D); |
|
219 |
Point2D[] points = new Point2D[data.getInt()]; |
|
207 | 220 |
for (int i=0; i < points.length; i++) |
208 | 221 |
{ |
209 | 222 |
parseTypeAndSRID(data); |
210 |
points[i] = parsePoint(data, gHaveZ, gHaveM);
|
|
223 |
multipoint.addPoint(parsePoint(data, gHaveZ, gHaveM));
|
|
211 | 224 |
} |
212 |
return new MultiPoint2D(points);
|
|
225 |
return multipoint;
|
|
213 | 226 |
} |
214 | 227 |
|
215 |
private Curve2D parseLineString(ByteBuffer data, boolean haveZ, boolean haveM) {
|
|
228 |
private Curve parseLineString(ByteBuffer data, boolean haveZ, boolean haveM) throws CreateGeometryException {
|
|
216 | 229 |
Point2D[] points = parsePointArray(data, haveZ, haveM); |
217 | 230 |
GeneralPathX gp = new GeneralPathX(); |
218 | 231 |
gp.moveTo(points[0].getX(), points[0].getY()); |
... | ... | |
220 | 233 |
{ |
221 | 234 |
gp.lineTo(points[i].getX(), points[i].getY()); |
222 | 235 |
} |
223 |
return new Curve2D(gp);
|
|
236 |
return (Curve) geomManager.createCurve(gp, SUBTYPES.GEOM2D);
|
|
224 | 237 |
} |
225 | 238 |
|
226 |
private Surface2D parseLinearRing(ByteBuffer data, boolean haveZ, boolean haveM) {
|
|
239 |
private Surface parseLinearRing(ByteBuffer data, boolean haveZ, boolean haveM) throws CreateGeometryException {
|
|
227 | 240 |
Point2D[] points = parsePointArray(data, haveZ, haveM); |
228 | 241 |
GeneralPathX gp = new GeneralPathX(); |
229 | 242 |
gp.moveTo(points[0].getX(), points[0].getY()); |
... | ... | |
231 | 244 |
{ |
232 | 245 |
gp.lineTo(points[i].getX(), points[i].getY()); |
233 | 246 |
} |
234 |
return new Surface2D(gp);
|
|
247 |
return (Surface) geomManager.createSurface(gp, SUBTYPES.GEOM2D);
|
|
235 | 248 |
} |
236 | 249 |
|
237 |
private Surface2D parsePolygon(ByteBuffer data, boolean haveZ, boolean haveM) {
|
|
250 |
private Surface parsePolygon(ByteBuffer data, boolean haveZ, boolean haveM) throws CreateGeometryException {
|
|
238 | 251 |
int count = data.getInt(); |
239 |
Surface2D[] rings = new Surface2D[count];
|
|
252 |
Surface[] rings = new Surface2D[count]; |
|
240 | 253 |
for (int i = 0; i < count; i++) { |
241 | 254 |
rings[i] = parseLinearRing(data, haveZ, haveM); |
242 | 255 |
|
... | ... | |
245 | 258 |
if (!shape.isClosed()) { |
246 | 259 |
shape.closePath(); |
247 | 260 |
} |
248 |
return new Surface2D(shape);
|
|
261 |
return (Surface) geomManager.createSurface(shape, SUBTYPES.GEOM2D);
|
|
249 | 262 |
} |
250 |
private Curve2D parseMultiLineString(ByteBuffer data) {
|
|
263 |
private Curve parseMultiLineString(ByteBuffer data) throws CreateGeometryException {
|
|
251 | 264 |
GeneralPathX gp = parseGeneralPath(data); |
252 | 265 |
// GeneralPathX shape=getGeneralPathX(strings); |
253 | 266 |
|
254 | 267 |
// parseGeometryArray(data, strings); |
255 |
return new Curve2D(gp);//strings[0]; //new MultiLineString(strings);
|
|
268 |
return (Curve) geomManager.createCurve(gp, SUBTYPES.GEOM2D);//strings[0]; //new MultiLineString(strings);
|
|
256 | 269 |
} |
257 | 270 |
|
258 | 271 |
/** |
... | ... | |
291 | 304 |
return gp; |
292 | 305 |
} |
293 | 306 |
|
294 |
private Surface2D parseMultiPolygon(ByteBuffer data) {
|
|
307 |
private Surface parseMultiPolygon(ByteBuffer data) throws CreateGeometryException {
|
|
295 | 308 |
int count = data.getInt(); |
296 | 309 |
// FPolygon2D[] polys = new FPolygon2D[count]; |
297 | 310 |
GeneralPathX gp = new GeneralPathX(); |
... | ... | |
322 | 335 |
} |
323 | 336 |
// GeneralPathX shape=getGeneralPathX(polys); |
324 | 337 |
|
325 |
return new Surface2D(gp);
|
|
338 |
return (Surface) geomManager.createSurface(gp, SUBTYPES.GEOM2D);
|
|
326 | 339 |
// return new FPolygon2D(parseGeneralPath(data)); |
327 | 340 |
} |
328 | 341 |
|
329 |
private BaseMultiPrimitive parseCollection(ByteBuffer data) {
|
|
342 |
private MultiPrimitive parseCollection(ByteBuffer data) throws CreateGeometryException {
|
|
330 | 343 |
int count = data.getInt(); |
331 | 344 |
Geometry[] geoms = new Geometry[count]; |
332 | 345 |
parseGeometryArray(data, geoms); |
333 |
return new BaseMultiPrimitive2D(geoms); |
|
346 |
MultiPrimitive multiPrimitive = (MultiPrimitive) geomManager.create(TYPES.AGGREGATE, SUBTYPES.GEOM2D); |
|
347 |
for (int i=0 ; i<geoms.length ; i++){ |
|
348 |
multiPrimitive.addPrimitive((Primitive) geoms[i]); |
|
349 |
} |
|
350 |
return multiPrimitive; |
|
334 | 351 |
} |
335 | 352 |
/** |
336 | 353 |
* Devuelve el GeneralPathX compuesto por todos los GeneralPath de todas |
Also available in: Unified diff