Revision 5389 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/shp/IndexedShpDriver.java
IndexedShpDriver.java | ||
---|---|---|
97 | 97 |
// private long[] m_posShapes; |
98 | 98 |
private int numReg; |
99 | 99 |
private Rectangle2D extent; |
100 |
|
|
100 |
|
|
101 | 101 |
// private File shxFile; |
102 | 102 |
private BigByteBuffer2 bbShx; |
103 | 103 |
private FileChannel channelShx; |
104 | 104 |
private FileInputStream finShx; |
105 |
|
|
105 |
|
|
106 | 106 |
private ShpWriter shpWriter = new ShpWriter(); |
107 |
|
|
108 | 107 |
|
108 |
|
|
109 | 109 |
/** |
110 | 110 |
* Cierra el fichero. |
111 | 111 |
* |
... | ... | |
115 | 115 |
*/ |
116 | 116 |
public void close() throws IOException { |
117 | 117 |
IOException ret = null; |
118 |
|
|
118 |
|
|
119 | 119 |
try { |
120 | 120 |
channel.close(); |
121 | 121 |
channelShx.close(); |
... | ... | |
155 | 155 |
// Get the file's size and then map it into memory |
156 | 156 |
// bb = channel.map(FileChannel.MapMode.READ_ONLY, 0, size); |
157 | 157 |
bb = new BigByteBuffer2(channel, FileChannel.MapMode.READ_ONLY); |
158 |
|
|
158 |
|
|
159 | 159 |
finShx = new FileInputStream(getShxFile(f)); |
160 | 160 |
|
161 | 161 |
// Open the file and then get a channel from the stream |
... | ... | |
194 | 194 |
int hasta; |
195 | 195 |
int desde; |
196 | 196 |
Rectangle2D.Double BoundingBox = new Rectangle2D.Double(); |
197 |
|
|
197 |
|
|
198 | 198 |
SHPShape shapeShp=null; |
199 | 199 |
FShape resulShape = null; |
200 | 200 |
try { |
... | ... | |
210 | 210 |
//Comprobaci?n punto. |
211 | 211 |
//System.err.println("p.x = "+p.x); |
212 | 212 |
//System.err.println("p.y = "+p.y); |
213 |
|
|
213 |
|
|
214 | 214 |
} else if ((tipoShape == FConstant.SHAPE_TYPE_POLYLINE) || |
215 | 215 |
(tipoShape == FConstant.SHAPE_TYPE_POLYGON)) { |
216 | 216 |
// BoundingBox |
... | ... | |
243 | 243 |
} |
244 | 244 |
} |
245 | 245 |
//FGeometry pol=new FPolyLine(points,tempParts,BoundingBox); |
246 |
|
|
246 |
|
|
247 | 247 |
resulShape = new FShape(tipoShape,elShape); |
248 | 248 |
} else if (tipoShape == FConstant.SHAPE_TYPE_MULTIPOINT) { |
249 | 249 |
// BoundingBox |
... | ... | |
268 | 268 |
numPoints = bb.getInt(); |
269 | 269 |
// part indexes. |
270 | 270 |
// Geometry geom = GeometryFactory.toGeometryArray(); |
271 |
|
|
271 |
|
|
272 | 272 |
GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, |
273 | 273 |
numPoints); |
274 | 274 |
int[] tempParts = new int[numParts]; |
... | ... | |
281 | 281 |
for (i = 0; i < numPoints; i++) { |
282 | 282 |
p = readPoint(bb); |
283 | 283 |
points[i]=new FPoint(p.x,p.y); |
284 |
|
|
284 |
|
|
285 | 285 |
if (i == tempParts[j]) { |
286 | 286 |
elShape.moveTo(p.x, p.y); |
287 | 287 |
if (j < (numParts - 1)) { |
... | ... | |
290 | 290 |
} else { |
291 | 291 |
elShape.lineTo(p.x, p.y); |
292 | 292 |
} |
293 |
|
|
293 |
|
|
294 | 294 |
} |
295 |
|
|
295 |
|
|
296 | 296 |
double[] boxZ = new double[2]; |
297 | 297 |
boxZ[0] = bb.getDouble(); |
298 | 298 |
boxZ[1] = bb.getDouble(); |
... | ... | |
347 | 347 |
|
348 | 348 |
//Rectangle2D.Double BoundingBox; |
349 | 349 |
// if (m_posShapes[index] == 0) |
350 |
|
|
350 |
|
|
351 | 351 |
// bb.position(m_posShapes[index]); |
352 | 352 |
bb.position(getPositionForRecord(index)); |
353 | 353 |
bb.order(ByteOrder.LITTLE_ENDIAN); |
... | ... | |
359 | 359 |
logger.info("El shape ="+index+ " de la capa ="+this.toString()+" es null"); |
360 | 360 |
return null; |
361 | 361 |
} |
362 |
|
|
362 |
|
|
363 | 363 |
// retrieve that shape. |
364 | 364 |
// tempRecord.setShape(readShape(tempShapeType, tempContentLength, in)); |
365 | 365 |
switch (type) { |
... | ... | |
532 | 532 |
} |
533 | 533 |
|
534 | 534 |
return ShapeFactory.createPolygon3D(elShape, poZ); |
535 |
|
|
535 |
|
|
536 | 536 |
case (SHP.MULTIPOINT2D): |
537 | 537 |
bb.position(bb.position() + 32); |
538 | 538 |
numPoints = bb.getInt(); |
... | ... | |
560 | 560 |
temY[i] = bb.getDouble(); |
561 | 561 |
//temZ[i] = bb.getDouble(); |
562 | 562 |
} |
563 |
|
|
563 |
|
|
564 | 564 |
for (i = 0; i < numPoints; i++) { |
565 | 565 |
temZ[i] = bb.getDouble(); |
566 | 566 |
} |
... | ... | |
618 | 618 |
public void initialize() throws IOException { |
619 | 619 |
// create a new header. |
620 | 620 |
ShapeFileHeader2 myHeader = new ShapeFileHeader2(); |
621 |
|
|
621 |
|
|
622 | 622 |
bb.position(0); |
623 | 623 |
|
624 | 624 |
// read the header |
... | ... | |
653 | 653 |
|
654 | 654 |
m_FichDbf.open(new File(strFichDbf)); |
655 | 655 |
numReg = m_FichDbf.getRecordCount(); |
656 |
|
|
656 |
|
|
657 | 657 |
// shpWriter.initialize(file); |
658 | 658 |
// m_posShapes = new long[numReg]; |
659 | 659 |
|
... | ... | |
810 | 810 |
*/ |
811 | 811 |
public String getName() { |
812 | 812 |
// Para que se use este driver en lugar del viejo DemoShpDriver. |
813 |
|
|
813 |
|
|
814 | 814 |
// return "gvSIG indexed shp driver"; |
815 | 815 |
return "gvSIG shp driver"; |
816 | 816 |
} |
... | ... | |
836 | 836 |
|
837 | 837 |
return new File(str.substring(0, str.length() - 3) + "shx"); |
838 | 838 |
} |
839 |
|
|
840 |
|
|
839 |
|
|
840 |
|
|
841 | 841 |
/* (non-Javadoc) |
842 | 842 |
* @see com.iver.cit.gvsig.fmap.drivers.BoundedShapes#getShapeType(int) |
843 | 843 |
*/ |
... | ... | |
854 | 854 |
public DriverAttributes getDriverAttributes() { |
855 | 855 |
return null; |
856 | 856 |
} |
857 |
|
|
857 |
|
|
858 | 858 |
private synchronized long getPositionForRecord(int numRec) |
859 | 859 |
{ |
860 | 860 |
// shx file has a 100 bytes header, then, records |
861 | 861 |
// 8 bytes length, one for each entity. |
862 | 862 |
// first 4 bytes are the offset |
863 | 863 |
// next 4 bytes are length |
864 |
|
|
864 |
|
|
865 | 865 |
int posIndex = 100 + (numRec * 8); |
866 | 866 |
// bbShx.position(posIndex); |
867 | 867 |
long pos = 8 + 2*bbShx.getInt(posIndex); |
868 |
|
|
868 |
|
|
869 | 869 |
return pos; |
870 | 870 |
} |
871 | 871 |
|
872 | 872 |
public File getFile() { |
873 | 873 |
return fileShp; |
874 | 874 |
} |
875 |
|
|
875 |
|
|
876 | 876 |
public void reLoad() throws IOException { |
877 | 877 |
initialize(); |
878 | 878 |
} |
879 | 879 |
|
880 |
public boolean canWriteGeometry(int gvSIGgeometryType) {
|
|
880 |
public boolean canWriteGeometry(int gvSIGgeometryType) { |
|
881 | 881 |
return shpWriter.canWriteGeometry(gvSIGgeometryType); |
882 | 882 |
} |
883 | 883 |
|
... | ... | |
886 | 886 |
*/ |
887 | 887 |
public void preProcess() throws EditionException { |
888 | 888 |
// Necesitamos crear un fichero temporal porque a la vez que esic |
889 |
// La cabecera ya existe, as? que no la sobreescribimos.
|
|
889 |
// La cabecera ya existe, as? que no la sobreescribimos. |
|
890 | 890 |
// shpWriter.setWriteHeaders(false); |
891 | 891 |
shpWriter.preProcess(); |
892 |
|
|
892 |
|
|
893 | 893 |
} |
894 | 894 |
|
895 | 895 |
public void process(IRowEdited row) throws EditionException { |
896 | 896 |
shpWriter.process(row); |
897 |
|
|
897 |
|
|
898 | 898 |
} |
899 | 899 |
|
900 | 900 |
public void postProcess() throws EditionException { |
901 |
shpWriter.postProcess();
|
|
902 |
|
|
901 |
shpWriter.postProcess(); |
|
902 |
|
|
903 | 903 |
try { |
904 |
|
|
904 |
|
|
905 | 905 |
// close(); |
906 |
|
|
906 |
|
|
907 | 907 |
// Shp |
908 | 908 |
FileChannel fcinShp = new FileInputStream(fTemp).getChannel(); |
909 | 909 |
FileChannel fcoutShp = new FileOutputStream(fileShp).getChannel(); |
... | ... | |
920 | 920 |
FileChannel fcinDbf = new FileInputStream(dbfFile).getChannel(); |
921 | 921 |
FileChannel fcoutDbf = new FileOutputStream(getDataFile(fileShp)).getChannel(); |
922 | 922 |
DriverUtilities.copy(fcinDbf, fcoutDbf); |
923 |
|
|
923 |
|
|
924 | 924 |
// Borramos los temporales |
925 | 925 |
fTemp.delete(); |
926 | 926 |
shxFile.delete(); |
927 | 927 |
dbfFile.delete(); |
928 | 928 |
reLoad(); |
929 |
|
|
930 |
|
|
931 |
|
|
929 |
|
|
930 |
|
|
931 |
|
|
932 | 932 |
} catch (FileNotFoundException e) { |
933 | 933 |
e.printStackTrace(); |
934 | 934 |
throw new EditionException(e); |
... | ... | |
936 | 936 |
e.printStackTrace(); |
937 | 937 |
throw new EditionException(e); |
938 | 938 |
} |
939 |
|
|
940 |
|
|
939 |
|
|
940 |
|
|
941 | 941 |
} |
942 | 942 |
|
943 | 943 |
public String getCapability(String capability) { |
... | ... | |
946 | 946 |
|
947 | 947 |
public void setCapabilities(Properties capabilities) { |
948 | 948 |
shpWriter.setCapabilities(capabilities); |
949 |
|
|
949 |
|
|
950 | 950 |
} |
951 | 951 |
|
952 | 952 |
public boolean canWriteAttribute(int sqlType) { |
... | ... | |
966 | 966 |
fTemp = new File(tempDirectoryPath + "/tmpShp" + aux + ".shp"); |
967 | 967 |
shpWriter.setFile(fTemp); |
968 | 968 |
shpWriter.initialize(layer); |
969 |
|
|
969 |
|
|
970 | 970 |
} |
971 |
|
|
971 |
|
|
972 |
public void setFlatness(double flatness) { |
|
973 |
shpWriter.setFlatness(flatness); |
|
974 |
} |
|
975 |
|
|
972 | 976 |
} |
Also available in: Unified diff