1 |
1 |
/*
|
2 |
2 |
* WKBParser.java
|
3 |
|
* Based in
|
|
3 |
* Based in
|
4 |
4 |
* PostGIS extension for PostgreSQL JDBC driver - Binary Parser
|
5 |
|
*
|
|
5 |
*
|
6 |
6 |
* NOTA: Es posible que lo mejor sea crear un PostGisGeometry que implemente
|
7 |
7 |
* la interfaz IGeometry, y as? nos sirve de base para tener IGeometries
|
8 |
8 |
* que encapsulan otras posibles geometr?as. Por ejemplo, un JTSGeometry.
|
9 |
9 |
* De esta forma, un driver no necesitar?a reescribirse.
|
10 |
|
*
|
|
10 |
*
|
11 |
11 |
* (C) 2005 Markus Schaber, schabios@logi-track.com
|
12 |
|
*
|
|
12 |
*
|
13 |
13 |
* This library is free software; you can redistribute it and/or modify it under
|
14 |
14 |
* the terms of the GNU Lesser General Public License as published by the Free
|
15 |
15 |
* Software Foundation, either version 2.1 of the License.
|
16 |
|
*
|
|
16 |
*
|
17 |
17 |
* This library is distributed in the hope that it will be useful, but WITHOUT
|
18 |
18 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
19 |
19 |
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
20 |
20 |
* details.
|
21 |
|
*
|
|
21 |
*
|
22 |
22 |
* You should have received a copy of the GNU Lesser General Public License
|
23 |
23 |
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
24 |
24 |
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
|
25 |
25 |
* http://www.gnu.org.
|
26 |
|
*
|
|
26 |
*
|
27 |
27 |
* $Id$
|
28 |
28 |
*/
|
29 |
29 |
package com.iver.cit.gvsig.fmap.drivers;
|
... | ... | |
48 |
48 |
/**
|
49 |
49 |
* Parse binary representation of geometries. Currently, only text rep (hexed)
|
50 |
50 |
* implementation is tested.
|
51 |
|
*
|
|
51 |
*
|
52 |
52 |
* It should be easy to add char[] and CharSequence ByteGetter instances,
|
53 |
53 |
* although the latter one is not compatible with older jdks.
|
54 |
|
*
|
|
54 |
*
|
55 |
55 |
* I did not implement real unsigned 32-bit integers or emulate them with long,
|
56 |
56 |
* as both java Arrays and Strings currently can have only 2^31-1 elements
|
57 |
57 |
* (bytes), so we cannot even get or build Geometries with more than approx.
|
58 |
58 |
* 2^28 coordinates (8 bytes each).
|
59 |
|
*
|
|
59 |
*
|
60 |
60 |
* @author markus.schaber@logi-track.com
|
61 |
|
*
|
|
61 |
*
|
62 |
62 |
*/
|
63 |
63 |
public class WKBParser2 {
|
64 |
64 |
|
... | ... | |
67 |
67 |
|
68 |
68 |
/**
|
69 |
69 |
* Parse a binary encoded geometry.
|
70 |
|
*
|
|
70 |
*
|
71 |
71 |
* Is synchronized to protect offset counter. (Unfortunately, Java does not
|
72 |
72 |
* have neither call by reference nor multiple return values.)
|
73 |
73 |
*/
|
... | ... | |
76 |
76 |
ByteBuffer buf = ByteBuffer.wrap(value);
|
77 |
77 |
return parseGeometry(buf);
|
78 |
78 |
}
|
79 |
|
|
|
79 |
|
80 |
80 |
protected void parseTypeAndSRID(ByteBuffer data)
|
81 |
81 |
{
|
82 |
82 |
byte endian = data.get(); //skip and test endian flag
|
... | ... | |
96 |
96 |
if (gHaveS) {
|
97 |
97 |
srid = data.getInt();
|
98 |
98 |
}
|
99 |
|
|
|
99 |
|
100 |
100 |
}
|
101 |
101 |
|
102 |
102 |
|
... | ... | |
188 |
188 |
/**
|
189 |
189 |
* Parse an Array of "slim" Points (without endianness and type, part of
|
190 |
190 |
* LinearRing and Linestring, but not MultiPoint!
|
191 |
|
*
|
|
191 |
*
|
192 |
192 |
* @param haveZ
|
193 |
193 |
* @param haveM
|
194 |
194 |
*/
|
... | ... | |
238 |
238 |
FPolygon2D[] rings = new FPolygon2D[count];
|
239 |
239 |
for (int i = 0; i < count; i++) {
|
240 |
240 |
rings[i] = parseLinearRing(data, haveZ, haveM);
|
241 |
|
|
|
241 |
|
242 |
242 |
}
|
243 |
243 |
GeneralPathX shape=(GeneralPathX)getGeneralPathX(rings);
|
|
244 |
shape.closePath();
|
244 |
245 |
return new FPolygon2D(shape);
|
245 |
246 |
}
|
246 |
247 |
private FPolyline2D parseMultiLineString(ByteBuffer data) {
|
247 |
248 |
GeneralPathX gp = parseGeneralPath(data);
|
248 |
249 |
// GeneralPathX shape=getGeneralPathX(strings);
|
249 |
|
|
|
250 |
|
250 |
251 |
// parseGeometryArray(data, strings);
|
251 |
252 |
return new FPolyline2D(gp);//strings[0]; //new MultiLineString(strings);
|
252 |
253 |
}
|
... | ... | |
268 |
269 |
for (int i = 0; i < count; i++) {
|
269 |
270 |
result[i] = parsePoint(data, haveZ, haveM);
|
270 |
271 |
}
|
271 |
|
return result; */
|
|
272 |
return result; */
|
272 |
273 |
/* FPoint2D p = parsePoint(data, gHaveZ, gHaveM);
|
273 |
274 |
gp.moveTo(p.getX(), p.getY());
|
274 |
275 |
for (int j = 1; j < count2; j++) {
|
275 |
276 |
p = parsePoint(data, gHaveZ, gHaveM);
|
276 |
277 |
gp.lineTo(p.getX(), p.getY());
|
277 |
278 |
} */
|
278 |
|
|
|
279 |
|
279 |
280 |
gp.moveTo(points[0].getX(), points[0].getY());
|
280 |
281 |
for (int j = 1; j< points.length; j++)
|
281 |
282 |
{
|
282 |
283 |
gp.lineTo(points[j].getX(), points[j].getY());
|
283 |
|
}
|
284 |
|
|
|
284 |
}
|
|
285 |
|
285 |
286 |
// strings[i] = parseLineString(data, gHaveZ, gHaveM);
|
286 |
287 |
}
|
287 |
288 |
return gp;
|
... | ... | |
300 |
301 |
for (int j = 0; j < countRings; j++) {
|
301 |
302 |
// rings[j] = parseLinearRing(data, gHaveZ, gHaveM);
|
302 |
303 |
FPoint2D[] points = parsePointArray(data, gHaveZ, gHaveM);
|
303 |
|
|
|
304 |
|
304 |
305 |
gp.moveTo(points[0].getX(), points[0].getY());
|
305 |
306 |
for (int k = 1; k< points.length; k++)
|
306 |
307 |
{
|
307 |
|
gp.lineTo(points[k].getX(), points[k].getY());
|
|
308 |
if (k==points.length-1){
|
|
309 |
gp.closePath();
|
|
310 |
}else{
|
|
311 |
gp.lineTo(points[k].getX(), points[k].getY());
|
|
312 |
}
|
|
313 |
|
308 |
314 |
}
|
309 |
|
|
|
315 |
|
310 |
316 |
}
|
311 |
317 |
// GeneralPathX shape=(GeneralPathX)getGeneralPathX(rings);
|
312 |
|
|
|
318 |
|
313 |
319 |
}
|
314 |
320 |
// GeneralPathX shape=getGeneralPathX(polys);
|
315 |
321 |
|