svn-gvsig-desktop / trunk / libraries / libGPE / src-test / org / gvsig / gpe / writers / warnings / GPEPolygonAutomaticallyClosedTest.java @ 19194
History | View | Annotate | Download (4.03 KB)
1 |
package org.gvsig.gpe.writers.warnings; |
---|---|
2 |
|
3 |
import org.gvsig.gpe.containers.Feature; |
4 |
import org.gvsig.gpe.containers.GeometryAsserts; |
5 |
import org.gvsig.gpe.containers.Layer; |
6 |
import org.gvsig.gpe.containers.Polygon; |
7 |
import org.gvsig.gpe.warnings.PolygonAutomaticallyClosedWarning; |
8 |
import org.gvsig.gpe.writers.GPEWriterBaseTest; |
9 |
|
10 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
11 |
*
|
12 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
13 |
*
|
14 |
* This program is free software; you can redistribute it and/or
|
15 |
* modify it under the terms of the GNU General Public License
|
16 |
* as published by the Free Software Foundation; either version 2
|
17 |
* of the License, or (at your option) any later version.
|
18 |
*
|
19 |
* This program is distributed in the hope that it will be useful,
|
20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
22 |
* GNU General Public License for more details.
|
23 |
*
|
24 |
* You should have received a copy of the GNU General Public License
|
25 |
* along with this program; if not, write to the Free Software
|
26 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
27 |
*
|
28 |
* For more information, contact:
|
29 |
*
|
30 |
* Generalitat Valenciana
|
31 |
* Conselleria d'Infraestructures i Transport
|
32 |
* Av. Blasco Ib??ez, 50
|
33 |
* 46010 VALENCIA
|
34 |
* SPAIN
|
35 |
*
|
36 |
* +34 963862235
|
37 |
* gvsig@gva.es
|
38 |
* www.gvsig.gva.es
|
39 |
*
|
40 |
* or
|
41 |
*
|
42 |
* IVER T.I. S.A
|
43 |
* Salamanca 50
|
44 |
* 46005 Valencia
|
45 |
* Spain
|
46 |
*
|
47 |
* +34 963163400
|
48 |
* dac@iver.es
|
49 |
*/
|
50 |
/* CVS MESSAGES:
|
51 |
*
|
52 |
* $Id: GPEPolygonAutomaticallyClosedTest.java 144 2007-06-07 14:53:59Z jorpiell $
|
53 |
* $Log$
|
54 |
* Revision 1.2 2007/06/07 14:52:28 jorpiell
|
55 |
* Add the schema support
|
56 |
*
|
57 |
* Revision 1.1 2007/05/16 09:28:34 jorpiell
|
58 |
* The polygons has to be closed
|
59 |
*
|
60 |
*
|
61 |
*/
|
62 |
/**
|
63 |
* This class creates a polygon without close it. When
|
64 |
* the polygon is readed, it has had to be closed and
|
65 |
* a warning has had to be throwed
|
66 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
67 |
*/
|
68 |
public abstract class GPEPolygonAutomaticallyClosedTest extends GPEWriterBaseTest{ |
69 |
private String layerId = "l1"; |
70 |
private String layerName = "Municipallity"; |
71 |
private String layerDescription = "Polygons test layer"; |
72 |
private String srs = "EPSG:23030"; |
73 |
private String feature1Name = "Madrid"; |
74 |
private String feature1Id = "f1"; |
75 |
private String polygon1Id = "p1"; |
76 |
private double[] polygon1X = generateRandomCoordinates(); |
77 |
private double[] polygon1Y = generateRandomCoordinates(); |
78 |
private double[] polygon1Z = generateRandomCoordinates(); |
79 |
|
80 |
/*
|
81 |
* (non-Javadoc)
|
82 |
* @see org.gvsig.gpe.writers.GPEWriterBaseTest#readObjects()
|
83 |
*/
|
84 |
public void readObjects() { |
85 |
Layer[] layers = getLayers();
|
86 |
assertEquals(layers.length, 1);
|
87 |
Layer layer = layers[0];
|
88 |
|
89 |
assertEquals(layer.getFeatures().size(), 1);
|
90 |
//FEATURE 1
|
91 |
Feature feature1 = (Feature)layer.getFeatures().get(0);
|
92 |
polygon1X = closePolygon(polygon1X); |
93 |
polygon1Y = closePolygon(polygon1Y); |
94 |
polygon1Z = closePolygon(polygon1Z); |
95 |
GeometryAsserts.polygon((Polygon)feature1.getGeometry(), polygon1X, polygon1Y, polygon1Z);
|
96 |
|
97 |
//Two warinings
|
98 |
boolean isClosed = false; |
99 |
for (int i=0 ; i<getErrorHandler().getWarningsSize() ; i++){ |
100 |
Object obj = getErrorHandler().getWarningAt(i);
|
101 |
if (obj instanceof PolygonAutomaticallyClosedWarning){ |
102 |
isClosed = true;
|
103 |
} |
104 |
System.out.println(getErrorHandler().getWarningAt(i));
|
105 |
} |
106 |
assertTrue(isClosed); |
107 |
} |
108 |
|
109 |
/*
|
110 |
* (non-Javadoc)
|
111 |
* @see org.gvsig.gpe.writers.GPEWriterBaseTest#writeObjects()
|
112 |
*/
|
113 |
public void writeObjects() { |
114 |
polygon1X[polygon1X.length - 1] = 0.0; |
115 |
polygon1Y[polygon1Y.length - 1] = 0.0; |
116 |
polygon1Z[polygon1Z.length - 1]= 0.0; |
117 |
|
118 |
getWriterHandler().initialize(); |
119 |
getWriterHandler().startLayer(layerId, layerName, layerDescription, srs, null);
|
120 |
getWriterHandler().startFeature(feature1Id,feature1Name, null);
|
121 |
getWriterHandler().startPolygon(polygon1Id, |
122 |
polygon1X, |
123 |
polygon1Y, |
124 |
polygon1Z, |
125 |
srs); |
126 |
getWriterHandler().endPolygon(); |
127 |
getWriterHandler().endFeature(); |
128 |
getWriterHandler().endLayer(); |
129 |
getWriterHandler().close(); |
130 |
} |
131 |
|
132 |
} |
133 |
|