Revision 21728
branches/v2_0_0_prep/libraries/libFMap_dataFile/src/org/gvsig/data/datastores/vectorial/file/shp/ShpFeaturesWriter.java | ||
---|---|---|
19 | 19 |
import org.gvsig.data.vectorial.InitializeWriterException; |
20 | 20 |
import org.gvsig.data.vectorial.UnsupportedEncodingException; |
21 | 21 |
import org.gvsig.fmap.geom.Geometry; |
22 |
import org.gvsig.fmap.geom.primitive.DefaultEnvelope; |
|
23 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
22 | 24 |
import org.gvsig.fmap.geom.primitive.NullGeometry; |
23 | 25 |
|
24 | 26 |
public class ShpFeaturesWriter extends DBFFeaturesWriter { |
... | ... | |
30 | 32 |
private SHPFileWrite shpWrite; |
31 | 33 |
private int[] supportedGeometryTypes; |
32 | 34 |
private boolean bWriteHeaders=true; |
33 |
private Rectangle2D fullExtent;
|
|
35 |
private Envelope envelope;
|
|
34 | 36 |
private int fileSize; |
35 | 37 |
|
36 | 38 |
public void init(FeatureStore store) throws InitializeWriterException { |
... | ... | |
50 | 52 |
|
51 | 53 |
public void postProcess() throws OpenException, WriteException { |
52 | 54 |
super.postProcess(); |
53 |
if (fullExtent == null)
|
|
54 |
fullExtent = new Rectangle2D.Double();
|
|
55 |
shpWrite.writeHeaders(fullExtent,
|
|
55 |
if (this.envelope == null)
|
|
56 |
this.envelope = new DefaultEnvelope(2);
|
|
57 |
shpWrite.writeHeaders(this.envelope,
|
|
56 | 58 |
shapeType, numRows, fileSize); |
57 | 59 |
} |
58 | 60 |
|
59 | 61 |
public void preProcess() throws WriteException, ReadException { |
60 | 62 |
super.preProcess(); |
61 | 63 |
if (bWriteHeaders){ |
62 |
shpWrite.writeHeaders(new Rectangle2D.Double(),
|
|
64 |
shpWrite.writeHeaders(new DefaultEnvelope(2),
|
|
63 | 65 |
shapeType, 0, 0); |
64 | 66 |
} |
65 |
fullExtent = null;
|
|
67 |
this.envelope = null;
|
|
66 | 68 |
} |
67 | 69 |
|
68 | 70 |
public void insertFeature(Feature feature) throws WriteException, UnsupportedEncodingException { |
... | ... | |
80 | 82 |
} |
81 | 83 |
super.insertFeature(feature); |
82 | 84 |
fileSize = shpWrite.writeIGeometry(theGeom); |
83 |
Rectangle2D boundsShp = theGeom.getBounds2D();
|
|
84 |
if (boundsShp!=null){
|
|
85 |
if (fullExtent == null) {
|
|
86 |
fullExtent = boundsShp;
|
|
85 |
Envelope envelope = theGeom.getEnvelope();
|
|
86 |
if (envelope!=null){
|
|
87 |
if (this.envelope == null) {
|
|
88 |
this.envelope = envelope;
|
|
87 | 89 |
} else { |
88 |
fullExtent.add(boundsShp);
|
|
90 |
this.envelope.add(envelope);
|
|
89 | 91 |
} |
90 | 92 |
} |
91 | 93 |
|
... | ... | |
155 | 157 |
shapeType= shpWrite.getShapeType(featureType.getGeometryTypes()[0]); |
156 | 158 |
} |
157 | 159 |
myHeader.setNumRecords(0); |
158 |
Rectangle2D fullExtent = new Rectangle2D.Double();
|
|
159 |
shpWrite.writeHeaders(fullExtent,
|
|
160 |
Envelope envelope = new DefaultEnvelope(2);
|
|
161 |
shpWrite.writeHeaders(envelope,
|
|
160 | 162 |
shapeType, 0, fileLength); |
161 | 163 |
shpChannel.close(); |
162 | 164 |
shxChannel.close(); |
... | ... | |
174 | 176 |
this.shpWrite.close(); |
175 | 177 |
this.shpWrite = null; |
176 | 178 |
} |
177 |
this.fullExtent = null;
|
|
179 |
this.envelope = null;
|
|
178 | 180 |
|
179 | 181 |
} |
180 | 182 |
} |
Also available in: Unified diff