Revision 3055
trunk/extensions/extGeoProcessing/src/com/iver/gvsig/geoprocessing/gui/GeoProcessingPanel.java | ||
---|---|---|
1357 | 1357 |
} |
1358 | 1358 |
} |
1359 | 1359 |
} |
1360 |
// A?ado a geometriesUned2 las geometr?as de geometriesToUnion que no |
|
1361 |
// intersectan con uningGeometries. |
|
1362 |
/*for (int i=0;i<geometriesToUnion.length;i++) { |
|
1363 |
Geometry geometryToUnion = geometriesToUnion[i]; |
|
1364 |
boolean intersectsWithAnyGeometry = false; |
|
1365 |
for (int j=0;j<uningGeometries.length;j++) { |
|
1366 |
Geometry uningGeometry = uningGeometries[j]; |
|
1367 |
if (geometryToUnion.intersects(uningGeometry)) intersectsWithAnyGeometry = true; |
|
1368 |
} |
|
1369 |
if (intersectsWithAnyGeometry) { |
|
1370 |
//Geometry difference = geometryToUnion.difference(geometryUned); |
|
1371 |
//geometriesUned2.add(difference); |
|
1372 |
} else { |
|
1373 |
geometriesUned2.add(geometryToUnion); |
|
1374 |
Value[] unionRow = new Value[unedLyrFieldNames.length+1]; |
|
1375 |
for (int k=0;k<lyrToUnionFieldNames.length-1;k++) { |
|
1376 |
unionRow[k] = lyrToUnionDS.getFieldValue(i, k); |
|
1377 |
} |
|
1378 |
for (int k=0;k<uningLyrFieldNames.length-1;k++) { |
|
1379 |
unionRow[k+l] = ValueFactory.createNullValue(); |
|
1380 |
} |
|
1381 |
unionRow[unedLyrFieldNames.length] = ValueFactory.createValue(i); |
|
1382 |
values.add(unionRow); |
|
1383 |
} |
|
1360 |
// Me creo un pol?gono con todos los pol?gonos intersecci?n y que usar? para |
|
1361 |
// recortar ... |
|
1362 |
Geometry cutPol = (Geometry)geometriesUned.get(0); |
|
1363 |
for (int i=1;i<geometriesUned.size();i++) { |
|
1364 |
cutPol = cutPol.union((Geometry)geometriesUned.get(i)); |
|
1384 | 1365 |
} |
1385 |
// A?ado a geometriesUned2 las geometr?as de uningGeometries que no |
|
1386 |
// intersectan con geometriesToUnion. |
|
1387 |
for (int i=0;i<uningGeometries.length;i++) { |
|
1388 |
Geometry uningGeometry = uningGeometries[i]; |
|
1389 |
boolean intersectsWithAnyGeometry = false; |
|
1390 |
for (int j=0;j<geometriesToUnion.length;j++) { |
|
1391 |
Geometry geometryToUnion = geometriesToUnion[j]; |
|
1392 |
if (uningGeometry.intersects(geometryToUnion)) intersectsWithAnyGeometry = true; |
|
1393 |
} |
|
1394 |
if (intersectsWithAnyGeometry) { |
|
1395 |
//Geometry difference = jtsUningGeometry.difference(jtsGeometryUned); |
|
1396 |
//jtsGeometriesUned2.add(difference); |
|
1397 |
} else { |
|
1398 |
geometriesUned2.add(uningGeometry); |
|
1399 |
Value[] uningRow = new Value[unedLyrFieldNames.length+1]; |
|
1400 |
for (int k=0;k<lyrToUnionFieldNames.length-1;k++) { |
|
1401 |
uningRow[k] = ValueFactory.createNullValue(); |
|
1402 |
} |
|
1403 |
for (int k=0;k<uningLyrFieldNames.length-1;k++) { |
|
1404 |
uningRow[k+l] = uningLyrDS.getFieldValue(i, k); |
|
1405 |
} |
|
1406 |
uningRow[unedLyrFieldNames.length] = ValueFactory.createValue(i); |
|
1407 |
values.add(uningRow); |
|
1408 |
} |
|
1409 |
}*/ |
|
1366 |
GeometryFactory gf = new GeometryFactory(new PrecisionModel(100000)); |
|
1367 |
Geometry cutPolAux = gf.createGeometry(cutPol); |
|
1368 |
//Geometry cutPolAux = cutPol.buffer(0); |
|
1369 |
// Cambio a vector para tener m?s juego ... |
|
1410 | 1370 |
Vector geometriesToUnionAux = new Vector(); |
1411 | 1371 |
for (int i=0;i<geometriesToUnion.length;i++) { |
1412 | 1372 |
geometriesToUnionAux.add(geometriesToUnion[i]); |
... | ... | |
1419 | 1379 |
// en realidad son un s?ntoma de los errores de redondeo. Ver que hacemos |
1420 | 1380 |
// con esto ... |
1421 | 1381 |
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 |
} else { |
|
1425 |
geometriesToUnionAux.set(i,((Geometry)geometriesToUnionAux.get(i)).difference((Geometry)geometriesUned.get(j))); |
|
1426 |
} |
|
1427 |
} |
|
1382 |
Geometry aux = gf.createGeometry((Geometry)geometriesToUnionAux.get(i)); |
|
1383 |
geometriesToUnionAux.set(i,(aux).difference(cutPolAux)); |
|
1428 | 1384 |
} |
1429 | 1385 |
for (int i=0;i<uningGeometriesAux.size();i++) { |
1430 |
for (int j=0;j<geometriesUned.size();j++) { |
|
1431 |
if (((Geometry)uningGeometriesAux.get(i)).equals((Geometry)geometriesUned.get(j))) { |
|
1432 |
} else { |
|
1433 |
uningGeometriesAux.set(i,((Geometry)uningGeometriesAux.get(i)).difference((Geometry)geometriesUned.get(j))); |
|
1434 |
} |
|
1435 |
} |
|
1386 |
Geometry aux = gf.createGeometry((Geometry)uningGeometriesAux.get(i)); |
|
1387 |
uningGeometriesAux.set(i,(aux).difference(cutPolAux)); |
|
1436 | 1388 |
} |
1437 |
// Rellenamos geometriesUned2 con estas intersecciones.
|
|
1389 |
// Rellenamos geometriesUned2 con las intersecciones.
|
|
1438 | 1390 |
Vector geometriesUned2 = new Vector(); |
1439 | 1391 |
for (int i=0;i<geometriesUned.size();i++) { |
1440 | 1392 |
geometriesUned2.add(geometriesUned.get(i)); |
... | ... | |
1478 | 1430 |
} |
1479 | 1431 |
} |
1480 | 1432 |
} |
1481 |
// Le quito los cachos que ya tengo a las geometrias que faltan de |
|
1482 |
// geometriesToUnion. |
|
1483 |
//BitSet bitSet1 = new BitSet(); |
|
1484 |
//bitSet1.clear(); |
|
1485 |
/*for (int i=0;i<geometriesUned.size();i++) { |
|
1486 |
Geometry geometryUned = (Geometry)geometriesUned.get(i); |
|
1487 |
for (int j=0;j<geometriesToUnion.length;j++) { |
|
1488 |
if (geometriesToUnion[j].intersects(geometryUned) && !geometriesToUnion[j].equals(geometryUned)) { |
|
1489 |
geometriesToUnion[j] = geometriesToUnion[j].difference(geometryUned); |
|
1490 |
bitSet1.set(j); |
|
1491 |
} |
|
1492 |
} |
|
1493 |
}*/ |
|
1494 |
/*for (int i=0;i<geometriesToUnion.length;i++) { |
|
1495 |
//Geometry geometryToUnion = geometriesToUnion[i]; |
|
1496 |
for (int j=0;j<uningGeometries.length;j++) { |
|
1497 |
// el equals da problemas porque el intersect crea una geometr?a ligeramente distinta |
|
1498 |
if (geometriesToUnion[i].intersects(uningGeometries[j]) && !(geometriesToUnion[i].equals((geometriesToUnion[i].intersection(uningGeometries[j]))))) { |
|
1499 |
// Buscar el cacho grande para utilizarlo en la resta y evitar el pol?gono con un |
|
1500 |
// agujero en el borde |
|
1501 |
/*Geometry difPol = null; |
|
1502 |
for (int k=0;k<uningGeometries.length;k++) { |
|
1503 |
if (uningGeometries[k].intersects(((Geometry)geometriesUned.get(j)))) { |
|
1504 |
difPol = uningGeometries[k]; |
|
1505 |
break; |
|
1506 |
} |
|
1507 |
} |
|
1508 |
geometriesToUnion[i] = geometriesToUnion[i].difference(difPol);*/ |
|
1509 |
/*geometriesToUnion[i] = geometriesToUnion[i].difference(uningGeometries[j]); |
|
1510 |
bitSet1.set(i); |
|
1511 |
} else { |
|
1512 |
//bitSet1.set(i, false); |
|
1513 |
} |
|
1514 |
} |
|
1515 |
}*/ |
|
1516 |
/*for (int i=0;i<geometriesUned.size();i++) { |
|
1517 |
Geometry geometryUned = (Geometry)geometriesUned.get(i); |
|
1518 |
for (int j=0;j<geometriesToUnion.length;j++) { |
|
1519 |
if (geometriesToUnion[j].intersects(geometryUned) && !geometriesToUnion[j].equals(geometryUned)) { |
|
1520 |
Geometry difPol = null; |
|
1521 |
for (int k=0;k<uningGeometries.length;k++) { |
|
1522 |
if (uningGeometries[k].intersects(geometryUned)) { |
|
1523 |
difPol = uningGeometries[k]; |
|
1524 |
break; |
|
1525 |
} |
|
1526 |
} |
|
1527 |
geometriesToUnion[j] = geometriesToUnion[j].difference(difPol); |
|
1528 |
geometriesToUnion[j] = geometriesToUnion[j].difference(geometryUned); |
|
1529 |
bitSet1.set(j); |
|
1530 |
} else { |
|
1531 |
//bitSet1.set(j, false); |
|
1532 |
} |
|
1533 |
} |
|
1534 |
}*/ |
|
1535 |
// Le quito los cachos que ya tengo a las geometrias que faltan de |
|
1536 |
// uningGeometries. |
|
1537 |
//BitSet bitSet2 = new BitSet(); |
|
1538 |
//bitSet2.clear(); |
|
1539 |
/*for (int i=0;i<geometriesUned.size();i++) { |
|
1540 |
Geometry geometryUned = (Geometry)geometriesUned.get(i); |
|
1541 |
for (int j=0;j<uningGeometries.length;j++) { |
|
1542 |
if (uningGeometries[j].intersects(geometryUned) && !uningGeometries[j].equals(geometryUned)) { |
|
1543 |
uningGeometries[j] = uningGeometries[j].difference(geometryUned); |
|
1544 |
bitSet2.set(j); |
|
1545 |
} |
|
1546 |
} |
|
1547 |
}*/ |
|
1548 |
/*for (int i=0;i<uningGeometries.length;i++) { |
|
1549 |
//Geometry uningGeometry = uningGeometries[i]; |
|
1550 |
for (int j=0;j<geometriesToUnionAux.length;j++) { |
|
1551 |
if ((uningGeometries[i].intersects(geometriesToUnionAux[j]) && !(uningGeometries[i]).equals((uningGeometries[i].intersection(geometriesToUnionAux[j]))))) { |
|
1552 |
// Buscar el cacho grande para utilizarlo en la resta y evitar el pol?gono con un |
|
1553 |
// agujero en el borde |
|
1554 |
/*Geometry difPol = null; |
|
1555 |
for (int k=0;k<geometriesToUnionAux.length;k++) { |
|
1556 |
if (geometriesToUnionAux[k].intersects(((Geometry)geometriesUned.get(j)))) { |
|
1557 |
difPol = geometriesToUnionAux[k]; |
|
1558 |
break; |
|
1559 |
} |
|
1560 |
} |
|
1561 |
uningGeometries[i] = uningGeometries[i].difference(difPol);*/ |
|
1562 |
/*uningGeometries[i] = uningGeometries[i].difference(geometriesToUnionAux[j]); |
|
1563 |
bitSet2.set(i); |
|
1564 |
} else { |
|
1565 |
//bitSet2.set(i, false); |
|
1566 |
} |
|
1567 |
} |
|
1568 |
}*/ |
|
1569 |
/*for (int i=0;i<geometriesUned.size();i++) { |
|
1570 |
Geometry geometryUned = (Geometry)geometriesUned.get(i); |
|
1571 |
for (int j=0;j<uningGeometries.length;j++) { |
|
1572 |
if (uningGeometries[j].intersects(geometryUned) && !uningGeometries[j].equals(geometryUned)) { |
|
1573 |
Geometry difPol = null; |
|
1574 |
for (int k=0;k<geometriesToUnionAux.length;k++) { |
|
1575 |
if (geometriesToUnionAux[k].intersects(geometryUned)) { |
|
1576 |
difPol = geometriesToUnionAux[k]; |
|
1577 |
break; |
|
1578 |
} |
|
1579 |
} |
|
1580 |
uningGeometries[j] = uningGeometries[j].difference(difPol); |
|
1581 |
uningGeometries[j] = uningGeometries[j].difference(geometryUned); |
|
1582 |
bitSet2.set(j); |
|
1583 |
} else { |
|
1584 |
bitSet2.set(j, false); |
|
1585 |
} |
|
1586 |
} |
|
1587 |
}*/ |
|
1588 |
// Ahora que les he quitado los cachos que ya ten?a, le meto los features que |
|
1589 |
// faltaban de geometriesToUnion |
|
1590 |
/*for (int i=0;i<geometriesToUnion.length;i++) { |
|
1591 |
if (bitSet1.get(i)) { |
|
1592 |
geometriesUned2.add(geometriesToUnion[i]); |
|
1593 |
Value[] unionRow = new Value[unedLyrFieldNames.length+1]; |
|
1594 |
for (int k=0;k<lyrToUnionFieldNames.length-1;k++) { |
|
1595 |
unionRow[k] = lyrToUnionDS.getFieldValue(i, k); |
|
1596 |
} |
|
1597 |
for (int k=0;k<uningLyrFieldNames.length-1;k++) { |
|
1598 |
unionRow[k+l] = ValueFactory.createNullValue(); |
|
1599 |
} |
|
1600 |
unionRow[unedLyrFieldNames.length] = ValueFactory.createValue(i); |
|
1601 |
values.add(unionRow); |
|
1602 |
} |
|
1603 |
} |
|
1604 |
// Ahora que les he quitado los cachos que ya ten?a, le meto los features que |
|
1605 |
// faltaban de uningGeometries |
|
1606 |
for (int i=0;i<uningGeometries.length;i++) { |
|
1607 |
if (bitSet2.get(i)) { |
|
1608 |
geometriesUned2.add(uningGeometries[i]); |
|
1609 |
Value[] uningRow = new Value[unedLyrFieldNames.length+1]; |
|
1610 |
for (int k=0;k<lyrToUnionFieldNames.length-1;k++) { |
|
1611 |
uningRow[k] = ValueFactory.createNullValue(); |
|
1612 |
} |
|
1613 |
for (int k=0;k<uningLyrFieldNames.length-1;k++) { |
|
1614 |
uningRow[k+l] = uningLyrDS.getFieldValue(i, k); |
|
1615 |
} |
|
1616 |
uningRow[unedLyrFieldNames.length] = ValueFactory.createValue(i); |
|
1617 |
values.add(uningRow); |
|
1618 |
} |
|
1619 |
}*/ |
|
1620 |
//selectable.setSelection(fBitSet); |
|
1621 | 1433 |
result = new Geometry[geometriesUned2.size()]; |
1622 | 1434 |
for (int i=0;i<geometriesUned2.size();i++) { |
1623 | 1435 |
result[i] = (Geometry)geometriesUned2.get(i); |
Also available in: Unified diff