Statistics
| Revision:

root / branches / v10 / extensions / extPublish / src / org / gvsig / publish / infoproject / datasources / ShapefileInfo.java @ 19419

History | View | Annotate | Download (5.36 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004-2006 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *   Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Iba?ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *   +34 963862235
28
 *   gvsig@gva.es
29
 *   www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.publish.infoproject.datasources;
42

    
43

    
44
import java.awt.geom.Rectangle2D;
45
import java.io.File;
46
import java.io.IOException;
47

    
48
import org.cresques.cts.ICoordTrans;
49
import org.cresques.cts.IProjection;
50
import org.gvsig.publish.PublishLogger;
51
import org.gvsig.publish.infoproject.IDataSourceInfo;
52

    
53
import com.iver.cit.gvsig.fmap.core.FShape;
54
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
55
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
56
import com.iver.cit.gvsig.fmap.drivers.shp.IndexedShpDriver;
57
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter;
58
import com.iver.utiles.FileUtils;
59
/**
60
 * Class that represents a shapefile information 
61
 * 
62
 * @author Jos? Vicente Hig?n (josevicente.higon@iver.es)
63
 * @see IFileInfo, IVectorialDSInfo
64
 *
65
 */
66
public class ShapefileInfo implements IFileInfo, IDataSourceInfo {        
67
        private IndexedShpDriver driver = null;
68
        private VectorialAdapter adapter;
69
        private String epsg=null;
70

    
71
        /**
72
         * Constructor 
73
         * @return
74
         */
75
        public ShapefileInfo(VectorialAdapter adapter) {
76
                this.adapter = adapter;
77
                this.driver = (IndexedShpDriver) adapter.getDriver();
78
        }        
79
        /**
80
         * @return the absolute path to the shapefile
81
         */
82
        public String getAbsolutePath() {                
83
                return driver.getFile().getAbsolutePath();
84
        }
85
        /**
86
         * @return the name of the file  
87
         */
88
        public String getFileName() {
89

    
90
                return driver.getFile().getName();
91
        }
92
        /**
93
         *  
94
         * @return the type of the datasource, SHAPEFILE, POSTGIS_TABLE, ... 
95
         * 
96
         */
97
//        public String getDataSourceType() {
98
//        return IVectorialDSInfo.SHAPEFILE;
99
//        }
100
        /**
101
         * @return the type of the geometries, POINT, POLYGON, LINE, MULTIGEOM, ...
102
         * @throws
103
         * TODO: Throw a publish exception  
104
         */
105
//        public String getGeomType(){
106
//        try {
107
//        switch (adapter.getShapeType()){
108
//        case FShape.POINT:
109
//        return IVectorialDSInfo.POINT;
110
//        case FShape.POLYGON:
111
//        return IVectorialDSInfo.POLYGON;
112
//        case FShape.LINE:
113
//        return IVectorialDSInfo.LINE;
114
//        }
115
//        } catch (DriverIOException e) {
116
//        // TODO Auto-generated catch block
117
//        e.printStackTrace();
118
//        }
119

    
120
//        return null;
121
//        }
122
        public Rectangle2D getNativeBBox() {
123
                
124
                Rectangle2D bbox = null;
125
                
126
                //adapter.getFullExtent()                
127
                try {
128
                        bbox = driver.getFullExtent();
129
                } catch (IOException e) {
130
                        PublishLogger.getLog().error("ERROR ShapefileInfo",e);
131
                }
132
                return bbox;
133
        }
134
        /**
135
         * 
136
         * @param epsg which has been set by the user
137
         */
138
        public void setEPSG(String epsg){
139
                this.epsg = epsg;
140
        }
141
        /**
142
         * I can't know the coordinate system of the shapefile. You must set it before.
143
         * TODO: see the projection in the prj file 
144
         */
145
        public String getEPSG() {                                        
146
                return epsg;
147
        }
148
        public String getDataType() {
149
                try {
150
                        switch (adapter.getShapeType()){
151
                        case FShape.POINT:
152
                                return IDataSourceInfo.POINT_DATA;
153
                        case FShape.POLYGON:
154
                                return IDataSourceInfo.POLYGON_DATA;
155
                        case FShape.LINE:
156
                                return IDataSourceInfo.LINE_DATA;
157
                        }
158
                } catch (DriverIOException e) {
159
                        PublishLogger.getLog().error("ERROR ShapefileInfo",e);
160
                }
161
                return null;
162
        }
163
        /**
164
         * 
165
         * @see org.gvsig.publish.infoproject.IDataSourceInfo#getType()
166
         */
167
        public String getType() {
168
                return SHAPE_TYPE;
169
        }
170
        /**
171
         * 
172
         * @see org.gvsig.publish.infoproject.datasources.IFileInfo#getExtension()
173
         */
174
        public String getExtension() {
175
                return FileUtils.getFileExtension(driver.getFile());
176
        }
177
        /**
178
         * 
179
         * @see org.gvsig.publish.infoproject.IDataSourceInfo#getLatLonBBox()
180
         */
181
        public Rectangle2D getLatLonBBox() {
182
                IProjection proj_source = CRSFactory.getCRS(getEPSG());
183
                IProjection proj_dest = CRSFactory.getCRS("EPSG:4326");
184
                ICoordTrans trans = proj_source.getCT(proj_dest);                
185
                return trans.convert(getNativeBBox());
186
        }
187
        /**
188
         * the datastore is the shapefile itself
189
         * @return shapefile name
190
         * @see org.gvsig.publish.infoproject.IDataSourceInfo#getConnectionName()
191
         */
192
        public String getConnectionName() {
193
                return getFileName();
194
        }
195
        /*
196
         * 
197
         * @see org.gvsig.publish.infoproject.datasources.IFileInfo#getFile()
198
         */
199
        public File getFile() {                
200
                return driver.getFile();
201
        }
202
        /*
203
         * (non-Javadoc)
204
         * @see org.gvsig.publish.infoproject.datasources.IFileInfo#getFilenameWithoutExtension()
205
         */
206
        public String getFilenameWithoutExtension() {
207
                String aux = getFileName();
208
                int i = aux.lastIndexOf(".");                
209
                return aux.substring(0,i);
210
        }
211
        
212
}