Statistics
| Revision:

root / trunk / libraries / libTopology / src / com / vividsolutions / jcs / simplify / FeatureShortSegmentRemover.java @ 22873

History | View | Annotate | Download (2.83 KB)

1
/*
2
 * The JCS Conflation Suite (JCS) is a library of Java classes that
3
 * can be used to build automated or semi-automated conflation solutions.
4
 *
5
 * Copyright (C) 2003 Vivid Solutions
6
 *
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
 *
21
 * For more information, contact:
22
 *
23
 * Vivid Solutions
24
 * Suite #1A
25
 * 2328 Government Street
26
 * Victoria BC  V8T 5G5
27
 * Canada
28
 *
29
 * (250)385-6040
30
 * www.vividsolutions.com
31
 */
32
package com.vividsolutions.jcs.simplify;
33

    
34
import java.util.*;
35
import com.vividsolutions.jump.feature.*;
36
import com.vividsolutions.jts.geom.*;
37
import com.vividsolutions.jump.task.*;
38

    
39
public class FeatureShortSegmentRemover {
40

    
41
  private FeatureCollection features;
42
  private FeatureCollection adjustedFC;
43
  private double minLength;
44
  private double maxDisplacement;
45
  private int updateCount = 0;
46
  private int segmentsRemovedCount = 0;
47

    
48
  public FeatureShortSegmentRemover(FeatureCollection features, double minLength, double maxDisplacement)
49
  {
50
    this.features = features;
51
    this.minLength = minLength;
52
    this.maxDisplacement = maxDisplacement;
53
  }
54

    
55
  public int getUpdateCount()
56
  {
57
    return updateCount;
58
  }
59

    
60
  public int getSegmentsRemovedCount() { return segmentsRemovedCount; }
61

    
62
  public FeatureCollection process(TaskMonitor monitor)
63
  {
64
    FeatureUpdateRecorder updates =  new FeatureUpdateRecorder();
65
    int totalSegments = features.size();
66
    int count = 0;
67
    for (Iterator i = features.iterator(); i.hasNext(); ) {
68
      monitor.report(++count, totalSegments, "features");
69
      Feature f = (Feature) i.next();
70
      Geometry geom = f.getGeometry();
71
      GeometryShortSegmentRemover remover = new GeometryShortSegmentRemover(geom, minLength, maxDisplacement);
72
      Geometry newGeom = remover.getResult();
73
      if (remover.isModified()) {
74
        // don't update geometry if it's not valid
75
        if (newGeom.isValid()) {
76
          Feature newFeat = f.clone(false);
77
          newFeat.setGeometry(newGeom);
78
          // record this feature as an update to the original
79
          updates.update(f, newFeat);
80
          segmentsRemovedCount += remover.getSegmentsRemovedCount();
81
        }
82
      }
83
    }
84
    updateCount = updates.getCount();
85

    
86
    return updates.applyUpdates(features);
87
  }
88
}