94 |
94 |
import com.iver.gvsig.geoprocessing.operations.GeoProcessingTableOperations;
|
95 |
95 |
import com.iver.gvsig.geoprocessing.operations.GeoProcessingTopologyOperations;
|
96 |
96 |
import com.iver.gvsig.geoprocessing.operations.strategies.SelectedShapeToJTSVisitor;
|
|
97 |
import com.vividsolutions.jts.geom.Coordinate;
|
97 |
98 |
import com.vividsolutions.jts.geom.Geometry;
|
|
99 |
import com.vividsolutions.jts.geom.GeometryCollection;
|
|
100 |
import com.vividsolutions.jts.geom.GeometryFactory;
|
|
101 |
import com.vividsolutions.jts.geom.LineString;
|
|
102 |
import com.vividsolutions.jts.geom.MultiPoint;
|
|
103 |
import com.vividsolutions.jts.geom.Point;
|
|
104 |
import com.vividsolutions.jts.geom.Polygon;
|
|
105 |
import com.vividsolutions.jts.operation.distance.DistanceOp;
|
98 |
106 |
|
99 |
107 |
import java.awt.Component;
|
100 |
108 |
import java.awt.GridLayout;
|
... | ... | |
104 |
112 |
import java.awt.CardLayout;
|
105 |
113 |
import javax.swing.BoxLayout;
|
106 |
114 |
import java.awt.BorderLayout;
|
|
115 |
import java.io.File;
|
107 |
116 |
import java.sql.Types;
|
108 |
117 |
import java.util.BitSet;
|
109 |
118 |
import java.util.Vector;
|
... | ... | |
500 |
509 |
FShape[] shapes = new FShape[jtsGeometries.length];
|
501 |
510 |
IGeometry[] geoms = new IGeometry[jtsGeometries.length];
|
502 |
511 |
for (int i=0;i<jtsGeometries.length;i++) {
|
503 |
|
shapes[i] = FConverter.jts_to_java2d(jtsGeometries[i]);
|
504 |
|
geoms[i] = ShapeFactory.createGeometry(shapes[i]);
|
|
512 |
if (jtsGeometries[i] instanceof MultiPoint) {
|
|
513 |
double[] xcoords = new double[jtsGeometries[i].getNumGeometries()];
|
|
514 |
double[] ycoords = new double[jtsGeometries[i].getNumGeometries()];
|
|
515 |
for (int j=0;j<jtsGeometries[i].getNumGeometries();j++) {
|
|
516 |
xcoords[j] = ((Point)jtsGeometries[i].getGeometryN(j)).getX();
|
|
517 |
ycoords[j] = ((Point)jtsGeometries[i].getGeometryN(j)).getY();
|
|
518 |
}
|
|
519 |
geoms[i] = ShapeFactory.createMultipoint2D(xcoords, ycoords);
|
|
520 |
} else {
|
|
521 |
shapes[i] = FConverter.jts_to_java2d(jtsGeometries[i]);
|
|
522 |
geoms[i] = ShapeFactory.createGeometry(shapes[i]);
|
|
523 |
}
|
505 |
524 |
}
|
506 |
525 |
return geoms;
|
507 |
526 |
}
|
508 |
527 |
private void bufferMethod() {
|
509 |
528 |
String bufferingLayerName = (String)((JComboBox)geoProcessingBufferPanel.getComponent(2)).getSelectedItem();
|
|
529 |
// TODO: Provisional. Hasta que Fernando le meta PKs al resto de ficheros.
|
|
530 |
//System.out.println("bufferingLayerName = " + bufferingLayerName);
|
|
531 |
boolean isDbfFile = false;
|
|
532 |
if (bufferingLayerName.endsWith(".shp") || bufferingLayerName.endsWith(".SHP")) isDbfFile = true;
|
510 |
533 |
FLayer bufferingLayer = layers.getLayer(bufferingLayerName);
|
511 |
534 |
boolean selected = false;
|
512 |
535 |
if (((JCheckBox)geoProcessingBufferPanel.getComponent(3)).isSelected()) selected = true;
|
... | ... | |
515 |
538 |
boolean dissolveBuffer = false;
|
516 |
539 |
// Realizo el buffer llamando al metodo makeBuffer de GeoProcessingTopologyOperations
|
517 |
540 |
if (((JRadioButton)geoProcessingBufferPanel.getComponent(4)).isSelected()) {
|
518 |
|
dissolveBuffer = true;
|
|
541 |
//dissolveBuffer = true;
|
519 |
542 |
double bufferDistance = Double.parseDouble(((JTextField)geoProcessingBufferPanel.getComponent(7)).getText());
|
520 |
543 |
if (((JCheckBox)geoProcessingBufferPanel.getComponent(13)).isSelected()) {
|
|
544 |
dissolveBuffer = true;
|
521 |
545 |
Geometry jtsBuffer = GeoProcessingTopologyOperations.makeDissolveBuffer(geometries, bufferDistance, getQuadrantSegments());
|
522 |
546 |
// Realizo las operaciones relacionadas con tablas que el buffer requiere llamando a los m?todos convenientes de GeoProcessingTableOperations
|
523 |
547 |
// (A lo mejor este paso no es necesario) Convierto las tablas modificadas y las nuevas entidades JTS al modelo de gvSIG
|
... | ... | |
547 |
571 |
// atributos.
|
548 |
572 |
}
|
549 |
573 |
} else if (((JRadioButton)geoProcessingBufferPanel.getComponent(5)).isSelected()) {
|
550 |
|
dissolveBuffer = false;
|
|
574 |
//dissolveBuffer = false;
|
551 |
575 |
double[] bufferDistances = getBufferDistancesFromTable(bufferingLayer);
|
552 |
576 |
if (((JCheckBox)geoProcessingBufferPanel.getComponent(13)).isSelected()) {
|
|
577 |
dissolveBuffer = true;
|
553 |
578 |
// Aqu? hay problemas ... Con distintas distancias y haciendo dissolve ...
|
554 |
579 |
Geometry jtsBuffer = GeoProcessingTopologyOperations.makeDissolveBuffer(geometries, bufferDistances, getQuadrantSegments());
|
555 |
580 |
// Realizo las operaciones relacionadas con tablas que el buffer requiere llamando a los m?todos convenientes de GeoProcessingTableOperations
|
... | ... | |
568 |
593 |
}
|
569 |
594 |
}
|
570 |
595 |
AlphanumericData lyr = (AlphanumericData)(layers.getLayer(geoProcessingBufferPanel.getSelectedLayerName()));
|
571 |
|
GeoProcessingPersistenceOperations.saveBufferResultsToShapeFile(shapes, geoProcessingBufferPanel.getOutputFile());
|
|
596 |
GeoProcessingPersistenceOperations.saveResultsToShapeFile(shapes, geoProcessingBufferPanel.getOutputFile());
|
572 |
597 |
try {
|
573 |
|
GeoProcessingTableOperations.saveBufferResultsToDbaseFile(geoProcessingBufferPanel.getOutputFile(), lyr, dissolveBuffer);
|
|
598 |
// TODO: Provisional. Hasta que Fernando le meta PKs al resto de ficheros.
|
|
599 |
GeoProcessingTableOperations.saveBufferResultsToDbaseFile(geoProcessingBufferPanel.getOutputFile(), lyr, dissolveBuffer, isDbfFile);
|
574 |
600 |
} catch (IncompatibleTypesException e) {
|
575 |
601 |
// TODO Auto-generated catch block
|
576 |
602 |
e.printStackTrace();
|
... | ... | |
592 |
618 |
private void mergeMethod() {
|
593 |
619 |
Object[] layerNamesToMerge = geoProcessingMergePanel.getLayerSelectedNames();
|
594 |
620 |
String fieldsFromLayerName = geoProcessingMergePanel.getFieldsFromLayerName();
|
|
621 |
// TODO: Provisional. Hasta que Fernando le meta PKs al resto de ficheros.
|
|
622 |
boolean isDbfFile = false;
|
|
623 |
if (fieldsFromLayerName.endsWith(".shp") || fieldsFromLayerName.endsWith(".SHP")) isDbfFile = true;
|
595 |
624 |
AlphanumericData lyr = (AlphanumericData)layers.getLayer(fieldsFromLayerName);
|
596 |
625 |
FLayer[] layersToMerge = new FLayer[layerNamesToMerge.length];
|
597 |
|
boolean selected = false;
|
|
626 |
boolean[] selecteds = new boolean[layersToMerge.length];
|
598 |
627 |
Vector allGeometriesToMerge = new Vector();
|
599 |
628 |
for (int i=0;i<layerNamesToMerge.length;i++) {
|
600 |
629 |
layersToMerge[i] = layers.getLayer((String)layerNamesToMerge[i]);
|
601 |
|
//if (!((Selectable)layersToMerge[i]).getSelection().isEmpty()) selected = true;
|
602 |
|
Geometry[] geometriesToMerge = getJtsGeometries(layersToMerge[i], selected);
|
|
630 |
if (!((Selectable)layersToMerge[i]).getSelection().isEmpty()) selecteds[i] = true;
|
|
631 |
Geometry[] geometriesToMerge = getJtsGeometries(layersToMerge[i], selecteds[i]);
|
603 |
632 |
for (int j=0;j<geometriesToMerge.length;j++) {
|
604 |
633 |
allGeometriesToMerge.add(geometriesToMerge[j]);
|
605 |
634 |
}
|
... | ... | |
614 |
643 |
lyrs[i] = (AlphanumericData)layersToMerge[i];
|
615 |
644 |
}
|
616 |
645 |
// Pasarle tb la capa con los campos.
|
617 |
|
GeoProcessingPersistenceOperations.saveMergeResultsToShapeFile(shapes, geoProcessingMergePanel.getOutputFile());
|
|
646 |
GeoProcessingPersistenceOperations.saveResultsToShapeFile(shapes, geoProcessingMergePanel.getOutputFile());
|
618 |
647 |
try {
|
619 |
|
GeoProcessingTableOperations.saveMergeResultsToDbaseFile(geoProcessingMergePanel.getOutputFile(), lyrs, lyr);
|
|
648 |
GeoProcessingTableOperations.saveMergeResultsToDbaseFile(geoProcessingMergePanel.getOutputFile(), lyrs, lyr, isDbfFile);
|
|
649 |
for (int i=0;i<lyrs.length;i++) {
|
|
650 |
lyrs[i].getRecordset().getSelection().clear();
|
|
651 |
}
|
620 |
652 |
} catch (IncompatibleTypesException e) {
|
621 |
653 |
// TODO Auto-generated catch block
|
622 |
654 |
e.printStackTrace();
|
... | ... | |
638 |
670 |
String layerToDissolveName = (String)((JComboBox)geoProcessingDissolvePanel.getComponent(2)).getSelectedItem();
|
639 |
671 |
FLayer layerToDissolve = layers.getLayer(layerToDissolveName);
|
640 |
672 |
boolean selected = false;
|
641 |
|
//if (((JCheckBox)geoProcessingDissolvePanel.getComponent(3)).isSelected()) selected = true;
|
|
673 |
if (((JCheckBox)geoProcessingDissolvePanel.getComponent(3)).isSelected()) selected = true;
|
642 |
674 |
Geometry[] geometriesToDissolve = getJtsGeometries(layerToDissolve, selected);
|
643 |
675 |
String dissolveAttributeName = (String)((JComboBox)geoProcessingDissolvePanel.getComponent(5)).getSelectedItem();
|
644 |
676 |
AlphanumericData lyr = (AlphanumericData)layerToDissolve;
|
... | ... | |
648 |
680 |
// se queda aqu?.
|
649 |
681 |
Vector resultGeometries = new Vector();
|
650 |
682 |
DataSource ds;
|
|
683 |
SelectableDataSource sds;
|
651 |
684 |
try {
|
652 |
685 |
ds = lyr.getRecordset();
|
|
686 |
sds = lyr.getRecordset();
|
653 |
687 |
int fieldId = ds.getFieldIndexByName(dissolveAttributeName);
|
654 |
|
Value[] fieldValues = new Value[(int)ds.getRowCount()];
|
655 |
|
//int j = 0;
|
|
688 |
FBitSet fBitSet = sds.getSelection();
|
|
689 |
if (fBitSet.cardinality()==0) fBitSet.set(0, (int)lyr.getRecordset().getRowCount());
|
|
690 |
Value[] fieldValues = new Value[sds.getSelection().cardinality()];
|
|
691 |
int k=0;
|
656 |
692 |
for (int i=0;i<ds.getRowCount();i++) {
|
657 |
|
fieldValues[i] = ds.getFieldValue(i, fieldId);
|
|
693 |
if (fBitSet.get(i)) {
|
|
694 |
fieldValues[k] = ds.getFieldValue(i, fieldId);
|
|
695 |
k++;
|
|
696 |
}
|
658 |
697 |
}
|
659 |
698 |
for (int i=0;i<fieldValues.length;i++) {
|
660 |
699 |
Value valuei = fieldValues[i];
|
661 |
700 |
Geometry geometryi = geometriesToDissolve[i];
|
662 |
|
//Geometry jtsGeometryi = geometryi.toJTSGeometry();
|
663 |
|
for (int j=0;j<ds.getRowCount();j++) {
|
|
701 |
for (int j=0;j<fieldValues.length;j++) {
|
664 |
702 |
if (j!=i) {
|
665 |
|
Value valuej = ds.getFieldValue(j, fieldId);
|
666 |
|
//if (((BooleanValue)(valuej.equals(valuei))).getValue() && geometriesToDissolve[j].intersects(geometryi)) {
|
|
703 |
Value valuej = fieldValues[j];
|
667 |
704 |
if (((BooleanValue)(valuej.equals(valuei))).getValue()) {
|
668 |
705 |
Geometry geometryj = geometriesToDissolve[j];
|
669 |
|
//Geometry jtsGeometryj = geometryj.toJTSGeometry();
|
670 |
|
//if (jtsGeometryj.intersection(jtsGeometryi) instanceof LineString ||
|
671 |
|
// jtsGeometryj.intersection(jtsGeometryi) instanceof LinearRing) {
|
672 |
706 |
geometryi = geometryj.union(geometryi);
|
673 |
|
//FPolygon2D union = (FPolygon2D)FConverter.jts_to_java2d(jtsUnion);
|
674 |
|
//resultGeometries.add(ShapeFactory.createGeometry(union));
|
675 |
|
//}
|
676 |
707 |
}
|
677 |
708 |
}
|
678 |
709 |
}
|
679 |
|
/*boolean isDifferent = true;
|
680 |
|
// El ID lo incrementa el solo y nunca es igual y esto no sirve pa
|
681 |
|
// n? ... ver que pasa ...
|
682 |
|
for (int j=0;j<i;j++) {
|
683 |
|
if (fieldValues[i]==fieldValues[j]) {
|
684 |
|
isDifferent = false;
|
685 |
|
}
|
686 |
|
}
|
687 |
|
if (isDifferent) resultGeometries.add(geometryi);*/
|
688 |
710 |
resultGeometries.add(geometryi);
|
689 |
711 |
}
|
690 |
712 |
for (int i=0;i<resultGeometries.size();i++) {
|
691 |
713 |
for (int j=0;j<resultGeometries.size();j++) {
|
692 |
|
if (j!=i) {
|
693 |
|
if (((Geometry)resultGeometries.get(i)).equals((Geometry)resultGeometries.get(j))) resultGeometries.remove(j);
|
|
714 |
if (j>i) {
|
|
715 |
if (((Geometry)resultGeometries.get(i)).equals((Geometry)resultGeometries.get(j))) {
|
|
716 |
resultGeometries.remove(j);
|
|
717 |
j--;
|
|
718 |
}
|
694 |
719 |
}
|
695 |
720 |
}
|
696 |
721 |
}
|
... | ... | |
712 |
737 |
//Geometry[] dissolvedGeometries = GeoProcessingTopologyOperations.makeDissolve(geometriesToDissolve, lyr, dissolveAttributeName);
|
713 |
738 |
IGeometry[] shapes = getFmapGeometries(dissolvedGeometries);
|
714 |
739 |
// Guardo la tabla mediante gdbms. Guardo tambi?n las entidades JTS mediante gvSIG o usando solo gdbms (probablemente bastar? con usar gdbms)
|
715 |
|
GeoProcessingPersistenceOperations.saveDissolveResultsToShapeFile(shapes, geoProcessingDissolvePanel.getOutputFile());
|
716 |
|
/*try {
|
717 |
|
GeoProcessingTableOperations.saveMergeResultsToDbaseFile(geoProcessingMergePanel.getOutputFile(), lyrs, lyr);
|
|
740 |
GeoProcessingPersistenceOperations.saveResultsToShapeFile(shapes, geoProcessingDissolvePanel.getOutputFile());
|
|
741 |
try {
|
|
742 |
GeoProcessingTableOperations.saveDissolveResultsToDbaseFile(geoProcessingDissolvePanel.getOutputFile(), lyr, dissolveAttributeName);
|
|
743 |
lyr.getRecordset().getSelection().clear();
|
718 |
744 |
} catch (IncompatibleTypesException e) {
|
719 |
745 |
// TODO Auto-generated catch block
|
720 |
746 |
e.printStackTrace();
|
... | ... | |
730 |
756 |
} catch (NoSuchTableException e) {
|
731 |
757 |
// TODO Auto-generated catch block
|
732 |
758 |
e.printStackTrace();
|
733 |
|
}*/
|
|
759 |
}
|
734 |
760 |
}
|
|
761 |
private void spatialjoinMethod() {
|
|
762 |
String layerToJoinName = (String)((JComboBox)geoProcessingSpatialjoinPanel.getComponent(0)).getSelectedItem();
|
|
763 |
FLayer layerToJoin = layers.getLayer(layerToJoinName);
|
|
764 |
String joiningLayerName = (String)((JComboBox)geoProcessingSpatialjoinPanel.getComponent(3)).getSelectedItem();
|
|
765 |
FLayer joiningLayer = layers.getLayer(joiningLayerName);
|
|
766 |
boolean selected = false;
|
|
767 |
try {
|
|
768 |
if (((JCheckBox)geoProcessingSpatialjoinPanel.getComponent(1)).isSelected()) selected = true;
|
|
769 |
Geometry[] geometriesToJoin = getJtsGeometries(layerToJoin, selected);
|
|
770 |
AlphanumericData lyrToJoin = (AlphanumericData)layerToJoin;
|
|
771 |
SelectableDataSource lyrToJoinSDS = lyrToJoin.getRecordset();
|
|
772 |
FBitSet bitsetToJoin = lyrToJoinSDS.getSelection();
|
|
773 |
if (bitsetToJoin.cardinality()==0) bitsetToJoin.set(0, (int)lyrToJoin.getRecordset().getRowCount());
|
|
774 |
if (((JCheckBox)geoProcessingSpatialjoinPanel.getComponent(5)).isSelected()) selected = true;
|
|
775 |
Geometry[] joiningGeometries = getJtsGeometries(joiningLayer, selected);
|
|
776 |
AlphanumericData joiningLyr = (AlphanumericData)joiningLayer;
|
|
777 |
SelectableDataSource joiningLyrSDS = joiningLyr.getRecordset();
|
|
778 |
FBitSet joiningBitset = joiningLyrSDS.getSelection();
|
|
779 |
if (joiningBitset.cardinality()==0) joiningBitset.set(0, (int)joiningLyr.getRecordset().getRowCount());
|
|
780 |
DataSource lyrToJoinDS;
|
|
781 |
DataSource joiningLyrDS;
|
|
782 |
lyrToJoinDS = lyrToJoin.getRecordset();
|
|
783 |
joiningLyrDS = joiningLyr.getRecordset();
|
|
784 |
// Los campos se a?aden siempre. Los valores solo cuando toca ...
|
|
785 |
String[] lyrToJoinFieldNames = new String[lyrToJoinDS.getFieldCount()];
|
|
786 |
int[] lyrToJoinFieldTypes = new int[lyrToJoinDS.getFieldCount()];
|
|
787 |
for (int i = 0; i < lyrToJoinDS.getFieldCount(); i++) {
|
|
788 |
lyrToJoinFieldNames[i] = lyrToJoinDS.getFieldName(i);
|
|
789 |
lyrToJoinFieldTypes[i] = lyrToJoinDS.getFieldType(i);
|
|
790 |
}
|
|
791 |
String[] joiningLyrFieldNames = new String[joiningLyrDS.getFieldCount()];
|
|
792 |
int[] joiningLyrFieldTypes = new int[joiningLyrDS.getFieldCount()];
|
|
793 |
for (int i = 0; i < joiningLyrDS.getFieldCount(); i++) {
|
|
794 |
joiningLyrFieldNames[i] = joiningLyrDS.getFieldName(i);
|
|
795 |
joiningLyrFieldTypes[i] = joiningLyrDS.getFieldType(i);
|
|
796 |
}
|
|
797 |
String[] joinedLyrFieldNames = new String[lyrToJoinDS.getFieldCount()+joiningLyrDS.getFieldCount()-2]; // Le quito los dos PKs
|
|
798 |
int[] joinedLyrFieldTypes = new int[lyrToJoinDS.getFieldCount()+joiningLyrDS.getFieldCount()-2];
|
|
799 |
int l=0;
|
|
800 |
for (int i=0;i<lyrToJoinFieldNames.length-1;i++) {
|
|
801 |
joinedLyrFieldNames[i] = lyrToJoinFieldNames[i];
|
|
802 |
joinedLyrFieldTypes[i] = lyrToJoinFieldTypes[i];
|
|
803 |
l++;
|
|
804 |
}
|
|
805 |
for (int i=0;i<joiningLyrFieldNames.length-1;i++) {
|
|
806 |
joinedLyrFieldNames[i+l] = joiningLyrFieldNames[i];
|
|
807 |
joinedLyrFieldTypes[i+l] = joiningLyrFieldTypes[i];
|
|
808 |
}
|
|
809 |
DataSourceFactory dsf = lyrToJoinSDS.getDataSourceFactory();
|
|
810 |
File file = geoProcessingSpatialjoinPanel.getOutputFile();
|
|
811 |
dsf.createFileDataSource("gdbms dbf driver", "new_table", file.getAbsolutePath().replaceAll(".shp", ".dbf"), joinedLyrFieldNames, joinedLyrFieldTypes);
|
|
812 |
DataSource ds = dsf.createRandomDataSource("new_table");
|
|
813 |
ds.start();
|
|
814 |
DataWare dw = ds.getDataWare(DataSourceFactory.MANUAL_OPENING);
|
|
815 |
dw.beginTrans();
|
|
816 |
ds.stop();
|
|
817 |
lyrToJoinDS.stop();
|
|
818 |
joiningLyrDS.stop();
|
|
819 |
lyrToJoinSDS.stop();
|
|
820 |
joiningLyrSDS.stop();
|
|
821 |
|
|
822 |
// Recorrer las geometr?as buscando las que intersectan. No porque
|
|
823 |
// por ejemplo los puntos no intersectan ...
|
|
824 |
// Ver de que combinaci?n se trata y calcular nearest, part of o inside
|
|
825 |
// seg?n corresponda.
|
|
826 |
// Si intersecta copiarle los atributos. O sea rellenar Values como
|
|
827 |
// toque ...
|
|
828 |
Value[][] values = new Value[geometriesToJoin.length][joinedLyrFieldNames.length+1]; // +1 porque faltaba el PK
|
|
829 |
// Movida para el nearest entre puntos
|
|
830 |
//Point[] joiningPoints = new Point[joiningGeometries.length];
|
|
831 |
Geometry[] joiningGeometrySet = new Geometry[joiningGeometries.length];
|
|
832 |
/*for (int i=0;i<joiningGeometries.length;i++) {
|
|
833 |
joiningPoints[i] = (Point)joiningGeometries[i];
|
|
834 |
}*/
|
|
835 |
for (int i=0;i<joiningGeometries.length;i++) {
|
|
836 |
joiningGeometrySet[i] = (Geometry)joiningGeometries[i];
|
|
837 |
}
|
|
838 |
//MultiPoint joiningMultiPoint = new MultiPoint(joiningPoints, new GeometryFactory());
|
|
839 |
GeometryCollection joiningGeometryCollection = new GeometryCollection(joiningGeometrySet, new GeometryFactory());
|
|
840 |
for (int i=0;i<geometriesToJoin.length;i++) {
|
|
841 |
Geometry geometryToJoin = geometriesToJoin[i];
|
|
842 |
// Movida para el nearest entre puntos
|
|
843 |
//Coordinate[] coords = DistanceOp.closestPoints(geometryToJoin, joiningMultiPoint);
|
|
844 |
Coordinate[] coords = DistanceOp.closestPoints(geometryToJoin, joiningGeometryCollection);
|
|
845 |
for (int j=0;j<joiningGeometries.length;j++) {
|
|
846 |
Geometry joiningGeometry = joiningGeometries[j];
|
|
847 |
if (geometryToJoin instanceof Point && joiningGeometry instanceof Point) {
|
|
848 |
// Rellenar el PK. Lo tengo que hacer antes del break
|
|
849 |
values[i][joinedLyrFieldNames.length] = ValueFactory.createValue(i);
|
|
850 |
for (int k=0;k<lyrToJoinFieldNames.length-1;k++) {
|
|
851 |
values[i][k] = lyrToJoinDS.getFieldValue(i, k);
|
|
852 |
}
|
|
853 |
if (coords[1].equals2D(joiningGeometry.getCoordinate())) {
|
|
854 |
for (int k=0;k<joiningLyrFieldNames.length-1;k++) {
|
|
855 |
values[i][k+l] = joiningLyrDS.getFieldValue(j, k);
|
|
856 |
}
|
|
857 |
break; // En el momento encontremos un pol?gono que contiene a otro le metemos los valores y nos vamos
|
|
858 |
} else {
|
|
859 |
for (int k=0;k<joiningLyrFieldNames.length-1;k++) {
|
|
860 |
values[i][k+l] = ValueFactory.createNullValue();
|
|
861 |
}
|
|
862 |
}
|
|
863 |
} else if (geometryToJoin instanceof Point && joiningGeometry instanceof LineString) {
|
|
864 |
// part of not supported yet
|
|
865 |
} else if (geometryToJoin instanceof Point && joiningGeometry instanceof Polygon) {
|
|
866 |
// Rellenar el PK. Lo tengo que hacer antes del break
|
|
867 |
values[i][joinedLyrFieldNames.length] = ValueFactory.createValue(i);
|
|
868 |
for (int k=0;k<lyrToJoinFieldNames.length-1;k++) {
|
|
869 |
values[i][k] = lyrToJoinDS.getFieldValue(i, k);
|
|
870 |
}
|
|
871 |
if (joiningGeometry.contains(geometryToJoin)) {
|
|
872 |
for (int k=0;k<joiningLyrFieldNames.length-1;k++) {
|
|
873 |
System.out.println(i);
|
|
874 |
values[i][k+l] = joiningLyrDS.getFieldValue(j, k);
|
|
875 |
}
|
|
876 |
break; // En el momento encontremos un pol?gono que contiene a otro le metemos los valores y nos vamos
|
|
877 |
} else {
|
|
878 |
for (int k=0;k<joiningLyrFieldNames.length-1;k++) {
|
|
879 |
values[i][k+l] = ValueFactory.createNullValue();
|
|
880 |
}
|
|
881 |
}
|
|
882 |
} else if (geometryToJoin instanceof LineString && joiningGeometry instanceof Point) {
|
|
883 |
// Rellenar el PK. Lo tengo que hacer antes del break
|
|
884 |
values[i][joinedLyrFieldNames.length] = ValueFactory.createValue(i);
|
|
885 |
for (int k=0;k<lyrToJoinFieldNames.length-1;k++) {
|
|
886 |
values[i][k] = lyrToJoinDS.getFieldValue(i, k);
|
|
887 |
}
|
|
888 |
if (coords[1].equals2D(joiningGeometry.getCoordinate())) {
|
|
889 |
for (int k=0;k<joiningLyrFieldNames.length-1;k++) {
|
|
890 |
values[i][k+l] = joiningLyrDS.getFieldValue(j, k);
|
|
891 |
}
|
|
892 |
break; // En el momento encontremos un pol?gono que contiene a otro le metemos los valores y nos vamos
|
|
893 |
} else {
|
|
894 |
for (int k=0;k<joiningLyrFieldNames.length-1;k++) {
|
|
895 |
values[i][k+l] = ValueFactory.createNullValue();
|
|
896 |
}
|
|
897 |
}
|
|
898 |
} else if (geometryToJoin instanceof LineString && joiningGeometry instanceof LineString) {
|
|
899 |
// Rellenar el PK. Lo tengo que hacer antes del break
|
|
900 |
values[i][joinedLyrFieldNames.length] = ValueFactory.createValue(i);
|
|
901 |
for (int k=0;k<lyrToJoinFieldNames.length-1;k++) {
|
|
902 |
values[i][k] = lyrToJoinDS.getFieldValue(i, k);
|
|
903 |
}
|
|
904 |
//if (coords[1].equals2D(joiningGeometry.getCoordinate())) {
|
|
905 |
if (joiningGeometry.contains(geometryToJoin) || geometryToJoin.contains(joiningGeometry)) {
|
|
906 |
for (int k=0;k<joiningLyrFieldNames.length-1;k++) {
|
|
907 |
values[i][k+l] = joiningLyrDS.getFieldValue(j, k);
|
|
908 |
}
|
|
909 |
break; // En el momento encontremos un pol?gono que contiene a otro le metemos los valores y nos vamos
|
|
910 |
} else {
|
|
911 |
for (int k=0;k<joiningLyrFieldNames.length-1;k++) {
|
|
912 |
values[i][k+l] = ValueFactory.createNullValue();
|
|
913 |
}
|
|
914 |
}
|
|
915 |
} else if (geometryToJoin instanceof LineString && joiningGeometry instanceof Polygon) {
|
|
916 |
// Rellenar el PK. Lo tengo que hacer antes del break
|
|
917 |
values[i][joinedLyrFieldNames.length] = ValueFactory.createValue(i);
|
|
918 |
for (int k=0;k<lyrToJoinFieldNames.length-1;k++) {
|
|
919 |
values[i][k] = lyrToJoinDS.getFieldValue(i, k);
|
|
920 |
}
|
|
921 |
if (joiningGeometry.contains(geometryToJoin)) {
|
|
922 |
for (int k=0;k<joiningLyrFieldNames.length-1;k++) {
|
|
923 |
values[i][k+l] = joiningLyrDS.getFieldValue(j, k);
|
|
924 |
}
|
|
925 |
break; // En el momento encontremos un pol?gono que contiene a otro le metemos los valores y nos vamos
|
|
926 |
} else {
|
|
927 |
for (int k=0;k<joiningLyrFieldNames.length-1;k++) {
|
|
928 |
values[i][k+l] = ValueFactory.createNullValue();
|
|
929 |
}
|
|
930 |
}
|
|
931 |
} else if (geometryToJoin instanceof Polygon && joiningGeometry instanceof Point) {
|
|
932 |
// nearest not supported yet
|
|
933 |
} else if (geometryToJoin instanceof Polygon && joiningGeometry instanceof LineString) {
|
|
934 |
// nearest not supported yet
|
|
935 |
} else if (geometryToJoin instanceof Polygon && joiningGeometry instanceof Polygon) {
|
|
936 |
// Rellenar el PK. Lo tengo que hacer antes del break
|
|
937 |
values[i][joinedLyrFieldNames.length] = ValueFactory.createValue(i);
|
|
938 |
for (int k=0;k<lyrToJoinFieldNames.length-1;k++) {
|
|
939 |
values[i][k] = lyrToJoinDS.getFieldValue(i, k);
|
|
940 |
}
|
|
941 |
if (joiningGeometry.contains(geometryToJoin)) {
|
|
942 |
for (int k=0;k<joiningLyrFieldNames.length-1;k++) {
|
|
943 |
values[i][k+l] = joiningLyrDS.getFieldValue(j, k);
|
|
944 |
}
|
|
945 |
break; // En el momento encontremos un pol?gono que contiene a otro le metemos los valores y nos vamos
|
|
946 |
} else {
|
|
947 |
for (int k=0;k<joiningLyrFieldNames.length-1;k++) {
|
|
948 |
values[i][k+l] = ValueFactory.createNullValue();
|
|
949 |
}
|
|
950 |
}
|
|
951 |
} else {
|
|
952 |
// MultiPoint, LineSegment, LinearRing, MultiLineString, MultiPolygon faltan
|
|
953 |
// por implementar ...
|
|
954 |
}
|
|
955 |
}
|
|
956 |
}
|
|
957 |
for (int i=0;i<lyrToJoinSDS.getSelection().cardinality();i++) {
|
|
958 |
dw.insertFilledRow(values[i]);
|
|
959 |
}
|
|
960 |
/*for (int i=0;i<lyrToJoinDS.getRowCount();i++) {
|
|
961 |
dw.insertFilledRow(values[i]);
|
|
962 |
}*/
|
|
963 |
dw.commitTrans();
|
|
964 |
IGeometry[] shapes = getFmapGeometries(geometriesToJoin);
|
|
965 |
// Guardo la tabla mediante gdbms. Guardo tambi?n las entidades JTS mediante gvSIG o usando solo gdbms (probablemente bastar? con usar gdbms)
|
|
966 |
// Guardar las viejas geometr?as.
|
|
967 |
GeoProcessingPersistenceOperations.saveResultsToShapeFile(shapes, geoProcessingSpatialjoinPanel.getOutputFile());
|
|
968 |
//lyrToJoinSDS.getSelection().clear();
|
|
969 |
//joiningLyrSDS.getSelection().clear();
|
|
970 |
lyrToJoinSDS.setSelection(new FBitSet());
|
|
971 |
joiningLyrSDS.setSelection(new FBitSet());
|
|
972 |
} catch (DriverException e) {
|
|
973 |
// TODO Auto-generated catch block
|
|
974 |
e.printStackTrace();
|
|
975 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
|
976 |
// TODO Auto-generated catch block
|
|
977 |
e.printStackTrace();
|
|
978 |
} catch (DriverLoadException e) {
|
|
979 |
// TODO Auto-generated catch block
|
|
980 |
e.printStackTrace();
|
|
981 |
} catch (NoSuchTableException e) {
|
|
982 |
// TODO Auto-generated catch block
|
|
983 |
e.printStackTrace();
|
|
984 |
}
|
|
985 |
}
|
|
986 |
// clip: intersect + dissolve
|
735 |
987 |
private void clipMethod() {
|
736 |
988 |
String layerToClipName = (String)((JComboBox)geoProcessingClipPanel.getComponent(0)).getSelectedItem();
|
737 |
989 |
FLayer layerToClip = layers.getLayer(layerToClipName);
|
738 |
990 |
boolean selected = false;
|
739 |
|
if (((JCheckBox)geoProcessingClipPanel.getComponent(1)).isSelected()) selected = true;
|
|
991 |
//if (((JCheckBox)geoProcessingClipPanel.getComponent(1)).isSelected()) selected = true;
|
740 |
992 |
Geometry[] geometriesToClip = getJtsGeometries(layerToClip, selected);
|
741 |
993 |
String clippingLayerName = (String)((JComboBox)geoProcessingClipPanel.getComponent(3)).getSelectedItem();
|
742 |
994 |
FLayer clippingLayer = layers.getLayer(clippingLayerName);
|
743 |
|
if (((JCheckBox)geoProcessingClipPanel.getComponent(5)).isSelected()) selected = true;
|
|
995 |
//if (((JCheckBox)geoProcessingClipPanel.getComponent(5)).isSelected()) selected = true;
|
744 |
996 |
Geometry[] clippingGeometries = getJtsGeometries(clippingLayer, selected);
|
745 |
|
Geometry[] clippedGeometries = GeoProcessingTopologyOperations.makeClip(geometriesToClip, clippingGeometries);
|
746 |
|
IGeometry[] shapes = getFmapGeometries(clippedGeometries);
|
747 |
|
// Guardo la tabla mediante gdbms. Guardo tambi?n las entidades JTS mediante gvSIG o usando solo gdbms (probablemente bastar? con usar gdbms)
|
748 |
|
GeoProcessingPersistenceOperations.saveResultsToShapeFile(shapes, geoProcessingClipPanel.getOutputFile());
|
|
997 |
AlphanumericData lyr = (AlphanumericData)layerToClip;
|
|
998 |
SelectableDataSource sds;
|
|
999 |
try {
|
|
1000 |
DataSource ds;
|
|
1001 |
ds = lyr.getRecordset();
|
|
1002 |
sds = lyr.getRecordset();
|
|
1003 |
// Tener en cuenta que podemos estar trabajando solo con una selecci?n
|
|
1004 |
//FBitSet fBitSet = ((Selectable)lyr).getSelection();
|
|
1005 |
String[] fieldNames = new String[sds.getFieldCount()-1];
|
|
1006 |
int[] fieldTypes = new int[sds.getFieldCount()-1];
|
|
1007 |
for (int i = 0; i < sds.getFieldCount()-1; i++) {
|
|
1008 |
fieldNames[i] = sds.getFieldName(i);
|
|
1009 |
fieldTypes[i] = sds.getFieldType(i);
|
|
1010 |
}
|
|
1011 |
DataSourceFactory dsf = sds.getDataSourceFactory();
|
|
1012 |
File file = geoProcessingClipPanel.getOutputFile();
|
|
1013 |
dsf.createFileDataSource("gdbms dbf driver", "new_table", file.getAbsolutePath().replaceAll(".shp", ".dbf"), fieldNames, fieldTypes);
|
|
1014 |
DataSource dataSource = dsf.createRandomDataSource("new_table");
|
|
1015 |
dataSource.start();
|
|
1016 |
DataWare dw = dataSource.getDataWare(DataSourceFactory.MANUAL_OPENING);
|
|
1017 |
dw.beginTrans();
|
|
1018 |
Vector values = new Vector();
|
|
1019 |
Vector geometriesClipped = new Vector();
|
|
1020 |
for (int i=0;i<geometriesToClip.length;i++) {
|
|
1021 |
Geometry geometryToClip = geometriesToClip[i];
|
|
1022 |
for (int j=0;j<clippingGeometries.length;j++) {
|
|
1023 |
Geometry clippingGeometry = clippingGeometries[j];
|
|
1024 |
if (clippingGeometry.intersects(geometryToClip)) {
|
|
1025 |
geometriesClipped.add(geometryToClip.intersection(clippingGeometry));
|
|
1026 |
Value[] rows = new Value[fieldNames.length+1]; // +1 porque faltaba el PK
|
|
1027 |
for (int m=0;m<fieldNames.length;m++) {
|
|
1028 |
rows[m] = ds.getFieldValue(i, m);
|
|
1029 |
}
|
|
1030 |
rows[fieldNames.length] = ValueFactory.createValue(i);
|
|
1031 |
values.add(rows);
|
|
1032 |
}
|
|
1033 |
}
|
|
1034 |
}
|
|
1035 |
//
|
|
1036 |
Vector resultGeometries = new Vector();
|
|
1037 |
for (int i=0;i<values.size();i++) {
|
|
1038 |
Value[] rowi = ((Value[])values.get(i));
|
|
1039 |
Geometry geometryi = ((Geometry)geometriesClipped.get(i));
|
|
1040 |
for (int j=0;j<values.size();j++) {
|
|
1041 |
if (j>i) {
|
|
1042 |
Value[] rowj = ((Value[])values.get(j));
|
|
1043 |
boolean areTheSameElement = true;
|
|
1044 |
for (int k=0;k<rowj.length;k++) {
|
|
1045 |
//Value valuei = ds.getFieldValue(i, k);
|
|
1046 |
//Value valuej = ds.getFieldValue(j, k);
|
|
1047 |
Value valuei = rowi[k];
|
|
1048 |
Value valuej = rowj[k];
|
|
1049 |
if (!((BooleanValue)(valuej.equals(valuei))).getValue()) {
|
|
1050 |
areTheSameElement = false;
|
|
1051 |
}
|
|
1052 |
}
|
|
1053 |
if (areTheSameElement) {
|
|
1054 |
Geometry geometryj = ((Geometry)geometriesClipped.get(j));
|
|
1055 |
geometryi = geometryj.union(geometryi);
|
|
1056 |
//values.remove(j); // igual esto peta ...
|
|
1057 |
}
|
|
1058 |
}
|
|
1059 |
}
|
|
1060 |
resultGeometries.add(geometryi);
|
|
1061 |
}
|
|
1062 |
for (int i=0;i<resultGeometries.size();i++) {
|
|
1063 |
for (int j=0;j<resultGeometries.size();j++) {
|
|
1064 |
if (j>i) {
|
|
1065 |
if (((Geometry)resultGeometries.get(i)).intersects((Geometry)resultGeometries.get(j))) resultGeometries.remove(j);
|
|
1066 |
}
|
|
1067 |
}
|
|
1068 |
}
|
|
1069 |
for (int i=0;i<values.size();i++) {
|
|
1070 |
Value[] rowi = ((Value[])values.get(i));
|
|
1071 |
for (int j=0;j<values.size();j++) {
|
|
1072 |
if (j!=i) {
|
|
1073 |
Value[] rowj = ((Value[])values.get(j));
|
|
1074 |
boolean areTheSameElement = true;
|
|
1075 |
for (int k=0;k<rowj.length;k++) {
|
|
1076 |
//Value valuei = ds.getFieldValue(i, k);
|
|
1077 |
//Value valuej = ds.getFieldValue(j, k);
|
|
1078 |
Value valuei = rowi[k];
|
|
1079 |
Value valuej = rowj[k];
|
|
1080 |
if (!((BooleanValue)(valuej.equals(valuei))).getValue()) {
|
|
1081 |
areTheSameElement = false;
|
|
1082 |
}
|
|
1083 |
}
|
|
1084 |
if (areTheSameElement) {
|
|
1085 |
values.remove(j);
|
|
1086 |
}
|
|
1087 |
}
|
|
1088 |
}
|
|
1089 |
}
|
|
1090 |
Geometry[] dissolvedGeometries = new Geometry[resultGeometries.size()];
|
|
1091 |
for (int i=0;i<resultGeometries.size();i++) {
|
|
1092 |
dissolvedGeometries[i] = (Geometry)resultGeometries.get(i);
|
|
1093 |
}
|
|
1094 |
IGeometry[] shapes = getFmapGeometries(dissolvedGeometries);
|
|
1095 |
Geometry[] clippedGeometries = new Geometry[geometriesClipped.size()];
|
|
1096 |
for (int i=0;i<geometriesClipped.size();i++) {
|
|
1097 |
clippedGeometries[i] = (Geometry)geometriesClipped.get(i);
|
|
1098 |
}
|
|
1099 |
GeoProcessingPersistenceOperations.saveResultsToShapeFile(shapes, geoProcessingClipPanel.getOutputFile());
|
|
1100 |
dataSource.stop();
|
|
1101 |
sds.stop();
|
|
1102 |
ds.stop();
|
|
1103 |
for (int i=0;i<values.size();i++) {
|
|
1104 |
dw.insertFilledRow(((Value[])values.get(i)));
|
|
1105 |
}
|
|
1106 |
dw.commitTrans();
|
|
1107 |
} catch (DriverException e) {
|
|
1108 |
// TODO Auto-generated catch block
|
|
1109 |
e.printStackTrace();
|
|
1110 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
|
1111 |
// TODO Auto-generated catch block
|
|
1112 |
e.printStackTrace();
|
|
1113 |
} catch (DriverLoadException e) {
|
|
1114 |
// TODO Auto-generated catch block
|
|
1115 |
e.printStackTrace();
|
|
1116 |
} catch (NoSuchTableException e) {
|
|
1117 |
// TODO Auto-generated catch block
|
|
1118 |
e.printStackTrace();
|
|
1119 |
} catch (IncompatibleTypesException e) {
|
|
1120 |
// TODO Auto-generated catch block
|
|
1121 |
e.printStackTrace();
|
|
1122 |
}
|
749 |
1123 |
}
|
|
1124 |
// Spatial join con Intersect
|
750 |
1125 |
private void intersectMethod() {
|
751 |
1126 |
String layerToIntersectName = (String)((JComboBox)geoProcessingIntersectPanel.getComponent(0)).getSelectedItem();
|
752 |
1127 |
FLayer layerToIntersect = layers.getLayer(layerToIntersectName);
|
|
1128 |
String intersectingLayerName = (String)((JComboBox)geoProcessingIntersectPanel.getComponent(3)).getSelectedItem();
|
|
1129 |
FLayer intersectingLayer = layers.getLayer(intersectingLayerName);
|
753 |
1130 |
boolean selected = false;
|
754 |
|
if (((JCheckBox)geoProcessingIntersectPanel.getComponent(1)).isSelected()) selected = true;
|
755 |
1131 |
Geometry[] geometriesToIntersect = getJtsGeometries(layerToIntersect, selected);
|
756 |
|
String intersectingLayerName = (String)((JComboBox)geoProcessingIntersectPanel.getComponent(3)).getSelectedItem();
|
757 |
|
FLayer intersectingLayer = layers.getLayer(intersectingLayerName);
|
758 |
|
if (((JCheckBox)geoProcessingIntersectPanel.getComponent(5)).isSelected()) selected = true;
|
759 |
1132 |
Geometry[] intersectingGeometries = getJtsGeometries(intersectingLayer, selected);
|
760 |
|
Geometry[] intersectedGeometries = GeoProcessingTopologyOperations.makeIntersect(geometriesToIntersect, intersectingGeometries);
|
761 |
|
IGeometry[] shapes = getFmapGeometries(intersectedGeometries);
|
762 |
|
// Guardo la tabla mediante gdbms. Guardo tambi?n las entidades JTS mediante gvSIG o usando solo gdbms (probablemente bastar? con usar gdbms)
|
763 |
|
GeoProcessingPersistenceOperations.saveResultsToShapeFile(shapes, geoProcessingIntersectPanel.getOutputFile());
|
|
1133 |
try {
|
|
1134 |
//if (((JCheckBox)geoProcessingIntersectPanel.getComponent(1)).isSelected()) selected = true;
|
|
1135 |
AlphanumericData lyrToIntersect = (AlphanumericData)layerToIntersect;
|
|
1136 |
SelectableDataSource lyrToIntersectSDS = lyrToIntersect.getRecordset();
|
|
1137 |
//if (((JCheckBox)geoProcessingIntersectPanel.getComponent(5)).isSelected()) selected = true;
|
|
1138 |
AlphanumericData intersectingLyr = (AlphanumericData)intersectingLayer;
|
|
1139 |
DataSource lyrToIntersectDS;
|
|
1140 |
DataSource intersectingLyrDS;
|
|
1141 |
lyrToIntersectDS = lyrToIntersect.getRecordset();
|
|
1142 |
intersectingLyrDS = intersectingLyr.getRecordset();
|
|
1143 |
// Los campos se a?aden siempre. Los valores solo cuando toca ...
|
|
1144 |
String[] lyrToIntersectFieldNames = new String[lyrToIntersectDS.getFieldCount()];
|
|
1145 |
int[] lyrToIntersectFieldTypes = new int[lyrToIntersectDS.getFieldCount()];
|
|
1146 |
for (int i = 0; i < lyrToIntersectDS.getFieldCount(); i++) {
|
|
1147 |
lyrToIntersectFieldNames[i] = lyrToIntersectDS.getFieldName(i);
|
|
1148 |
lyrToIntersectFieldTypes[i] = lyrToIntersectDS.getFieldType(i);
|
|
1149 |
}
|
|
1150 |
String[] intersectingLyrFieldNames = new String[intersectingLyrDS.getFieldCount()];
|
|
1151 |
int[] intersectingLyrFieldTypes = new int[intersectingLyrDS.getFieldCount()];
|
|
1152 |
for (int i = 0; i < intersectingLyrDS.getFieldCount(); i++) {
|
|
1153 |
intersectingLyrFieldNames[i] = intersectingLyrDS.getFieldName(i);
|
|
1154 |
intersectingLyrFieldTypes[i] = intersectingLyrDS.getFieldType(i);
|
|
1155 |
}
|
|
1156 |
String[] intersectedLyrFieldNames = new String[lyrToIntersectDS.getFieldCount()+intersectingLyrDS.getFieldCount()-2]; // Le quito los dos PKs
|
|
1157 |
int[] intersectedLyrFieldTypes = new int[lyrToIntersectDS.getFieldCount()+intersectingLyrDS.getFieldCount()-2];
|
|
1158 |
int l=0;
|
|
1159 |
for (int i=0;i<lyrToIntersectFieldNames.length-1;i++) {
|
|
1160 |
intersectedLyrFieldNames[i] = lyrToIntersectFieldNames[i];
|
|
1161 |
intersectedLyrFieldTypes[i] = lyrToIntersectFieldTypes[i];
|
|
1162 |
l++;
|
|
1163 |
}
|
|
1164 |
for (int i=0;i<intersectingLyrFieldNames.length-1;i++) {
|
|
1165 |
intersectedLyrFieldNames[i+l] = intersectingLyrFieldNames[i];
|
|
1166 |
intersectedLyrFieldTypes[i+l] = intersectingLyrFieldTypes[i];
|
|
1167 |
}
|
|
1168 |
DataSourceFactory dsf = lyrToIntersectSDS.getDataSourceFactory();
|
|
1169 |
File file = geoProcessingIntersectPanel.getOutputFile();
|
|
1170 |
dsf.createFileDataSource("gdbms dbf driver", "new_table", file.getAbsolutePath().replaceAll(".shp", ".dbf"), intersectedLyrFieldNames, intersectedLyrFieldTypes);
|
|
1171 |
DataSource ds = dsf.createRandomDataSource("new_table");
|
|
1172 |
ds.start();
|
|
1173 |
DataWare dw = ds.getDataWare(DataSourceFactory.MANUAL_OPENING);
|
|
1174 |
dw.beginTrans();
|
|
1175 |
ds.stop();
|
|
1176 |
// Si cierro no tendr? problemas a continuaci?n?
|
|
1177 |
lyrToIntersectSDS.stop();
|
|
1178 |
|
|
1179 |
Vector values = new Vector();
|
|
1180 |
Vector geometriesIntersected = new Vector();
|
|
1181 |
for (int i=0;i<geometriesToIntersect.length;i++) {
|
|
1182 |
Geometry geometryToIntersect = geometriesToIntersect[i];
|
|
1183 |
String geometryToIntersectType = geometryToIntersect.getGeometryType();
|
|
1184 |
System.out.println("geometryToIntersectType = " + geometryToIntersectType);
|
|
1185 |
for (int j=0;j<intersectingGeometries.length;j++) {
|
|
1186 |
Geometry intersectingGeometry = intersectingGeometries[j];
|
|
1187 |
if (intersectingGeometry.intersects(geometryToIntersect)) {
|
|
1188 |
geometriesIntersected.add(geometryToIntersect.intersection(intersectingGeometry));
|
|
1189 |
/*for (int m=0;m<intersectedLyrFieldNames.length;m++) {
|
|
1190 |
rows[m] = ds.getFieldValue(i, m);
|
|
1191 |
}*/
|
|
1192 |
Value[] rows = new Value[intersectedLyrFieldNames.length+1]; // +1 porque faltaba el PK
|
|
1193 |
for (int k=0;k<lyrToIntersectFieldNames.length-1;k++) {
|
|
1194 |
rows[k] = lyrToIntersectDS.getFieldValue(i, k);
|
|
1195 |
}
|
|
1196 |
for (int k=0;k<intersectingLyrFieldNames.length-1;k++) {
|
|
1197 |
rows[k+l] = intersectingLyrDS.getFieldValue(j, k);
|
|
1198 |
}
|
|
1199 |
rows[intersectedLyrFieldNames.length] = ValueFactory.createValue(i);
|
|
1200 |
values.add(rows);
|
|
1201 |
}
|
|
1202 |
}
|
|
1203 |
}
|
|
1204 |
|
|
1205 |
for (int i=0;i<geometriesIntersected.size();i++) {
|
|
1206 |
dw.insertFilledRow(((Value[])values.get(i)));
|
|
1207 |
}
|
|
1208 |
dw.commitTrans();
|
|
1209 |
Geometry[] geometriesIntersectedArray = new Geometry[geometriesIntersected.size()];
|
|
1210 |
for (int i=0;i<geometriesIntersected.size();i++) {
|
|
1211 |
geometriesIntersectedArray[i] = (Geometry)geometriesIntersected.get(i);
|
|
1212 |
}
|
|
1213 |
IGeometry[] shapes = getFmapGeometries(geometriesIntersectedArray);
|
|
1214 |
// Guardo la tabla mediante gdbms. Guardo tambi?n las entidades JTS mediante gvSIG o usando solo gdbms (probablemente bastar? con usar gdbms)
|
|
1215 |
// Guardar las viejas geometr?as.
|
|
1216 |
GeoProcessingPersistenceOperations.saveResultsToShapeFile(shapes, geoProcessingIntersectPanel.getOutputFile());
|
|
1217 |
} catch (DriverException e) {
|
|
1218 |
// TODO Auto-generated catch block
|
|
1219 |
e.printStackTrace();
|
|
1220 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
|
1221 |
// TODO Auto-generated catch block
|
|
1222 |
e.printStackTrace();
|
|
1223 |
} catch (DriverLoadException e) {
|
|
1224 |
// TODO Auto-generated catch block
|
|
1225 |
e.printStackTrace();
|
|
1226 |
} catch (NoSuchTableException e) {
|
|
1227 |
// TODO Auto-generated catch block
|
|
1228 |
e.printStackTrace();
|
|
1229 |
}
|
764 |
1230 |
}
|
765 |
1231 |
private void unionMethod() {
|
766 |
1232 |
String layerToUnionName = (String)((JComboBox)geoProcessingUnionPanel.getComponent(0)).getSelectedItem();
|
767 |
1233 |
FLayer layerToUnion = layers.getLayer(layerToUnionName);
|
768 |
1234 |
boolean selected = false;
|
769 |
|
if (((JCheckBox)geoProcessingUnionPanel.getComponent(1)).isSelected()) selected = true;
|
|
1235 |
//if (((JCheckBox)geoProcessingUnionPanel.getComponent(1)).isSelected()) selected = true;
|
770 |
1236 |
Geometry[] geometriesToUnion = getJtsGeometries(layerToUnion, selected);
|
771 |
1237 |
String uningLayerName = (String)((JComboBox)geoProcessingUnionPanel.getComponent(3)).getSelectedItem();
|
772 |
1238 |
FLayer uningLayer = layers.getLayer(uningLayerName);
|
773 |
|
if (((JCheckBox)geoProcessingUnionPanel.getComponent(5)).isSelected()) selected = true;
|
|
1239 |
//if (((JCheckBox)geoProcessingUnionPanel.getComponent(5)).isSelected()) selected = true;
|
774 |
1240 |
Geometry[] uningGeometries = getJtsGeometries(uningLayer, selected);
|
775 |
|
Geometry[] unedGeometries = GeoProcessingTopologyOperations.makeUnion(geometriesToUnion, uningGeometries);
|
776 |
|
IGeometry[] shapes = getFmapGeometries(unedGeometries);
|
777 |
|
// Guardo la tabla mediante gdbms. Guardo tambi?n las entidades JTS mediante gvSIG o usando solo gdbms (probablemente bastar? con usar gdbms)
|
778 |
|
GeoProcessingPersistenceOperations.saveResultsToShapeFile(shapes, geoProcessingUnionPanel.getOutputFile());
|
|
1241 |
|
|
1242 |
//if (((JCheckBox)geoProcessingIntersectPanel.getComponent(1)).isSelected()) selected = true;
|
|
1243 |
AlphanumericData lyrToUnion = (AlphanumericData)layerToUnion;
|
|
1244 |
SelectableDataSource lyrToUnionSDS;
|
|
1245 |
try {
|
|
1246 |
lyrToUnionSDS = lyrToUnion.getRecordset();
|
|
1247 |
//if (((JCheckBox)geoProcessingIntersectPanel.getComponent(5)).isSelected()) selected = true;
|
|
1248 |
AlphanumericData uningLyr = (AlphanumericData)uningLayer;
|
|
1249 |
DataSource lyrToUnionDS;
|
|
1250 |
DataSource uningLyrDS;
|
|
1251 |
lyrToUnionDS = lyrToUnion.getRecordset();
|
|
1252 |
uningLyrDS = uningLyr.getRecordset();
|
|
1253 |
// Los campos se a?aden siempre. Los valores solo cuando toca ...
|
|
1254 |
String[] lyrToUnionFieldNames = new String[lyrToUnionDS.getFieldCount()];
|
|
1255 |
int[] lyrToUnionFieldTypes = new int[lyrToUnionDS.getFieldCount()];
|
|
1256 |
for (int i = 0; i < lyrToUnionDS.getFieldCount(); i++) {
|
|
1257 |
lyrToUnionFieldNames[i] = lyrToUnionDS.getFieldName(i);
|
|
1258 |
lyrToUnionFieldTypes[i] = lyrToUnionDS.getFieldType(i);
|
|
1259 |
}
|
|
1260 |
String[] uningLyrFieldNames = new String[uningLyrDS.getFieldCount()];
|
|
1261 |
int[] uningLyrFieldTypes = new int[uningLyrDS.getFieldCount()];
|
|
1262 |
for (int i = 0; i < uningLyrDS.getFieldCount(); i++) {
|
|
1263 |
uningLyrFieldNames[i] = uningLyrDS.getFieldName(i);
|
|
1264 |
uningLyrFieldTypes[i] = uningLyrDS.getFieldType(i);
|
|
1265 |
}
|
|
1266 |
String[] unedLyrFieldNames = new String[lyrToUnionDS.getFieldCount()+uningLyrDS.getFieldCount()-2]; // Le quito los dos PKs
|
|
1267 |
int[] unedLyrFieldTypes = new int[lyrToUnionDS.getFieldCount()+uningLyrDS.getFieldCount()-2];
|
|
1268 |
int l=0;
|
|
1269 |
for (int i=0;i<lyrToUnionFieldNames.length-1;i++) {
|
|
1270 |
unedLyrFieldNames[i] = lyrToUnionFieldNames[i];
|
|
1271 |
unedLyrFieldTypes[i] = lyrToUnionFieldTypes[i];
|
|
1272 |
l++;
|
|
1273 |
}
|
|
1274 |
for (int i=0;i<uningLyrFieldNames.length-1;i++) {
|
|
1275 |
unedLyrFieldNames[i+l] = uningLyrFieldNames[i];
|
|
1276 |
unedLyrFieldTypes[i+l] = uningLyrFieldTypes[i];
|
|
1277 |
}
|
|
1278 |
DataSourceFactory dsf = lyrToUnionSDS.getDataSourceFactory();
|
|
1279 |
File file = geoProcessingUnionPanel.getOutputFile();
|
|
1280 |
dsf.createFileDataSource("gdbms dbf driver", "new_table", file.getAbsolutePath().replaceAll(".shp", ".dbf"), unedLyrFieldNames, unedLyrFieldTypes);
|
|
1281 |
DataSource ds = dsf.createRandomDataSource("new_table");
|
|
1282 |
ds.start();
|
|
1283 |
DataWare dw = ds.getDataWare(DataSourceFactory.MANUAL_OPENING);
|
|
1284 |
dw.beginTrans();
|
|
1285 |
ds.stop();
|
|
1286 |
lyrToUnionSDS.stop();
|
|
1287 |
|
|
1288 |
Vector values = new Vector();
|
|
1289 |
|
|
1290 |
//Geometry[] unedGeometries = GeoProcessingTopologyOperations.makeUnion(geometriesToUnion, uningGeometries);
|
|
1291 |
Geometry[] result = new Geometry[geometriesToUnion.length];
|
|
1292 |
Vector geometriesUned = new Vector();
|
|
1293 |
//Selectable selectable = (Selectable)layerToUnion;
|
|
1294 |
//FBitSet fBitSet = new FBitSet();
|
|
1295 |
// Metememos en geometriesUned las intersecciones.
|
|
1296 |
for (int i=0;i<geometriesToUnion.length;i++) {
|
|
1297 |
Geometry geometryToUnion = geometriesToUnion[i];
|
|
1298 |
for (int j=0;j<uningGeometries.length;j++) {
|
|
1299 |
Geometry uningGeometry = uningGeometries[j];
|
|
1300 |
if (uningGeometry.intersects(geometryToUnion)) {
|
|
1301 |
//fBitSet.set(i);
|
|
1302 |
geometriesUned.add(geometryToUnion.intersection(uningGeometry));
|
|
1303 |
Value[] intersectRow = new Value[unedLyrFieldNames.length+1];
|
|
1304 |
for (int k=0;k<lyrToUnionFieldNames.length-1;k++) {
|
|
1305 |
intersectRow[k] = lyrToUnionDS.getFieldValue(i, k);
|
|
1306 |
}
|
|
1307 |
for (int k=0;k<uningLyrFieldNames.length-1;k++) {
|
|
1308 |
intersectRow[k+l] = uningLyrDS.getFieldValue(j, k);
|
|
1309 |
}
|
|
1310 |
intersectRow[unedLyrFieldNames.length] = ValueFactory.createValue(i);
|
|
1311 |
values.add(intersectRow);
|
|
1312 |
//geometriesUned.add(geometryToUnion.difference(uningGeometry));
|
|
1313 |
}
|
|
1314 |
}
|
|
1315 |
}
|
|
1316 |
// Rellenamos geometriesUned2 con estas intersecciones.
|
|
1317 |
Vector geometriesUned2 = new Vector();
|
|
1318 |
for (int i=0;i<geometriesUned.size();i++) {
|
|
1319 |
geometriesUned2.add(geometriesUned.get(i));
|
|
1320 |
}
|
|
1321 |
//int num = geometriesUned.size();
|
|
1322 |
// A?ado a geometriesUned2 las geometr?as de geometriesToUnion que no
|
|
1323 |
// intersectan con uningGeometries.
|
|
1324 |
for (int i=0;i<geometriesToUnion.length;i++) {
|
|
1325 |
Geometry geometryToUnion = geometriesToUnion[i];
|
|
1326 |
boolean intersectsWithAnyGeometry = false;
|
|
1327 |
for (int j=0;j<geometriesUned.size();j++) {
|
|
1328 |
Geometry geometryUned = (Geometry)geometriesUned.get(j);
|
|
1329 |
if (geometryToUnion.intersects(geometryUned)) intersectsWithAnyGeometry = true;
|
|
1330 |
}
|
|
1331 |
if (intersectsWithAnyGeometry) {
|
|
1332 |
//Geometry difference = geometryToUnion.difference(geometryUned);
|
|
1333 |
//geometriesUned2.add(difference);
|
|
1334 |
} else {
|
|
1335 |
geometriesUned2.add(geometryToUnion);
|
|
1336 |
Value[] unionRow = new Value[unedLyrFieldNames.length+1];
|
|
1337 |
for (int k=0;k<lyrToUnionFieldNames.length-1;k++) {
|
|
1338 |
unionRow[k] = lyrToUnionDS.getFieldValue(i, k);
|
|
1339 |
}
|
|
1340 |
for (int k=0;k<uningLyrFieldNames.length-1;k++) {
|
|
1341 |
unionRow[k+l] = ValueFactory.createNullValue();
|
|
1342 |
}
|
|
1343 |
unionRow[unedLyrFieldNames.length] = ValueFactory.createValue(i);
|
|
1344 |
values.add(unionRow);
|
|
1345 |
}
|
|
1346 |
}
|
|
1347 |
// A?ado a geometriesUned2 las geometr?as de uningGeometries que no
|
|
1348 |
// intersectan con geometriesToUnion.
|
|
1349 |
for (int i=0;i<uningGeometries.length;i++) {
|
|
1350 |
Geometry uningGeometry = uningGeometries[i];
|
|
1351 |
boolean intersectsWithAnyGeometry = false;
|
|
1352 |
for (int j=0;j<geometriesUned.size();j++) {
|
|
1353 |
Geometry geometryUned = (Geometry)geometriesUned.get(j);
|
|
1354 |
if (uningGeometry.intersects(geometryUned)) intersectsWithAnyGeometry = true;
|
|
1355 |
}
|
|
1356 |
if (intersectsWithAnyGeometry) {
|
|
1357 |
//Geometry difference = jtsUningGeometry.difference(jtsGeometryUned);
|
|
1358 |
//jtsGeometriesUned2.add(difference);
|
|
1359 |
} else {
|
|
1360 |
geometriesUned2.add(uningGeometry);
|
|
1361 |
Value[] uningRow = new Value[unedLyrFieldNames.length+1];
|
|
1362 |
for (int k=0;k<lyrToUnionFieldNames.length-1;k++) {
|
|
1363 |
uningRow[k] = ValueFactory.createNullValue();
|
|
1364 |
}
|
|
1365 |
for (int k=0;k<uningLyrFieldNames.length-1;k++) {
|
|
1366 |
uningRow[k+l] = uningLyrDS.getFieldValue(i, k);
|
|
1367 |
}
|
|
1368 |
uningRow[unedLyrFieldNames.length] = ValueFactory.createValue(i);
|
|
1369 |
values.add(uningRow);
|
|
1370 |
}
|
|
1371 |
}
|
|
1372 |
//System.out.println("geometriesUned2.size() = " + geometriesUned2.size());
|
|
1373 |
// Le quito los cachos que ya tengo a las geometrias que faltan de
|
|
1374 |
// uningGeometries.
|
|
1375 |
BitSet bitSet1 = new BitSet();
|
|
1376 |
bitSet1.clear();
|
|
1377 |
//int k1=0;
|
|
1378 |
for (int i=0;i<geometriesUned2.size();i++) {
|
|
1379 |
Geometry geometryUned2 = (Geometry)geometriesUned2.get(i);
|
|
1380 |
for (int j=0;j<uningGeometries.length;j++) {
|
|
1381 |
//System.out.println("!(uningGeometries[j].equals(geometryUned2)) = " + !(uningGeometries[j].equals(geometryUned2)));
|
|
1382 |
if (uningGeometries[j].intersects(geometryUned2) && !(uningGeometries[j].equals(geometryUned2))) {
|
|
1383 |
uningGeometries[j] = uningGeometries[j].difference(geometryUned2);
|
|
1384 |
//bitSet1.set(k1);
|
|
1385 |
bitSet1.set(j);
|
|
1386 |
}
|
|
1387 |
//k1++;
|
|
1388 |
}
|
|
1389 |
}
|
|
1390 |
// Le quito los cachos que ya tengo a las geometrias que faltan de
|
|
1391 |
// geometriesToUnion.
|
|
1392 |
BitSet bitSet2 = new BitSet();
|
|
1393 |
bitSet2.clear();
|
|
1394 |
int k2=0;
|
|
1395 |
for (int i=0;i<geometriesUned2.size();i++) {
|
|
1396 |
Geometry geometryUned2 = (Geometry)geometriesUned2.get(i);
|
|
1397 |
for (int j=0;j<geometriesToUnion.length;j++) {
|
|
1398 |
//System.out.println("!(geometriesToUnion[j].equals(geometryUned2)) = " + !(geometriesToUnion[j].equals(geometryUned2)));
|
|
1399 |
if (geometriesToUnion[j].intersects(geometryUned2) && !(geometriesToUnion[j].equals(geometryUned2))) {
|
|
1400 |
geometriesToUnion[j] = geometriesToUnion[j].difference(geometryUned2);
|
|
1401 |
bitSet2.set(k2);
|
|
1402 |
//bitSet2.set(j);
|
|
1403 |
}
|
|
1404 |
k2++;
|
|
1405 |
}
|
|
1406 |
}
|
|
1407 |
//for (int i=0;i<bitSet2.size();i++) {
|
|
1408 |
// System.out.println("bitSet2.get(" + i + ") = " + bitSet2.get(i));
|
|
1409 |
//}
|
|
1410 |
// Ahora que les he quitado los cachos que ya ten?a, le meto los features que
|
|
1411 |
// faltaban de uningGeometries
|
|
1412 |
for (int i=0;i<uningGeometries.length;i++) {
|
|
1413 |
if (bitSet1.get(i)) {
|
|
1414 |
geometriesUned2.add(uningGeometries[i]);
|
|
1415 |
Value[] uningRow = new Value[unedLyrFieldNames.length+1];
|
|
1416 |
for (int k=0;k<lyrToUnionFieldNames.length-1;k++) {
|
|
1417 |
uningRow[k] = ValueFactory.createNullValue();
|
|
1418 |
}
|
|
1419 |
for (int k=0;k<uningLyrFieldNames.length-1;k++) {
|
|
1420 |
uningRow[k+l] = uningLyrDS.getFieldValue(i, k);
|
|
1421 |
}
|
|
1422 |
uningRow[unedLyrFieldNames.length] = ValueFactory.createValue(i);
|
|
1423 |
values.add(uningRow);
|
|
1424 |
}
|
|
1425 |
}
|
|
1426 |
// Ahora que les he quitado los cachos que ya ten?a, le meto los features que
|
|
1427 |
// faltaban de geometriesToUnion
|
|
1428 |
for (int i=0;i<geometriesToUnion.length;i++) {
|
|
1429 |
if (bitSet2.get(i)) {
|
|
1430 |
geometriesUned2.add(geometriesToUnion[i]);
|
|
1431 |
Value[] unionRow = new Value[unedLyrFieldNames.length+1];
|
|
1432 |
for (int k=0;k<lyrToUnionFieldNames.length-1;k++) {
|
|
1433 |
unionRow[k] = lyrToUnionDS.getFieldValue(i, k);
|
|
1434 |
}
|
|
1435 |
for (int k=0;k<uningLyrFieldNames.length-1;k++) {
|
|
1436 |
unionRow[k+l] = ValueFactory.createNullValue();
|
|
1437 |
}
|
|
1438 |
unionRow[unedLyrFieldNames.length] = ValueFactory.createValue(i);
|
|
1439 |
values.add(unionRow);
|
|
1440 |
}
|
|
1441 |
}
|
|
1442 |
//selectable.setSelection(fBitSet);
|
|
1443 |
result = new Geometry[geometriesUned2.size()];
|
|
1444 |
for (int i=0;i<geometriesUned2.size();i++) {
|
|
1445 |
result[i] = (Geometry)geometriesUned2.get(i);
|
|
1446 |
}
|
|
1447 |
|
|
1448 |
for (int i=0;i<result.length;i++) {
|
|
1449 |
dw.insertFilledRow(((Value[])values.get(i)));
|
|
1450 |
}
|
|
1451 |
dw.commitTrans();
|
|
1452 |
|
|
1453 |
IGeometry[] shapes = getFmapGeometries(result);
|
|
1454 |
// Guardo la tabla mediante gdbms. Guardo tambi?n las entidades JTS mediante gvSIG o usando solo gdbms (probablemente bastar? con usar gdbms)
|
|
1455 |
GeoProcessingPersistenceOperations.saveResultsToShapeFile(shapes, geoProcessingUnionPanel.getOutputFile());
|
|
1456 |
} catch (DriverException e) {
|
|
1457 |
// TODO Auto-generated catch block
|
|
1458 |
e.printStackTrace();
|
|
1459 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
|
1460 |
// TODO Auto-generated catch block
|
|
1461 |
e.printStackTrace();
|
|
1462 |
} catch (DriverLoadException e) {
|
|
1463 |
// TODO Auto-generated catch block
|
|
1464 |
e.printStackTrace();
|
|
1465 |
} catch (NoSuchTableException e) {
|
|
1466 |
// TODO Auto-generated catch block
|
|
1467 |
e.printStackTrace();
|
|
1468 |
}
|
779 |
1469 |
}
|
780 |
|
private void spatialjoinMethod() {
|
781 |
|
String layerToSJoinName = (String)((JComboBox)geoProcessingSpatialjoinPanel.getComponent(0)).getSelectedItem();
|
782 |
|
FLayer layerToSJoin = layers.getLayer(layerToSJoinName);
|
783 |
|
boolean selected = false;
|
784 |
|
if (((JCheckBox)geoProcessingSpatialjoinPanel.getComponent(1)).isSelected()) selected = true;
|
785 |
|
Geometry[] geometriesToSJoin = getJtsGeometries(layerToSJoin, selected);
|
786 |
|
//Geometry[] sJoinGeometries = geometriesToSJoin;
|
787 |
|
IGeometry[] shapes = getFmapGeometries(geometriesToSJoin);
|
788 |
|
// Guardo la tabla mediante gdbms. Guardo tambi?n las entidades JTS mediante gvSIG o usando solo gdbms (probablemente bastar? con usar gdbms)
|
789 |
|
GeoProcessingPersistenceOperations.saveResultsToShapeFile(shapes, geoProcessingSpatialjoinPanel.getOutputFile());
|
790 |
|
}
|
791 |
1470 |
public double[] getBufferDistancesFromTable(FLayer bufferingLayer) {
|
792 |
1471 |
AlphanumericData lyr = (AlphanumericData)bufferingLayer;
|
793 |
1472 |
DataSource ds;
|
... | ... | |
798 |
1477 |
Value[] fieldValues = new Value[(int)ds.getRowCount()];
|
799 |
1478 |
SelectableDataSource selectableDataSource = (SelectableDataSource)ds;
|
800 |
1479 |
FBitSet fBitSet = selectableDataSource.getSelection();
|
|
1480 |
if (fBitSet.cardinality()==0) {
|
|
1481 |
fBitSet.set(0, (int)lyr.getRecordset().getRowCount());
|
|
1482 |
}
|
801 |
1483 |
Value[] valuesSelected = new Value[fBitSet.cardinality()];
|
802 |
1484 |
int j = 0;
|
803 |
1485 |
for (int i=0;i<ds.getRowCount();i++) {
|