Revision: 4341
http://sourceforge.net/p/jump-pilot/code/4341
Author: michaudm
Date: 2015-03-16 23:03:34 +0000 (Mon, 16 Mar 2015)
Log Message:
-----------
Change integer field length in dbf file format (length = 3,6,9,12,15,18, +
according to real data length). Integer with more than 9 digits are interpreted
as long.
Modified Paths:
--------------
core/trunk/src/com/vividsolutions/jump/io/ShapefileWriter.java
core/trunk/src/com/vividsolutions/jump/workbench/ui/AttributeTablePanel.java
core/trunk/src/org/geotools/dbffile/DbfFile.java
Modified: core/trunk/src/com/vividsolutions/jump/io/ShapefileWriter.java
===================================================================
--- core/trunk/src/com/vividsolutions/jump/io/ShapefileWriter.java
2015-03-15 22:10:27 UTC (rev 4340)
+++ core/trunk/src/com/vividsolutions/jump/io/ShapefileWriter.java
2015-03-16 23:03:34 UTC (rev 4341)
@@ -437,18 +437,46 @@
if (columnType == AttributeType.INTEGER ||
columnType == AttributeType.SMALLINT ||
columnType == AttributeType.TINYINT) {
- fields[f] = new DbfFieldDef(columnName, 'N', 11, 0); //LDB:
previously 16
+ int maxlength = findMaxStringLength(featureCollection, t);
+ if (maxlength <= 3) fields[f] = new DbfFieldDef(columnName,
'N', 3, 0);
+ else if (maxlength <= 6) fields[f] = new
DbfFieldDef(columnName, 'N', 6, 0);
+ else if (maxlength <= 9) fields[f] = new
DbfFieldDef(columnName, 'N', 9, 0);
+ else fields[f] = new DbfFieldDef(columnName, 'N', maxlength,
0);
DbfFieldDef fromFile =
overrideWithExistingCompatibleDbfFieldDef(fields[f], fieldMap);
if (fromFile.fieldnumdec == 0)
fields[f] = fromFile;
f++;
- } else if (columnType == AttributeType.LONG || columnType ==
AttributeType.BIGINT) {
- fields[f] = new DbfFieldDef(columnName, 'N', 21, 0);
+ }
+
+ else if (columnType == AttributeType.LONG ||
+ columnType == AttributeType.BIGINT) {
+ int maxlength = findMaxStringLength(featureCollection, t);
+ if (maxlength <= 12) fields[f] = new DbfFieldDef(columnName,
'N', 12, 0);
+ else if (maxlength <= 15) fields[f] = new
DbfFieldDef(columnName, 'N', 15, 0);
+ else if (maxlength <= 18) fields[f] = new
DbfFieldDef(columnName, 'N', 18, 0);
+ else fields[f] = new DbfFieldDef(columnName, 'N', maxlength,
0);
DbfFieldDef fromFile =
overrideWithExistingCompatibleDbfFieldDef(fields[f], fieldMap);
if (fromFile.fieldnumdec == 0)
fields[f] = fromFile;
f++;
- } else if (columnType == AttributeType.DOUBLE ||
+ }
+
+ //if (columnType == AttributeType.INTEGER ||
+ // columnType == AttributeType.SMALLINT ||
+ // columnType == AttributeType.TINYINT) {
+ // fields[f] = new DbfFieldDef(columnName, 'N', 11, 0); //LDB:
previously 16
+ // DbfFieldDef fromFile =
overrideWithExistingCompatibleDbfFieldDef(fields[f], fieldMap);
+ // if (fromFile.fieldnumdec == 0)
+ // fields[f] = fromFile;
+ // f++;
+ //} else if (columnType == AttributeType.LONG || columnType ==
AttributeType.BIGINT) {
+ // fields[f] = new DbfFieldDef(columnName, 'N', 21, 0);
+ // DbfFieldDef fromFile =
overrideWithExistingCompatibleDbfFieldDef(fields[f], fieldMap);
+ // if (fromFile.fieldnumdec == 0)
+ // fields[f] = fromFile;
+ // f++;
+ //}
+ else if (columnType == AttributeType.DOUBLE ||
columnType == AttributeType.REAL ||
columnType == AttributeType.FLOAT ||
columnType == AttributeType.NUMERIC ||
@@ -706,6 +734,7 @@
return Math.max(1, maxlen); //LDB: don't allow zero length strings
}
+
/**
* Find the generic geometry type of the feature collection.
* Simple method - find the 1st non null geometry and its type
Modified:
core/trunk/src/com/vividsolutions/jump/workbench/ui/AttributeTablePanel.java
===================================================================
---
core/trunk/src/com/vividsolutions/jump/workbench/ui/AttributeTablePanel.java
2015-03-15 22:10:27 UTC (rev 4340)
+++
core/trunk/src/com/vividsolutions/jump/workbench/ui/AttributeTablePanel.java
2015-03-16 23:03:34 UTC (rev 4341)
@@ -38,6 +38,9 @@
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.image.BufferedImage;
+import java.math.BigDecimal;
+import java.sql.Time;
+import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -193,6 +196,24 @@
else setText(formatter.format(value));
}
});
+ setDefaultRenderer(Time.class, new DefaultTableCellRenderer() {
+ public void setValue(Object value) {
+ if (value == null) {
+ setIcon(nullString);
+ setHorizontalAlignment(SwingConstants.CENTER);
+ }
+ else setText(formatter.format(value));
+ }
+ });
+ setDefaultRenderer(Timestamp.class, new
DefaultTableCellRenderer() {
+ public void setValue(Object value) {
+ if (value == null) {
+ setIcon(nullString);
+ setHorizontalAlignment(SwingConstants.CENTER);
+ }
+ else setText(formatter.format(value));
+ }
+ });
// Set default editor here too, as we want date display and
date editing
// to be synchronized
setDefaultEditor(Date.class, new
FlexibleDateParser.CellEditor(formatter));
@@ -214,6 +235,15 @@
else setText(value.toString());
}
});
+ setDefaultRenderer(Long.class, new DefaultTableCellRenderer() {
+ public void setValue(Object value) {
+ if (value == null) {
+ setIcon(nullString);
+ setHorizontalAlignment(SwingConstants.CENTER);
+ }
+ else setText(value.toString());
+ }
+ });
setDefaultRenderer(Double.class, new
DefaultTableCellRenderer() {
public void setValue(Object value) {
if (value == null) {
@@ -223,6 +253,15 @@
else setText(value.toString());
}
});
+ setDefaultRenderer(BigDecimal.class, new
DefaultTableCellRenderer() {
+ public void setValue(Object value) {
+ if (value == null) {
+ setIcon(nullString);
+ setHorizontalAlignment(SwingConstants.CENTER);
+ }
+ else setText(value.toString());
+ }
+ });
if
(AttributeTablePanel.this.getModel().getLayer().isEditable()
&&
!AttributeTablePanel.this.getModel()
Modified: core/trunk/src/org/geotools/dbffile/DbfFile.java
===================================================================
--- core/trunk/src/org/geotools/dbffile/DbfFile.java 2015-03-15 22:10:27 UTC
(rev 4340)
+++ core/trunk/src/org/geotools/dbffile/DbfFile.java 2015-03-16 23:03:34 UTC
(rev 4341)
@@ -135,7 +135,7 @@
case 'N':
if (fielddef[col].fieldnumdec == 0) {
- if (fielddef[col].fieldlen > 11) {
+ if (fielddef[col].fieldlen > 9) {
realtype = "LONG";
} else {
realtype = "INTEGER";
@@ -293,7 +293,7 @@
// fields of type 'F' are always represented as Doubles
boolean isInteger = fielddef[wantedCol].fieldnumdec == 0
&& fielddef[wantedCol].fieldtype == 'N';
- boolean isLong = isInteger && fielddef[wantedCol].fieldlen >
11;
+ boolean isLong = isInteger && fielddef[wantedCol].fieldlen > 9;
// The number field should be trimed from the start AND the
end.
// Added .trim() to 'String numb = rec.substring(start, end)'
instead. [Kevin Neufeld]
@@ -377,14 +377,14 @@
try {
String tt = t.substring(fielddef[i].fieldstart,
fielddef[i].fieldstart + fielddef[i].fieldlen);
- if (fielddef[i].fieldlen > 11) {
+ if (fielddef[i].fieldlen > 9) {
record.addElement(Long.parseLong(tt.trim()));
}
else {
record.addElement(Integer.parseInt(tt.trim()));
}
} catch (java.lang.NumberFormatException e) {
- if (fielddef[i].fieldlen > 11) {
+ if (fielddef[i].fieldlen > 9) {
record.addElement(null);
} else {
record.addElement(null);
------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Jump-pilot-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel