Revision 28678 branches/v2_0_0_prep/libraries/libFMap_daldb/src/org/gvsig/fmap/dal/store/postgresql/PostgreSQLHelper.java
PostgreSQLHelper.java | ||
---|---|---|
76 | 76 |
import org.gvsig.fmap.geom.Geometry; |
77 | 77 |
import org.gvsig.fmap.geom.GeometryLocator; |
78 | 78 |
import org.gvsig.fmap.geom.GeometryManager; |
79 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
|
80 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
|
81 | 79 |
import org.gvsig.fmap.geom.operation.fromwkb.FromWKB; |
82 | 80 |
import org.gvsig.fmap.geom.operation.fromwkb.FromWKBGeometryOperationContext; |
83 | 81 |
import org.gvsig.fmap.geom.operation.towkb.ToWKB; |
84 | 82 |
import org.gvsig.fmap.geom.operation.towkb.ToWKBOperationContext; |
85 | 83 |
import org.gvsig.fmap.geom.primitive.Envelope; |
86 | 84 |
import org.gvsig.tools.exception.BaseException; |
87 |
import org.postgis.PGbox2d; |
|
88 |
import org.postgis.PGbox3d; |
|
89 | 85 |
import org.postgresql.PGResultSetMetaData; |
90 |
import org.postgresql.util.PGobject; |
|
91 | 86 |
import org.slf4j.Logger; |
92 | 87 |
import org.slf4j.LoggerFactory; |
93 | 88 |
|
... | ... | |
550 | 545 |
throws DataException { |
551 | 546 |
|
552 | 547 |
StringBuilder strb = new StringBuilder(); |
553 |
strb.append("Select extent("); |
|
548 |
strb.append("Select asbinary(extent(");
|
|
554 | 549 |
strb.append(geometryAttrName); |
555 |
strb.append(") from "); |
|
550 |
strb.append(")) from ");
|
|
556 | 551 |
|
557 | 552 |
if (storeParams.getSQL() != null |
558 | 553 |
&& storeParams.getSQL().trim().length() == 0) { |
... | ... | |
597 | 592 |
return null; |
598 | 593 |
} |
599 | 594 |
|
600 |
PGobject data = (PGobject) rs.getObject(1);
|
|
595 |
byte[] data = rs.getBytes(1);
|
|
601 | 596 |
if (data == null) { |
602 | 597 |
return null; |
603 | 598 |
} |
604 |
if (data instanceof PGbox3d) { |
|
605 |
PGbox3d box3d = (PGbox3d) data; |
|
606 |
fullEnvelope = geoMan.createEnvelope(SUBTYPES.GEOM3D); |
|
607 |
fullEnvelope.getLowerCorner().setCoordinates(new double[]{ |
|
608 |
box3d.getLLB().x, |
|
609 |
box3d.getLLB().y, box3d.getLLB().z}); |
|
610 |
fullEnvelope.getUpperCorner().setCoordinates(new double[]{box3d.getURT().x, |
|
611 |
box3d |
|
612 |
.getURT().y, |
|
613 |
box3d.getURT().z }); |
|
599 |
initializeFromWKBOperation(); |
|
600 |
fromWKBContext.setData(data); |
|
601 |
Geometry geom = (Geometry) fromWKB.invoke(null, fromWKBContext); |
|
614 | 602 |
|
615 |
} else { |
|
616 |
PGbox2d box2d = (PGbox2d) data; |
|
617 |
fullEnvelope = geoMan.createEnvelope(SUBTYPES.GEOM2D); |
|
618 |
fullEnvelope.getLowerCorner().setX(box2d.getLLB().x); |
|
619 |
fullEnvelope.getLowerCorner().setY(box2d.getLLB().y); |
|
620 |
fullEnvelope.getUpperCorner().setX(box2d.getURT().x); |
|
621 |
fullEnvelope.getUpperCorner().setY(box2d.getURT().y); |
|
622 |
} |
|
603 |
fullEnvelope = geom.getEnvelope(); |
|
604 |
|
|
623 | 605 |
return fullEnvelope; |
624 | 606 |
} catch (java.sql.SQLException e) { |
625 | 607 |
throw new JDBCSQLException(e); |
626 |
} catch (CreateEnvelopeException e) {
|
|
627 |
throw new InitializeException(e);
|
|
608 |
} catch (BaseException e) {
|
|
609 |
throw new ReadException(user.getName(), e);
|
|
628 | 610 |
} finally { |
629 | 611 |
try{ rs.close(); } catch (Exception e){}; |
630 | 612 |
try{ st.close(); } catch (Exception e){}; |
... | ... | |
638 | 620 |
|
639 | 621 |
} |
640 | 622 |
|
641 |
public Geometry getGeometry(byte[] buffer) |
|
642 |
throws BaseException { |
|
643 |
if (buffer == null) { |
|
644 |
return null; |
|
645 |
} |
|
623 |
private void initializeFromWKBOperation() throws BaseException { |
|
646 | 624 |
if (fromWKB == null) { |
647 | 625 |
fromWKB = (FromWKB) GeometryLocator.getGeometryManager() |
648 | 626 |
.getGeometryOperation(FromWKB.CODE, |
... | ... | |
650 | 628 |
fromWKBContext = new FromWKBGeometryOperationContext(); |
651 | 629 |
|
652 | 630 |
} |
631 |
} |
|
632 |
|
|
633 |
public Geometry getGeometry(byte[] buffer) throws BaseException { |
|
634 |
if (buffer == null) { |
|
635 |
return null; |
|
636 |
} |
|
637 |
initializeFromWKBOperation(); |
|
653 | 638 |
Geometry geom; |
654 | 639 |
try { |
655 | 640 |
fromWKBContext.setData(buffer); |
Also available in: Unified diff