Revision 36210
trunk/extensions/extOracleSpatial/src/es/prodevelop/cit/gvsig/jdbc_spatial/ExportToOracle.java | ||
---|---|---|
197 | 197 |
boolean savesrs = (opt == JOptionPane.YES_OPTION); |
198 | 198 |
writer.setStoreWithSrid(savesrs); |
199 | 199 |
|
200 |
String orasrid = OracleSpatialDriver.epsgSridToOracleSrid(strSRID); |
|
201 |
boolean geo_cs = OracleSpatialUtils.getIsGCS(orasrid, savesrs); |
|
200 |
String orasrid = ""; |
|
201 |
boolean geo_cs = false; |
|
202 |
|
|
203 |
try { |
|
204 |
orasrid = OracleSpatialDriver.epsgSridToOracleSrid(strSRID); |
|
205 |
geo_cs = OracleSpatialUtils.getIsGCS(orasrid, savesrs); |
|
206 |
} catch (Exception ex) { |
|
207 |
// not found: same |
|
208 |
orasrid = strSRID; |
|
209 |
geo_cs = false; |
|
210 |
} |
|
211 |
|
|
212 |
|
|
213 |
|
|
202 | 214 |
writer.setGeoCS(geo_cs); |
203 | 215 |
|
204 | 216 |
OracleSpatialDriver oDriver = new OracleSpatialDriver(); |
trunk/extensions/extOracleSpatial/src/es/prodevelop/cit/gvsig/fmap/drivers/jdbc/oracle/OracleSpatialDriver.java | ||
---|---|---|
154 | 154 |
public static final String DEFAULT_GEO_FIELD = "GEOMETRY"; |
155 | 155 |
// public static final String DEFAULT_GEO_FIELD = "MERGEDGEOMETRY"; |
156 | 156 |
|
157 |
|
|
157 | 158 |
public static final String ORACLE_ID_FIELD = "ROWID"; |
158 | 159 |
public static final String DEFAULT_ID_FIELD_CASE_SENSITIVE = "GID"; |
159 | 160 |
public static final String ORACLE_GEO_SCHEMA = "MDSYS"; |
... | ... | |
191 | 192 |
|
192 | 193 |
// switch variable |
193 | 194 |
private boolean use_geotools = false; |
194 |
private boolean tableHasSrid = true; |
|
195 |
private boolean table_HasSrid = true;
|
|
195 | 196 |
|
196 | 197 |
// ------------------------------------------------ |
197 | 198 |
private boolean isNotAvailableYet = true; |
... | ... | |
209 | 210 |
private String idFieldNames; |
210 | 211 |
private int oneBasedGeoColInd = 0; |
211 | 212 |
private int shapeType = -1; |
212 |
private boolean needsCollectionLayer = true; |
|
213 | 213 |
|
214 | 214 |
// ---------------------------------------------- |
215 | 215 |
// one feature is cached to avoid querying for each attribute request: |
... | ... | |
223 | 223 |
private String fullTableName = ""; |
224 | 224 |
private String geoColName = ""; |
225 | 225 |
private String oracleSRID; |
226 |
private String epsgSRID; |
|
226 |
private String epsg_SRID;
|
|
227 | 227 |
private String destProj = ""; |
228 | 228 |
private Rectangle2D full_Extent = null; |
229 | 229 |
private boolean emptyWhereClause = true; |
... | ... | |
344 | 344 |
|
345 | 345 |
if (tn.indexOf(".") == -1) { |
346 | 346 |
|
347 |
if (lyrDef.getSchema() == null) { |
|
347 |
if (lyrDef.getSchema() == null || lyrDef.getSchema().length() == 0) {
|
|
348 | 348 |
fullTableName = _cwp.getUser().toUpperCase() + "." + tn; |
349 | 349 |
} else { |
350 | 350 |
fullTableName = lyrDef.getSchema() + "." + tn; |
... | ... | |
362 | 362 |
// getMetaDataInThisThread(); |
363 | 363 |
cleanWhereClause(); |
364 | 364 |
loadSdoMetadata(); |
365 |
oneRowMetadata(); |
|
365 |
oneRowMetadata();
|
|
366 | 366 |
|
367 | 367 |
setDestProjection(lyrDef.getSRID_EPSG()); |
368 | 368 |
workingAreaInViewsCS = lyrDef.getWorkingArea(); |
369 | 369 |
|
370 |
if ((workingAreaInViewsCS != null) && (epsgSRID != null)) {
|
|
370 |
if ((workingAreaInViewsCS != null) && isTableHasSrid() && (getEpsgSRID() != null)) {
|
|
371 | 371 |
IProjection viewProj = CRSFactory.getCRS(destProj); |
372 |
IProjection tableProj = CRSFactory.getCRS("EPSG:" + epsgSRID);
|
|
372 |
IProjection tableProj = CRSFactory.getCRS("EPSG:" + getEpsgSRID());
|
|
373 | 373 |
ICoordTrans reprojecter = viewProj.getCT(tableProj); |
374 | 374 |
workingAreaInTablesCS = reprojecter.convert(workingAreaInViewsCS); |
375 | 375 |
workingAreaInTablesCSStruct = shapeToStruct(workingAreaInTablesCS, |
376 |
FShape.NULL, tableHasSrid, false, true); |
|
376 |
FShape.NULL, isTableHasSrid(), false, true); |
|
377 |
} else { |
|
378 |
if (workingAreaInViewsCS != null) { |
|
379 |
workingAreaInTablesCS = (Rectangle2D) workingAreaInViewsCS.clone(); |
|
380 |
workingAreaInTablesCSStruct = shapeToStruct(workingAreaInTablesCS, |
|
381 |
FShape.NULL, isTableHasSrid(), false, true); |
|
382 |
} |
|
377 | 383 |
} |
378 | 384 |
|
379 | 385 |
cancelIDLoad = false; |
... | ... | |
421 | 427 |
|
422 | 428 |
if (obj == null) { |
423 | 429 |
logger.warn("No SRID found for this table."); |
424 |
tableHasSrid = false;
|
|
430 |
setTableHasSrid(false);
|
|
425 | 431 |
|
426 | 432 |
return null; |
427 | 433 |
} |
... | ... | |
492 | 498 |
|
493 | 499 |
} |
494 | 500 |
|
495 |
ResultSet _rs = _st.executeQuery(qry); |
|
501 |
ResultSet _rs = _st.executeQuery(qry);
|
|
496 | 502 |
|
497 | 503 |
if (_rs.next()) { |
498 | 504 |
oracleSRID = getOracleSridFromCurrentRecord(_rs); |
499 | 505 |
|
500 |
isGeogCS = OracleSpatialUtils.getIsGCS(oracleSRID, tableHasSrid);
|
|
506 |
isGeogCS = OracleSpatialUtils.getIsGCS(oracleSRID, isTableHasSrid());
|
|
501 | 507 |
|
502 |
try { |
|
503 |
epsgSRID = oracleSridToEpsgSrid(oracleSRID); |
|
504 |
} catch (Exception e) { |
|
505 |
logger.error("Unknown oracle SRID: " + oracleSRID); |
|
506 |
tableHasSrid = false; |
|
507 |
} |
|
508 |
if (oracleSRID == null) { |
|
509 |
setTableHasSrid(false); |
|
510 |
} else { |
|
511 |
try { |
|
512 |
setEpsgSRID( oracleSridToEpsgSrid(oracleSRID) ); |
|
513 |
} catch (Exception e) { |
|
514 |
// logger.error("Unknown oracle SRID: " + oracleSRID); |
|
515 |
setTableHasSrid(true); |
|
516 |
setEpsgSRID( oracleSRID ); |
|
517 |
} |
|
518 |
} |
|
519 |
|
|
508 | 520 |
full_Extent = getFullExtentFromCurrentRecord(_rs); |
509 | 521 |
|
510 | 522 |
hasRealiableExtent = realiableExtent(full_Extent, isGeogCS); |
... | ... | |
789 | 801 |
logger.warn("Assumed MULTI"); |
790 | 802 |
} |
791 | 803 |
|
792 |
return resp; |
|
804 |
return resp;
|
|
793 | 805 |
} |
794 | 806 |
|
795 | 807 |
private int getShapeTypeFromArray(ArrayList arrlist) { |
796 | 808 |
|
809 |
int sz = arrlist.size(); |
|
810 |
|
|
811 |
if (sz == 0) { |
|
812 |
return FShape.MULTI; |
|
813 |
} |
|
814 |
|
|
797 | 815 |
int resp = ((Integer) arrlist.get(0)).intValue(); |
816 |
boolean needs3d = (resp > FShape.Z) ? true : false; |
|
798 | 817 |
|
799 |
int sz = arrlist.size(); |
|
800 | 818 |
int aux = 0; |
801 | 819 |
for (int i=1; i<sz; i++) { |
802 | 820 |
aux = ((Integer) arrlist.get(i)).intValue(); |
803 |
if (aux != resp) return FShape.MULTI; |
|
821 |
if (aux != resp) { |
|
822 |
resp = FShape.MULTI; |
|
823 |
} |
|
824 |
if (aux > FShape.Z) { |
|
825 |
needs3d = true; |
|
826 |
} |
|
804 | 827 |
} |
805 |
return resp;
|
|
828 |
return needs3d ? ((resp % FShape.Z) + FShape.Z) : (resp % FShape.Z);
|
|
806 | 829 |
} |
807 | 830 |
|
808 | 831 |
private String getIdFieldNames() { |
... | ... | |
852 | 875 |
|
853 | 876 |
singleCachedFeatureRowNum = -1; |
854 | 877 |
|
855 |
Object[] rs_st = getViewResultSet(null, sql, tableHasSrid);
|
|
878 |
Object[] rs_st = getViewResultSet(null, sql, isTableHasSrid());
|
|
856 | 879 |
|
857 | 880 |
ResultSet localrs = (ResultSet) rs_st[0]; |
858 | 881 |
Statement _st = (Statement) rs_st[1]; |
... | ... | |
893 | 916 |
|
894 | 917 |
singleCachedFeatureRowNum = -1; |
895 | 918 |
|
896 |
STRUCT local_st = shapeToStruct(r, FShape.NULL, tableHasSrid, false, true);
|
|
897 |
Object[] rs_st = getViewResultSet(local_st, null, tableHasSrid);
|
|
919 |
STRUCT local_st = shapeToStruct(r, FShape.NULL, isTableHasSrid(), false, true);
|
|
920 |
Object[] rs_st = getViewResultSet(local_st, null, isTableHasSrid());
|
|
898 | 921 |
ResultSet localrs = (ResultSet) rs_st[0]; |
899 | 922 |
Statement _st = (Statement) rs_st[1]; |
900 | 923 |
|
... | ... | |
924 | 947 |
return getFeatureIterator(r, strEPSG); |
925 | 948 |
} else { |
926 | 949 |
|
927 |
STRUCT local_st = shapeToStruct(r, FShape.NULL, tableHasSrid, false, true);
|
|
928 |
Object[] rs_st = getViewResultSet(local_st, null, tableHasSrid);
|
|
950 |
STRUCT local_st = shapeToStruct(r, FShape.NULL, isTableHasSrid(), false, true);
|
|
951 |
Object[] rs_st = getViewResultSet(local_st, null, isTableHasSrid());
|
|
929 | 952 |
ResultSet localrs = (ResultSet) rs_st[0]; |
930 | 953 |
Statement _st = (Statement) rs_st[1]; |
931 | 954 |
|
... | ... | |
1096 | 1119 |
st.close(); |
1097 | 1120 |
numReg = row; |
1098 | 1121 |
|
1099 |
needsCollectionLayer = OracleSpatialUtils.hasSeveralGeometryTypes(types, false); |
|
1122 |
/* |
|
1123 |
boolean needsCollectionLayer = OracleSpatialUtils.hasSeveralGeometryTypes(types, false); |
|
1100 | 1124 |
|
1101 | 1125 |
if (needsCollectionLayer) { |
1102 | 1126 |
shapeType = FShape.MULTI; |
1103 | 1127 |
} |
1128 |
*/ |
|
1104 | 1129 |
} |
1105 | 1130 |
catch (SQLException e) { |
1106 | 1131 |
logger.error("While setting id-row hashmap: " + e.getMessage()); |
... | ... | |
1366 | 1391 |
gtype = new NUMBER((dim * 1000) + |
1367 | 1392 |
(item_info_array[1].intValue() % 1000)); |
1368 | 1393 |
|
1369 |
if (tableHasSrid) {
|
|
1394 |
if (isTableHasSrid()) {
|
|
1370 | 1395 |
_srid = new NUMBER(Integer.parseInt(oracleSRID)); |
1371 | 1396 |
} |
1372 | 1397 |
} |
... | ... | |
1379 | 1404 |
|
1380 | 1405 |
STRUCT itemst = null; |
1381 | 1406 |
|
1382 |
if (tableHasSrid) {
|
|
1407 |
if (isTableHasSrid()) {
|
|
1383 | 1408 |
|
1384 | 1409 |
itemst = OracleSpatialUtils.createStruct(gtype, _srid, |
1385 | 1410 |
item_info_array, item_ords, ((ConnectionJDBC)conn).getConnection()); |
... | ... | |
1655 | 1680 |
} |
1656 | 1681 |
} else { |
1657 | 1682 |
String waqry = getValidViewConstructor(workingAreaInTablesCSStruct, |
1658 |
oracleSRID, tableHasSrid, isGeogCS);
|
|
1683 |
oracleSRID, isTableHasSrid(), isGeogCS);
|
|
1659 | 1684 |
|
1660 | 1685 |
if (emptyWhereClause) { |
1661 | 1686 |
resp = resp + _where + "(sdo_relate(" + geoColName + ", " + waqry |
... | ... | |
2220 | 2245 |
} |
2221 | 2246 |
|
2222 | 2247 |
if (ds.getRowCount() > 1) { |
2223 |
logger.error("==============="); |
|
2224 |
logger.error(
|
|
2225 |
"DBF file is wrong: More than one preferred Oracle Spatial code found for EPSG code: " + |
|
2248 |
// logger.error("===============");
|
|
2249 |
logger.warn(
|
|
2250 |
"DBF file is wrong?: More than one preferred Oracle Spatial code found for EPSG code: " +
|
|
2226 | 2251 |
epsg); |
2227 | 2252 |
|
2228 | 2253 |
for (int i = 0; i < ds.getRowCount(); i++) { |
... | ... | |
2231 | 2256 |
if (i == 0) { |
2232 | 2257 |
resp = "" + aux; |
2233 | 2258 |
} |
2234 |
|
|
2235 |
logger.error("" + aux); |
|
2259 |
// logger.error("" + aux); |
|
2236 | 2260 |
} |
2237 |
|
|
2238 |
logger.error("==============="); |
|
2239 |
|
|
2261 |
// logger.error("==============="); |
|
2240 | 2262 |
return resp; |
2241 | 2263 |
} |
2242 | 2264 |
|
2243 | 2265 |
resp = "" + |
2244 | 2266 |
Math.round(((DoubleValue) ds.getRow(0)[0]).doubleValue()); |
2267 |
} catch (Exception pe) { |
|
2268 |
throw pe; |
|
2269 |
// logger.error("Error with SQL statement. " + pe.getMessage()); |
|
2245 | 2270 |
} |
2246 |
catch (Exception pe) { |
|
2247 |
logger.error("Error with SQL statement. " + pe.getMessage()); |
|
2248 |
} |
|
2249 | 2271 |
|
2250 | 2272 |
return resp; |
2251 | 2273 |
} |
... | ... | |
2274 | 2296 |
DataSourceFactory.AUTOMATIC_OPENING); |
2275 | 2297 |
|
2276 | 2298 |
if (ds.getRowCount() == 0) { |
2277 |
logger.error("Oracle Spatial code not found in table: " + ora);
|
|
2299 |
logger.warn("Oracle Spatial code not found in table: " + ora);
|
|
2278 | 2300 |
throw new Exception("Unknown Oracle code: " + ora); |
2279 | 2301 |
} |
2280 | 2302 |
|
2281 | 2303 |
if (ds.getRowCount() > 1) { |
2282 |
logger.error("==============="); |
|
2283 |
logger.error(
|
|
2284 |
"DBF file is wrong: More than one EPSG code found for Oracle Spatial code: " + |
|
2304 |
// logger.error("===============");
|
|
2305 |
logger.warn(
|
|
2306 |
"DBF file is wrong?: More than one EPSG code found for Oracle Spatial code: " +
|
|
2285 | 2307 |
ora); |
2286 | 2308 |
|
2287 | 2309 |
for (int i = 0; i < ds.getRowCount(); i++) { |
... | ... | |
2292 | 2314 |
resp = aux; |
2293 | 2315 |
} |
2294 | 2316 |
|
2295 |
logger.error("" + aux);
|
|
2317 |
// logger.error("" + aux);
|
|
2296 | 2318 |
} |
2297 | 2319 |
|
2298 |
logger.error("===============");
|
|
2320 |
// logger.error("===============");
|
|
2299 | 2321 |
|
2300 | 2322 |
return resp; |
2301 | 2323 |
} |
2302 | 2324 |
|
2303 | 2325 |
resp = "" + |
2304 | 2326 |
Math.round(((DoubleValue) ds.getRow(0)[0]).doubleValue()); |
2327 |
} catch (Exception pe) { |
|
2328 |
throw pe; |
|
2329 |
// logger.warn("Error with SQL statement. " + pe.getMessage()); |
|
2305 | 2330 |
} |
2306 |
catch (Exception pe) { |
|
2307 |
logger.error("Error with SQL statement. " + pe.getMessage()); |
|
2308 |
} |
|
2309 | 2331 |
|
2310 | 2332 |
return resp; |
2311 | 2333 |
} |
... | ... | |
2867 | 2889 |
|
2868 | 2890 |
try { |
2869 | 2891 |
STRUCT the_struct = OracleSpatialUtils.fShapeToSTRUCT(shp, _conn, |
2870 |
_srid, agu_bien, hasSrid, _isGeoCS); |
|
2892 |
_srid, agu_bien, hasSrid, _isGeoCS, forced_type);
|
|
2871 | 2893 |
|
2872 | 2894 |
return the_struct; |
2873 | 2895 |
} |
... | ... | |
3271 | 3293 |
logger.error("While initializing OS Writer: " + e.getMessage(), e); |
3272 | 3294 |
} |
3273 | 3295 |
|
3274 |
writer.setStoreWithSrid(tableHasSrid);
|
|
3296 |
writer.setStoreWithSrid(isTableHasSrid());
|
|
3275 | 3297 |
} |
3276 | 3298 |
|
3277 | 3299 |
return writer; |
... | ... | |
3865 | 3887 |
public void setAdaptedFetchSize(int v) { |
3866 | 3888 |
adaptedFetchSize = v; |
3867 | 3889 |
} |
3868 |
|
|
3869 |
|
|
3870 | 3890 |
|
3891 |
private boolean isTableHasSrid() { |
|
3892 |
return table_HasSrid; |
|
3893 |
} |
|
3894 |
|
|
3895 |
private void setTableHasSrid(boolean b) { |
|
3896 |
this.table_HasSrid = b; |
|
3897 |
} |
|
3898 |
|
|
3899 |
private String getEpsgSRID() { |
|
3900 |
return epsg_SRID; |
|
3901 |
} |
|
3902 |
|
|
3903 |
private void setEpsgSRID(String e) { |
|
3904 |
this.epsg_SRID = e; |
|
3905 |
} |
|
3906 |
|
|
3871 | 3907 |
} |
3872 | 3908 |
|
3873 | 3909 |
// [eiel-gestion-conexiones] |
trunk/extensions/extOracleSpatial/src/es/prodevelop/cit/gvsig/fmap/drivers/jdbc/oracle/OracleSpatialWriter.java | ||
---|---|---|
50 | 50 |
|
51 | 51 |
import org.apache.log4j.Logger; |
52 | 52 |
|
53 |
import sun.print.PSPrinterJob.EPSPrinter; |
|
54 |
|
|
53 | 55 |
import com.hardcode.gdbms.driver.exceptions.InitializeWriterException; |
54 | 56 |
import com.hardcode.gdbms.driver.exceptions.WriteDriverException; |
55 | 57 |
import com.iver.cit.gvsig.exceptions.visitors.StartWriterVisitorException; |
... | ... | |
158 | 160 |
try { |
159 | 161 |
_ora_srid = OracleSpatialDriver.epsgSridToOracleSrid(srid_epsg); |
160 | 162 |
} catch (Exception e1) { |
161 |
logger.error("Unknown EPSG code: " + srid_epsg); |
|
162 |
with_srid = false; |
|
163 |
logger.error("Unknown EPSG code: " + srid_epsg + ", using it as oracle code in empty table"); |
|
164 |
// with_srid = false; |
|
165 |
_ora_srid = srid_epsg; |
|
163 | 166 |
} |
164 | 167 |
|
165 | 168 |
boolean table_exists = true; |
... | ... | |
267 | 270 |
oracleSRID = OracleSpatialDriver.epsgSridToOracleSrid(srid_epsg); |
268 | 271 |
} catch (Exception e1) { |
269 | 272 |
// not found |
270 |
logger.error("unknown EPSG code: " + srid_epsg); |
|
271 |
storeWithSrid = false; |
|
273 |
oracleSRID = srid_epsg; |
|
274 |
logger.warn("unknown EPSG code: " + srid_epsg + ", using it as ora code"); |
|
275 |
// storeWithSrid = false; |
|
272 | 276 |
} |
273 | 277 |
|
274 | 278 |
String _sql_rem_meta = |
... | ... | |
426 | 430 |
_ig = OracleSpatialUtils.makeLinear((FPolygon2D) shp); |
427 | 431 |
} |
428 | 432 |
|
429 |
|
|
430 |
// STRUCT st = driver.shapeToStruct(shp, lyrShapeType, conn, oracleSRID, false); |
|
433 |
// STRUCT st = driver.shapeToStruct(shp, lyrShapeType, conn, oracleSRID, false) |
|
431 | 434 |
STRUCT st; |
432 | 435 |
|
433 |
if ((oracleSRID == null) || (driver.getDestProjectionOracleCode().compareToIgnoreCase(oracleSRID) == 0)) { |
|
436 |
if ((oracleSRID == null) || |
|
437 |
!differentSRS(driver.getDestProjectionOracleCode(), oracleSRID) |
|
438 |
// (driver.getDestProjectionOracleCode().compareToIgnoreCase(oracleSRID) == 0) |
|
439 |
) { |
|
434 | 440 |
|
435 | 441 |
st = OracleSpatialDriver.iGeometryToSTRUCT(_ig, |
436 | 442 |
lyrShapeType, conn, oracleSRID, storeWithSrid, aguBien, |
... | ... | |
467 | 473 |
} |
468 | 474 |
} |
469 | 475 |
|
470 |
private void deleteRow(IRowEdited irow) throws VisitorException { |
|
476 |
private boolean differentSRS(String srsa, String srsb) { |
|
477 |
|
|
478 |
if (srsa == null || srsb == null || srsa.length() == 0 || srsb.length() == 0) { |
|
479 |
return false; |
|
480 |
} else { |
|
481 |
if (srsa.compareToIgnoreCase(srsb) == 0) return false; |
|
482 |
String aux = ""; |
|
483 |
try { aux = OracleSpatialDriver.oracleSridToEpsgSrid(srsa); } catch (Exception ex) { } |
|
484 |
if (aux.compareToIgnoreCase(srsb) == 0 || |
|
485 |
corrToSameOracleCode(aux, srsb)) { return false; } |
|
486 |
try { aux = OracleSpatialDriver.epsgSridToOracleSrid(srsa); } catch (Exception ex) { } |
|
487 |
if (aux.compareToIgnoreCase(srsb) == 0 || |
|
488 |
corrToSameEpsgCode(aux, srsb)) { return false; } |
|
489 |
return true; |
|
490 |
} |
|
491 |
|
|
492 |
} |
|
493 |
|
|
494 |
private boolean corrToSameEpsgCode(String a, String b) { |
|
495 |
try { |
|
496 |
String aa = OracleSpatialDriver.oracleSridToEpsgSrid(a); |
|
497 |
String bb = OracleSpatialDriver.oracleSridToEpsgSrid(b); |
|
498 |
return (aa.compareToIgnoreCase(bb) == 0); |
|
499 |
} catch (Exception ex) { |
|
500 |
return false; |
|
501 |
} |
|
502 |
} |
|
503 |
|
|
504 |
private boolean corrToSameOracleCode(String a, String b) { |
|
505 |
try { |
|
506 |
String aa = OracleSpatialDriver.epsgSridToOracleSrid(a); |
|
507 |
String bb = OracleSpatialDriver.epsgSridToOracleSrid(b); |
|
508 |
return (aa.compareToIgnoreCase(bb) == 0); |
|
509 |
} catch (Exception ex) { |
|
510 |
return false; |
|
511 |
} |
|
512 |
} |
|
513 |
|
|
514 |
private void deleteRow(IRowEdited irow) throws VisitorException { |
|
471 | 515 |
DefaultRowEdited _row = (DefaultRowEdited) irow; |
472 | 516 |
DefaultRow row = (DefaultRow) _row.getLinkedRow(); |
473 | 517 |
|
... | ... | |
523 | 567 |
String _sql_update = OracleSpatialDriver.getRowUpdateSql(ifeat, |
524 | 568 |
(DBLayerDefinition) tableDef, rowIndex, geoColName); |
525 | 569 |
|
526 |
logger.debug("############ SQL UPDATE = " + _sql_update);
|
|
570 |
logger.debug("# SQL UPDATE = " + _sql_update); |
|
527 | 571 |
|
528 | 572 |
IConnection conn = ((DBLayerDefinition) tableDef).getConnection(); |
529 | 573 |
|
... | ... | |
534 | 578 |
IGeometry _ig = ifeat.getGeometry(); |
535 | 579 |
STRUCT st; |
536 | 580 |
|
537 |
logger.debug("############ driver.getDestProjectionOracleCode() = " |
|
538 |
+ driver.getDestProjectionOracleCode()); |
|
539 |
logger.debug("############ oracleSRID = " + oracleSRID); |
|
581 |
if ((oracleSRID == null) || |
|
582 |
!differentSRS(driver.getDestProjectionOracleCode(), oracleSRID) |
|
583 |
// (driver.getDestProjectionOracleCode().compareToIgnoreCase(oracleSRID) == 0) |
|
584 |
) { |
|
540 | 585 |
|
541 |
if ((oracleSRID == null) || (driver.getDestProjectionOracleCode().compareToIgnoreCase(oracleSRID) == 0)) { |
|
542 |
|
|
543 | 586 |
st = OracleSpatialDriver.iGeometryToSTRUCT(_ig, |
544 | 587 |
lyrShapeType, conn, oracleSRID, storeWithSrid, aguBien, |
545 | 588 |
isGeoCS); |
546 | 589 |
|
547 | 590 |
} else { |
548 | 591 |
|
592 |
logger.debug("# Update + Reproj: driver.getDestProjectionOracleCode() = " |
|
593 |
+ driver.getDestProjectionOracleCode()); |
|
594 |
logger.debug("# Update + Reproj: oracleSRID = " + oracleSRID); |
|
595 |
|
|
549 | 596 |
String viewSrid = driver.getDestProjectionOracleCode(); |
550 | 597 |
boolean isViewSridGedetic = driver.getIsDestProjectionGeog(); |
551 | 598 |
st = OracleSpatialDriver.iGeometryToSTRUCT(_ig, |
trunk/extensions/extOracleSpatial/src/es/prodevelop/cit/gvsig/fmap/drivers/jdbc/oracle/OracleSpatialUtils.java | ||
---|---|---|
108 | 108 |
import com.vividsolutions.jts.geom.LineString; |
109 | 109 |
import com.vividsolutions.jts.geom.LinearRing; |
110 | 110 |
import com.vividsolutions.jts.geom.impl.CoordinateArraySequence; |
111 |
import com.vividsolutions.jts.linearref.LinearIterator; |
|
111 | 112 |
|
112 | 113 |
|
113 | 114 |
/** |
... | ... | |
257 | 258 |
* @throws SQLException |
258 | 259 |
*/ |
259 | 260 |
public static STRUCT fShapeToSTRUCT(Object fshp, IConnection c, int srid, |
260 |
boolean agu_b, boolean hasSrid, boolean is_geodet) throws SQLException { |
|
261 |
boolean agu_b, boolean hasSrid, boolean is_geodet, int forced_shptype) throws SQLException { |
|
262 |
|
|
261 | 263 |
boolean three = false; |
262 | 264 |
|
263 |
if (fshp instanceof FShape3D) { |
|
264 |
three = true; |
|
265 |
if (fshp instanceof FShape3D || (forced_shptype > FShape.Z)) {
|
|
266 |
three = true;
|
|
265 | 267 |
} |
266 | 268 |
|
267 | 269 |
STRUCT resp = null; |
... | ... | |
287 | 289 |
else { |
288 | 290 |
if (fshp instanceof FPolygon2D) { // polygon 2/3d |
289 | 291 |
|
290 |
if ((fshp instanceof FCircle2D) && (!is_geodet)) { |
|
292 |
if ((fshp instanceof FCircle2D) && (!is_geodet) && (!three)) {
|
|
291 | 293 |
resp = getCircleAsStruct((FCircle2D) fshp, srid, c, hasSrid); |
292 | 294 |
} else { |
293 | 295 |
// also FEllipse2D |
... | ... | |
297 | 299 |
// ArrayList polys = getPolygonsEasily(fshp); |
298 | 300 |
// resp = getMultiPolygonAsStruct(polys, srid, three, c); |
299 | 301 |
} |
300 |
} |
|
301 |
else { // line 2/3d |
|
302 |
} else { // line 2/3d |
|
302 | 303 |
|
303 |
ArrayList _lines = getLineStrings((FShape) fshp, is_geodet); |
|
304 |
resp = getMultiLineAsStruct(_lines, srid, three, c, hasSrid); |
|
304 |
if (forced_shptype % FShape.Z == FShape.POLYGON) { |
|
305 |
|
|
306 |
// force line to polygon |
|
307 |
resp = multiLineToMultiPolygonStruct((FShape) fshp, srid, three, |
|
308 |
c, agu_b, hasSrid, is_geodet); |
|
309 |
|
|
310 |
} else { |
|
311 |
ArrayList _lines = getLineStrings((FShape) fshp, is_geodet); |
|
312 |
resp = getMultiLineAsStruct(_lines, srid, three, c, hasSrid); |
|
313 |
} |
|
305 | 314 |
} |
306 | 315 |
} |
307 | 316 |
|
... | ... | |
887 | 896 |
Coordinate[] cc = ls.getLs().getCoordinates(); |
888 | 897 |
double[] z = ls.getZc(); |
889 | 898 |
int size = cc.length; |
899 |
double _z = 0; |
|
890 | 900 |
|
891 | 901 |
if (threed) { |
892 | 902 |
for (int i = 0; i < size; i++) { |
893 |
resp = resp + cc[i].x + " " + cc[i].y + " " + z[i] + ", "; |
|
903 |
_z = (z==null) ? 0 : z[i]; |
|
904 |
resp = resp + cc[i].x + " " + cc[i].y + " " + _z + ", "; |
|
894 | 905 |
} |
895 | 906 |
|
896 | 907 |
resp = resp.substring(0, resp.length() - 2); |
... | ... | |
1017 | 1028 |
|
1018 | 1029 |
private static boolean lineString3DIsContainedBy(LineString3D contained, |
1019 | 1030 |
LineString3D container) { |
1020 |
int samples = 10; |
|
1031 |
|
|
1032 |
int samples = 25; |
|
1033 |
|
|
1021 | 1034 |
LineString _in = contained.getLs(); |
1022 | 1035 |
LineString _out = container.getLs(); |
1023 | 1036 |
Coordinate[] inc = _in.getCoordinates(); |
1024 | 1037 |
Coordinate aux; |
1025 | 1038 |
int size = inc.length; |
1026 | 1039 |
|
1027 |
if (size <= 10) {
|
|
1040 |
if (size <= samples) {
|
|
1028 | 1041 |
for (int i = 0; i < size; i++) { |
1029 | 1042 |
aux = inc[i]; |
1030 | 1043 |
|
... | ... | |
1073 | 1086 |
|
1074 | 1087 |
int _ind = 0; |
1075 | 1088 |
NUMBER[] ords = new NUMBER[acum]; |
1089 |
double _z = 0; |
|
1076 | 1090 |
|
1077 | 1091 |
for (int i = 0; i < size; i++) { |
1078 | 1092 |
LineString3D ls = (LineString3D) pols.get(i); |
... | ... | |
1083 | 1097 |
ords[_ind + 1] = new NUMBER(ls.getLs().getCoordinateN(j).y); |
1084 | 1098 |
|
1085 | 1099 |
if (threed) { |
1086 |
ords[_ind + 2] = new NUMBER(ls.getZc()[j]); |
|
1100 |
_z = (ls.getZc() == null) ? 0 : ls.getZc()[j]; |
|
1101 |
ords[_ind + 2] = new NUMBER(_z); |
|
1087 | 1102 |
} |
1088 | 1103 |
|
1089 | 1104 |
_ind = _ind + dim; |
... | ... | |
1123 | 1138 |
int geotype = 2006; |
1124 | 1139 |
int dim = 2; |
1125 | 1140 |
int acum = 0; |
1141 |
double _z = 0; |
|
1126 | 1142 |
|
1127 | 1143 |
if (threed) { |
1128 | 1144 |
geotype = 3006; |
... | ... | |
1151 | 1167 |
ords[_ind + 1] = new NUMBER(ls.getLs().getCoordinateN(j).y); |
1152 | 1168 |
|
1153 | 1169 |
if (threed) { |
1154 |
ords[_ind + 2] = new NUMBER(ls.getZc()[j]); |
|
1170 |
_z = (ls.getZc() == null) ? 0 : ls.getZc()[j]; |
|
1171 |
ords[_ind + 2] = new NUMBER(_z); |
|
1155 | 1172 |
} |
1156 | 1173 |
|
1157 | 1174 |
_ind = _ind + dim; |
... | ... | |
1532 | 1549 |
|
1533 | 1550 |
for (int i = 0; i < shells.length; i++) { |
1534 | 1551 |
resp_shells.add(all_ls.get(shells[i])); |
1535 |
aux_holes = getHolesOf(i, final_cont, all_ls);
|
|
1552 |
aux_holes = getHolesOf(shells[i], final_cont, all_ls);
|
|
1536 | 1553 |
resp_holes_for_shells.add(aux_holes); |
1537 | 1554 |
} |
1538 | 1555 |
|
... | ... | |
1564 | 1581 |
ArrayList ho = reverseHoles(_ho); |
1565 | 1582 |
|
1566 | 1583 |
return getMultiPolygonAsStruct(sh, ho, srid, threed, _conn, agu_bien, hasSrid); |
1567 |
|
|
1568 | 1584 |
} |
1585 |
|
|
1586 |
private static STRUCT multiLineToMultiPolygonStruct(FShape mpol, int srid, |
|
1587 |
boolean threed, IConnection _conn, boolean agu_bien, boolean hasSrid, boolean isgeo) |
|
1588 |
throws SQLException { |
|
1589 |
ArrayList all_ls = getPolygonsEasily(mpol, isgeo); |
|
1590 |
|
|
1591 |
ArrayList no_holes = new ArrayList(); |
|
1592 |
int n_sh = all_ls.size(); |
|
1593 |
for (int i=0; i<n_sh; i++) no_holes.add(new ArrayList()); |
|
1569 | 1594 |
|
1595 |
return getMultiPolygonAsStruct( |
|
1596 |
all_ls, |
|
1597 |
no_holes, |
|
1598 |
srid, threed, _conn, agu_bien, hasSrid); |
|
1599 |
} |
|
1600 |
|
|
1570 | 1601 |
private static ArrayList reverseHoles(ArrayList hh) { |
1571 | 1602 |
ArrayList resp = new ArrayList(); |
1572 | 1603 |
|
... | ... | |
1633 | 1664 |
|
1634 | 1665 |
int _ind = 0; |
1635 | 1666 |
NUMBER[] ords = new NUMBER[acum]; |
1667 |
double _z = 0; |
|
1636 | 1668 |
|
1637 | 1669 |
for (int i = 0; i < shells.size(); i++) { |
1638 | 1670 |
// -------------------------------- |
... | ... | |
1644 | 1676 |
ords[_ind + 1] = new NUMBER(ls.getLs().getCoordinateN(j).y); |
1645 | 1677 |
|
1646 | 1678 |
if (threed) { |
1647 |
ords[_ind + 2] = new NUMBER(ls.getZc()[j]); |
|
1679 |
_z = (ls.getZc() == null) ? 0 : ls.getZc()[j]; |
|
1680 |
ords[_ind + 2] = new NUMBER(_z); |
|
1648 | 1681 |
} |
1649 |
|
|
1650 | 1682 |
_ind = _ind + dim; |
1651 | 1683 |
} |
1652 | 1684 |
|
... | ... | |
1662 | 1694 |
ords[_ind + 1] = new NUMBER(ls.getLs().getCoordinateN(k).y); |
1663 | 1695 |
|
1664 | 1696 |
if (threed) { |
1665 |
ords[_ind + 2] = new NUMBER(ls.getZc()[k]); |
|
1697 |
_z = (ls.getZc() == null) ? 0 : ls.getZc()[k]; |
|
1698 |
ords[_ind + 2] = new NUMBER(_z); |
|
1666 | 1699 |
} |
1667 | 1700 |
|
1668 | 1701 |
_ind = _ind + dim; |
... | ... | |
1983 | 2016 |
int[] start_ind; |
1984 | 2017 |
int[] end_ind; |
1985 | 2018 |
|
2019 |
|
|
1986 | 2020 |
int dims = 0; |
1987 | 2021 |
boolean next_must_do_first = true; |
1988 | 2022 |
|
... | ... | |
2004 | 2038 |
|
2005 | 2039 |
info_array = (Datum[]) infoARRAY.getOracleArray(); |
2006 | 2040 |
ords_array = (Datum[]) ordsARRAY.getOracleArray(); |
2041 |
|
|
2007 | 2042 |
info_array_size = info_array.length / 3; |
2008 | 2043 |
|
2009 | 2044 |
int last_index = ords_array.length - dims + 1; |
... | ... | |
2022 | 2057 |
|
2023 | 2058 |
int lineType = PathIterator.SEG_LINETO; |
2024 | 2059 |
|
2060 |
|
|
2025 | 2061 |
if (end_ind[0] == 0) { // collection of paths |
2026 | 2062 |
|
2027 | 2063 |
for (int i = 1; i < info_array_size; i++) { |
2028 | 2064 |
lineType = getLineToType(info_array, i); |
2029 | 2065 |
|
2030 | 2066 |
// ----------------------- |
2031 |
if (end_ind[i] == (start_ind[i] - 1)) |
|
2067 |
if (end_ind[i] == (start_ind[i] - 1)) |
|
2068 |
// ((i>0) && (start_ind[i] == (start_ind[i-1]))) |
|
2069 |
//first(?) |
|
2032 | 2070 |
lineType = PathIterator.SEG_MOVETO; |
2033 | 2071 |
// ----------------------- |
2034 | 2072 |
|
2035 | 2073 |
next_must_do_first = addOrdsToGPX(resp, start_ind[i] - 1, |
2036 | 2074 |
end_ind[i] - 1, ords_array, dims, lineType, |
2037 |
(i == 1) || (lineType == PathIterator.SEG_MOVETO), |
|
2075 |
(i == 1) || (lineType == PathIterator.SEG_MOVETO) |
|
2076 |
|| firstInSubgroup(start_ind, i), |
|
2038 | 2077 |
next_must_do_first); |
2039 | 2078 |
} |
2040 | 2079 |
} else { |
2041 |
|
|
2042 | 2080 |
// standard case, do the moveto always |
2043 | 2081 |
for (int i = 0; i < info_array_size; i++) { |
2044 | 2082 |
lineType = getLineToType(info_array, i); |
... | ... | |
2054 | 2092 |
return resp; |
2055 | 2093 |
} |
2056 | 2094 |
|
2057 |
private static int getLineToType(Datum[] infos, int i) { |
|
2095 |
private static int getPos(double[] da, double x, double y, int _d) { |
|
2096 |
int len = da.length / _d; |
|
2097 |
for (int i=0; i<len; i=i+_d) { |
|
2098 |
if (veryClose(da[i*_d],da[i*_d+1],x,y,1)) { |
|
2099 |
return i; |
|
2100 |
} |
|
2101 |
} |
|
2102 |
return -1; |
|
2103 |
} |
|
2104 |
|
|
2105 |
private static boolean veryClose( |
|
2106 |
double x1, double y1, |
|
2107 |
double x2, double y2, |
|
2108 |
double tol) { |
|
2109 |
double d = (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1); |
|
2110 |
return d < (tol*tol); |
|
2111 |
} |
|
2112 |
|
|
2113 |
private static boolean firstInSubgroup(int[] s_i, int i) { |
|
2114 |
return (i>0) && (s_i[i] == s_i[i-1]); |
|
2115 |
} |
|
2116 |
|
|
2117 |
private static int getLineToType(Datum[] infos, int i) { |
|
2058 | 2118 |
int resp = PathIterator.SEG_LINETO; |
2059 | 2119 |
|
2120 |
|
|
2060 | 2121 |
try { |
2061 |
if (((NUMBER) infos[(3 * i) + 2]).intValue() == 2) { |
|
2122 |
if ( |
|
2123 |
(((NUMBER) infos[(3 * i) + 2]).intValue() == 2) |
|
2124 |
&& |
|
2125 |
(((NUMBER) infos[(3 * i) + 1]).intValue() == 2) |
|
2126 |
) { |
|
2062 | 2127 |
resp = PathIterator.SEG_QUADTO; |
2128 |
} else { |
|
2129 |
if ( |
|
2130 |
(((NUMBER) infos[(3 * i) + 1]).intValue() == 1003) |
|
2131 |
|| |
|
2132 |
(((NUMBER) infos[(3 * i) + 1]).intValue() == 2003) |
|
2133 |
|| |
|
2134 |
(((NUMBER) infos[(3 * i) + 1]).intValue() == 1005) |
|
2135 |
|| |
|
2136 |
(((NUMBER) infos[(3 * i) + 1]).intValue() == 2005) |
|
2137 |
) { |
|
2138 |
resp = PathIterator.SEG_MOVETO; |
|
2139 |
} |
|
2063 | 2140 |
} |
2064 |
} |
|
2065 |
catch (SQLException e) { |
|
2141 |
} catch (SQLException e) { |
|
2066 | 2142 |
logger.error("While getting line-to type: " + e.getMessage() + |
2067 | 2143 |
" (returned SEG_LINETO)"); |
2068 | 2144 |
} |
... | ... | |
2402 | 2478 |
} catch (Exception ex) { |
2403 | 2479 |
logger.error("While reprojecting: " + ex.getMessage()); |
2404 | 2480 |
return fromStruct; |
2405 |
} |
|
2481 |
}
|
|
2406 | 2482 |
|
2407 | 2483 |
if (resp == null) { |
2408 | 2484 |
return fromStruct; |
... | ... | |
2638 | 2714 |
if (gpx.isLinearized()) { |
2639 | 2715 |
int count = countCoords(gpx); |
2640 | 2716 |
z = new double[count]; |
2641 |
logger.warn("Linearized a 3D GPX, z[i] = 0"); |
|
2717 |
// logger.warn("Linearized a 3D GPX, z[i] = 0");
|
|
2642 | 2718 |
} else { |
2643 | 2719 |
z = getIndBigDecimalModule(ords, 2, dim); |
2644 | 2720 |
} |
... | ... | |
2856 | 2932 |
|
2857 | 2933 |
int _first = info[1] % 1000; |
2858 | 2934 |
int second = info[4] % 1000; |
2859 |
int item = 0; |
|
2935 |
int _item = 0; |
|
2936 |
int _item_mod = 0; |
|
2860 | 2937 |
|
2938 |
|
|
2861 | 2939 |
for (int i = 2; i < size; i++) { |
2862 |
item = info[(i * 3) + 1] % 1000; |
|
2863 |
if ((item != second) && |
|
2864 |
( ! ((item == 5) && (second == 2)) ) && |
|
2865 |
( ! ((item == 2) && (second == 5)) ) |
|
2940 |
_item = info[(i * 3) + 1]; |
|
2941 |
_item_mod = _item % 1000; |
|
2942 |
if ((_item_mod != second) && |
|
2943 |
( ! ((_item == 2003) && (second == 2)) ) && |
|
2944 |
( ! ((_item_mod == 5) && (second == 2)) ) && |
|
2945 |
( ! ((_item_mod == 2) && (second == 5)) ) |
|
2866 | 2946 |
) { |
2867 | 2947 |
return COLLECTION_VALUE_YES_COLLECTION; |
2868 | 2948 |
} |
Also available in: Unified diff