?? ?
2010-04-20 b326756ddd7eee426d7d0e93a485ec30b6fbb5fd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package com.ximple.io.dgn7;
 
//~--- non-JDK imports --------------------------------------------------------
 
import org.apache.log4j.Logger;
 
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
 
import com.ximple.util.DgnUtility;
 
/**
 * LineElement
 *
 * @author Ulysses
 * @version 0.1
 * @since 2006/5/18 �W�� 11:34:59
 */
public class LineElement extends Element implements GeometryConverter {
    private static final Logger logger = Logger.getLogger(LineElement.class);
 
    LineElement(byte[] raw) {
        super(raw);
    }
 
    public Coordinate getCentroid(double dTolerance) {
        return null;
    }
 
    public Coordinate getEndPoint() {
        int endX = ((raw[22] << 16) & 0xffff0000) | (raw[23] & 0x0000ffff);
        int endY = ((raw[24] << 16) & 0xffff0000) | (raw[25] & 0x0000ffff);
 
 
        double x = DgnUtility.converUnitToCoord(endX);
        double y = DgnUtility.converUnitToCoord(endY);
 
        return new Coordinate(x, y);
    }
 
    public Coordinate getNormal() {
        return null;
    }
 
    public Coordinate getOrigin() {
        return null;
    }
 
    public Coordinate getStartPoint() {
        int startX = ((raw[18] << 16) & 0xffff0000);
        startX = startX + (raw[19] & 0x0000ffff);
 
        double x = DgnUtility.converUnitToCoord(startX);
        int startY = ((raw[20] << 16) & 0xffff0000);
 
        startY = startY + (raw[21] & 0x0000ffff);
 
        double y = DgnUtility.converUnitToCoord(startY);
 
        return new Coordinate(x, y);
    }
 
    public Coordinate getVertex(int index) {
        return (index == 0)
            ? getStartPoint()
            : getEndPoint();
    }
 
    public double getLength() {
        Coordinate p1 = getStartPoint();
        Coordinate p2 = getEndPoint();
 
        return DgnUtility.getLength(p1.x, p1.y, p2.x, p2.y);
    }
 
    public Coordinate pointAtDistance(double dDistance, double dTolerance) {
        return null;
    }
 
    public Coordinate[] getVertices() {
        Coordinate[] result = new Coordinate[2];
 
        result[0] = getStartPoint();
        result[1] = getEndPoint();
 
        return result;
    }
 
    public Geometry toGeometry(GeometryFactory factory) {
        return factory.createLineString(getVertices());
    }
 
    public static class ElementHandler extends Element.ElementHandler {
        private static ElementHandler instance = null;
 
        public ElementHandler() {
            super(ElementType.LINE);
        }
 
        public static IElementHandler getInstance() {
            if (instance == null) {
                instance = new ElementHandler();
            }
 
            return instance;
        }
 
        protected Element createElement(byte[] raw) {
            return new LineElement(raw);
        }
    }
}