root / branches / v2_0_0_prep / extensions / extRasterTools-SE / src / org / gvsig / rastertools / vectorizacion / vector / VectorProcess.java @ 26368
History | View | Annotate | Download (5.06 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.mapcontext.exceptions.LoadLayerException; |
25 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
26 |
import org.gvsig.fmap.mapcontext.layers.LayerFactory; |
27 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
28 |
import org.gvsig.raster.IProcessActions; |
29 |
import org.gvsig.raster.RasterLibrary; |
30 |
import org.gvsig.raster.RasterProcess; |
31 |
import org.gvsig.raster.grid.filter.FilterTypeException; |
32 |
import org.gvsig.raster.util.RasterToolsUtil; |
33 |
import org.gvsig.raster.util.RasterUtilities; |
34 |
import org.gvsig.rastertools.vectorizacion.process.ContourLinesProcess; |
35 |
import org.gvsig.rastertools.vectorizacion.process.PotraceProcess; |
36 |
|
37 |
/**
|
38 |
* Procesos necesarios para la funcionalidad de vectorizaci?n.
|
39 |
*
|
40 |
* 11/07/2008
|
41 |
* @author Nacho Brodin nachobrodin@gmail.com
|
42 |
*/
|
43 |
public class VectorProcess implements IProcessActions { |
44 |
private FLyrRasterSE sourceLayer = null; |
45 |
private IProcessActions endActions = null; |
46 |
private String shapeName = null; |
47 |
private IProjection proj = null; |
48 |
|
49 |
/**
|
50 |
* Constructor que asigna el nombre de capa
|
51 |
* @param lyrPath
|
52 |
*/
|
53 |
public VectorProcess(FLyrRasterSE lyr, IProcessActions endActions, IProjection proj) {
|
54 |
this.sourceLayer = lyr;
|
55 |
this.endActions = endActions;
|
56 |
this.proj = proj;
|
57 |
} |
58 |
|
59 |
/**
|
60 |
* Aplica el proceso de recorte sobre el raster inicial
|
61 |
* @throws FilterTypeException
|
62 |
* @throws LoadLayerException
|
63 |
*/
|
64 |
public void contourLines(double distance) throws FilterTypeException, LoadLayerException { |
65 |
if(sourceLayer == null) |
66 |
return;
|
67 |
|
68 |
RasterProcess contourLinesProcess = new ContourLinesProcess();
|
69 |
contourLinesProcess.setActions(this);
|
70 |
shapeName = RasterLibrary.tempCacheDirectoryPath + File.separator + RasterLibrary.usesOnlyLayerName() + ".shp"; |
71 |
contourLinesProcess.addParam("filename", shapeName);
|
72 |
contourLinesProcess.addParam("layer", sourceLayer);
|
73 |
contourLinesProcess.addParam("min", new Double(0)); |
74 |
contourLinesProcess.addParam("max", new Double(255)); |
75 |
contourLinesProcess.addParam("distance", new Double(distance)); |
76 |
contourLinesProcess.start(); |
77 |
} |
78 |
|
79 |
/**
|
80 |
* Aplica el proceso para vectorizar con potrace
|
81 |
*/
|
82 |
public void potraceLines(int policy, int bezierPoints, int despeckle, double cornerThreshold, double optimizationTolerance, int outputQuantization, boolean curveOptimization) { |
83 |
PotraceProcess potraceProcess = new PotraceProcess();
|
84 |
potraceProcess.setActions(this);
|
85 |
shapeName = RasterLibrary.tempCacheDirectoryPath + File.separator + RasterLibrary.usesOnlyLayerName() + ".shp"; |
86 |
potraceProcess.addParam("filename", shapeName);
|
87 |
potraceProcess.addParam("layer", sourceLayer);
|
88 |
potraceProcess.addParam("policy", new Integer(policy)); |
89 |
potraceProcess.addParam("points", new Integer(bezierPoints)); |
90 |
potraceProcess.addParam("despeckle", new Integer(despeckle)); |
91 |
potraceProcess.addParam("cornerThreshold", new Double(cornerThreshold)); |
92 |
potraceProcess.addParam("optimizationTolerance", new Double(optimizationTolerance)); |
93 |
potraceProcess.addParam("outputQuantization", new Integer(outputQuantization)); |
94 |
potraceProcess.addParam("curveoptimization", new Boolean(curveOptimization)); |
95 |
potraceProcess.start(); |
96 |
} |
97 |
|
98 |
/*
|
99 |
* (non-Javadoc)
|
100 |
* @see org.gvsig.raster.IProcessActions#end(java.lang.Object)
|
101 |
*/
|
102 |
public void end(Object param) { |
103 |
FLayer shpLyr = null;
|
104 |
try {
|
105 |
String layerName = RasterUtilities.getFileNameFromCanonical(shapeName);
|
106 |
shpLyr = LayerFactory.createLayer(layerName, "gvSIG shp driver", new File(shapeName), proj); |
107 |
} catch (LoadLayerException e) {
|
108 |
RasterToolsUtil.messageBoxError("error_generating_layer", null, e); |
109 |
} |
110 |
if(endActions != null) |
111 |
endActions.end(new Object[]{this, shpLyr}); |
112 |
} |
113 |
|
114 |
/*
|
115 |
* (non-Javadoc)
|
116 |
* @see org.gvsig.raster.IProcessActions#interrupted(java.lang.Object)
|
117 |
*/
|
118 |
public void interrupted() { |
119 |
} |
120 |
|
121 |
/**
|
122 |
* Asigna la capa raster a vectorizar
|
123 |
* @param lyr
|
124 |
*/
|
125 |
public void setSourceLayer(FLyrRasterSE lyr) { |
126 |
this.sourceLayer = lyr;
|
127 |
} |
128 |
|
129 |
/**
|
130 |
* Asigna el interfaz para que el proceso ejectute las acciones de finalizaci?n
|
131 |
* al acabar.
|
132 |
* @param endActions
|
133 |
*/
|
134 |
public void setProcessActions(IProcessActions endActions) { |
135 |
this.endActions = endActions;
|
136 |
} |
137 |
} |