Revision 27010 branches/v2_0_0_prep/libraries/libGeocoding/src/org/gvsig/geocoding/styles/SimpleCentroid.java
SimpleCentroid.java | ||
---|---|---|
27 | 27 |
|
28 | 28 |
package org.gvsig.geocoding.styles; |
29 | 29 |
|
30 |
import java.util.ArrayList; |
|
31 |
import java.util.HashMap; |
|
32 |
import java.util.Iterator; |
|
30 | 33 |
import java.util.List; |
34 |
import java.util.Map; |
|
31 | 35 |
|
32 | 36 |
import org.gvsig.fmap.dal.feature.Feature; |
33 |
import org.gvsig.geocoding.Component; |
|
37 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
38 |
import org.gvsig.fmap.dal.feature.FeatureReference; |
|
39 |
import org.gvsig.fmap.geom.Geometry; |
|
40 |
import org.gvsig.geocoding.geommatches.MatcherUtils; |
|
41 |
import org.gvsig.geocoding.result.DissolveResult; |
|
34 | 42 |
|
35 | 43 |
/** |
36 | 44 |
* |
... | ... | |
40 | 48 |
*/ |
41 | 49 |
|
42 | 50 |
public class SimpleCentroid extends AbstractGeocodingStyle { |
43 |
|
|
51 |
|
|
44 | 52 |
/** |
45 | 53 |
* Dissolve features geometry behind one folder |
46 | 54 |
* |
47 | 55 |
* @param field |
48 | 56 |
* @param features |
49 | 57 |
*/ |
50 |
public void dissolveFeatures(Component field, List<Feature> features) { |
|
51 |
}; |
|
58 |
public List<DissolveResult> dissolveFeatures( |
|
59 |
FeatureAttributeDescriptor field, List<Feature> features) { |
|
60 |
|
|
61 |
List<DissolveResult> listResults = new ArrayList<DissolveResult>(); |
|
62 |
|
|
63 |
// Group geometries by main attribute |
|
64 |
HashMap<String, List<Feature>> dissolAttributes = MatcherUtils |
|
65 |
.groupFeaturesByAttribute(field, features); |
|
66 |
|
|
67 |
// For each group of features, to do geometries dissolve process getting one o |
|
68 |
// more geometries |
|
69 |
for (Iterator<Map.Entry<String, List<Feature>>> iterator = dissolAttributes |
|
70 |
.entrySet().iterator(); iterator.hasNext();) { |
|
71 |
Map.Entry<String, List<Feature>> e = iterator.next(); |
|
72 |
List<Feature> feats = e.getValue(); |
|
73 |
// parse gvSIG geometries to JTS geometries |
|
74 |
List<Geometry> geoss = new ArrayList<Geometry>(); |
|
75 |
for (int i = 0; i < feats.size(); i++) { |
|
76 |
geoss.add(feats.get(i).getDefaultGeometry()); |
|
77 |
} |
|
78 |
List<com.vividsolutions.jts.geom.Geometry> jtsGeomsList = MatcherUtils |
|
79 |
.parseGeomsGVToJTS(geoss); |
|
80 |
// dissolve Lines (first geometry of array is Line) |
|
81 |
List<com.vividsolutions.jts.geom.Geometry> geomsDissol = null; |
|
82 |
if (jtsGeomsList.get(0).getDimension() == 1) { |
|
83 |
geomsDissol = MatcherUtils.dissolveLinesJTS(jtsGeomsList); |
|
84 |
} |
|
85 |
// dissolve Polys (first geometry of array is Poly) |
|
86 |
if (jtsGeomsList.get(0).getDimension() == 2) { |
|
87 |
geomsDissol = MatcherUtils.dissolvePolysJTS(jtsGeomsList); |
|
88 |
} |
|
89 |
// Parse JTS geometries to gvSIG geometries |
|
90 |
List<Geometry> gvGeoms = MatcherUtils |
|
91 |
.parseGeomsJTSToGV(geomsDissol); |
|
92 |
// Store dissolve geometries and the features references in the dissolve result |
|
93 |
DissolveResult res = new DissolveResult(); |
|
94 |
res.setGeoms(gvGeoms); |
|
95 |
List <FeatureReference> refs = new ArrayList<FeatureReference>(); |
|
96 |
for (int i = 0; i < feats.size(); i++) { |
|
97 |
refs.add(feats.get(i).getReference()); |
|
98 |
} |
|
99 |
res.setFeaturesReferences(refs); |
|
100 |
listResults.add(res); |
|
101 |
} |
|
102 |
return listResults; |
|
103 |
} |
|
52 | 104 |
} |
Also available in: Unified diff