Revision 41342 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.csv/src/main/java/org/gvsig/fmap/dal/store/csv/CSVStoreProvider.java
CSVStoreProvider.java | ||
---|---|---|
748 | 748 |
|
749 | 749 |
private static final Logger logger = LoggerFactory.getLogger(ToPointEvaluaror.class); |
750 | 750 |
|
751 |
private static final int XNAME = 0; |
|
752 |
private static final int YNAME = 1; |
|
753 |
private static final int ZNAME = 2; |
|
754 |
|
|
751 | 755 |
private final GeometryManager geommgr; |
752 |
private final String xname; |
|
753 |
private final String yname; |
|
754 |
private final String zname; |
|
756 |
private final String[] fieldNames; |
|
755 | 757 |
private final Coercion toDouble; |
756 | 758 |
private final DataType dataType; |
757 | 759 |
private int errorcount = 0; |
758 | 760 |
|
759 | 761 |
public PointAttributeEmulator(String[] pointDimensionNames) { |
760 |
this.xname = pointDimensionNames[0]; |
|
761 |
this.yname = pointDimensionNames[1]; |
|
762 | 762 |
if ( pointDimensionNames.length > 2 ) { |
763 |
this.zname = pointDimensionNames[2]; |
|
763 |
this.fieldNames = new String[3]; |
|
764 |
this.fieldNames[ZNAME] = pointDimensionNames[2]; |
|
764 | 765 |
} else { |
765 |
this.zname = null;
|
|
766 |
this.fieldNames = new String[2];
|
|
766 | 767 |
} |
768 |
this.fieldNames[XNAME] = pointDimensionNames[0]; |
|
769 |
this.fieldNames[YNAME] = pointDimensionNames[1]; |
|
767 | 770 |
this.geommgr = GeometryLocator.getGeometryManager(); |
768 | 771 |
DataTypesManager datatypeManager = ToolsLocator.getDataTypesManager(); |
769 | 772 |
|
... | ... | |
773 | 776 |
|
774 | 777 |
public Object get(Feature feature) { |
775 | 778 |
try { |
776 |
double x = ((Double) toDouble.coerce(feature.get(xname))).doubleValue(); |
|
777 |
double y = ((Double) toDouble.coerce(feature.get(yname))).doubleValue(); |
|
779 |
Object value = feature.get(this.fieldNames[XNAME]); |
|
780 |
double x = ((Double) toDouble.coerce(value)).doubleValue(); |
|
781 |
double y = ((Double) toDouble.coerce(feature.get(this.fieldNames[YNAME]))).doubleValue(); |
|
778 | 782 |
Point point = geommgr.createPoint(x, y, Geometry.SUBTYPES.GEOM3D); |
779 |
if ( zname != null ) {
|
|
780 |
double z = ((Double) toDouble.coerce(feature.get(zname))).doubleValue();
|
|
783 |
if( this.fieldNames.length>2 ) {
|
|
784 |
double z = ((Double) toDouble.coerce(feature.get(this.fieldNames[ZNAME]))).doubleValue();
|
|
781 | 785 |
point.setCoordinateAt(2, z); |
782 | 786 |
} |
783 | 787 |
return point; |
784 | 788 |
} catch (Exception ex) { |
785 | 789 |
if ( ++errorcount < 5 ) { |
786 | 790 |
logger.warn("[" + errorcount + "] Can't create point in CSV provider. XNAME='" |
787 |
+ xname + "', YNAME='" + yname + "', ZNAME='" + zname + "', feature=" + feature.toString());
|
|
791 |
+ this.fieldNames[XNAME] + "', YNAME='" + this.fieldNames[XNAME] + "' feature=" + feature.toString(),ex);
|
|
788 | 792 |
} |
789 | 793 |
return null; |
790 | 794 |
} |
... | ... | |
800 | 804 |
} else { |
801 | 805 |
point = (Point) value; |
802 | 806 |
} |
803 |
feature.set(xname, point.getX());
|
|
804 |
feature.set(yname, point.getY());
|
|
805 |
if( zname != null ) {
|
|
806 |
feature.set(yname, point.getCoordinateAt(2));
|
|
807 |
feature.set(this.fieldNames[XNAME], point.getX());
|
|
808 |
feature.set(this.fieldNames[YNAME], point.getY());
|
|
809 |
if( this.fieldNames.length>2 ) {
|
|
810 |
feature.set(this.fieldNames[ZNAME], point.getCoordinateAt(2));
|
|
807 | 811 |
} |
808 | 812 |
} |
809 | 813 |
|
810 | 814 |
public boolean allowSetting() { |
811 | 815 |
return true; |
812 | 816 |
} |
817 |
|
|
818 |
public String[] getRequiredFieldNames() { |
|
819 |
return this.fieldNames; |
|
820 |
} |
|
821 |
|
|
822 |
|
|
813 | 823 |
} |
814 | 824 |
|
815 | 825 |
static class ToPointEvaluaror extends AbstractEvaluator { |
Also available in: Unified diff