root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / ShapeMFactory.java @ 38563
History | View | Annotate | Download (5.25 KB)
1 |
package com.iver.cit.gvsig.fmap.core; |
---|---|
2 |
|
3 |
import java.nio.ByteBuffer; |
4 |
import java.util.ArrayList; |
5 |
|
6 |
|
7 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
8 |
*
|
9 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
10 |
*
|
11 |
* This program is free software; you can redistribute it and/or
|
12 |
* modify it under the terms of the GNU General Public License
|
13 |
* as published by the Free Software Foundation; either version 2
|
14 |
* of the License, or (at your option) any later version.
|
15 |
*
|
16 |
* This program is distributed in the hope that it will be useful,
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19 |
* GNU General Public License for more details.
|
20 |
*
|
21 |
* You should have received a copy of the GNU General Public License
|
22 |
* along with this program; if not, write to the Free Software
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
24 |
*
|
25 |
* For more information, contact:
|
26 |
*
|
27 |
* Generalitat Valenciana
|
28 |
* Conselleria d'Infraestructures i Transport
|
29 |
* Av. Blasco Ib??ez, 50
|
30 |
* 46010 VALENCIA
|
31 |
* SPAIN
|
32 |
*
|
33 |
* +34 963862235
|
34 |
* gvsig@gva.es
|
35 |
* www.gvsig.gva.es
|
36 |
*
|
37 |
* or
|
38 |
*
|
39 |
* IVER T.I. S.A
|
40 |
* Salamanca 50
|
41 |
* 46005 Valencia
|
42 |
* Spain
|
43 |
*
|
44 |
* +34 963163400
|
45 |
* dac@iver.es
|
46 |
*/
|
47 |
/* CVS MESSAGES:
|
48 |
*
|
49 |
* $Id: ShapeMFactory.java,v 1.1 2007/10/19 10:03:45 jorpiell Exp $
|
50 |
* $Log: ShapeMFactory.java,v $
|
51 |
* Revision 1.1 2007/10/19 10:03:45 jorpiell
|
52 |
* First commit
|
53 |
*
|
54 |
*
|
55 |
*/
|
56 |
/**
|
57 |
* This factory is used to create geoemtries with the M
|
58 |
* coordinate
|
59 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
60 |
*/
|
61 |
public class ShapeMFactory { |
62 |
|
63 |
public static IGeometry createPoint2DM(double x, double y, double m) { |
64 |
return new FGeometryM(new FPoint2DM(x, y, m)); |
65 |
} |
66 |
|
67 |
|
68 |
/**
|
69 |
* Creates a Polyline in 2D with the M coordinate
|
70 |
* @param gp
|
71 |
* Coordinates to create the polyline
|
72 |
* @param ms
|
73 |
* Array with the M values
|
74 |
* @return
|
75 |
* A Geometry with Ms
|
76 |
*/
|
77 |
public static IGeometryM createPolyline2DM(GeneralPathX gp, double[] ms) { |
78 |
return new FGeometryM(new FPolyline2DM(gp, ms)); |
79 |
} |
80 |
|
81 |
public static IGeometryM createPolyline2DM(FPolyline2DM polyline) { |
82 |
return new FGeometryM(polyline); |
83 |
} |
84 |
|
85 |
public static IGeometry createPolyline2DM(ByteBuffer data) { |
86 |
|
87 |
int count = data.getInt();
|
88 |
GeneralPathX gp = new GeneralPathX();
|
89 |
//double[] ms = new double[count - 1];
|
90 |
//ArrayList alMs = new ArrayList();
|
91 |
|
92 |
ArrayList<Double> ms = new ArrayList<Double>(); |
93 |
// ArrayList<Double> ms_aux = null;
|
94 |
// double[] ms = null; //Intento de evitar el tener que encapsular las m's en
|
95 |
// double[] ms_aux = null; //objetos Double y de tener que recorrer un ArrayList
|
96 |
int ms_lentgh = 0; |
97 |
|
98 |
for (int i=0; i < count; i++) { |
99 |
parseTypeAndSRID(data); |
100 |
FPoint2DM[] points = parsePointArray(data);
|
101 |
// ms_aux = new double[ms_lentgh + points.length];
|
102 |
|
103 |
gp.moveTo(points[0].getX(), points[0].getY()); |
104 |
//alMs.add(new Double(points[0].getM()));
|
105 |
// ms_aux[ms_lentgh + 0] = points[0].getM();
|
106 |
ms.add(points[0].getM());
|
107 |
|
108 |
for (int j = 1; j< points.length; j++) { |
109 |
ms.add(points[j].getM()); |
110 |
// ms_aux[ms_lentgh + j] = points[j].getM();
|
111 |
gp.lineTo(points[j].getX(), points[j].getY()); |
112 |
} |
113 |
|
114 |
//ms[i] = points[i].getM();
|
115 |
// if (ms != null) {
|
116 |
// System.arraycopy(ms, 0, ms_aux, ms.length, ms.length);
|
117 |
// }
|
118 |
// ms = ms_aux;
|
119 |
// ms_lentgh = ms.length;
|
120 |
// ms_aux = null;
|
121 |
}//for
|
122 |
|
123 |
|
124 |
// OJO: Para ahorrarme esto tendr?a que modificar la clase FPolyline2DM para
|
125 |
// que las ms se almacenaran como objetos Double en lugar de usar el tipo
|
126 |
// primitivo double.
|
127 |
double[] aMs = new double[ms.size()]; |
128 |
for (int i = 0; i < ms.size(); i++) { |
129 |
aMs[i] = ((Double)ms.get(i)).doubleValue();
|
130 |
} |
131 |
|
132 |
return new FGeometryM(new FPolyline2DM(gp, aMs)); |
133 |
} |
134 |
|
135 |
public static IGeometry createPolygon2DM(GeneralPathX gp, double[] pM) { |
136 |
return new FGeometryM(new FPolygon2DM(gp, pM)); |
137 |
} |
138 |
|
139 |
|
140 |
public static IGeometry createMultipoint2DM(double[] x, double[] y, |
141 |
double[] m) { |
142 |
throw new UnsupportedOperationException(); |
143 |
} |
144 |
|
145 |
private static void parseTypeAndSRID(ByteBuffer data) { |
146 |
byte endian = data.get(); //skip and test endian flag |
147 |
/* if (endian != data.endian) {
|
148 |
throw new IllegalArgumentException("Endian inconsistency!");
|
149 |
} */
|
150 |
int typeword = data.getInt();
|
151 |
int realtype = typeword & 0x1FFFFFFF; //cut off high flag bits |
152 |
|
153 |
boolean gHaveZ = (typeword & 0x80000000) != 0; |
154 |
boolean gHaveM = (typeword & 0x40000000) != 0; |
155 |
boolean gHaveS = (typeword & 0x20000000) != 0; |
156 |
|
157 |
int srid = -1; |
158 |
|
159 |
if (gHaveS) {
|
160 |
srid = data.getInt(); |
161 |
} |
162 |
|
163 |
} |
164 |
|
165 |
/**
|
166 |
* Parse an Array of "slim" Points (without endianness and type, part of
|
167 |
* LinearRing and Linestring, but not MultiPoint!
|
168 |
*
|
169 |
* @param haveZ
|
170 |
* @param haveM
|
171 |
*/
|
172 |
private static FPoint2DM[] parsePointArray(ByteBuffer data) { |
173 |
int count = data.getInt();
|
174 |
FPoint2DM[] result = new FPoint2DM[count]; |
175 |
for (int i = 0; i < count; i++) { |
176 |
result[i] = parsePoint(data); |
177 |
} |
178 |
return result;
|
179 |
} |
180 |
|
181 |
private static FPoint2DM parsePoint(ByteBuffer data) { |
182 |
double X = data.getDouble();
|
183 |
double Y = data.getDouble();
|
184 |
double M = data.getDouble();
|
185 |
|
186 |
return new FPoint2DM(X, Y, M); |
187 |
} |
188 |
|
189 |
|
190 |
} |