Revision 42811 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.shp/src/main/java/org/gvsig/fmap/dal/store/shp/utils/AbstractSHPReader.java

View differences:

AbstractSHPReader.java
25 25
import java.nio.ByteOrder;
26 26

  
27 27
import org.gvsig.fmap.dal.exception.ReadException;
28
import org.gvsig.fmap.dal.exception.ReadRuntimeException;
29
import org.gvsig.fmap.dal.store.shp.SHPStoreParameters;
28 30
import org.gvsig.fmap.geom.Geometry;
29 31
import org.gvsig.fmap.geom.aggregate.MultiPrimitive;
30 32
import org.gvsig.fmap.geom.exception.CreateGeometryException;
......
41 43
 *
42 44
 */
43 45
public abstract class AbstractSHPReader implements SHPReader {
46
    private final SHPStoreParameters params;
44 47

  
45 48
    /**
46 49
     *
50
     * @param params
47 51
     */
48
    public AbstractSHPReader() {
49
        // TODO Auto-generated constructor stub
52
    public AbstractSHPReader(SHPStoreParameters params) {
53
        this.params = params;
50 54
    }
55
    
56
    protected class InvalidNumberOfPointsInLinearRingException extends ReadRuntimeException {
51 57

  
58
        private final static String MESSAGE_FORMAT = "Invalid number of points in LinearRing (found %(NumPoints) - must be 0 or >= 4).\nCheck 'Fix LinearRings' in the shape's properties of the add layer dialog to try fix it.";
59
        private final static String MESSAGE_KEY = "_InvalidNumberOfPointsInLinearRingException";
60
        private static final long serialVersionUID = -8265770463632826027L;
61

  
62
        public InvalidNumberOfPointsInLinearRingException(int numPoints) {
63
            super(MESSAGE_FORMAT, null, MESSAGE_KEY, serialVersionUID);
64
            setValue("NumPoints", numPoints);
65
            this.getMessage();
66
        }
67
    }
68
    
69
    public void checkNumVerticesOfRing(Ring ring ) throws InvalidNumberOfPointsInLinearRingException {
70
            if( ring.getNumVertices()<4 ) {
71
                if( this.fixLinearRings() ) {
72
                    Point p = ring.getVertex(ring.getNumVertices()-1);
73
                    while( ring.getNumVertices()<4 ) {
74
                        p = (Point) p.cloneGeometry();
75
                        ring.addVertex(p);
76
                    }
77
                } else {
78
                    throw new InvalidNumberOfPointsInLinearRingException(ring.getNumVertices());
79
                }
80
            }        
81
    }
82
    
83
    public boolean fixLinearRings() {
84
        return params.getFixLinearRings();
85
    }
86
    
52 87
    /**
53 88
     * @param p
54 89
     * @param bb

Also available in: Unified diff