~ubuntu-branches/ubuntu/feisty/postgis/feisty

« back to all changes in this revision

Viewing changes to jdbc/org/postgis/MultiLineString.java

  • Committer: Bazaar Package Importer
  • Author(s): Alex Bodnaru
  • Date: 2005-05-05 10:02:45 UTC
  • Revision ID: james.westby@ubuntu.com-20050505100245-3005l6jn1jwvpsrw
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.postgis;
 
2
 
 
3
import org.postgresql.util.*;
 
4
import java.sql.*;
 
5
import java.util.*;
 
6
 
 
7
 
 
8
public class MultiLineString extends Geometry 
 
9
{
 
10
 
 
11
        LineString[] lines;
 
12
        
 
13
        public MultiLineString() 
 
14
        {
 
15
                type = MULTILINESTRING;
 
16
        }
 
17
 
 
18
        public MultiLineString(LineString[] lines) 
 
19
        {
 
20
                this();
 
21
                this.lines = lines;
 
22
                dimension = lines[0].dimension;
 
23
        }
 
24
        
 
25
        public MultiLineString(String value) throws SQLException
 
26
        {
 
27
                this();
 
28
                value = value.trim();
 
29
                if ( value.indexOf("MULTILINESTRING") == 0 ) 
 
30
                {
 
31
                        PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value.substring(15).trim()),',');
 
32
                        int nlines = t.getSize();
 
33
                        lines = new LineString[nlines];
 
34
                        for( int p = 0; p < nlines; p++)
 
35
                        {
 
36
                                lines[p] = new LineString(t.getToken(p));
 
37
                        }
 
38
                        dimension = lines[0].dimension;
 
39
                } else {
 
40
                        throw new SQLException("postgis.multilinestringgeometry");
 
41
                }
 
42
        }
 
43
        
 
44
        public String toString() 
 
45
        {
 
46
                return "MULTILINESTRING " + getValue();
 
47
        }
 
48
 
 
49
        public String getValue() 
 
50
        {
 
51
                StringBuffer b = new StringBuffer("(");
 
52
                for( int p = 0; p < lines.length; p++ )
 
53
                {
 
54
                        if( p > 0 ) b.append(",");
 
55
                        b.append(lines[p].getValue());
 
56
                }
 
57
                b.append(")");
 
58
                return b.toString();
 
59
        }
 
60
        
 
61
        public int numLines() 
 
62
        {
 
63
                return lines.length;
 
64
        }
 
65
        
 
66
        public LineString getLine(int idx) 
 
67
        {
 
68
                if( idx >= 0 & idx < lines.length ) {
 
69
                        return lines[idx];
 
70
                }
 
71
                else {
 
72
                        return null;
 
73
                }
 
74
        }
 
75
 
 
76
}