Revision 31889 branches/v2_0_0_prep/extensions/org.gvsig.oracle/src/org/gvsig/fmap/dal/store/oracle/OracleUtils.java
OracleUtils.java | ||
---|---|---|
56 | 56 |
import oracle.sql.StructDescriptor; |
57 | 57 |
|
58 | 58 |
import org.apache.log4j.Logger; |
59 |
import org.cresques.cts.IProjection; |
|
60 |
import org.geotools.xml.filter.FilterOpsComplexTypes.UpperBoundaryType; |
|
61 |
import org.gvsig.fmap.dal.DALLocator; |
|
62 |
import org.gvsig.fmap.dal.DataManager; |
|
63 |
import org.gvsig.fmap.dal.exception.DataException; |
|
64 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
65 |
import org.gvsig.fmap.dal.feature.Feature; |
|
66 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
|
67 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
68 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
59 | 69 |
import org.gvsig.fmap.geom.Geometry; |
60 | 70 |
import org.gvsig.fmap.geom.GeometryLocator; |
61 | 71 |
import org.gvsig.fmap.geom.GeometryManager; |
72 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
|
73 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
|
74 |
import org.gvsig.fmap.geom.aggregate.MultiPrimitive; |
|
62 | 75 |
import org.gvsig.fmap.geom.aggregate.impl.MultiPoint2D; |
63 | 76 |
import org.gvsig.fmap.geom.aggregate.impl.MultiPoint2DZ; |
64 | 77 |
import org.gvsig.fmap.geom.complex.Complex; |
... | ... | |
66 | 79 |
import org.gvsig.fmap.geom.primitive.Curve; |
67 | 80 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
68 | 81 |
import org.gvsig.fmap.geom.primitive.Point; |
82 |
import org.gvsig.fmap.geom.primitive.Primitive; |
|
69 | 83 |
import org.gvsig.fmap.geom.primitive.Surface; |
70 | 84 |
import org.gvsig.fmap.geom.primitive.impl.Circle2D; |
71 | 85 |
import org.gvsig.fmap.geom.primitive.impl.Curve2DZ; |
... | ... | |
95 | 109 |
private static double FLATNESS = 0.8; |
96 | 110 |
private static GeometryFactory geomFactory = new GeometryFactory(); |
97 | 111 |
private static final double IRRELEVANT_DISTANCE = 0.00000001; |
112 |
public static final Rectangle2D DEFAULT_BBOX = new Rectangle2D.Double(-180, -90, 360, 180);; |
|
98 | 113 |
private static Random rnd = new Random(); |
99 | 114 |
private static DecimalFormat df = new DecimalFormat(); |
100 | 115 |
private static DecimalFormatSymbols dfs = new DecimalFormatSymbols(); |
116 |
|
|
117 |
public static final String ENVELOPE_ID = "Envelope_Key"; |
|
118 |
public static final String DIMENSIONS_ID = "Dimensions_Key"; |
|
101 | 119 |
|
120 |
|
|
102 | 121 |
/** |
103 | 122 |
* COnstructs a geometry from a file that contains a vertex per line: |
104 | 123 |
* |
... | ... | |
2396 | 2415 |
return resp; |
2397 | 2416 |
} |
2398 | 2417 |
|
2399 |
/** |
|
2400 |
* |
|
2401 |
* @param oGeom |
|
2402 |
* @return |
|
2403 |
*/ |
|
2404 |
public static int[] getGeometryTypeAndSubtypeFromOracleGeom(int oGeom){ |
|
2405 |
|
|
2406 |
int[] gTypes = new int[2]; |
|
2407 |
|
|
2408 |
int type = oGeom % 10; |
|
2409 |
int subtype = oGeom / 1000; |
|
2410 |
// type 0 |
|
2411 |
if(type == OracleValues.ORACLE_GTYPE_UNKNOWN){ |
|
2412 |
gTypes[0] = Geometry.TYPES.GEOMETRY; |
|
2413 |
if(subtype == 2){ |
|
2414 |
gTypes[1] = Geometry.SUBTYPES.GEOM2D; |
|
2415 |
}else if(subtype == 3){ |
|
2416 |
gTypes[1] = Geometry.SUBTYPES.GEOM2DZ; |
|
2417 |
}else{ |
|
2418 |
gTypes[1] = Geometry.SUBTYPES.GEOM3DM; |
|
2419 |
} |
|
2420 |
} |
|
2421 |
// type 1 |
|
2422 |
else if(type == OracleValues.ORACLE_GTYPE_POINT){ |
|
2423 |
gTypes[0] = Geometry.TYPES.POINT; |
|
2424 |
if(subtype == 2){ |
|
2425 |
gTypes[1] = Geometry.SUBTYPES.GEOM2D; |
|
2426 |
}else if(subtype == 3){ |
|
2427 |
gTypes[1] = Geometry.SUBTYPES.GEOM2DZ; |
|
2428 |
}else{ |
|
2429 |
gTypes[1] = Geometry.SUBTYPES.GEOM3DM; |
|
2430 |
} |
|
2431 |
} |
|
2432 |
// type 2 |
|
2433 |
else if(type == OracleValues.ORACLE_GTYPE_LINE){ |
|
2434 |
gTypes[0] = Geometry.TYPES.CURVE; |
|
2435 |
if(subtype == 2){ |
|
2436 |
gTypes[1] = Geometry.SUBTYPES.GEOM2D; |
|
2437 |
}else if(subtype == 3){ |
|
2438 |
gTypes[1] = Geometry.SUBTYPES.GEOM2DZ; |
|
2439 |
}else{ |
|
2440 |
gTypes[1] = Geometry.SUBTYPES.GEOM3DM; |
|
2441 |
} |
|
2442 |
} |
|
2443 |
// type 3 |
|
2444 |
else if(type == OracleValues.ORACLE_GTYPE_POLYGON){ |
|
2445 |
gTypes[0] = Geometry.TYPES.SURFACE; |
|
2446 |
if(subtype == 2){ |
|
2447 |
gTypes[1] = Geometry.SUBTYPES.GEOM2D; |
|
2448 |
}else if(subtype == 3){ |
|
2449 |
gTypes[1] = Geometry.SUBTYPES.GEOM2DZ; |
|
2450 |
}else{ |
|
2451 |
gTypes[1] = Geometry.SUBTYPES.GEOM3DM; |
|
2452 |
} |
|
2453 |
} |
|
2454 |
// type 4 |
|
2455 |
else if(type == OracleValues.ORACLE_GTYPE_COLLECTION){ |
|
2456 |
gTypes[0] = Geometry.TYPES.AGGREGATE; |
|
2457 |
if(subtype == 2){ |
|
2458 |
gTypes[1] = Geometry.SUBTYPES.GEOM2D; |
|
2459 |
}else if(subtype == 3){ |
|
2460 |
gTypes[1] = Geometry.SUBTYPES.GEOM2DZ; |
|
2461 |
}else{ |
|
2462 |
gTypes[1] = Geometry.SUBTYPES.GEOM3DM; |
|
2463 |
} |
|
2464 |
} |
|
2465 |
// type 5 |
|
2466 |
else if(type == OracleValues.ORACLE_GTYPE_MULTIPOINT){ |
|
2467 |
gTypes[0] = Geometry.TYPES.MULTIPOINT; |
|
2468 |
if(subtype == 2){ |
|
2469 |
gTypes[1] = Geometry.SUBTYPES.GEOM2D; |
|
2470 |
}else if(subtype == 3){ |
|
2471 |
gTypes[1] = Geometry.SUBTYPES.GEOM2DZ; |
|
2472 |
}else{ |
|
2473 |
gTypes[1] = Geometry.SUBTYPES.GEOM3DM; |
|
2474 |
} |
|
2475 |
} |
|
2476 |
// type 6 |
|
2477 |
else if(type == OracleValues.ORACLE_GTYPE_MULTILINE){ |
|
2478 |
gTypes[0] = Geometry.TYPES.MULTICURVE; |
|
2479 |
if(subtype == 2){ |
|
2480 |
gTypes[1] = Geometry.SUBTYPES.GEOM2D; |
|
2481 |
}else if(subtype == 3){ |
|
2482 |
gTypes[1] = Geometry.SUBTYPES.GEOM2DZ; |
|
2483 |
}else{ |
|
2484 |
gTypes[1] = Geometry.SUBTYPES.GEOM3DM; |
|
2485 |
} |
|
2486 |
} |
|
2487 |
// type 7 |
|
2488 |
else if(type == OracleValues.ORACLE_GTYPE_MULTIPOLYGON){ |
|
2489 |
gTypes[0] = Geometry.TYPES.MULTISURFACE; |
|
2490 |
if(subtype == 2){ |
|
2491 |
gTypes[1] = Geometry.SUBTYPES.GEOM2D; |
|
2492 |
}else if(subtype == 3){ |
|
2493 |
gTypes[1] = Geometry.SUBTYPES.GEOM2DZ; |
|
2494 |
}else{ |
|
2495 |
gTypes[1] = Geometry.SUBTYPES.GEOM3DM; |
|
2496 |
} |
|
2497 |
} |
|
2498 |
|
|
2499 |
return gTypes; |
|
2500 |
} |
|
2501 | 2418 |
|
2419 |
|
|
2420 |
|
|
2502 | 2421 |
/** |
2503 | 2422 |
* Gets a struct's coordinates array. |
2504 | 2423 |
* |
... | ... | |
2740 | 2659 |
break; |
2741 | 2660 |
|
2742 | 2661 |
case OracleValues.ORACLE_GTYPE_COLLECTION: |
2743 |
resp = Geometry.TYPES.GEOMETRY;
|
|
2662 |
resp = Geometry.TYPES.AGGREGATE;
|
|
2744 | 2663 |
break; |
2745 | 2664 |
} |
2746 | 2665 |
// =========== not complex ================= |
... | ... | |
3523 | 3442 |
|
3524 | 3443 |
/** |
3525 | 3444 |
* |
3526 |
* @param sample |
|
3527 |
* @return |
|
3445 |
* @param sample input STRUCT
|
|
3446 |
* @return type and subtype of geometry
|
|
3528 | 3447 |
* @throws SQLException |
3529 | 3448 |
*/ |
3530 |
public static int getShapeTypeOfStruct(STRUCT sample) throws SQLException {
|
|
3449 |
public static int[] getGeoTypeSubTypeOfStruct(STRUCT sample) throws SQLException {
|
|
3531 | 3450 |
|
3532 |
int code = ((NUMBER) sample.getOracleAttributes()[0]).intValue(); |
|
3451 |
int _code = ((NUMBER) sample.getOracleAttributes()[0]).intValue(); |
|
3452 |
return getGeoTypeSubTypeOfOracleCode(_code); |
|
3453 |
} |
|
3533 | 3454 |
|
3455 |
|
|
3456 |
public static int[] getGeoTypeSubTypeOfOracleCode(int code) { |
|
3457 |
|
|
3458 |
// [TYPES.?, SUBTYPES.?] |
|
3459 |
int[] resp = new int[2]; |
|
3460 |
|
|
3534 | 3461 |
int type_part = code % 10; |
3535 | 3462 |
int dim_part = code / 1000; |
3536 | 3463 |
|
3537 |
int z_added = 0;
|
|
3464 |
resp[1] = SUBTYPES.GEOM2D;
|
|
3538 | 3465 |
if (dim_part == 3) { |
3539 |
z_added = Geometry.SUBTYPES.GEOM3D;
|
|
3466 |
resp[1] = SUBTYPES.GEOM3D;
|
|
3540 | 3467 |
} else { |
3541 | 3468 |
if (dim_part == 4) { |
3542 |
z_added = Geometry.SUBTYPES.GEOM3DM;
|
|
3469 |
resp[1] = SUBTYPES.GEOM3DM;
|
|
3543 | 3470 |
} |
3544 | 3471 |
} |
3545 | 3472 |
|
3473 |
resp[0] = TYPES.GEOMETRY; |
|
3474 |
|
|
3546 | 3475 |
switch (type_part) { |
3547 | 3476 |
case 1: |
3548 |
return z_added + Geometry.TYPES.POINT;
|
|
3549 |
|
|
3477 |
resp[0] = Geometry.TYPES.POINT;
|
|
3478 |
break; |
|
3550 | 3479 |
case 2: |
3551 |
return z_added + Geometry.TYPES.CURVE;
|
|
3552 |
|
|
3480 |
resp[0] = Geometry.TYPES.CURVE;
|
|
3481 |
break; |
|
3553 | 3482 |
case 3: |
3554 |
return z_added + Geometry.TYPES.SURFACE;
|
|
3555 |
|
|
3483 |
resp[0] = Geometry.TYPES.SURFACE;
|
|
3484 |
break; |
|
3556 | 3485 |
case 4: |
3557 |
return z_added + Geometry.TYPES.AGGREGATE;
|
|
3558 |
|
|
3486 |
resp[0] = Geometry.TYPES.AGGREGATE;
|
|
3487 |
break; |
|
3559 | 3488 |
case 5: |
3560 |
return z_added + Geometry.TYPES.MULTIPOINT;
|
|
3561 |
|
|
3489 |
resp[0] = Geometry.TYPES.MULTIPOINT;
|
|
3490 |
break; |
|
3562 | 3491 |
case 6: |
3563 |
return z_added + Geometry.TYPES.MULTICURVE;
|
|
3564 |
|
|
3492 |
resp[0] = Geometry.TYPES.CURVE;
|
|
3493 |
break; |
|
3565 | 3494 |
case 7: |
3566 |
return z_added + Geometry.TYPES.MULTISURFACE; |
|
3495 |
resp[0] = Geometry.TYPES.SURFACE; |
|
3496 |
break; |
|
3497 |
default: |
|
3498 |
logger.error("Unknown geometry type: " + code); |
|
3499 |
break; |
|
3567 | 3500 |
} |
3568 | 3501 |
|
3569 |
logger.error("Unknown geometry type: " + code); |
|
3570 |
|
|
3571 |
return Geometry.TYPES.NULL; |
|
3502 |
return resp; |
|
3572 | 3503 |
} |
3573 |
|
|
3574 | 3504 |
/** |
3575 | 3505 |
* |
3576 | 3506 |
* @param info |
... | ... | |
3816 | 3746 |
|
3817 | 3747 |
return resp; |
3818 | 3748 |
} |
3749 |
|
|
3750 |
|
|
3751 |
|
|
3819 | 3752 |
|
3753 |
|
|
3754 |
|
|
3755 |
public static int getShapeTypeFromArray(ArrayList arrlist) { |
|
3756 |
|
|
3757 |
int resp = ((Integer) arrlist.get(0)).intValue(); |
|
3758 |
|
|
3759 |
int sz = arrlist.size(); |
|
3760 |
int aux = 0; |
|
3761 |
for (int i=1; i<sz; i++) { |
|
3762 |
aux = ((Integer) arrlist.get(i)).intValue(); |
|
3763 |
if (aux != resp) return TYPES.GEOMETRY; |
|
3764 |
} |
|
3765 |
return resp; |
|
3766 |
} |
|
3767 |
|
|
3768 |
// condition using ROWNUM with growing indexs to do a size-independent sample |
|
3769 |
public static String EXPONENTIAL_INDICES_CONDITION = null; |
|
3770 |
static { |
|
3771 |
|
|
3772 |
String sb = ""; |
|
3773 |
int i=0; |
|
3774 |
sb = "(rownum = 1)"; |
|
3775 |
for (i=2; i<20; i++) { |
|
3776 |
sb = "(" + sb + " OR (rownum = " + i + "))"; |
|
3777 |
} |
|
3778 |
int cnt = 0; |
|
3779 |
float aux = 1; |
|
3780 |
while (cnt < 35) { |
|
3781 |
aux = aux * 1.5f; |
|
3782 |
i = 20 + Math.round(aux); |
|
3783 |
sb = "(" + sb + " OR (rownum = " + i + "))"; |
|
3784 |
cnt++; |
|
3785 |
} |
|
3786 |
aux = aux * 1.5f; |
|
3787 |
i = 20 + Math.round(aux); |
|
3788 |
sb = "(" + sb + " OR (rownum = " + i + "))"; |
|
3789 |
EXPONENTIAL_INDICES_CONDITION = sb; |
|
3790 |
} |
|
3791 |
|
|
3792 |
|
|
3793 |
public static void copyFeatureTypeToOracleStoreParams( |
|
3794 |
EditableFeatureType efType, OracleStoreParameters params) { |
|
3795 |
|
|
3796 |
|
|
3797 |
// TODO Auto-generated method stub |
|
3798 |
|
|
3799 |
} |
|
3800 |
|
|
3801 |
|
|
3802 |
|
|
3803 |
/** |
|
3804 |
* Utility method to transform a struct into a IGeometry. |
|
3805 |
* |
|
3806 |
* @param st the struct to be converted |
|
3807 |
* @param complex comes from a complex sdo geometry |
|
3808 |
* @return the IGeometry |
|
3809 |
*/ |
|
3810 |
public static Geometry getGeometry( |
|
3811 |
STRUCT st, |
|
3812 |
boolean complex, |
|
3813 |
boolean __tablehassrid, |
|
3814 |
String __tablesrid, |
|
3815 |
Connection _conn) { |
|
3816 |
|
|
3817 |
GeometryManager gm = GeometryLocator.getGeometryManager(); |
|
3818 |
|
|
3819 |
if (st == null) { |
|
3820 |
Geometry aux = null; |
|
3821 |
try { |
|
3822 |
aux = gm.createNullGeometry(SUBTYPES.GEOM2D); |
|
3823 |
} catch (CreateGeometryException e) { |
|
3824 |
logger.error("While creating null Geometry: " + e.getMessage()); |
|
3825 |
} |
|
3826 |
return aux; |
|
3827 |
} |
|
3828 |
|
|
3829 |
Datum[] the_data = null; |
|
3830 |
|
|
3831 |
try { |
|
3832 |
the_data = st.getOracleAttributes(); |
|
3833 |
|
|
3834 |
int jgtype = ((NUMBER) the_data[0]).intValue() % 1000; |
|
3835 |
jgtype = oracleGTypeToFShapeType(jgtype, complex); |
|
3836 |
|
|
3837 |
int dim = ((NUMBER) the_data[0]).intValue() / 1000; |
|
3838 |
|
|
3839 |
if (dim < 2) { |
|
3840 |
dim = 2; |
|
3841 |
} |
|
3842 |
|
|
3843 |
int subty = getSubTypeFromDims(dim); |
|
3844 |
Geometry ig = gm.createNullGeometry(subty); |
|
3845 |
|
|
3846 |
if (isActuallyACollection(the_data)) { |
|
3847 |
jgtype = TYPES.AGGREGATE; |
|
3848 |
} |
|
3849 |
|
|
3850 |
switch (jgtype) { |
|
3851 |
case TYPES.AGGREGATE: |
|
3852 |
ig = getFMapGeometryCollection(the_data, dim, __tablehassrid, __tablesrid, _conn); |
|
3853 |
break; |
|
3854 |
|
|
3855 |
case TYPES.POINT: |
|
3856 |
ig = getFMapGeometryPoint(the_data, dim); |
|
3857 |
break; |
|
3858 |
|
|
3859 |
case TYPES.CURVE: |
|
3860 |
ig = getFMapGeometryMultiLineString(the_data, dim); |
|
3861 |
break; |
|
3862 |
|
|
3863 |
case TYPES.SURFACE: |
|
3864 |
ig = getFMapGeometryMultipolygon(the_data, dim); |
|
3865 |
break; |
|
3866 |
} |
|
3867 |
|
|
3868 |
return ig; |
|
3869 |
} catch (Exception e) { |
|
3870 |
logger.error("While creating Geometry from STRUCT: " + e.getMessage()); |
|
3871 |
} |
|
3872 |
return null; |
|
3873 |
} |
|
3874 |
|
|
3875 |
|
|
3876 |
/** |
|
3877 |
* Utility method to transform a struct into a IGeometry. |
|
3878 |
* |
|
3879 |
* @param st the struct to be converted |
|
3880 |
* @param complex comes from a complex sdo geometry |
|
3881 |
* @return the IGeometry |
|
3882 |
*/ |
|
3883 |
public static Primitive getPrimitive(STRUCT st, boolean complex) { |
|
3884 |
|
|
3885 |
GeometryManager gm = GeometryLocator.getGeometryManager(); |
|
3886 |
Primitive resp = null; |
|
3887 |
|
|
3888 |
if (st == null) { |
|
3889 |
try { |
|
3890 |
resp = gm.createNullGeometry(SUBTYPES.GEOM2D); |
|
3891 |
} catch (CreateGeometryException e) { |
|
3892 |
logger.error("While creating null geometry: " + e.getMessage()); |
|
3893 |
} |
|
3894 |
return resp; |
|
3895 |
} |
|
3896 |
|
|
3897 |
Datum[] the_data = null; |
|
3898 |
try { |
|
3899 |
the_data = st.getOracleAttributes(); |
|
3900 |
|
|
3901 |
int jgtype = ((NUMBER) the_data[0]).intValue() % 1000; |
|
3902 |
jgtype = oracleGTypeToFShapeType(jgtype, complex); |
|
3903 |
|
|
3904 |
int dim = ((NUMBER) the_data[0]).intValue() / 1000; |
|
3905 |
|
|
3906 |
if (dim < 2) { |
|
3907 |
dim = 2; |
|
3908 |
} |
|
3909 |
|
|
3910 |
int subty = getSubTypeFromDims(dim); |
|
3911 |
Primitive ig = null; |
|
3912 |
try { |
|
3913 |
ig = gm.createNullGeometry(subty); |
|
3914 |
} catch (CreateGeometryException e) { |
|
3915 |
logger.error("While creating null geometry: " + e.getMessage()); |
|
3916 |
} |
|
3917 |
|
|
3918 |
if (isActuallyACollection(the_data)) { |
|
3919 |
jgtype = TYPES.AGGREGATE; |
|
3920 |
} |
|
3921 |
|
|
3922 |
try { |
|
3923 |
switch (jgtype) { |
|
3924 |
case TYPES.POINT: |
|
3925 |
ig = (Primitive) getFMapGeometryPoint(the_data, dim); |
|
3926 |
break; |
|
3927 |
|
|
3928 |
case TYPES.CURVE: |
|
3929 |
ig = (Primitive) getFMapGeometryMultiLineString(the_data, dim); |
|
3930 |
break; |
|
3931 |
|
|
3932 |
case TYPES.SURFACE: |
|
3933 |
ig = (Primitive) getFMapGeometryMultipolygon(the_data, dim); |
|
3934 |
break; |
|
3935 |
default: |
|
3936 |
logger.error("Aggregate of non primitives not supported."); |
|
3937 |
break; |
|
3938 |
} |
|
3939 |
} catch (Exception ex) { |
|
3940 |
logger.error("While creating primitive: " + ex.getMessage()); |
|
3941 |
} |
|
3942 |
|
|
3943 |
return ig; |
|
3944 |
} catch (SQLException e) { |
|
3945 |
logger.error(e); |
|
3946 |
} |
|
3947 |
|
|
3948 |
return null; |
|
3949 |
} |
|
3950 |
|
|
3951 |
|
|
3952 |
private static int getSubTypeFromDims(int dim) { |
|
3953 |
|
|
3954 |
switch (dim) { |
|
3955 |
case 3: |
|
3956 |
return SUBTYPES.GEOM3D; |
|
3957 |
case 4: |
|
3958 |
return SUBTYPES.GEOM3DM; |
|
3959 |
default: |
|
3960 |
return SUBTYPES.GEOM2D; |
|
3961 |
} |
|
3962 |
} |
|
3963 |
|
|
3964 |
public static Geometry getFMapGeometryCollection( |
|
3965 |
Datum[] the_data, |
|
3966 |
int dim, |
|
3967 |
boolean tableHasSrid, |
|
3968 |
String table_srid, |
|
3969 |
Connection _conn) { |
|
3970 |
|
|
3971 |
NUMBER _srid = new NUMBER(0); |
|
3972 |
NUMBER main_type = new NUMBER((dim * 1000) + getStructType(the_data)); |
|
3973 |
|
|
3974 |
|
|
3975 |
Datum[] all_info_array = null; |
|
3976 |
Object[] elems_info_aray = null; |
|
3977 |
Datum[] all_ords = null; |
|
3978 |
|
|
3979 |
Object[] ords_of_groups = null; |
|
3980 |
Object[] _elems_info_aray = null; |
|
3981 |
try { |
|
3982 |
all_info_array = ((ARRAY) the_data[3]).getOracleArray(); |
|
3983 |
elems_info_aray = groupByElement(all_info_array); |
|
3984 |
all_ords = ((ARRAY) the_data[4]).getOracleArray(); |
|
3985 |
|
|
3986 |
ords_of_groups = getOrdOfGroups(all_ords, elems_info_aray); |
|
3987 |
_elems_info_aray = new Object[elems_info_aray.length]; |
|
3988 |
} |
|
3989 |
catch (SQLException e) { |
|
3990 |
logger.error("Unexpected error: " + e.getMessage()); |
|
3991 |
} |
|
3992 |
|
|
3993 |
|
|
3994 |
for (int i = 0; i < elems_info_aray.length; i++) { |
|
3995 |
_elems_info_aray[i] = updateIndexes((Datum[]) elems_info_aray[i]); |
|
3996 |
} |
|
3997 |
|
|
3998 |
// _elems_info_aray, ords_of_groups |
|
3999 |
int no_of_elems = ords_of_groups.length; |
|
4000 |
Primitive[] geoms = new Primitive[no_of_elems]; |
|
4001 |
|
|
4002 |
for (int i = 0; i < no_of_elems; i++) { |
|
4003 |
Datum[] item_info_array = null; |
|
4004 |
Datum[] item_ords = null; |
|
4005 |
NUMBER gtype = null; |
|
4006 |
|
|
4007 |
try { |
|
4008 |
item_info_array = (Datum[]) _elems_info_aray[i]; |
|
4009 |
item_ords = (Datum[]) ords_of_groups[i]; |
|
4010 |
|
|
4011 |
gtype = new NUMBER((dim * 1000) + |
|
4012 |
(item_info_array[1].intValue() % 1000)); |
|
4013 |
|
|
4014 |
if (tableHasSrid) { |
|
4015 |
_srid = new NUMBER(Integer.parseInt(table_srid)); |
|
4016 |
} |
|
4017 |
} |
|
4018 |
catch (SQLException se) { |
|
4019 |
logger.error("Unexpected error: " + se.getMessage()); |
|
4020 |
} |
|
4021 |
|
|
4022 |
// if it's the first geometry, the type is the collection's main type (no?) - no |
|
4023 |
// if (i == 0) gtype = main_type; |
|
4024 |
|
|
4025 |
STRUCT itemst = null; |
|
4026 |
|
|
4027 |
if (tableHasSrid) { |
|
4028 |
|
|
4029 |
itemst = createStruct(gtype, _srid, |
|
4030 |
item_info_array, item_ords, _conn); |
|
4031 |
} |
|
4032 |
else { |
|
4033 |
itemst = createStruct(gtype, null, |
|
4034 |
item_info_array, item_ords, _conn); |
|
4035 |
} |
|
4036 |
geoms[i] = getPrimitive(itemst, true); |
|
4037 |
} |
|
4038 |
|
|
4039 |
GeometryManager gm = GeometryLocator.getGeometryManager(); |
|
4040 |
int subt = getSubTypeFromDims(dim); |
|
4041 |
MultiPrimitive resp = null; |
|
4042 |
|
|
4043 |
try { |
|
4044 |
resp = (MultiPrimitive) gm.create(TYPES.AGGREGATE, subt); |
|
4045 |
for (int i = 0; i < no_of_elems; i++) { |
|
4046 |
resp.addPrimitive(geoms[i]); |
|
4047 |
} |
|
4048 |
} catch (Exception e) { |
|
4049 |
logger.error("While creating multi primitive: " + e.getMessage()); |
|
4050 |
} |
|
4051 |
return resp; |
|
4052 |
} |
|
4053 |
|
|
4054 |
// =========================================================== |
|
4055 |
|
|
4056 |
/** |
|
4057 |
* Get oracle srid from srs code(EPSG code) |
|
4058 |
* |
|
4059 |
* @param epsg |
|
4060 |
* @return oraSRID |
|
4061 |
*/ |
|
4062 |
public static String epsgToOracleSrid(String epsg) { |
|
4063 |
|
|
4064 |
DataManager manager = DALLocator.getDataManager(); |
|
4065 |
int isrs = -1; |
|
4066 |
if (epsg != null) { |
|
4067 |
FeatureStore oraSrsStore = (FeatureStore) OracleLibrary |
|
4068 |
.getSRSDataStore(); |
|
4069 |
|
|
4070 |
FeatureSet set = null; |
|
4071 |
try { |
|
4072 |
FeatureQuery query = oraSrsStore.createFeatureQuery(); |
|
4073 |
query.setFilter(manager.createExpresion("EPSG = " + epsg)); |
|
4074 |
set = (FeatureSet) oraSrsStore.getDataSet(query); |
|
4075 |
if (set.getSize() > 0) { |
|
4076 |
Iterator<Feature> it = set.iterator(); |
|
4077 |
while (it.hasNext()) { |
|
4078 |
Feature feat = it.next(); |
|
4079 |
Double ora = feat.getDouble("ORACLE"); |
|
4080 |
int iora = ora.intValue(); |
|
4081 |
double prefe = feat.getDouble("PRF_ORACLE"); |
|
4082 |
if (prefe == 1) { |
|
4083 |
isrs = iora; |
|
4084 |
break; |
|
4085 |
} |
|
4086 |
} |
|
4087 |
} |
|
4088 |
} catch (DataException e) { |
|
4089 |
e.printStackTrace(); |
|
4090 |
} |
|
4091 |
if (isrs >= 0) { |
|
4092 |
return Integer.toString(isrs); |
|
4093 |
} |
|
4094 |
} |
|
4095 |
return null; |
|
4096 |
} |
|
4097 |
|
|
4098 |
/** |
|
4099 |
* Get EPSG SRS from Oracle SRS |
|
4100 |
* |
|
4101 |
* @param oraSRID |
|
4102 |
* @return |
|
4103 |
*/ |
|
4104 |
public static Integer oracleSridToEpsg(String oraSRID) { |
|
4105 |
|
|
4106 |
DataManager manager = DALLocator.getDataManager(); |
|
4107 |
Integer isrs = null; |
|
4108 |
|
|
4109 |
if (oraSRID != null) { |
|
4110 |
FeatureStore oraSrsStore = (FeatureStore) OracleLibrary |
|
4111 |
.getSRSDataStore(); |
|
4112 |
|
|
4113 |
FeatureSet set = null; |
|
4114 |
try { |
|
4115 |
FeatureQuery query = oraSrsStore.createFeatureQuery(); |
|
4116 |
query.setFilter(manager.createExpresion("ORACLE = " + oraSRID)); |
|
4117 |
set = (FeatureSet) oraSrsStore.getDataSet(query); |
|
4118 |
if (set.getSize() > 0) { |
|
4119 |
Iterator<Feature> it = set.iterator(); |
|
4120 |
while (it.hasNext()) { |
|
4121 |
Feature feat = it.next(); |
|
4122 |
isrs = new Integer(feat.getInt("EPSG")); |
|
4123 |
} |
|
4124 |
} |
|
4125 |
} catch (DataException e) { |
|
4126 |
logger.error("While getting EPSG from oracle srid: " + e.getMessage()); |
|
4127 |
} |
|
4128 |
return isrs; |
|
4129 |
} else { |
|
4130 |
return null; |
|
4131 |
} |
|
4132 |
} |
|
4133 |
|
|
4134 |
/** |
|
4135 |
* Get Oracle SRS from gvSIG projection |
|
4136 |
* |
|
4137 |
* @param proj |
|
4138 |
* @return |
|
4139 |
*/ |
|
4140 |
public static String projectionToOracleSrid(IProjection proj) { |
|
4141 |
if (proj != null) { |
|
4142 |
String epsg = proj.getAbrev().trim(); |
|
4143 |
int ocu = epsg.indexOf(":"); |
|
4144 |
if (ocu != -1) { |
|
4145 |
epsg = epsg.substring(ocu + 1); |
|
4146 |
} |
|
4147 |
return epsgToOracleSrid(epsg); |
|
4148 |
} else { |
|
4149 |
return null; |
|
4150 |
} |
|
4151 |
} |
|
4152 |
|
|
4153 |
public static int dimensionsFromSubtype(int subtype) { |
|
4154 |
|
|
4155 |
switch (subtype) { |
|
4156 |
|
|
4157 |
case SUBTYPES.GEOM2D: |
|
4158 |
return 2; |
|
4159 |
case SUBTYPES.GEOM3D: |
|
4160 |
case SUBTYPES.GEOM2DZ: |
|
4161 |
case SUBTYPES.GEOM2DM: |
|
4162 |
return 3; |
|
4163 |
case SUBTYPES.GEOM3DM: |
|
4164 |
return 4; |
|
4165 |
default: |
|
4166 |
logger.error("Unknown subtype: " + subtype + ". Returned 2 as number of dimensions."); |
|
4167 |
return 2; |
|
4168 |
} |
|
4169 |
} |
|
4170 |
|
|
4171 |
public static Rectangle2D envelopeToRectangle2D(org.gvsig.fmap.geom.primitive.Envelope envelope) { |
|
4172 |
|
|
4173 |
double x = envelope.getMinimum(0); |
|
4174 |
double y = envelope.getMinimum(1); |
|
4175 |
double w = envelope.getLength(0); |
|
4176 |
double h = envelope.getLength(1); |
|
4177 |
Rectangle2D resp = new Rectangle2D.Double(x,y,w,h); |
|
4178 |
return resp; |
|
4179 |
} |
|
4180 |
|
|
3820 | 4181 |
} |
Also available in: Unified diff