Statistics
| Revision:

root / trunk / libraries / libCq CMS for java.old / src / org / cresques / io / GeoFile.java @ 8120

History | View | Annotate | Download (3.97 KB)

1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 *
4
 * Copyright (C) 2004-5.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 * cresques@gmail.com
23
 */
24
package org.cresques.io;
25

    
26
import java.awt.geom.AffineTransform;
27
import java.awt.geom.Point2D;
28
import java.util.Date;
29

    
30
import org.cresques.cts.ICoordTrans;
31
import org.cresques.cts.IProjection;
32
import org.cresques.geo.Projected;
33
import org.cresques.px.Extent;
34
import org.cresques.px.IObjList;
35

    
36

    
37
/**
38
 * Ancestro de todos los formatos geogr?ficos
39
 *
40
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>* @author administrador
41
 */
42
public abstract class GeoFile implements Projected, Extent.Has {
43
    IProjection proj = null;
44
    protected Extent extent = null;
45
    
46
    /**
47
     * Esto corresponde a la transformaci?n del extent de la imagen. Se calcula a partir del extent
48
     * guardado en el fichero .rmf asociado a la imagen.  En caso de que no exista este fichero no habr?
49
     * transformaci?n
50
     */
51
    protected AffineTransform        transformNewExtent = null;
52
    protected AffineTransform        transformOldExtent = null;
53
    protected Point2D                         extentsRatio = null;
54
    
55
    
56
    protected boolean                        rmfExists = false;
57
    long fileSize = 0;
58
    protected long bytesReaded = 0;
59
    protected long lineCnt = 0;
60
    String name;
61

    
62
    public GeoFile() {
63
    }
64

    
65
    public GeoFile(IProjection p, String n) {
66
        proj = p;
67
        name = n;
68

    
69
        if (name != null) {
70
            name = DataSource.normalize(name);
71
        }
72
        extent = new Extent();
73
        extentsRatio = new Point2D.Double();
74
            transformNewExtent = new AffineTransform();
75
            transformOldExtent = new AffineTransform();
76
    }
77

    
78
    public String getName() {
79
        return name;
80
    }
81

    
82
    public void setName(String n) {
83
        name = n;
84
    }
85

    
86
    public long getFileSize() {
87
        return fileSize;
88
    }
89

    
90
    public void setFileSize(long sz) {
91
        fileSize = sz;
92
    }
93

    
94
    public IProjection getProjection() {
95
        return proj;
96
    }
97

    
98
    public void setProjection(IProjection p) {
99
        proj = p;
100
    }
101

    
102
    abstract public void reProject(ICoordTrans rp);
103

    
104
    public Extent getExtent() {
105
        return extent;
106
    }
107
    
108
    /**
109
     * Obtiene la relaci?n entre anchos y altos de la georreferenciaci?n de la imagen y la asignada
110
     * a trav?s del fichero .rmf. Esto se usa para poder realizar transformaciones entre ambos sistemas
111
     * al asignar una vista.
112
     * @return
113
     */
114
    public Point2D getExtentRatio() {
115
        return extentsRatio;
116
    }
117

    
118
    abstract public GeoFile load();
119

    
120
    abstract public void close();
121

    
122
    abstract public IObjList getObjects();
123

    
124
    /**
125
     * Filtra espacios en blanco. Deja solo uno por
126
     */
127
    public static String filterWS(String buf) {
128
        boolean lastCharWhite = false;
129
        String str = "";
130
        buf = buf.trim();
131

    
132
        for (int i = 0; i < buf.length(); i++) {
133
            char c = buf.charAt(i);
134

    
135
            if (Character.isWhitespace(c)) {
136
                if (lastCharWhite) {
137
                    continue;
138
                }
139

    
140
                lastCharWhite = true;
141
                c = ' ';
142
            } else {
143
                lastCharWhite = false;
144
            }
145

    
146
            str += c;
147
        }
148

    
149
        return str;
150
    }
151

    
152
    protected long getTime() {
153
        return (new Date()).getTime();
154
    }
155
}