root / trunk / extensions / extGeoProcessing / src-test / com / iver / cit / gvsig / geoprocess / impl / buffer / BufferTest.java @ 12955
History | View | Annotate | Download (5.68 KB)
1 |
/*
|
---|---|
2 |
* Created on 25-abr-2007
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
21 |
*
|
22 |
* For more information, contact:
|
23 |
*
|
24 |
* Generalitat Valenciana
|
25 |
* Conselleria d'Infraestructures i Transport
|
26 |
* Av. Blasco Ib??ez, 50
|
27 |
* 46010 VALENCIA
|
28 |
* SPAIN
|
29 |
*
|
30 |
* +34 963862235
|
31 |
* gvsig@gva.es
|
32 |
* www.gvsig.gva.es
|
33 |
*
|
34 |
* or
|
35 |
*
|
36 |
* IVER T.I. S.A
|
37 |
* Salamanca 50
|
38 |
* 46005 Valencia
|
39 |
* Spain
|
40 |
*
|
41 |
* +34 963163400
|
42 |
* dac@iver.es
|
43 |
*/
|
44 |
/* CVS MESSAGES:
|
45 |
*
|
46 |
* $Id: BufferTest.java 12955 2007-08-07 16:21:00Z azabala $
|
47 |
* $Log$
|
48 |
* Revision 1.1 2007-08-07 16:21:00 azabala
|
49 |
* new version in cvs.
|
50 |
*
|
51 |
* Revision 1.1 2007/07/12 11:33:24 azabala
|
52 |
* *** empty log message ***
|
53 |
*
|
54 |
*
|
55 |
*/
|
56 |
package com.iver.cit.gvsig.geoprocess.impl.buffer; |
57 |
|
58 |
import java.io.File; |
59 |
import java.net.URL; |
60 |
import java.util.HashMap; |
61 |
|
62 |
import junit.framework.TestCase; |
63 |
|
64 |
import org.cresques.cts.IProjection; |
65 |
|
66 |
import com.hardcode.gdbms.driver.exceptions.InitializeWriterException; |
67 |
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException; |
68 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
69 |
import com.iver.cit.gvsig.fmap.drivers.SHPLayerDefinition; |
70 |
import com.iver.cit.gvsig.fmap.edition.IWriter; |
71 |
import com.iver.cit.gvsig.fmap.edition.ShpSchemaManager; |
72 |
import com.iver.cit.gvsig.fmap.edition.writers.shp.MultiShpWriter; |
73 |
import com.iver.cit.gvsig.fmap.edition.writers.shp.ShpWriter; |
74 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
75 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
76 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
77 |
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException; |
78 |
import com.iver.cit.gvsig.geoprocess.core.fmap.XTypes; |
79 |
import com.iver.cit.gvsig.geoprocess.impl.buffer.fmap.BufferGeoprocess; |
80 |
import com.iver.cit.gvsig.geoprocess.impl.buffer.fmap.BufferVisitor; |
81 |
|
82 |
|
83 |
//TODO All geoprocessing test classes must hava a common abstract base class
|
84 |
//(a lot of code is repeated)
|
85 |
//
|
86 |
|
87 |
public class BufferTest extends TestCase { |
88 |
|
89 |
static final String fwAndamiDriverPath = "../_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/drivers"; |
90 |
private static File baseDataPath; |
91 |
private static File baseDriversPath; |
92 |
public static String SHP_DRIVER_NAME = "gvSIG shp driver"; |
93 |
|
94 |
static IProjection PROJECTION_DEFAULT = CRSFactory.getCRS("EPSG:23030"); |
95 |
|
96 |
|
97 |
protected void setUp() throws Exception { |
98 |
URL url = BufferTest.class.getResource("testdata"); |
99 |
if (url == null) |
100 |
throw new Exception("No se encuentra el directorio con datos de prueba"); |
101 |
|
102 |
baseDataPath = new File(url.getFile()); |
103 |
if (!baseDataPath.exists())
|
104 |
throw new Exception("No se encuentra el directorio con datos de prueba"); |
105 |
|
106 |
baseDriversPath = new File(fwAndamiDriverPath); |
107 |
if (!baseDriversPath.exists())
|
108 |
throw new Exception("Can't find drivers path: " + fwAndamiDriverPath); |
109 |
|
110 |
LayerFactory.setDriversPath(baseDriversPath.getAbsolutePath()); |
111 |
LayerFactory.setWritersPath(baseDriversPath.getAbsolutePath()); |
112 |
if (LayerFactory.getDM().getDriverNames().length < 1) |
113 |
throw new Exception("Can't find drivers in path: " + fwAndamiDriverPath); |
114 |
|
115 |
} |
116 |
|
117 |
|
118 |
public static FLayer newLayer(String fileName, |
119 |
String driverName)
|
120 |
throws LoadLayerException {
|
121 |
File file = new File(baseDataPath, fileName); |
122 |
return LayerFactory.createLayer(fileName,
|
123 |
driverName, |
124 |
file, PROJECTION_DEFAULT); |
125 |
} |
126 |
|
127 |
|
128 |
|
129 |
public void test1() throws LoadLayerException, InitializeWriterException, GeoprocessException { |
130 |
FLyrVect inputLayer = (FLyrVect) newLayer("parcelas.shp", SHP_DRIVER_NAME);
|
131 |
File outputFile = new File(baseDataPath+"/test1result.shp"); |
132 |
BufferGeoprocess geoprocess = new BufferGeoprocess(inputLayer);
|
133 |
|
134 |
HashMap params = new HashMap(); |
135 |
//buffer all features (onlySelection = false)
|
136 |
//buffer distance = 10m, buffer type = outside, number of radial polygons = 1
|
137 |
params.put("layer_selection", new Boolean(false)); |
138 |
params.put("dissolve_buffers", new Boolean(true)); |
139 |
params.put("buffer_distance", new Double(10d)); |
140 |
params.put("strategy_flag", new Byte(BufferGeoprocess.CONSTANT_DISTANCE_STRATEGY)); |
141 |
params.put("numRings", new Integer(1)); |
142 |
params.put("typePolBuffer", new Byte(BufferVisitor.BUFFER_OUTSIDE_POLY)); |
143 |
params.put("cap", new Byte(BufferVisitor.CAP_ROUND)); |
144 |
params.put("projection", PROJECTION_DEFAULT);
|
145 |
params.put("distanceunits", new Integer(1)); |
146 |
params.put("mapunits", new Integer(1)); |
147 |
|
148 |
geoprocess.setParameters(params); |
149 |
|
150 |
|
151 |
SHPLayerDefinition definition = (SHPLayerDefinition) geoprocess.createLayerDefinition(); |
152 |
definition.setFile(outputFile); |
153 |
ShpSchemaManager schemaManager = new ShpSchemaManager(outputFile.getAbsolutePath());
|
154 |
IWriter writer = null;
|
155 |
int shapeType = definition.getShapeType();
|
156 |
if(shapeType != XTypes.MULTI){
|
157 |
writer = new ShpWriter();
|
158 |
((ShpWriter) writer).setFile(definition.getFile()); |
159 |
writer.initialize(definition); |
160 |
}else{
|
161 |
writer = new MultiShpWriter();
|
162 |
((MultiShpWriter) writer).setFile(definition.getFile()); |
163 |
writer.initialize(definition); |
164 |
} |
165 |
geoprocess.setResultLayerProperties(writer, schemaManager); |
166 |
|
167 |
geoprocess.checkPreconditions(); |
168 |
geoprocess.process(); |
169 |
|
170 |
} |
171 |
|
172 |
} |
173 |
|