svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.geometry / org.gvsig.fmap.geometry.operation / src / main / java / org / gvsig / fmap / geom / operation / tojts / ToJTS.java @ 40559
History | View | Annotate | Download (2.65 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.fmap.geom.operation.tojts; |
25 |
|
26 |
import java.lang.reflect.Array; |
27 |
|
28 |
import org.gvsig.fmap.geom.Geometry; |
29 |
import org.gvsig.fmap.geom.GeometryLocator; |
30 |
import org.gvsig.fmap.geom.GeometryManager; |
31 |
import org.gvsig.fmap.geom.operation.GeometryOperation; |
32 |
import org.gvsig.fmap.geom.operation.GeometryOperationContext; |
33 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
34 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
35 |
import org.gvsig.fmap.geom.util.Converter; |
36 |
|
37 |
import com.vividsolutions.jts.geom.Coordinate; |
38 |
|
39 |
public abstract class ToJTS extends GeometryOperation { |
40 |
public static final String NAME = "toJTS"; |
41 |
protected static GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
42 |
public static final int CODE = geomManager.getGeometryOperationCode(NAME); |
43 |
protected final static com.vividsolutions.jts.geom.GeometryFactory geomFactory = new com.vividsolutions.jts.geom.GeometryFactory(); |
44 |
|
45 |
public int getOperationIndex() { |
46 |
return CODE;
|
47 |
} |
48 |
|
49 |
protected boolean isClosed(Coordinate firstCoordinate, Coordinate lastCoordinate){ |
50 |
double diff = Math.abs(lastCoordinate.x - firstCoordinate.x); |
51 |
if (diff > 0.000001){ |
52 |
return false; |
53 |
} |
54 |
diff = Math.abs(lastCoordinate.y - firstCoordinate.y);
|
55 |
if (diff > 0.000001) { |
56 |
return false; |
57 |
} |
58 |
return true; |
59 |
} |
60 |
|
61 |
protected boolean pointInList(Coordinate testPoint, Coordinate[] pointList) { |
62 |
int t;
|
63 |
int numpoints;
|
64 |
Coordinate p; |
65 |
|
66 |
numpoints = Array.getLength(pointList);
|
67 |
|
68 |
for (t = 0; t < numpoints; t++) { |
69 |
p = pointList[t]; |
70 |
|
71 |
if ((testPoint.x == p.x) && (testPoint.y == p.y) &&
|
72 |
((testPoint.z == p.z) || (!(testPoint.z == testPoint.z))) //nan test; x!=x iff x is nan
|
73 |
) { |
74 |
return true; |
75 |
} |
76 |
} |
77 |
|
78 |
return false; |
79 |
} |
80 |
} |