root / branches / v2_0_0_prep / extensions / extRasterTools-SE / src / org / gvsig / rastertools / vectorizacion / vector / VectorProcess.java @ 32880
History | View | Annotate | Download (5.75 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
package org.gvsig.rastertools.vectorizacion.vector; |
20 |
|
21 |
import java.io.File; |
22 |
|
23 |
import org.cresques.cts.IProjection; |
24 |
import org.gvsig.fmap.dal.DALLocator; |
25 |
import org.gvsig.fmap.dal.DataManager; |
26 |
import org.gvsig.fmap.dal.exception.InitializeException; |
27 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
28 |
import org.gvsig.fmap.dal.store.shp.SHPStoreParameters; |
29 |
import org.gvsig.fmap.dal.store.shp.SHPStoreProvider; |
30 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
31 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
32 |
import org.gvsig.fmap.mapcontext.layers.LayerFactory; |
33 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
34 |
import org.gvsig.raster.IProcessActions; |
35 |
import org.gvsig.raster.RasterLibrary; |
36 |
import org.gvsig.raster.RasterProcess; |
37 |
import org.gvsig.raster.grid.filter.FilterTypeException; |
38 |
import org.gvsig.raster.util.RasterToolsUtil; |
39 |
import org.gvsig.raster.util.RasterUtilities; |
40 |
import org.gvsig.rastertools.vectorizacion.process.ContourLinesProcess; |
41 |
import org.gvsig.rastertools.vectorizacion.process.PotraceProcess; |
42 |
|
43 |
/**
|
44 |
* Procesos necesarios para la funcionalidad de vectorizaci?n.
|
45 |
*
|
46 |
* 11/07/2008
|
47 |
* @author Nacho Brodin nachobrodin@gmail.com
|
48 |
*/
|
49 |
public class VectorProcess implements IProcessActions { |
50 |
private FLyrRasterSE sourceLayer = null; |
51 |
private IProcessActions endActions = null; |
52 |
private String shapeName = null; |
53 |
private IProjection proj = null; |
54 |
|
55 |
/**
|
56 |
* Constructor que asigna el nombre de capa
|
57 |
* @param lyrPath
|
58 |
*/
|
59 |
public VectorProcess(FLyrRasterSE lyr, IProcessActions endActions, IProjection proj) {
|
60 |
this.sourceLayer = lyr;
|
61 |
this.endActions = endActions;
|
62 |
this.proj = proj;
|
63 |
} |
64 |
|
65 |
/**
|
66 |
* Aplica el proceso de recorte sobre el raster inicial
|
67 |
* @throws FilterTypeException
|
68 |
* @throws LoadLayerException
|
69 |
*/
|
70 |
public void contourLines(double distance) throws FilterTypeException, LoadLayerException { |
71 |
if(sourceLayer == null) |
72 |
return;
|
73 |
|
74 |
RasterProcess contourLinesProcess = new ContourLinesProcess();
|
75 |
contourLinesProcess.setActions(this);
|
76 |
shapeName = RasterLibrary.getTemporalPath() + File.separator + RasterLibrary.usesOnlyLayerName() + ".shp"; |
77 |
contourLinesProcess.addParam("filename", shapeName);
|
78 |
contourLinesProcess.addParam("layer", sourceLayer);
|
79 |
contourLinesProcess.addParam("min", new Double(0)); |
80 |
contourLinesProcess.addParam("max", new Double(255)); |
81 |
contourLinesProcess.addParam("distance", new Double(distance)); |
82 |
contourLinesProcess.start(); |
83 |
} |
84 |
|
85 |
/**
|
86 |
* Aplica el proceso para vectorizar con potrace
|
87 |
*/
|
88 |
public void potraceLines(int policy, int bezierPoints, int despeckle, double cornerThreshold, double optimizationTolerance, int outputQuantization, boolean curveOptimization) { |
89 |
PotraceProcess potraceProcess = new PotraceProcess();
|
90 |
potraceProcess.setActions(this);
|
91 |
shapeName = RasterLibrary.getTemporalPath() + File.separator + RasterLibrary.usesOnlyLayerName() + ".shp"; |
92 |
potraceProcess.addParam("filename", shapeName);
|
93 |
potraceProcess.addParam("layer", sourceLayer);
|
94 |
potraceProcess.addParam("policy", new Integer(policy)); |
95 |
potraceProcess.addParam("points", new Integer(bezierPoints)); |
96 |
potraceProcess.addParam("despeckle", new Integer(despeckle)); |
97 |
potraceProcess.addParam("cornerThreshold", new Double(cornerThreshold)); |
98 |
potraceProcess.addParam("optimizationTolerance", new Double(optimizationTolerance)); |
99 |
potraceProcess.addParam("outputQuantization", new Integer(outputQuantization)); |
100 |
potraceProcess.addParam("curveoptimization", new Boolean(curveOptimization)); |
101 |
potraceProcess.start(); |
102 |
} |
103 |
|
104 |
/*
|
105 |
* (non-Javadoc)
|
106 |
* @see org.gvsig.raster.IProcessActions#end(java.lang.Object)
|
107 |
*/
|
108 |
public void end(Object param) { |
109 |
FLayer shpLyr = null;
|
110 |
try {
|
111 |
String layerName = RasterUtilities.getFileNameFromCanonical(shapeName);
|
112 |
DataManager datamanager=DALLocator.getDataManager(); |
113 |
SHPStoreParameters params=null;
|
114 |
try {
|
115 |
params = (SHPStoreParameters)datamanager.createStoreParameters(SHPStoreProvider.NAME); |
116 |
params.setCRS(proj); |
117 |
} catch (InitializeException e) {
|
118 |
throw new LoadLayerException(shapeName,e); |
119 |
} catch (ProviderNotRegisteredException e) {
|
120 |
throw new LoadLayerException(shapeName,e); |
121 |
} |
122 |
params.setFile(shapeName); |
123 |
|
124 |
shpLyr = LayerFactory.getInstance().createLayer(layerName, params); |
125 |
} catch (LoadLayerException e) {
|
126 |
RasterToolsUtil.messageBoxError("error_generating_layer", null, e); |
127 |
} |
128 |
if(endActions != null) |
129 |
endActions.end(new Object[]{this, shpLyr}); |
130 |
} |
131 |
|
132 |
/*
|
133 |
* (non-Javadoc)
|
134 |
* @see org.gvsig.raster.IProcessActions#interrupted(java.lang.Object)
|
135 |
*/
|
136 |
public void interrupted() { |
137 |
} |
138 |
|
139 |
/**
|
140 |
* Asigna la capa raster a vectorizar
|
141 |
* @param lyr
|
142 |
*/
|
143 |
public void setSourceLayer(FLyrRasterSE lyr) { |
144 |
this.sourceLayer = lyr;
|
145 |
} |
146 |
|
147 |
/**
|
148 |
* Asigna el interfaz para que el proceso ejectute las acciones de finalizaci?n
|
149 |
* al acabar.
|
150 |
* @param endActions
|
151 |
*/
|
152 |
public void setProcessActions(IProcessActions endActions) { |
153 |
this.endActions = endActions;
|
154 |
} |
155 |
} |