root / branches / v2_0_0_prep / libraries / libFMap_geometries / src / org / gvsig / fmap / geom / operation / flip / Flip.java @ 30323
History | View | Annotate | Download (3.15 KB)
1 |
package org.gvsig.fmap.geom.operation.flip; |
---|---|
2 |
|
3 |
import java.awt.geom.PathIterator; |
4 |
import java.util.ArrayList; |
5 |
|
6 |
import org.gvsig.fmap.geom.Geometry; |
7 |
import org.gvsig.fmap.geom.GeometryLocator; |
8 |
import org.gvsig.fmap.geom.GeometryManager; |
9 |
import org.gvsig.fmap.geom.operation.GeometryOperation; |
10 |
import org.gvsig.fmap.geom.operation.GeometryOperationContext; |
11 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
12 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
13 |
import org.gvsig.fmap.geom.util.Converter; |
14 |
|
15 |
import com.vividsolutions.jts.geom.Coordinate; |
16 |
import com.vividsolutions.jts.geom.CoordinateList; |
17 |
import com.vividsolutions.jts.geom.CoordinateSequences; |
18 |
import com.vividsolutions.jts.geom.impl.CoordinateArraySequence; |
19 |
|
20 |
/**
|
21 |
* This class converts the path into points, then flip it down.
|
22 |
*
|
23 |
* @author Carlos S?nchez Peri??n <a href = "mailto:csanchez@prodevelop.es"> e-mail </a>
|
24 |
*/
|
25 |
public class Flip extends GeometryOperation{ |
26 |
public static final String NAME = "flip"; |
27 |
private static GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
28 |
public static final int CODE = geomManager.getGeometryOperationCode(NAME); |
29 |
|
30 |
private GeneralPathX generalPathX = null; |
31 |
|
32 |
public int getOperationIndex() { |
33 |
return CODE;
|
34 |
} |
35 |
|
36 |
public Object invoke(Geometry geom, GeometryOperationContext ctx) throws GeometryOperationException { |
37 |
generalPathX = geom.getGeneralPath(); |
38 |
if(generalPathX == null){ |
39 |
//if there isn't path the operation hasn't sense.
|
40 |
return null; |
41 |
} |
42 |
PathIterator theIterator = geom.getPathIterator(null, geomManager.getFlatness()); //polyLine.getPathIterator(null, flatness); |
43 |
double[] theData = new double[6]; |
44 |
//Coordinate first = null;
|
45 |
CoordinateList coordList = new CoordinateList();
|
46 |
Coordinate c1; |
47 |
GeneralPathX newGp = new GeneralPathX();
|
48 |
ArrayList listOfParts = new ArrayList(); |
49 |
while (!theIterator.isDone()) {
|
50 |
//while not done
|
51 |
int type = theIterator.currentSegment(theData);
|
52 |
switch (type)
|
53 |
{ |
54 |
case (byte) PathIterator.SEG_MOVETO: |
55 |
coordList = new CoordinateList();
|
56 |
listOfParts.add(coordList); |
57 |
c1= new Coordinate(theData[0], theData[1]); |
58 |
coordList.add(c1, true);
|
59 |
break;
|
60 |
case (byte) PathIterator.SEG_LINETO: |
61 |
c1= new Coordinate(theData[0], theData[1]); |
62 |
coordList.add(c1, true);
|
63 |
break;
|
64 |
case (byte) PathIterator.SEG_CLOSE: |
65 |
coordList.add(coordList.getCoordinate(0));
|
66 |
break;
|
67 |
} |
68 |
theIterator.next(); |
69 |
} |
70 |
|
71 |
for (int i=listOfParts.size()-1; i>=0; i--) |
72 |
{ |
73 |
coordList = (CoordinateList) listOfParts.get(i); |
74 |
Coordinate[] coords = coordList.toCoordinateArray();
|
75 |
CoordinateArraySequence seq = new CoordinateArraySequence(coords);
|
76 |
CoordinateSequences.reverse(seq); |
77 |
coords = seq.toCoordinateArray(); |
78 |
newGp.moveTo(coords[0].x, coords[0].y); |
79 |
for (int j=1; j < coords.length; j++) |
80 |
{ |
81 |
newGp.lineTo(coords[j].x, coords[j].y); |
82 |
} |
83 |
} |
84 |
generalPathX.reset(); |
85 |
generalPathX.append(newGp.getPathIterator(null), false); |
86 |
|
87 |
return null; |
88 |
} |
89 |
} |