Revision 3050 trunk/extensions/extGeoProcessing/src/com/iver/gvsig/geoprocessing/gui/GeoProcessingPanel.java
GeoProcessingPanel.java | ||
---|---|---|
102 | 102 |
import com.vividsolutions.jts.geom.MultiPoint; |
103 | 103 |
import com.vividsolutions.jts.geom.Point; |
104 | 104 |
import com.vividsolutions.jts.geom.Polygon; |
105 |
import com.vividsolutions.jts.geom.PrecisionModel; |
|
105 | 106 |
import com.vividsolutions.jts.operation.distance.DistanceOp; |
106 | 107 |
|
107 | 108 |
import java.awt.Component; |
... | ... | |
1356 | 1357 |
} |
1357 | 1358 |
} |
1358 | 1359 |
} |
1359 |
// Rellenamos geometriesUned2 con estas intersecciones. |
|
1360 |
Vector geometriesUned2 = new Vector(); |
|
1361 |
for (int i=0;i<geometriesUned.size();i++) { |
|
1362 |
geometriesUned2.add(geometriesUned.get(i)); |
|
1363 |
} |
|
1364 | 1360 |
// A?ado a geometriesUned2 las geometr?as de geometriesToUnion que no |
1365 | 1361 |
// intersectan con uningGeometries. |
1366 |
for (int i=0;i<geometriesToUnion.length;i++) { |
|
1362 |
/*for (int i=0;i<geometriesToUnion.length;i++) {
|
|
1367 | 1363 |
Geometry geometryToUnion = geometriesToUnion[i]; |
1368 | 1364 |
boolean intersectsWithAnyGeometry = false; |
1369 | 1365 |
for (int j=0;j<uningGeometries.length;j++) { |
... | ... | |
1410 | 1406 |
uningRow[unedLyrFieldNames.length] = ValueFactory.createValue(i); |
1411 | 1407 |
values.add(uningRow); |
1412 | 1408 |
} |
1409 |
}*/ |
|
1410 |
Vector geometriesToUnionAux = new Vector(); |
|
1411 |
for (int i=0;i<geometriesToUnion.length;i++) { |
|
1412 |
geometriesToUnionAux.add(geometriesToUnion[i]); |
|
1413 | 1413 |
} |
1414 |
Vector uningGeometriesAux = new Vector(); |
|
1415 |
for (int i=0;i<uningGeometries.length;i++) { |
|
1416 |
uningGeometriesAux.add(uningGeometries[i]); |
|
1417 |
} |
|
1418 |
// Al restar una geometr?a consigo misma se producen GeometryCollections que |
|
1419 |
// en realidad son un s?ntoma de los errores de redondeo. Ver que hacemos |
|
1420 |
// con esto ... |
|
1421 |
for (int i=0;i<geometriesToUnionAux.size();i++) { |
|
1422 |
for (int j=0;j<geometriesUned.size();j++) { |
|
1423 |
if (((Geometry)geometriesToUnionAux.get(i)).equals((Geometry)geometriesUned.get(j))) { |
|
1424 |
//geometriesToUnionAux.remove(i); |
|
1425 |
//i--; |
|
1426 |
} else { |
|
1427 |
// Para evitar el error topol?gico del agujero en el borde y a |
|
1428 |
// la vez no cagarla en el resto de casos ... |
|
1429 |
GeometryFactory gf = new GeometryFactory(new PrecisionModel()); |
|
1430 |
LineString toUnionShell = gf.createLineString(((Geometry)geometriesToUnionAux.get(i)).getCoordinates()); |
|
1431 |
LineString unedShell = gf.createLineString(((Geometry)geometriesUned.get(j)).getCoordinates()); |
|
1432 |
//if (((Geometry)geometriesToUnionAux.get(i)).crosses(((Geometry)geometriesUned.get(j)))) { |
|
1433 |
if (toUnionShell.crosses(unedShell)) { |
|
1434 |
Geometry difPol = null; |
|
1435 |
for (int k=0;k<uningGeometriesAux.size();k++) { |
|
1436 |
if (((Geometry)uningGeometriesAux.get(k)).intersects(((Geometry)geometriesUned.get(j)))) { |
|
1437 |
difPol = ((Geometry)uningGeometriesAux.get(k)); |
|
1438 |
break; |
|
1439 |
} |
|
1440 |
} |
|
1441 |
geometriesToUnionAux.set(i,((Geometry)geometriesToUnionAux.get(i)).difference(difPol)); |
|
1442 |
} else { |
|
1443 |
geometriesToUnionAux.set(i,((Geometry)geometriesToUnionAux.get(i)).difference((Geometry)geometriesUned.get(j))); |
|
1444 |
} |
|
1445 |
} |
|
1446 |
} |
|
1447 |
} |
|
1448 |
for (int i=0;i<uningGeometriesAux.size();i++) { |
|
1449 |
for (int j=0;j<geometriesUned.size();j++) { |
|
1450 |
if (((Geometry)uningGeometriesAux.get(i)).equals((Geometry)geometriesUned.get(j))) { |
|
1451 |
//uningGeometriesAux.remove(i); |
|
1452 |
//i--; |
|
1453 |
} else { |
|
1454 |
GeometryFactory gf = new GeometryFactory(new PrecisionModel()); |
|
1455 |
LineString uningShell = gf.createLineString(((Geometry)uningGeometriesAux.get(i)).getCoordinates()); |
|
1456 |
LineString unedShell = gf.createLineString(((Geometry)geometriesUned.get(j)).getCoordinates()); |
|
1457 |
//if (((Geometry)uningGeometriesAux.get(i)).crosses(((Geometry)geometriesUned.get(j)))) { |
|
1458 |
if (uningShell.crosses(unedShell)) { |
|
1459 |
Geometry difPol = null; |
|
1460 |
for (int k=0;k<geometriesToUnionAux.size();k++) { |
|
1461 |
if (((Geometry)geometriesToUnionAux.get(k)).intersects(((Geometry)geometriesUned.get(j)))) { |
|
1462 |
difPol = ((Geometry)geometriesToUnionAux.get(k)); |
|
1463 |
break; |
|
1464 |
} |
|
1465 |
} |
|
1466 |
uningGeometriesAux.set(i,((Geometry)uningGeometriesAux.get(i)).difference(difPol)); |
|
1467 |
} else { |
|
1468 |
uningGeometriesAux.set(i,((Geometry)uningGeometriesAux.get(i)).difference((Geometry)geometriesUned.get(j))); |
|
1469 |
} |
|
1470 |
} |
|
1471 |
} |
|
1472 |
} |
|
1473 |
// Rellenamos geometriesUned2 con estas intersecciones. |
|
1474 |
Vector geometriesUned2 = new Vector(); |
|
1475 |
for (int i=0;i<geometriesUned.size();i++) { |
|
1476 |
geometriesUned2.add(geometriesUned.get(i)); |
|
1477 |
} |
|
1478 |
// A?ado a geometriesUned2 las geometr?as de geometriesToUnion menos las |
|
1479 |
// intersecciones. |
|
1480 |
for (int i=0;i<geometriesToUnionAux.size();i++) { |
|
1481 |
geometriesUned2.add(geometriesToUnionAux.get(i)); |
|
1482 |
Value[] unionRow = new Value[unedLyrFieldNames.length+1]; |
|
1483 |
for (int k=0;k<lyrToUnionFieldNames.length-1;k++) { |
|
1484 |
unionRow[k] = lyrToUnionDS.getFieldValue(i, k); |
|
1485 |
} |
|
1486 |
for (int k=0;k<uningLyrFieldNames.length-1;k++) { |
|
1487 |
unionRow[k+l] = ValueFactory.createNullValue(); |
|
1488 |
} |
|
1489 |
unionRow[unedLyrFieldNames.length] = ValueFactory.createValue(i); |
|
1490 |
values.add(unionRow); |
|
1491 |
} |
|
1492 |
for (int i=0;i<uningGeometriesAux.size();i++) { |
|
1493 |
geometriesUned2.add(uningGeometriesAux.get(i)); |
|
1494 |
Value[] uningRow = new Value[unedLyrFieldNames.length+1]; |
|
1495 |
for (int k=0;k<lyrToUnionFieldNames.length-1;k++) { |
|
1496 |
uningRow[k] = ValueFactory.createNullValue(); |
|
1497 |
} |
|
1498 |
for (int k=0;k<uningLyrFieldNames.length-1;k++) { |
|
1499 |
uningRow[k+l] = uningLyrDS.getFieldValue(i, k); |
|
1500 |
} |
|
1501 |
uningRow[unedLyrFieldNames.length] = ValueFactory.createValue(i); |
|
1502 |
values.add(uningRow); |
|
1503 |
} |
|
1504 |
// Quito las repetidas que se forman cuando son la misma. C?digo sacado del |
|
1505 |
// clip. |
|
1506 |
for (int i=0;i<geometriesUned2.size();i++) { |
|
1507 |
for (int j=0;j<geometriesUned2.size();j++) { |
|
1508 |
if (j>i) { |
|
1509 |
if (((Geometry)geometriesUned2.get(i)).equals((Geometry)geometriesUned2.get(j))) { |
|
1510 |
geometriesUned2.remove(j); |
|
1511 |
values.remove(j); |
|
1512 |
j--; |
|
1513 |
} |
|
1514 |
} |
|
1515 |
} |
|
1516 |
} |
|
1414 | 1517 |
// Le quito los cachos que ya tengo a las geometrias que faltan de |
1415 | 1518 |
// geometriesToUnion. |
1416 |
BitSet bitSet1 = new BitSet(); |
|
1417 |
bitSet1.clear(); |
|
1519 |
//BitSet bitSet1 = new BitSet();
|
|
1520 |
//bitSet1.clear();
|
|
1418 | 1521 |
/*for (int i=0;i<geometriesUned.size();i++) { |
1419 | 1522 |
Geometry geometryUned = (Geometry)geometriesUned.get(i); |
1420 | 1523 |
for (int j=0;j<geometriesToUnion.length;j++) { |
... | ... | |
1424 | 1527 |
} |
1425 | 1528 |
} |
1426 | 1529 |
}*/ |
1427 |
Geometry[] geometriesToUnionAux = new Geometry[geometriesToUnion.length]; |
|
1428 |
for (int i=0;i<geometriesToUnion.length;i++) { |
|
1429 |
geometriesToUnionAux[i] = geometriesToUnion[i]; |
|
1430 |
} |
|
1431 |
Geometry[] uningGeometriesAux = new Geometry[uningGeometries.length]; |
|
1432 |
for (int i=0;i<uningGeometries.length;i++) { |
|
1433 |
uningGeometriesAux[i] = uningGeometries[i]; |
|
1434 |
} |
|
1435 |
for (int i=0;i<geometriesToUnion.length;i++) { |
|
1530 |
/*for (int i=0;i<geometriesToUnion.length;i++) { |
|
1436 | 1531 |
//Geometry geometryToUnion = geometriesToUnion[i]; |
1437 | 1532 |
for (int j=0;j<uningGeometries.length;j++) { |
1438 | 1533 |
// el equals da problemas porque el intersect crea una geometr?a ligeramente distinta |
... | ... | |
1447 | 1542 |
} |
1448 | 1543 |
} |
1449 | 1544 |
geometriesToUnion[i] = geometriesToUnion[i].difference(difPol);*/ |
1450 |
geometriesToUnion[i] = geometriesToUnion[i].difference(uningGeometries[j]); |
|
1545 |
/*geometriesToUnion[i] = geometriesToUnion[i].difference(uningGeometries[j]);
|
|
1451 | 1546 |
bitSet1.set(i); |
1452 | 1547 |
} else { |
1453 | 1548 |
//bitSet1.set(i, false); |
1454 | 1549 |
} |
1455 | 1550 |
} |
1456 |
} |
|
1551 |
}*/
|
|
1457 | 1552 |
/*for (int i=0;i<geometriesUned.size();i++) { |
1458 | 1553 |
Geometry geometryUned = (Geometry)geometriesUned.get(i); |
1459 | 1554 |
for (int j=0;j<geometriesToUnion.length;j++) { |
... | ... | |
1475 | 1570 |
}*/ |
1476 | 1571 |
// Le quito los cachos que ya tengo a las geometrias que faltan de |
1477 | 1572 |
// uningGeometries. |
1478 |
BitSet bitSet2 = new BitSet(); |
|
1479 |
bitSet2.clear(); |
|
1573 |
//BitSet bitSet2 = new BitSet();
|
|
1574 |
//bitSet2.clear();
|
|
1480 | 1575 |
/*for (int i=0;i<geometriesUned.size();i++) { |
1481 | 1576 |
Geometry geometryUned = (Geometry)geometriesUned.get(i); |
1482 | 1577 |
for (int j=0;j<uningGeometries.length;j++) { |
... | ... | |
1486 | 1581 |
} |
1487 | 1582 |
} |
1488 | 1583 |
}*/ |
1489 |
for (int i=0;i<uningGeometries.length;i++) { |
|
1584 |
/*for (int i=0;i<uningGeometries.length;i++) {
|
|
1490 | 1585 |
//Geometry uningGeometry = uningGeometries[i]; |
1491 | 1586 |
for (int j=0;j<geometriesToUnionAux.length;j++) { |
1492 | 1587 |
if ((uningGeometries[i].intersects(geometriesToUnionAux[j]) && !(uningGeometries[i]).equals((uningGeometries[i].intersection(geometriesToUnionAux[j]))))) { |
... | ... | |
1500 | 1595 |
} |
1501 | 1596 |
} |
1502 | 1597 |
uningGeometries[i] = uningGeometries[i].difference(difPol);*/ |
1503 |
uningGeometries[i] = uningGeometries[i].difference(geometriesToUnionAux[j]); |
|
1598 |
/*uningGeometries[i] = uningGeometries[i].difference(geometriesToUnionAux[j]);
|
|
1504 | 1599 |
bitSet2.set(i); |
1505 | 1600 |
} else { |
1506 | 1601 |
//bitSet2.set(i, false); |
1507 | 1602 |
} |
1508 | 1603 |
} |
1509 |
} |
|
1604 |
}*/
|
|
1510 | 1605 |
/*for (int i=0;i<geometriesUned.size();i++) { |
1511 | 1606 |
Geometry geometryUned = (Geometry)geometriesUned.get(i); |
1512 | 1607 |
for (int j=0;j<uningGeometries.length;j++) { |
... | ... | |
1528 | 1623 |
}*/ |
1529 | 1624 |
// Ahora que les he quitado los cachos que ya ten?a, le meto los features que |
1530 | 1625 |
// faltaban de geometriesToUnion |
1531 |
for (int i=0;i<geometriesToUnion.length;i++) { |
|
1626 |
/*for (int i=0;i<geometriesToUnion.length;i++) {
|
|
1532 | 1627 |
if (bitSet1.get(i)) { |
1533 | 1628 |
geometriesUned2.add(geometriesToUnion[i]); |
1534 | 1629 |
Value[] unionRow = new Value[unedLyrFieldNames.length+1]; |
... | ... | |
1557 | 1652 |
uningRow[unedLyrFieldNames.length] = ValueFactory.createValue(i); |
1558 | 1653 |
values.add(uningRow); |
1559 | 1654 |
} |
1560 |
} |
|
1655 |
}*/
|
|
1561 | 1656 |
//selectable.setSelection(fBitSet); |
1562 | 1657 |
result = new Geometry[geometriesUned2.size()]; |
1563 | 1658 |
for (int i=0;i<geometriesUned2.size();i++) { |
Also available in: Unified diff