svn-gvsig-desktop / tags / v2_0_0_Build_2052 / extensions / extGPE-gvSIG / src / org / gvsig / fmap / dal / store / gpe / handlers / FmapContentHandler.java @ 38825
History | View | Annotate | Download (23.9 KB)
1 |
package org.gvsig.fmap.dal.store.gpe.handlers; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.io.IOException; |
5 |
import java.util.ArrayList; |
6 |
import java.util.HashMap; |
7 |
import java.util.Iterator; |
8 |
import java.util.List; |
9 |
import java.util.Map; |
10 |
|
11 |
import org.cresques.cts.IProjection; |
12 |
import org.gvsig.fmap.dal.DataTypes; |
13 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
14 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
15 |
import org.gvsig.fmap.dal.feature.Feature; |
16 |
import org.gvsig.fmap.dal.feature.FeatureType; |
17 |
import org.gvsig.fmap.dal.feature.spi.DefaultFeatureProvider; |
18 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
19 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProviderServices; |
20 |
import org.gvsig.fmap.dal.store.gpe.GPEStoreProvider; |
21 |
import org.gvsig.fmap.dal.store.gpe.model.GPEElement; |
22 |
import org.gvsig.fmap.dal.store.gpe.model.GPEFeature; |
23 |
import org.gvsig.fmap.geom.Geometry; |
24 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
25 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
26 |
import org.gvsig.fmap.geom.GeometryLocator; |
27 |
import org.gvsig.fmap.geom.GeometryManager; |
28 |
import org.gvsig.fmap.geom.aggregate.MultiCurve; |
29 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
30 |
import org.gvsig.fmap.geom.aggregate.MultiPrimitive; |
31 |
import org.gvsig.fmap.geom.aggregate.MultiSurface; |
32 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
33 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
34 |
import org.gvsig.fmap.geom.primitive.Curve; |
35 |
import org.gvsig.fmap.geom.primitive.Envelope; |
36 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
37 |
import org.gvsig.fmap.geom.primitive.Point; |
38 |
import org.gvsig.fmap.geom.primitive.Primitive; |
39 |
import org.gvsig.fmap.geom.primitive.Surface; |
40 |
import org.gvsig.gpe.lib.api.parser.IAttributesIterator; |
41 |
import org.gvsig.gpe.lib.api.parser.ICoordinateIterator; |
42 |
import org.gvsig.gpe.lib.api.parser.IGPEErrorHandler; |
43 |
import org.gvsig.gpe.lib.impl.parser.GPEContentHandler; |
44 |
import org.jfree.util.Log; |
45 |
import org.slf4j.Logger; |
46 |
import org.slf4j.LoggerFactory; |
47 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
48 |
*
|
49 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
50 |
*
|
51 |
* This program is free software; you can redistribute it and/or
|
52 |
* modify it under the terms of the GNU General Public License
|
53 |
* as published by the Free Software Foundation; either version 2
|
54 |
* of the License, or (at your option) any later version.
|
55 |
*
|
56 |
* This program is distributed in the hope that it will be useful,
|
57 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
58 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
59 |
* GNU General Public License for more details.
|
60 |
*
|
61 |
* You should have received a copy of the GNU General Public License
|
62 |
* along with this program; if not, write to the Free Software
|
63 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
64 |
*
|
65 |
* For more information, contact:
|
66 |
*
|
67 |
* Generalitat Valenciana
|
68 |
* Conselleria d'Infraestructures i Transport
|
69 |
* Av. Blasco Ib??ez, 50
|
70 |
* 46010 VALENCIA
|
71 |
* SPAIN
|
72 |
*
|
73 |
* +34 963862235
|
74 |
* gvsig@gva.es
|
75 |
* www.gvsig.gva.es
|
76 |
*
|
77 |
* or
|
78 |
*
|
79 |
* IVER T.I. S.A
|
80 |
* Salamanca 50
|
81 |
* 46005 Valencia
|
82 |
* Spain
|
83 |
*
|
84 |
* +34 963163400
|
85 |
* dac@iver.es
|
86 |
*/
|
87 |
/* CVS MESSAGES:
|
88 |
*
|
89 |
* $Id$
|
90 |
* $Log$
|
91 |
*
|
92 |
*/
|
93 |
/**
|
94 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
95 |
*/
|
96 |
public class FmapContentHandler extends GPEContentHandler { |
97 |
private static final Logger LOG = LoggerFactory.getLogger(FmapContentHandler.class); |
98 |
|
99 |
private HashMap featureSet = null; |
100 |
private EditableFeatureType featureType = null; |
101 |
private FeatureStoreProviderServices store = null; |
102 |
private GPEStoreProvider storeProvider = null; |
103 |
private GeometryManager geomManager = GeometryLocator.getGeometryManager();
|
104 |
private int featureId = 0; |
105 |
private Envelope envelope = null; |
106 |
private File file = null; |
107 |
private IProjection srs = null; |
108 |
private int geometryType = 0; |
109 |
|
110 |
public FmapContentHandler(IGPEErrorHandler errorHandler, FeatureStoreProviderServices store,
|
111 |
GPEStoreProvider storeProvider, File file, IProjection srs, int geometryType) { |
112 |
super();
|
113 |
setErrorHandler(errorHandler); |
114 |
this.store = store;
|
115 |
this.storeProvider = storeProvider;
|
116 |
this.file = file;
|
117 |
this.srs = srs;
|
118 |
this.geometryType = geometryType;
|
119 |
} |
120 |
|
121 |
public int getFeaturesCount(){ |
122 |
return featureSet.size();
|
123 |
} |
124 |
|
125 |
public Feature getFeatureAt(int index){ |
126 |
return (Feature)featureSet.get(new Integer(index)); |
127 |
} |
128 |
|
129 |
public EditableFeatureType getFeatureType(){
|
130 |
return featureType;
|
131 |
} |
132 |
|
133 |
|
134 |
/**
|
135 |
* @return the featureSet
|
136 |
*/
|
137 |
public HashMap getFeatureSet() { |
138 |
return featureSet;
|
139 |
} |
140 |
|
141 |
/*
|
142 |
* (non-Javadoc)
|
143 |
* @see org.gvsig.gpe.parser.GPEContentHandler#startLayer(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.gvsig.gpe.parser.IAttributesIterator, java.lang.Object, java.lang.Object)
|
144 |
*/
|
145 |
public Object startLayer(String id, String namespace, String name, |
146 |
String description, String srs, IAttributesIterator iterator, Object parentLayer, Object box) { |
147 |
if (featureSet == null){ |
148 |
featureSet = new HashMap(); |
149 |
} |
150 |
if (envelope == null){ |
151 |
try {
|
152 |
envelope = geomManager.createEnvelope(SUBTYPES.GEOM2D); |
153 |
} catch (CreateEnvelopeException e) {
|
154 |
Log.error("Error creating the envelope", e);
|
155 |
} |
156 |
} |
157 |
return featureSet;
|
158 |
} |
159 |
|
160 |
/*
|
161 |
* (non-Javadoc)
|
162 |
* @see org.gvsig.gpe.IGPEContentHandler#endLayer(java.lang.Object)
|
163 |
*/
|
164 |
public void endLayer(Object layer) { |
165 |
if (featureType == null){ |
166 |
createFeatureType(null);
|
167 |
} |
168 |
storeProvider.setEnvelope(envelope); |
169 |
} |
170 |
|
171 |
/*
|
172 |
* (non-Javadoc)
|
173 |
* @see org.gvsig.gpe.parser.GPEContentHandler#startPoint(java.lang.String, org.gvsig.gpe.parser.ICoordinateIterator, java.lang.String)
|
174 |
*/
|
175 |
public Object startPoint(String id, ICoordinateIterator coords, String srs) { |
176 |
return createPoint(coords);
|
177 |
} |
178 |
|
179 |
private Point createPoint(ICoordinateIterator coords){ |
180 |
double[] buffer = new double[coords.getDimension()]; |
181 |
try {
|
182 |
coords.hasNext(); |
183 |
coords.next(buffer); |
184 |
Point point = null; |
185 |
if (coords.getDimension() == 2){ |
186 |
point = (Point) geomManager.create(TYPES.POINT, SUBTYPES.GEOM2D);
|
187 |
}else if (coords.getDimension() == 3){ |
188 |
point = (Point) geomManager.create(TYPES.POINT, SUBTYPES.GEOM3D);
|
189 |
} |
190 |
for (int i=0 ; i<buffer.length ; i++){ |
191 |
point.setCoordinateAt(i, buffer[i]); |
192 |
} |
193 |
return point;
|
194 |
} catch (IOException e) { |
195 |
getErrorHandler().addError(e); |
196 |
} catch (CreateGeometryException e) {
|
197 |
getErrorHandler().addError(e); |
198 |
} |
199 |
return null; |
200 |
} |
201 |
|
202 |
private Point createPoint(double[] buffer){ |
203 |
try {
|
204 |
Point point = null; |
205 |
if (buffer.length == 2){ |
206 |
point = (Point) geomManager.create(TYPES.POINT, SUBTYPES.GEOM2D);
|
207 |
}else if (buffer.length == 3){ |
208 |
point = (Point) geomManager.create(TYPES.POINT, SUBTYPES.GEOM3D);
|
209 |
} |
210 |
for (int i=0 ; i<buffer.length ; i++){ |
211 |
point.setCoordinateAt(i, buffer[i]); |
212 |
} |
213 |
return point;
|
214 |
}catch (CreateGeometryException e) {
|
215 |
getErrorHandler().addError(e); |
216 |
} |
217 |
return null; |
218 |
} |
219 |
|
220 |
|
221 |
/* (non-Javadoc)
|
222 |
* @see org.gvsig.gpe.parser.GPEContentHandler#startLineString(java.lang.String, org.gvsig.gpe.parser.ICoordinateIterator, java.lang.String)
|
223 |
*/
|
224 |
public Object startLineString(String id, ICoordinateIterator coords, |
225 |
String srs) {
|
226 |
return createCurve(coords);
|
227 |
} |
228 |
|
229 |
private Curve createCurve(ICoordinateIterator coords){
|
230 |
GeneralPathX gp = createGeneralPathX(coords); |
231 |
try {
|
232 |
Curve curve = null;
|
233 |
if (coords.getDimension() == 2){ |
234 |
curve = (Curve) geomManager.create(TYPES.CURVE, SUBTYPES.GEOM2D); |
235 |
}else if (coords.getDimension() == 3){ |
236 |
curve = (Curve) geomManager.create(TYPES.CURVE, SUBTYPES.GEOM3D); |
237 |
} |
238 |
curve.setGeneralPath(gp); |
239 |
return curve;
|
240 |
} catch (CreateGeometryException e) {
|
241 |
getErrorHandler().addError(e); |
242 |
} |
243 |
return null; |
244 |
} |
245 |
|
246 |
private GeneralPathX createGeneralPathX(ICoordinateIterator coords){
|
247 |
GeneralPathX gp = new GeneralPathX();
|
248 |
if (coords == null){ |
249 |
return gp;
|
250 |
} |
251 |
double[] buffer = new double[coords.getDimension()]; |
252 |
try {
|
253 |
if (coords.hasNext()){
|
254 |
coords.next(buffer); |
255 |
gp.moveTo(buffer[0], buffer[1]); |
256 |
} |
257 |
while(coords.hasNext()){
|
258 |
coords.next(buffer); |
259 |
gp.lineTo(buffer[0], buffer[1]); |
260 |
} |
261 |
} catch (IOException e) { |
262 |
getErrorHandler().addError(e); |
263 |
} |
264 |
return gp;
|
265 |
} |
266 |
|
267 |
/* (non-Javadoc)
|
268 |
* @see org.gvsig.gpe.parser.GPEContentHandler#startPolygon(java.lang.String, org.gvsig.gpe.parser.ICoordinateIterator, java.lang.String)
|
269 |
*/
|
270 |
|
271 |
public Object startPolygon(String id, ICoordinateIterator coords, String srs) { |
272 |
return createSurface(coords);
|
273 |
} |
274 |
|
275 |
private Surface createSurface(ICoordinateIterator coords){
|
276 |
GeneralPathX gp = createGeneralPathX(coords); |
277 |
try {
|
278 |
Surface surface = null;
|
279 |
if (coords.getDimension() == 2){ |
280 |
surface = (Surface) geomManager.create(TYPES.SURFACE, SUBTYPES.GEOM2D); |
281 |
}else if (coords.getDimension() == 3){ |
282 |
surface = (Surface) geomManager.create(TYPES.SURFACE, SUBTYPES.GEOM3D); |
283 |
} |
284 |
surface.setGeneralPath(gp); |
285 |
return surface;
|
286 |
} catch (CreateGeometryException e) {
|
287 |
getErrorHandler().addError(e); |
288 |
} |
289 |
return null; |
290 |
} |
291 |
|
292 |
|
293 |
/* (non-Javadoc)
|
294 |
* @see org.gvsig.gpe.parser.GPEContentHandler#startInnerPolygon(java.lang.String, org.gvsig.gpe.parser.ICoordinateIterator, java.lang.String)
|
295 |
*/
|
296 |
public Object startInnerPolygon(String id, ICoordinateIterator coords, |
297 |
String srs) {
|
298 |
return createSurface(coords);
|
299 |
} |
300 |
|
301 |
/*
|
302 |
* (non-Javadoc)
|
303 |
* @see org.gvsig.gpe.IGPEContentHandler#addGeometryToFeature(java.lang.Object, java.lang.Object)
|
304 |
*/
|
305 |
public void addGeometryToFeature(Object geometry, Object feature) { |
306 |
((GPEFeature)feature).setGeometry((Geometry)geometry); |
307 |
} |
308 |
|
309 |
/*
|
310 |
* (non-Javadoc)
|
311 |
* @see org.gvsig.gpe.IGPEContentHandler#addBboxToLayer(java.lang.Object, java.lang.Object)
|
312 |
*/
|
313 |
public void addBboxToLayer(Object bbox, Object layer) { |
314 |
// if (layer != null){
|
315 |
// GPEBBox gpeBBox = (GPEBBox)bbox;
|
316 |
// if (gpeBBox.getSrs() != null){
|
317 |
// IProjection projection = null;
|
318 |
// try{
|
319 |
// CRSFactory.getCRS(gpeBBox.getSrs());
|
320 |
// }catch(Exception e){
|
321 |
// //If the CRS factory has an error.
|
322 |
// }
|
323 |
// if ((projection != null) && (!(projection.equals(((FLayer)layer).getProjection())))){
|
324 |
// //TODO reproyectar la bbox y asignarsela a la capa
|
325 |
// }
|
326 |
// }
|
327 |
// ((IGPEDriver)layer).setExtent(gpeBBox.getBbox2D());
|
328 |
// }
|
329 |
} |
330 |
|
331 |
/*
|
332 |
* (non-Javadoc)
|
333 |
* @see org.gvsig.gpe.IGPEContentHandler#addElementToFeature(java.lang.Object, java.lang.Object)
|
334 |
*/
|
335 |
public void addElementToFeature(Object element, Object feature) { |
336 |
GPEElement gpeElement = (GPEElement)element; |
337 |
((GPEFeature)feature).addElement(gpeElement); |
338 |
} |
339 |
|
340 |
/*
|
341 |
* (non-Javadoc)
|
342 |
* @see org.gvsig.gpe.IGPEContentHandler#addFeatureToLayer(java.lang.Object, java.lang.Object)
|
343 |
*/
|
344 |
public void addFeatureToLayer(Object feature, Object layer) { |
345 |
GPEFeature gpefeature = (GPEFeature)feature; |
346 |
Envelope currentEnvelope = gpefeature.getEnvelope(); |
347 |
if (featureType == null){ |
348 |
createFeatureType(gpefeature); |
349 |
|
350 |
//Initialize the envelope
|
351 |
try {
|
352 |
envelope = geomManager.createEnvelope(SUBTYPES.GEOM2D); |
353 |
} catch (CreateEnvelopeException e) {
|
354 |
getErrorHandler().addError(e); |
355 |
} |
356 |
//Calculates the envelope
|
357 |
envelope = currentEnvelope; |
358 |
}else{
|
359 |
//Calculates the envelope
|
360 |
if (currentEnvelope != null){ |
361 |
envelope.add(currentEnvelope); |
362 |
} |
363 |
} |
364 |
//If it is null is a multilayer: not supported yet
|
365 |
if (layer != null){ |
366 |
FeatureProvider data = new DefaultFeatureProvider(featureType.getNotEditableCopy(), storeProvider.createNewOID());
|
367 |
Map elements = gpefeature.getelements();
|
368 |
Iterator keys = elements.keySet().iterator();
|
369 |
String gid = gpefeature.getId();
|
370 |
data.setOID(gid); |
371 |
while (keys.hasNext()){
|
372 |
String elementName = (String)keys.next(); |
373 |
data.set(elementName, ((GPEElement)elements.get(elementName)).getValue()); |
374 |
} |
375 |
data.setDefaultGeometry(gpefeature.getGeometry()); |
376 |
data.set(featureType.getDefaultGeometryAttributeIndex(), gpefeature.getGeometry()); |
377 |
((HashMap)layer).put(gid, data);
|
378 |
} |
379 |
} |
380 |
|
381 |
private void createFeatureType(GPEFeature gpefeature){ |
382 |
featureType = store.createFeatureType(); |
383 |
|
384 |
//Adding the Geometry field
|
385 |
EditableFeatureAttributeDescriptor attributeDescriptor = featureType.add("the_geom", DataTypes.GEOMETRY).setGeometryType(geometryType);
|
386 |
attributeDescriptor.setGeometrySubType(SUBTYPES.GEOM2D); |
387 |
attributeDescriptor.setSRS(srs); |
388 |
featureType.setDefaultGeometryAttributeName("the_geom");
|
389 |
|
390 |
//Adding the ID
|
391 |
featureType.add("gid", DataTypes.LONG);
|
392 |
featureType.setHasOID(true);
|
393 |
|
394 |
if (gpefeature != null){ |
395 |
Map elements = gpefeature.getelements();
|
396 |
Iterator keys = elements.keySet().iterator();
|
397 |
while (keys.hasNext()){
|
398 |
String elementName = (String)keys.next(); |
399 |
if (!elementName.equals("the_geom")){ |
400 |
featureType.add(elementName, DataTypes.STRING); |
401 |
} |
402 |
} |
403 |
} |
404 |
|
405 |
FeatureType defaultType = featureType.getNotEditableCopy(); |
406 |
List types = new ArrayList(1); |
407 |
types.add(defaultType); |
408 |
this.store.setFeatureTypes(types, defaultType);
|
409 |
} |
410 |
|
411 |
/*
|
412 |
* (non-Javadoc)
|
413 |
* @see org.gvsig.gpe.IGPEContentHandler#addInnerPolygonToPolygon(java.lang.Object, java.lang.Object)
|
414 |
*/
|
415 |
public void addInnerPolygonToPolygon(Object innerPolygon, Object Polygon) { |
416 |
//((Geometry)Polygon).addGeometry((GPEGeometry)innerPolygon);
|
417 |
} |
418 |
|
419 |
/*
|
420 |
* (non-Javadoc)
|
421 |
* @see org.gvsig.gpe.IGPEContentHandler#addNameToFeature(java.lang.String, java.lang.Object)
|
422 |
*/
|
423 |
public void addNameToFeature(String name, Object feature) { |
424 |
|
425 |
} |
426 |
|
427 |
/*
|
428 |
* (non-Javadoc)
|
429 |
* @see org.gvsig.gpe.IGPEContentHandler#addParentElementToElement(java.lang.Object, java.lang.Object)
|
430 |
*/
|
431 |
public void addParentElementToElement(Object parent, Object element) { |
432 |
|
433 |
} |
434 |
|
435 |
/*
|
436 |
* (non-Javadoc)
|
437 |
* @see org.gvsig.gpe.IGPEContentHandler#addSrsToLayer(java.lang.String, java.lang.Object)
|
438 |
*/
|
439 |
public void addSrsToLayer(String srs, Object Layer) { |
440 |
// this.srs = srs;
|
441 |
} |
442 |
|
443 |
|
444 |
/* (non-Javadoc)
|
445 |
* @see org.gvsig.gpe.parser.GPEContentHandler#startBbox(java.lang.String, org.gvsig.gpe.parser.ICoordinateIterator, java.lang.String)
|
446 |
*/
|
447 |
public Object startBbox(String id, ICoordinateIterator coords, String srs) { |
448 |
Envelope envelope = null;
|
449 |
try {
|
450 |
if (coords.getDimension() == 2){ |
451 |
envelope = geomManager.createEnvelope(SUBTYPES.GEOM2D); |
452 |
}else if (coords.getDimension() == 3){ |
453 |
envelope = geomManager.createEnvelope(SUBTYPES.GEOM3D); |
454 |
} |
455 |
double[] buffer = new double[coords.getDimension()]; |
456 |
|
457 |
if (coords.hasNext()){
|
458 |
coords.next(buffer); |
459 |
envelope.setLowerCorner(createPoint(buffer)); |
460 |
} |
461 |
if (coords.hasNext()){
|
462 |
coords.next(buffer); |
463 |
envelope.setUpperCorner(createPoint(buffer)); |
464 |
} |
465 |
} catch (IOException e) { |
466 |
getErrorHandler().addError(e); |
467 |
} catch (CreateEnvelopeException e) {
|
468 |
getErrorHandler().addError(e); |
469 |
} |
470 |
return envelope;
|
471 |
} |
472 |
|
473 |
/*
|
474 |
* (non-Javadoc)
|
475 |
* @see org.gvsig.gpe.parser.GPEContentHandler#startElement(java.lang.String, java.lang.String, java.lang.Object, org.gvsig.gpe.parser.IAttributesIterator, java.lang.Object)
|
476 |
*/
|
477 |
public Object startElement(String namespace, String name, Object value, |
478 |
IAttributesIterator attributesIterator, Object parentElement) {
|
479 |
return new GPEElement(name, value, (GPEElement)parentElement); |
480 |
} |
481 |
|
482 |
/*
|
483 |
* (non-Javadoc)
|
484 |
* @see org.gvsig.gpe.parser.GPEContentHandler#startFeature(java.lang.String, java.lang.String, java.lang.String, org.gvsig.gpe.parser.IAttributesIterator, java.lang.Object)
|
485 |
*/
|
486 |
public Object startFeature(String id, String namespace, String name, |
487 |
IAttributesIterator attributes, Object layer){
|
488 |
String sId;
|
489 |
if (id == null){ |
490 |
sId = new String(new Long(featureId).toString()); |
491 |
}else{
|
492 |
sId = id; |
493 |
} |
494 |
featureId++; |
495 |
//Check the xml schema...
|
496 |
// for (int i=0 ; i<schemas.size() ; i++){
|
497 |
// IXSSchema schema = schemas.get(i);
|
498 |
// IXSElementDeclaration element = schema.getElementDeclarationByName(namespace, name);
|
499 |
// if (element != null){
|
500 |
// featureType = store.createFeatureType();
|
501 |
// IXSTypeDefinition type = element.getTypeDefinition();
|
502 |
// if (type instanceof IXSComplexTypeDefinition){
|
503 |
// IXSComplexTypeDefinition complexType = (IXSComplexTypeDefinition)type;
|
504 |
// complexType.getContentType().
|
505 |
// }
|
506 |
//
|
507 |
// featureType.add("the_geom", DataTypes.GEOMETRY).setGeometryType(TYPES.GEOMETRY);
|
508 |
// featureType.setDefaultGeometryAttributeName("the_geom");
|
509 |
// featureType.setHasOID(true);
|
510 |
// while (keys.hasNext()){
|
511 |
// String elementName = (String)keys.next();
|
512 |
// featureType.add(elementName, DataTypes.STRING);
|
513 |
// }
|
514 |
// FeatureType defaultType = featureType.getNotEditableCopy();
|
515 |
// List types = new ArrayList(1);
|
516 |
// types.add(defaultType);
|
517 |
// this.store.setFeatureTypes(types, defaultType);
|
518 |
//
|
519 |
// //Initialize the envelope
|
520 |
// try {
|
521 |
// envelope = geomManager.createEnvelope(SUBTYPES.GEOM2D);
|
522 |
// } catch (CreateEnvelopeException e) {
|
523 |
// getErrorHandler().addError(e);
|
524 |
// }
|
525 |
// }
|
526 |
// }
|
527 |
return new GPEFeature(sId, |
528 |
name, name); |
529 |
} |
530 |
|
531 |
/* (non-Javadoc)
|
532 |
* @see org.gvsig.gpe.parser.GPEContentHandler#startLinearRing(java.lang.String, org.gvsig.gpe.parser.ICoordinateIterator, java.lang.String)
|
533 |
*/
|
534 |
public Object startLinearRing(String id, ICoordinateIterator coords, |
535 |
String srs) {
|
536 |
return createSurface(coords);
|
537 |
} |
538 |
|
539 |
/*
|
540 |
* (non-Javadoc)
|
541 |
* @see org.gvsig.gpe.IGPEContentHandler#startMultiPoint(java.lang.String, java.lang.String)
|
542 |
*/
|
543 |
public Object startMultiPoint(String id, String srs) { |
544 |
try {
|
545 |
return geomManager.create(TYPES.MULTIPOINT, SUBTYPES.GEOM2D);
|
546 |
} catch (CreateGeometryException e) {
|
547 |
getErrorHandler().addError(e); |
548 |
} |
549 |
return null; |
550 |
} |
551 |
|
552 |
/*
|
553 |
* (non-Javadoc)
|
554 |
* @see org.gvsig.gpe.IGPEContentHandler#addPointToMultiPoint(java.lang.Object, java.lang.Object)
|
555 |
*/
|
556 |
public void addPointToMultiPoint(Object point, Object multiPoint) { |
557 |
((MultiPoint)multiPoint).addPoint((Point)point);
|
558 |
} |
559 |
|
560 |
/*
|
561 |
* (non-Javadoc)
|
562 |
* @see org.gvsig.gpe.IGPEContentHandler#startMultiLineString(java.lang.String, java.lang.String)
|
563 |
*/
|
564 |
public Object startMultiLineString(String id, String srs) { |
565 |
super.startMultiLineString(id, srs);
|
566 |
try {
|
567 |
return geomManager.create(TYPES.MULTICURVE, SUBTYPES.GEOM2D);
|
568 |
} catch (CreateGeometryException e) {
|
569 |
getErrorHandler().addError(e); |
570 |
} |
571 |
return null; |
572 |
} |
573 |
|
574 |
/*
|
575 |
* (non-Javadoc)
|
576 |
* @see org.gvsig.gpe.IGPEContentHandler#addLineStringToMultiLineString(java.lang.Object, java.lang.Object)
|
577 |
*/
|
578 |
public void addLineStringToMultiLineString(Object lineString, Object multiLineString) { |
579 |
((MultiCurve)multiLineString).addCurve((Curve)lineString); |
580 |
} |
581 |
|
582 |
/*
|
583 |
* (non-Javadoc)
|
584 |
* @see org.gvsig.gpe.IGPEContentHandler#startMultiPolygon(java.lang.String, java.lang.String)
|
585 |
*/
|
586 |
public Object startMultiPolygon(String id, String srs) { |
587 |
super.startMultiPolygon(id, srs);
|
588 |
try {
|
589 |
return geomManager.create(TYPES.MULTISURFACE, SUBTYPES.GEOM2D);
|
590 |
} catch (CreateGeometryException e) {
|
591 |
getErrorHandler().addError(e); |
592 |
} |
593 |
return null; |
594 |
} |
595 |
|
596 |
/*
|
597 |
* (non-Javadoc)
|
598 |
* @see org.gvsig.gpe.IGPEContentHandler#addPolygonToMultiPolygon(java.lang.Object, java.lang.Object)
|
599 |
*/
|
600 |
public void addPolygonToMultiPolygon(Object polygon, Object multiPolygon) { |
601 |
((MultiSurface)multiPolygon).addSurface((Surface)polygon); |
602 |
} |
603 |
|
604 |
/* (non-Javadoc)
|
605 |
* @see org.gvsig.gpe.GPEContentHandler#addCurveToMultiCurve(java.lang.Object, java.lang.Object)
|
606 |
*/
|
607 |
public void addCurveToMultiCurve(Object curve, Object multiCurve) { |
608 |
((MultiCurve)multiCurve).addCurve((Curve)curve); |
609 |
} |
610 |
|
611 |
/* (non-Javadoc)
|
612 |
* @see org.gvsig.gpe.GPEContentHandler#addSegmentToCurve(java.lang.Object, java.lang.Object)
|
613 |
*/
|
614 |
public void addSegmentToCurve(Object segment, Object curve) { |
615 |
((Curve)curve).addVertex((Point)segment);
|
616 |
} |
617 |
|
618 |
/* (non-Javadoc)
|
619 |
* @see org.gvsig.gpe.parser.GPEContentHandler#startCurve(java.lang.String, org.gvsig.gpe.parser.ICoordinateIterator, java.lang.String)
|
620 |
*/
|
621 |
public Object startCurve(String id, ICoordinateIterator coords, String srs) { |
622 |
return createCurve(coords);
|
623 |
} |
624 |
|
625 |
/* (non-Javadoc)
|
626 |
* @see org.gvsig.gpe.GPEContentHandler#startCurve(java.lang.String, java.lang.String)
|
627 |
*/
|
628 |
public Object startCurve(String id, String srs) { |
629 |
return createCurve(null); |
630 |
} |
631 |
|
632 |
/* (non-Javadoc)
|
633 |
* @see org.gvsig.gpe.GPEContentHandler#startMultiCurve(java.lang.String, java.lang.String)
|
634 |
*/
|
635 |
public Object startMultiCurve(String id, String srs) { |
636 |
try {
|
637 |
return geomManager.create(TYPES.MULTICURVE, SUBTYPES.GEOM2D);
|
638 |
} catch (CreateGeometryException e) {
|
639 |
getErrorHandler().addError(e); |
640 |
} |
641 |
return null; |
642 |
} |
643 |
|
644 |
/* (non-Javadoc)
|
645 |
* @see org.gvsig.gpe.GPEContentHandler#addGeometryToMultiGeometry(java.lang.Object, java.lang.Object)
|
646 |
*/
|
647 |
public void addGeometryToMultiGeometry(Object geometry, Object multiGeometry) { |
648 |
((MultiPrimitive)multiGeometry).addPrimitive((Primitive)geometry); |
649 |
} |
650 |
|
651 |
/* (non-Javadoc)
|
652 |
* @see org.gvsig.gpe.GPEContentHandler#startMultiGeometry(java.lang.String, java.lang.String)
|
653 |
*/
|
654 |
public Object startMultiGeometry(String id, String srs) { |
655 |
try {
|
656 |
return geomManager.create(TYPES.AGGREGATE, SUBTYPES.GEOM2D);
|
657 |
} catch (CreateGeometryException e) {
|
658 |
getErrorHandler().addError(e); |
659 |
} |
660 |
return null; |
661 |
} |
662 |
|
663 |
/**
|
664 |
* @return a new OID
|
665 |
*/
|
666 |
public Object createNewOID() { |
667 |
featureId++; |
668 |
return String.valueOf(featureId); |
669 |
} |
670 |
|
671 |
/**
|
672 |
* @param envelope the envelope to set
|
673 |
*/
|
674 |
public void setEnvelope(Envelope envelope) { |
675 |
this.envelope = envelope;
|
676 |
} |
677 |
|
678 |
/**
|
679 |
* @param featureType the featureType to set
|
680 |
*/
|
681 |
public void setFeatureType(EditableFeatureType featureType) { |
682 |
this.featureType = featureType;
|
683 |
} |
684 |
} |