Revision 47669 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.gml/src/main/java/org/gvsig/fmap/dal/store/gml/simplereaders/GMLReader.java

View differences:

GMLReader.java
6 6
package org.gvsig.fmap.dal.store.gml.simplereaders;
7 7

  
8 8
import java.io.File;
9
import java.io.FileInputStream;
9 10
import java.io.IOException;
10 11
import java.io.Reader;
11 12
import java.nio.charset.Charset;
13
import java.util.Collection;
12 14
import java.util.List;
13 15
import org.apache.commons.io.FilenameUtils;
14 16
import org.apache.commons.io.IOUtils;
......
18 20
import org.gvsig.fmap.dal.store.gml.GMLStoreParameters;
19 21
import org.gvsig.fmap.dal.store.gml.virtualrows.GfsFile;
20 22
import org.gvsig.fmap.dal.store.gml.virtualrows.XMLFileAsList;
23
import org.gvsig.fmap.dal.store.gml.virtualrows.XmlCommons;
21 24
import org.gvsig.fmap.dal.store.simplereader.SimpleReaderStoreParameters;
22 25
import static org.gvsig.fmap.dal.store.simplereader.SimpleReaderUtils.isFileNewer;
23 26
import org.gvsig.fmap.dal.store.simplereader.simplereaders.AbstractSimpleReader;
27
import org.gvsig.fmap.geom.GeometryUtils;
28
import org.gvsig.fmap.geom.type.GeometryType;
24 29
import org.gvsig.tools.ToolsLocator;
25 30
import org.gvsig.tools.dataTypes.DataType;
26 31
import org.gvsig.tools.dataTypes.DataTypesManager;
......
47 52

  
48 53
    public GMLReader(Reader reader, GMLStoreParameters theParameters) throws IOException {
49 54
        File gmlFile = theParameters.getFile();
50
        File gmlIdx = new File(FilenameUtils.removeExtension(gmlFile.getAbsolutePath())+".gmlidx");
55
//        File gmlIdx = new File(FilenameUtils.removeExtension(gmlFile.getAbsolutePath())+".gmlidx");
51 56
        File gfsFile = new File(FilenameUtils.removeExtension(gmlFile.getAbsolutePath())+".gfs");
52 57
        gfs = new GfsFile();
53 58
        if(gfsFile.exists() && isFileNewer(gfsFile, gmlFile)){
......
73 78
    private IProjection toProjection(String srs){
74 79
        IProjection proj;
75 80
//        http://www.opengis.net/def/crs/EPSG/0/25830
81
//        urn:ogc:def:crs,crs:EPSG:6.12:3068,crs:EPSG:6.12:5783
82
//        urn:ogc:def:crs:EPSG:6.12:3068
83
//        urn:ogc:def:crs:EPSG::4326
84
//        urn:ogc:def:crs:OGC:2:84 //Este formato no lo parseamos
76 85
        try {
77 86
            if(StringUtils.startsWithIgnoreCase(srs, "http://www.opengis.net/def/crs")){
78 87
                String[] ss = StringUtils.split(srs, "/");
79 88
                String crs = ss[ss.length-3]+":"+ss[ss.length-1];
80 89
                proj = CRSFactory.getCRS(crs);
90
            } else if(StringUtils.startsWithIgnoreCase(srs, "urn:ogc:def:crs,crs:")){
91
                String[] ss = StringUtils.split(srs, ",");
92
                String[] ss2 = StringUtils.split(ss[1],":");
93
                String crs = ss2[1]+":"+ss2[ss2.length-1];
94
                proj = CRSFactory.getCRS(crs);
95
            } else if(StringUtils.startsWithIgnoreCase(srs, "urn:ogc:def:crs:")){
96
                String[] ss = StringUtils.split(srs, ":");
97
                String crs = ss[4]+":"+ss[ss.length-1];
98
                proj = CRSFactory.getCRS(crs);
81 99
            } else {
82 100
                proj = CRSFactory.getCRS(srs);
83 101
            }
......
92 110
    @Override
93 111
    public String[] getHeader() throws IOException {
94 112
        if (this.header == null) {
95
            List<String> geoms = gfs.getGeometryElementPaths();
113
            Collection<GfsFile.GeometryPropertyDefn> geoms = gfs.getGeometryElements();
96 114
            String[] theHeader = new String[gfs.size()+(geoms==null?0:geoms.size())];
97 115
            int i = 0;
98 116
            DataTypesManager dataTypesManager = ToolsLocator.getDataTypesManager();
......
100 118
                DataType dataType = dataTypesManager.get(item.getType());
101 119
                theHeader[i++] = item.getName()+"/"+dataType.getName();
102 120
            }
103
            if(geoms != null) {
104
                List<String> srss = gfs.getGeometryElementSrss();
121
            if(geoms != null && !geoms.isEmpty()) {
105 122
                if(this.parameters.getGeometryCombineMode() == XMLFileAsList.COMBINE_FIRST_NOT_NULL){
106
                    String srs = srss.get(0);
107
                    for (int j = 0; j < srss.size(); j++) {
108
                        if(!StringUtils.equalsIgnoreCase(srs, srss.get(j))){
109
                            srs = null;
110
                            break;
123
                    String srs = null;
124
                    for (GfsFile.GeometryPropertyDefn geom : geoms) {
125
                        if(srs == null){
126
                            srs = geom.getSrs();
127
                        } else {
128
                            if(!StringUtils.equalsIgnoreCase(srs, geom.getSrs())){
129
                                srs = null;
130
                                break;
131
                            }
111 132
                        }
112 133
                    }
113 134
                    IProjection proj = null;
......
115 136
                        proj = toProjection(srs);
116 137
                    }
117 138
                    if(proj == null){
118
                        theHeader[i++] = FilenameUtils.getBaseName(getGeometryAttributeName())+"/Geometry";
139
                        theHeader[i++] = getGeometryAttributeName()+"/Geometry";
119 140
                    } else {
120
                        theHeader[i++] = FilenameUtils.getBaseName(getGeometryAttributeName())+"/Geometry/set/srs="+proj.getAbrev().replace(":", "@");
141
                        theHeader[i++] = getGeometryAttributeName()+"/Geometry/set/srs="+proj.getAbrev().replace(":", "@");
121 142
                    }
122 143
                } else {
123
                    for (int j = 0; j < srss.size(); j++) {
124
                        IProjection srs = toProjection(srss.get(j));
144
                    for (GfsFile.GeometryPropertyDefn geom : geoms) {
145
                        GeometryType geomType = geom.getGeometryType();
146
                        String geomType_s = "/set/geomtype="+GeometryUtils.getGeometryTypeName(geomType.getType())+":"+GeometryUtils.getGeometrySubtypeName(geomType.getSubType());
147
                        IProjection srs = toProjection(geom.getSrs());
125 148
                        if(srs == null){
126
                            theHeader[i++] = FilenameUtils.getBaseName(geoms.get(j))+"/Geometry";
149
                            theHeader[i++] = geom.getName()+"/Geometry"+geomType_s;
127 150
                        } else {
128
                            theHeader[i++] = FilenameUtils.getBaseName(geoms.get(j))+"/Geometry/set/srs="+srs.getAbrev().replace(":", "@");
151
                            theHeader[i++] = geom.getName()+"/Geometry/set/srs="+srs.getAbrev().replace(":", "@")+geomType_s;
129 152
                        }
130 153
                    }
131 154
                }
......
207 230
    public GetItemWithSize64<List<String>> getVirtualRows(SimpleTaskStatus status) {
208 231
        try {
209 232
            File gmlFile = this.parameters.getFile();
233
            String charset = SimpleReaderStoreParameters.getCharset(this.parameters);
234
            if(StringUtils.isBlank(charset)){
235
                FileInputStream fis = null;
236
                try {
237
                    fis = new FileInputStream(gmlFile);
238
                    charset = XmlCommons.detectCharsetName(fis);
239
                } catch (Throwable t) {
240
                    charset = "UTF-8";
241
                } finally {
242
                    IOUtils.closeQuietly(fis);
243
                }
244
            }
210 245

  
211 246
            XMLFileAsList x = new XMLFileAsList(
212 247
                gmlFile,
213
                Charset.forName(SimpleReaderStoreParameters.getCharset(this.parameters)),
248
                Charset.forName(charset),
214 249
                gfs.getBaseElementPath(),
215 250
                gfs.getGeometryElementPaths(),
216 251
                gfs.getPropertiesPaths()

Also available in: Unified diff