svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_geometries / src / org / gvsig / fmap / geom / operation / tojts / MultiCurveToJTS.java @ 39280
History | View | Annotate | Download (3.82 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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 2
|
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 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2009 {Iver T.I.} {Task}
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.fmap.geom.operation.tojts; |
29 |
|
30 |
import java.util.ArrayList; |
31 |
import java.util.List; |
32 |
|
33 |
import com.vividsolutions.jts.geom.LineString; |
34 |
import com.vividsolutions.jts.geom.MultiLineString; |
35 |
|
36 |
import org.slf4j.Logger; |
37 |
import org.slf4j.LoggerFactory; |
38 |
|
39 |
import org.gvsig.fmap.geom.Geometry; |
40 |
import org.gvsig.fmap.geom.aggregate.MultiCurve; |
41 |
import org.gvsig.fmap.geom.operation.GeometryOperationContext; |
42 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
43 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
44 |
|
45 |
/**
|
46 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
47 |
*/
|
48 |
public class MultiCurveToJTS extends ToJTS{ |
49 |
|
50 |
private static Logger logger = LoggerFactory.getLogger(MultiCurveToJTS.class); |
51 |
/*
|
52 |
* (non-Javadoc)
|
53 |
* @see org.gvsig.fmap.geom.operation.tojts.ToJTS#invoke(org.gvsig.fmap.geom.Geometry, org.gvsig.fmap.geom.operation.GeometryOperationContext)
|
54 |
*/
|
55 |
public Object invoke(Geometry geom, GeometryOperationContext ctx) throws GeometryOperationException { |
56 |
int srid = -1; |
57 |
if (ctx != null){ |
58 |
srid = ((JTSGeometryOperationContext)ctx).getSrid(); |
59 |
} |
60 |
MultiCurve multiCurve = (MultiCurve)geom; |
61 |
Object item = null; |
62 |
List ls_list = new ArrayList(); |
63 |
|
64 |
int prim_n = multiCurve.getPrimitivesNumber();
|
65 |
|
66 |
for (int i = 0; i < prim_n; i++){ |
67 |
try {
|
68 |
item = multiCurve.getPrimitiveAt(i).invokeOperation(CODE, ctx); |
69 |
|
70 |
if (item instanceof MultiLineString) { |
71 |
|
72 |
/*
|
73 |
* A multilinestring can also be returned
|
74 |
*/
|
75 |
MultiLineString mls = (MultiLineString) item; |
76 |
for (int k = 0; k<mls.getNumGeometries(); k++) { |
77 |
com.vividsolutions.jts.geom.Geometry p = mls.getGeometryN(k); |
78 |
if (p instanceof LineString) { |
79 |
ls_list.add(p); |
80 |
} |
81 |
} |
82 |
|
83 |
} else {
|
84 |
if (item instanceof LineString) { |
85 |
/*
|
86 |
* Including primitives converted to linestring.
|
87 |
* Short primitives can return a point
|
88 |
*/
|
89 |
ls_list.add(item); |
90 |
} else {
|
91 |
String txt = (item == null) ? "NULL" : item.getClass().getName(); |
92 |
logger.info("Warning: excluding primitive in MultiCurveToJTS because it converted to a JTS " + txt);
|
93 |
} |
94 |
} |
95 |
|
96 |
} catch (GeometryOperationNotSupportedException e) {
|
97 |
throw new GeometryOperationException(e); |
98 |
} |
99 |
} |
100 |
|
101 |
LineString[] lines = (LineString[]) ls_list.toArray(new LineString[0]); |
102 |
|
103 |
MultiLineString lineString = new com.vividsolutions.jts.geom.GeometryFactory().createMultiLineString(lines);
|
104 |
lineString.setSRID(srid); |
105 |
return lineString;
|
106 |
} |
107 |
} |