Revision 13044
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/shp/IndexedShpDriver.java | ||
---|---|---|
164 | 164 |
// bb = channel.map(FileChannel.MapMode.READ_ONLY, 0, size); |
165 | 165 |
bb = new BigByteBuffer2(channel, FileChannel.MapMode.READ_ONLY); |
166 | 166 |
|
167 |
finShx = new FileInputStream(getShxFile(f)); |
|
167 |
finShx = new FileInputStream(SHP.getShxFile(f));
|
|
168 | 168 |
|
169 | 169 |
// Open the file and then get a channel from the stream |
170 | 170 |
channelShx = finShx.getChannel(); |
... | ... | |
620 | 620 |
public synchronized Rectangle2D getShapeBounds(int index) throws ReadDriverException { |
621 | 621 |
Point2D p = new Point2D.Double(); |
622 | 622 |
Rectangle2D BoundingBox = new Rectangle2D.Double(); |
623 |
bb.position(getPositionForRecord(index)); |
|
623 |
try { |
|
624 |
bb.position(getPositionForRecord(index)); |
|
625 |
}catch (Exception e) { |
|
626 |
logger.error(" Shapefile is corrupted. Drawing aborted. ="+e+ " "+"index = "+index); |
|
627 |
} |
|
624 | 628 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
625 | 629 |
|
626 | 630 |
int tipoShape = bb.getInt(); |
... | ... | |
683 | 687 |
return "gdbms dbf driver"; |
684 | 688 |
} |
685 | 689 |
|
686 |
/** |
|
687 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getDataFile(java.io.File) |
|
688 |
*/ |
|
689 |
public File getDataFile(File f) { |
|
690 |
String str = f.getAbsolutePath(); |
|
691 |
|
|
692 |
return new File(str.substring(0, str.length() - 3) + "dbf"); |
|
693 |
} |
|
694 |
|
|
695 |
public File getShxFile(File f) { |
|
696 |
String str = f.getAbsolutePath(); |
|
697 |
|
|
698 |
return new File(str.substring(0, str.length() - 3) + "shx"); |
|
699 |
} |
|
700 |
|
|
701 |
|
|
702 | 690 |
/* (non-Javadoc) |
703 | 691 |
* @see com.iver.cit.gvsig.fmap.drivers.BoundedShapes#getShapeType(int) |
704 | 692 |
*/ |
... | ... | |
778 | 766 |
DriverUtilities.copy(fcinShp, fcoutShp); |
779 | 767 |
|
780 | 768 |
// Shx |
781 |
File shxFile = getShxFile(fTemp); |
|
769 |
File shxFile = SHP.getShxFile(fTemp);
|
|
782 | 770 |
FileChannel fcinShx = new FileInputStream(shxFile).getChannel(); |
783 |
FileChannel fcoutShx = new FileOutputStream(getShxFile(fileShp)).getChannel(); |
|
771 |
FileChannel fcoutShx = new FileOutputStream(SHP.getShxFile(fileShp)).getChannel();
|
|
784 | 772 |
DriverUtilities.copy(fcinShx, fcoutShx); |
785 | 773 |
|
786 | 774 |
// Dbf |
... | ... | |
865 | 853 |
public boolean isWriteAll() { |
866 | 854 |
return true; |
867 | 855 |
} |
868 |
|
|
856 |
public File getDataFile(File f) { |
|
857 |
return SHP.getDbfFile(f); |
|
858 |
} |
|
869 | 859 |
} |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/shp/SHP.java | ||
---|---|---|
178 | 178 |
|
179 | 179 |
return new double[] { min, max }; |
180 | 180 |
} |
181 |
public static File getDbfFile(File shpFile){ |
|
182 |
String str = shpFile.getAbsolutePath(); |
|
183 |
File directory=shpFile.getParentFile(); |
|
184 |
MyFileFilter myFileFilter = new MyFileFilter(str); |
|
185 |
File[] files=directory.listFiles(myFileFilter); |
|
186 |
String[] ends=new String[] {"dbf","DBF","Dbf","dBf","DBf","dbF","DbF","dBF"}; |
|
187 |
File dbfFile=findEnd(str,files,ends); |
|
188 |
return dbfFile; |
|
189 |
} |
|
190 |
public static File getShxFile(File shpFile){ |
|
191 |
String str = shpFile.getAbsolutePath(); |
|
192 |
File directory=shpFile.getParentFile(); |
|
193 |
MyFileFilter myFileFilter = new MyFileFilter(str); |
|
194 |
File[] files=directory.listFiles(myFileFilter); |
|
195 |
String[] ends=new String[] {"shx","SHX","Shx","sHx","SHx","shX","ShX","sHX"}; |
|
196 |
File shxFile=findEnd(str,files,ends); |
|
197 |
return shxFile; |
|
198 |
} |
|
199 |
private static File findEnd(String str,File[] files, String[] ends) { |
|
200 |
for (int i=0;i<files.length;i++) { |
|
201 |
File dbfFile=files[i]; |
|
202 |
if (dbfFile.getAbsolutePath().endsWith(ends[0])) |
|
203 |
return dbfFile; |
|
204 |
} |
|
205 |
for (int i=0;i<files.length;i++) { |
|
206 |
File dbfFile=files[i]; |
|
207 |
if (dbfFile.getAbsolutePath().endsWith(ends[1])) |
|
208 |
return dbfFile; |
|
209 |
} |
|
210 |
for (int i=0;i<files.length;i++) { |
|
211 |
File dbfFile=files[i]; |
|
212 |
if (dbfFile.getAbsolutePath().endsWith(ends[2])) |
|
213 |
return dbfFile; |
|
214 |
} |
|
215 |
for (int i=0;i<files.length;i++) { |
|
216 |
File dbfFile=files[i]; |
|
217 |
if (dbfFile.getAbsolutePath().endsWith(ends[3])) |
|
218 |
return dbfFile; |
|
219 |
} |
|
220 |
for (int i=0;i<files.length;i++) { |
|
221 |
File dbfFile=files[i]; |
|
222 |
if (dbfFile.getAbsolutePath().endsWith(ends[4])) |
|
223 |
return dbfFile; |
|
224 |
} |
|
225 |
for (int i=0;i<files.length;i++) { |
|
226 |
File dbfFile=files[i]; |
|
227 |
if (dbfFile.getAbsolutePath().endsWith(ends[5])) |
|
228 |
return dbfFile; |
|
229 |
} |
|
230 |
for (int i=0;i<files.length;i++) { |
|
231 |
File dbfFile=files[i]; |
|
232 |
if (dbfFile.getAbsolutePath().endsWith(ends[6])) |
|
233 |
return dbfFile; |
|
234 |
} |
|
235 |
for (int i=0;i<files.length;i++) { |
|
236 |
File dbfFile=files[i]; |
|
237 |
if (dbfFile.getAbsolutePath().endsWith(ends[7])) |
|
238 |
return dbfFile; |
|
239 |
} |
|
240 |
return new File(str.substring(0, str.length() - 3) + ends[0]); |
|
241 |
} |
|
242 |
|
|
181 | 243 |
} |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/shp/MyFileFilter.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.fmap.drivers.shp; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.FileFilter; |
|
5 |
|
|
6 |
public class MyFileFilter implements FileFilter { |
|
7 |
private String shpPath; |
|
8 |
public MyFileFilter(String shpPath){ |
|
9 |
this.shpPath=shpPath; |
|
10 |
} |
|
11 |
public boolean accept(File pathname) { |
|
12 |
String strend=pathname.getAbsolutePath(); |
|
13 |
strend=strend.substring(0,strend.length()-3); |
|
14 |
String strshp=shpPath.substring(0, shpPath.length() - 3); |
|
15 |
if (strend.equals(strshp)) { |
|
16 |
return true; |
|
17 |
} |
|
18 |
return false; |
|
19 |
} |
|
20 |
|
|
21 |
} |
|
0 | 22 |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/edition/writers/shp/ShpWriter.java | ||
---|---|---|
22 | 22 |
import com.iver.cit.gvsig.fmap.drivers.ITableDefinition; |
23 | 23 |
import com.iver.cit.gvsig.fmap.drivers.shp.DbaseFileHeaderNIO; |
24 | 24 |
import com.iver.cit.gvsig.fmap.drivers.shp.DbaseFileWriterNIO; |
25 |
import com.iver.cit.gvsig.fmap.drivers.shp.SHP; |
|
25 | 26 |
import com.iver.cit.gvsig.fmap.drivers.shp.write.SHPFileWrite; |
26 | 27 |
import com.iver.cit.gvsig.fmap.drivers.shp.write.ShapefileException; |
27 | 28 |
import com.iver.cit.gvsig.fmap.edition.IRowEdited; |
... | ... | |
72 | 73 |
{ |
73 | 74 |
shpPath = f.getAbsolutePath(); |
74 | 75 |
|
75 |
String strFichshx = f.getAbsolutePath().replaceAll("\\.shp", ".shx"); |
|
76 |
shxPath = strFichshx.replaceAll("\\.SHP", ".SHX"); |
|
76 |
shxPath = SHP.getShxFile(f).getAbsolutePath(); |
|
77 | 77 |
|
78 |
String strFichDbf = f.getAbsolutePath().replaceAll("\\.shp", ".dbf"); |
|
79 |
dbfPath = strFichDbf.replaceAll("\\.SHP", ".DBF"); |
|
78 |
dbfPath = SHP.getDbfFile(f).getAbsolutePath(); |
|
80 | 79 |
|
81 | 80 |
shpFile = f; |
82 | 81 |
} |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/edition/writers/dbf/DbfWriter.java | ||
---|---|---|
17 | 17 |
import com.iver.cit.gvsig.fmap.drivers.ITableDefinition; |
18 | 18 |
import com.iver.cit.gvsig.fmap.drivers.shp.DbaseFileHeaderNIO; |
19 | 19 |
import com.iver.cit.gvsig.fmap.drivers.shp.DbaseFileWriterNIO; |
20 |
import com.iver.cit.gvsig.fmap.drivers.shp.SHP; |
|
20 | 21 |
import com.iver.cit.gvsig.fmap.edition.IRowEdited; |
21 | 22 |
import com.iver.cit.gvsig.fmap.edition.fieldmanagers.AddFieldCommand; |
22 | 23 |
import com.iver.cit.gvsig.fmap.edition.fieldmanagers.FieldCommand; |
... | ... | |
49 | 50 |
} |
50 | 51 |
|
51 | 52 |
public void setFile(File f) { |
52 |
String strFichDbf = f.getAbsolutePath().replaceAll("\\.shp", ".dbf"); |
|
53 |
dbfPath = strFichDbf.replaceAll("\\.SHP", ".DBF"); |
|
53 |
String absolutePath=f.getAbsolutePath(); |
|
54 |
if (absolutePath.toUpperCase().endsWith("DBF")){ |
|
55 |
dbfPath=absolutePath; |
|
56 |
} else { |
|
57 |
dbfPath = SHP.getDbfFile(f).getAbsolutePath(); |
|
58 |
} |
|
54 | 59 |
} |
55 | 60 |
|
56 | 61 |
private WritableByteChannel getWriteChannel(String path) throws IOException { |
Also available in: Unified diff