You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2014/10/24 19:28:30 UTC
svn commit: r1634099 [3/3] - in /sis/branches/JDK6: ./
application/sis-javafx/
core/sis-build-helper/src/main/java/org/apache/sis/util/resources/
core/sis-build-helper/src/test/
core/sis-feature/src/main/java/org/apache/sis/feature/ core/sis-feature/sr...
Modified: sis/branches/JDK6/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/DataType.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/DataType.java?rev=1634099&r1=1634098&r2=1634099&view=diff
==============================================================================
--- sis/branches/JDK6/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/DataType.java [UTF-8] (original)
+++ sis/branches/JDK6/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/DataType.java [UTF-8] Fri Oct 24 17:28:28 2014
@@ -21,40 +21,79 @@ package org.apache.sis.storage.shapefile
* Provides a simple DataType class.
*
* @author Travis L. Pinney
- * @since 0.4
- * @version 0.4
+ * @since 0.5
+ * @version 0.5
* @module
*
* @see <a href="http://www.clicketyclick.dk/databases/xbase/format/data_types.html">Xbase Data Types</a>
*/
public enum DataType {
+ /** Character (less than 254 characters). */
+ Character('C'),
+
+ /** Number (less than 18 characters, can include sign and decimal). */
+ Number('N'),
+
+ /** Logical (3 way, ? Y,y,T,t N,n,F,f). */
+ Logical('L'),
+
+ /** Date (YYYYMMDD format). */
+ Date('D'),
+
+ /** Memo (Pointer to ASCII text field). */
+ Memo('M'),
+
+ /** Floating point (20 digits). */
+ FloatingPoint('F'),
- Character('C'), // < 254 characters
- Number('N'), // < 18 characters, can include sign and decimal
- Logical('L'), // 3 way, ? Y,y,T,t N,n,F,f
- Date('D'), // YYYYMMDD
- Memo('M'), // Pointer to ASCII text field
- FloatingPoint('F'), // 20 digits
// CharacterNameVariable("?"), //1-254 Characters
- Picture('P'), // Memo
- Currency('Y'), // Foxpro
- DateTime('T'), // 32 bit little-endian Julian date, 32 byte little endian milliseconds since midnight
- Integer('I'), // 4 byte little endian
- VariField('V'), // ???
- Variant('X'), // ???
- TimeStamp('@'), // see url
- Double('O'), //
- AutoIncrement('+'); // ???
+ /** Picture (memo). */
+ Picture('P'),
+
+ /** Currency (Foxpro). */
+ Currency('Y'),
+
+ /** Date time (32 bit little-endian Julian date, 32 byte little endian milliseconds since midnight). */
+ DateTime('T'),
+
+ /** Integer (4 byte little endian). */
+ Integer('I'),
+
+ /** Varifield (???). */
+ VariField('V'),
+
+ /** Variant (???). */
+ Variant('X'),
+
+ /** Time stamp (see url). */
+ TimeStamp('@'),
+
+ /** Double. */
+ Double('O'),
+
+ /** Auto increment. */
+ AutoIncrement('+');
+
+ /** Data type. */
public final char datatype;
- DataType(char datatype) {
- this.datatype = datatype;
+ /**
+ * Construct a datatype.
+ * @param type Data type.
+ */
+ DataType(char type) {
+ this.datatype = type;
}
- public static DataType valueOfDataType(char datatype) {
+ /**
+ * Return the Datatype enum of a code.
+ * @param code Character code describing the dbf datatype.
+ * @return Datatype.
+ */
+ public static DataType valueOfDataType(char code) {
for (DataType v : values()) {
- if (v.datatype == datatype) {
+ if (v.datatype == code) {
return v;
}
}
Copied: sis/branches/JDK6/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/Database.java (from r1634098, sis/branches/JDK7/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/Database.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/Database.java?p2=sis/branches/JDK6/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/Database.java&p1=sis/branches/JDK7/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/Database.java&r1=1634098&r2=1634099&rev=1634099&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/Database.java [UTF-8] (original)
+++ sis/branches/JDK6/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/Database.java [UTF-8] Fri Oct 24 17:28:28 2014
@@ -23,6 +23,9 @@ import java.util.*;
import org.opengis.feature.*;
+// Branch-dependent imports
+import org.apache.sis.internal.jdk7.Objects;
+
/**
* Load a whole DBF file.
*
@@ -33,7 +36,7 @@ import org.opengis.feature.*;
*
* @see <a href="http://ulisse.elettra.trieste.it/services/doc/dbase/DBFstruct.htm" >Database structure</a>
*/
-public class Database implements AutoCloseable {
+public class Database {
/** Database filename. */
private String m_dbfFile;
@@ -59,7 +62,7 @@ public class Database implements AutoClo
public byte[] DbasePlusLanReserved = new byte[13];
/** Fields descriptor. */
- public ArrayList<FieldDescriptor> fieldsDescriptors = new ArrayList<>();
+ public ArrayList<FieldDescriptor> fieldsDescriptors = new ArrayList<FieldDescriptor>();
/** Input Stream on the DBF. */
private FileInputStream fis;
@@ -149,7 +152,7 @@ public class Database implements AutoClo
df.get(); // denotes whether deleted or current
// read first part of record
- HashMap<String, Object> fieldsValues = new HashMap<>();
+ HashMap<String, Object> fieldsValues = new HashMap<String, Object>();
for (FieldDescriptor fd : this.fieldsDescriptors) {
byte[] data = new byte[fd.getLength()];
@@ -247,7 +250,7 @@ public class Database implements AutoClo
/**
* @see java.lang.AutoCloseable#close()
*/
- @Override
+ // No @Override on JDK6
public void close() throws IOException {
if (fc != null)
fc.close();
Modified: sis/branches/JDK6/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/FieldDescriptor.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/FieldDescriptor.java?rev=1634099&r1=1634098&r2=1634099&view=diff
==============================================================================
--- sis/branches/JDK6/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/FieldDescriptor.java [UTF-8] (original)
+++ sis/branches/JDK6/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/FieldDescriptor.java [UTF-8] Fri Oct 24 17:28:28 2014
@@ -18,26 +18,43 @@ package org.apache.sis.storage.shapefile
/**
+ * Field descriptor.
*
* @author Travis L. Pinney
- * @since 0.4
- * @version 0.4
+ * @since 0.5
+ * @version 0.5
* @module
*/
public class FieldDescriptor {
-
+ /** Field name. */
public byte[] FieldName = new byte[11];
+
+ /** Field type. */
public DataType FieldType;
+
public byte[] FieldAddress = new byte[4];
+
+ /** Field length. */
public byte FieldLength;
+
+ /** Decimal count. */
public byte FieldDecimalCount;
+
+ /** Reserved 2. */
public byte[] DbasePlusLanReserved2 = new byte[2];
+
+ /** Work area id. */
public byte WorkAreaID;
- public byte[] DbasePlusLanReserved3 = new byte[2];
- public byte SetFields;
+ /** Reserved 3. */
+ public byte[] DbasePlusLanReserved3 = new byte[2];
+ public byte SetFields;
+ /**
+ * Return the field name.
+ * @return Field name.
+ */
public String getName() {
int length = FieldName.length;
while (length != 0 && FieldName[length - 1] <= ' ') {
@@ -46,10 +63,17 @@ public class FieldDescriptor {
return new String(this.FieldName, 0, length);
}
+ /**
+ * Return the field length.
+ * @return field length.
+ */
public int getLength() {
return this.FieldLength & 0xFF;
}
+ /**
+ * @see java.lang.Object#toString()
+ */
@Override
public String toString() {
Modified: sis/branches/JDK6/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/ShapeFile.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/ShapeFile.java?rev=1634099&r1=1634098&r2=1634099&view=diff
==============================================================================
--- sis/branches/JDK6/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/ShapeFile.java [UTF-8] (original)
+++ sis/branches/JDK6/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/ShapeFile.java [UTF-8] Fri Oct 24 17:28:28 2014
@@ -21,9 +21,9 @@ import java.nio.ByteOrder;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.io.FileInputStream;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
+import java.text.MessageFormat;
import com.esri.core.geometry.Point;
import com.esri.core.geometry.Polygon;
import com.esri.core.geometry.Polyline;
@@ -34,9 +34,9 @@ import org.apache.sis.feature.DefaultAtt
import org.apache.sis.storage.DataStoreException;
// Branch-dependent imports
+import org.apache.sis.internal.jdk7.Objects;
import org.opengis.feature.Feature;
-
/**
* Provides a ShapeFile Reader.
*
@@ -49,232 +49,289 @@ import org.opengis.feature.Feature;
* @see <a href="http://ulisse.elettra.trieste.it/services/doc/dbase/DBFstruct.htm">dBASE III File Structure</a>
*/
public class ShapeFile {
+ /** Name of the Geometry field. */
private static final String GEOMETRY_NAME = "geometry";
- public int FileCode; // big
- public int FileLength; // big // The value for file length is the total length of the file in 16-bit words
+ /** File code. */
+ public int FileCode; // big
+
+ /** File length. */
+ public int FileLength; // big // The value for file length is the total length of the file in 16-bit words
+
+ /** File version. */
public int Version; // little
+
+ /** Shapefile type. */
public ShapeTypeEnum ShapeType; // little
+
+ /** X Min. */
public double xmin; // little
+
+ /** Y Min. */
public double ymin; // little
+
+ /** X Max. */
public double xmax; // little
+
+ /** Y Max. */
public double ymax; // little
+
+ /** Z Min. */
public double zmin; // little
+
+ /** Z Max. */
public double zmax; // little
+
+ /** M Min. */
public double mmin; // little
- public double mmax; // little
+ /** M Max. */
+ public double mmax; // little
- // http://ulisse.elettra.trieste.it/services/doc/dbase/DBFstruct.htm
- public byte DbaseVersion;
- public byte[] DbaseLastUpdate = new byte[3];
- public int FeatureCount;
- public short DbaseHeaderBytes;
- public short DbaseRecordBytes;
- // reserve 3 bytes
- public byte[] DbasePlusLanReserved = new byte[13];
- // reserve 4 bytes
+ /** Underlying databasefile content. */
+ private Database dbf;
- public ArrayList<FieldDescriptor> FDArray = new ArrayList<FieldDescriptor>();
+ /** Features existing in the shapefile. */
public Map<Integer, Feature> FeatureMap = new HashMap<Integer, Feature>();
+ /**
+ * Construct a Shapefile from a file.
+ * @param shpfile file to read.
+ * @throws IOException if the file cannot be opened.
+ * @throws DataStoreException if the shapefile is not valid.
+ */
+ public ShapeFile(String shpfile) throws IOException, DataStoreException {
+ Objects.requireNonNull(shpfile, "The shapefile to load cannot be null.");
+
+ // Deduct database file name.
+ StringBuilder b = new StringBuilder(shpfile);
+ b.replace(shpfile.length() - 3, shpfile.length(), "dbf");
+ dbf = new Database(b.toString());
- public ShapeFile(String shpfile) throws IOException, DataStoreException {
FileInputStream fis = new FileInputStream(shpfile);
FileChannel fc = fis.getChannel();
- int fsize = (int) fc.size();
- MappedByteBuffer rf = fc.map(FileChannel.MapMode.READ_ONLY, 0, fsize);
-
- this.FileCode = rf.getInt();
- rf.getInt(); rf.getInt(); rf.getInt(); rf.getInt(); rf.getInt();
- this.FileLength = rf.getInt() * 2;
-
- byte [] data = new byte[4];
-
- rf.order(ByteOrder.LITTLE_ENDIAN);
- this.Version = rf.getInt();
- this.ShapeType = ShapeTypeEnum.get(rf.getInt());
- this.xmin = rf.getDouble();
- this.ymin = rf.getDouble();
- this.xmax = rf.getDouble();
- this.ymax = rf.getDouble();
- this.zmin = rf.getDouble();
- this.zmax = rf.getDouble();
- this.mmin = rf.getDouble();
- this.mmax = rf.getDouble();
- rf.order(ByteOrder.BIG_ENDIAN);
+ try {
+ int fsize = (int) fc.size();
+ MappedByteBuffer rf = fc.map(FileChannel.MapMode.READ_ONLY, 0, fsize);
+
+ this.FileCode = rf.getInt();
+ rf.getInt();
+ rf.getInt();
+ rf.getInt();
+ rf.getInt();
+ rf.getInt();
+ this.FileLength = rf.getInt() * 2;
- StringBuilder b = new StringBuilder(shpfile);
- b.replace(shpfile.length() - 3, shpfile.length() , "dbf");
- String file_base = b.toString();
+ rf.order(ByteOrder.LITTLE_ENDIAN);
+ this.Version = rf.getInt();
+ this.ShapeType = ShapeTypeEnum.get(rf.getInt());
+ this.xmin = rf.getDouble();
+ this.ymin = rf.getDouble();
+ this.xmax = rf.getDouble();
+ this.ymax = rf.getDouble();
+ this.zmin = rf.getDouble();
+ this.zmax = rf.getDouble();
+ this.mmin = rf.getDouble();
+ this.mmax = rf.getDouble();
+ rf.order(ByteOrder.BIG_ENDIAN);
- FileInputStream fis2 = new FileInputStream(file_base);
- FileChannel fc2 = fis2.getChannel();
- int fsize2 = (int) fc2.size();
- MappedByteBuffer df = fc2.map(FileChannel.MapMode.READ_ONLY, 0, fsize2);
-
- this.DbaseVersion = df.get();
- df.get(this.DbaseLastUpdate);
-
- df.order(ByteOrder.LITTLE_ENDIAN);
- this.FeatureCount = df.getInt();
- this.DbaseHeaderBytes = df.getShort();
- this.DbaseRecordBytes = df.getShort();
- df.order(ByteOrder.BIG_ENDIAN);
- df.getShort(); // reserved
- df.get(); // reserved
- df.get(DbasePlusLanReserved);
- df.getInt();
-
- while(df.position() < this.DbaseHeaderBytes - 1) {
- FieldDescriptor fd = new FieldDescriptor();
- df.get(fd.FieldName);
- char dt = (char) df.get();
- fd.FieldType = DataType.valueOfDataType(dt);
- df.get(fd.FieldAddress);
- fd.FieldLength = df.get();
- fd.FieldDecimalCount = df.get();
- df.getShort(); // reserved
- df.get(fd.DbasePlusLanReserved2);
- fd.WorkAreaID = df.get();
- df.get(fd.DbasePlusLanReserved3);
- fd.SetFields = df.get();
- data = new byte[6];
- df.get(data); // reserved
+ dbf.loadDescriptor();
+ final DefaultFeatureType featureType = getFeatureType(shpfile);
- this.FDArray.add(fd);
- // loop until you hit the 0Dh field terminator
+ dbf.getByteBuffer().get(); // should be 0d for field terminator
+ loadFeatures(featureType, rf);
+ } finally {
+ dbf.close();
+ fc.close();
+ fis.close();
}
- final DefaultFeatureType featureType = getFeatureType(shpfile);
+ }
- df.get(); // should be 0d for field terminator
+ /**
+ * Returns the underlying database file.
+ * @return Underlying database file.
+ */
+ public Database getDatabase() {
+ return this.dbf;
+ }
- for (Integer i = 0; i < this.FeatureCount; i++) {
+ /**
+ * Returns the feature count of the shapefile.
+ * @return Feature count.
+ */
+ public int getFeatureCount() {
+ return this.dbf.getRecordCount();
+ }
+
+ /**
+ * Load the features of a shapefile.
+ * @param featureType Features descriptor.
+ * @param rf byte buffer mapper.
+ * @throws DataStoreException if a validation problem occurs.
+ */
+ private void loadFeatures(DefaultFeatureType featureType, MappedByteBuffer rf) throws DataStoreException {
+ for (Integer i = 0; i < this.dbf.getRecordCount(); i++) {
// insert points into some type of list
int RecordNumber = rf.getInt();
+ @SuppressWarnings("unused")
int ContentLength = rf.getInt();
- data = new byte[4];
rf.order(ByteOrder.LITTLE_ENDIAN);
- int ShapeType = rf.getInt();
+ int iShapeType = rf.getInt();
final Feature f = featureType.newInstance();
- if (ShapeType == ShapeTypeEnum.Point.getValue()) {
- double x = rf.getDouble();
- double y = rf.getDouble();
- Point pnt = new Point(x,y);
- f.setPropertyValue(GEOMETRY_NAME, pnt);
-
- } else if (ShapeType == ShapeTypeEnum.Polygon.getValue()) {
- double xmin = rf.getDouble();
- double ymin = rf.getDouble();
- double xmax = rf.getDouble();
- double ymax = rf.getDouble();
- int NumParts = rf.getInt();
- int NumPoints = rf.getInt();
-
- if (NumParts > 1) {
- throw new DataStoreException("Polygons with multiple linear rings have not implemented yet.");
- }
-
- // read the one part
- int Part = rf.getInt();
- Polygon poly = new Polygon();
-
- // create a line from the points
- double xpnt = rf.getDouble();
- double ypnt = rf.getDouble();
- //Point oldpnt = new Point(xpnt, ypnt);
- poly.startPath(xpnt, ypnt);
- for (int j=0; j < NumPoints-1; j++) {
- xpnt = rf.getDouble();
- ypnt = rf.getDouble();
- poly.lineTo(xpnt, ypnt);
- }
- f.setPropertyValue(GEOMETRY_NAME, poly);
-
- } else if (ShapeType == ShapeTypeEnum.PolyLine.getValue()) {
- double xmin = rf.getDouble();
- double ymin = rf.getDouble();
- double xmax = rf.getDouble();
- double ymax = rf.getDouble();
-
- int NumParts = rf.getInt();
- int NumPoints = rf.getInt();
-
- int [] NumPartArr = new int[NumParts+1];
-
- for (int n=0; n < NumParts; n++) {
- int idx = rf.getInt();
- NumPartArr[n] = idx;
- }
- NumPartArr[NumParts] = NumPoints;
-
- data = new byte[8];
-
- double xpnt, ypnt;
- Polyline ply = new Polyline();
-
- for (int m=0; m < NumParts; m++) {
- xpnt = rf.getDouble();
- ypnt = rf.getDouble();
- ply.startPath(xpnt, ypnt);
-
- for (int j=NumPartArr[m]; j < NumPartArr[m+1] - 1; j++) {
- xpnt = rf.getDouble();
- ypnt = rf.getDouble();
- ply.lineTo(xpnt, ypnt);
- }
- }
+ ShapeTypeEnum type = ShapeTypeEnum.get(iShapeType);
+
+ if (type == null)
+ throw new DataStoreException(MessageFormat.format("The shapefile feature type {0} doesn''t match to any known feature type.", featureType));
- f.setPropertyValue(GEOMETRY_NAME, ply);
+ switch (type) {
+ case Point:
+ loadPointFeature(rf, f);
+ break;
+
+ case Polygon:
+ loadPolygonFeature(rf, f);
+ break;
+
+ case PolyLine:
+ loadPolylineFeature(rf, f);
+ break;
- } else {
- throw new DataStoreException("Unsupported shapefile type: " + this.ShapeType);
+ default:
+ throw new DataStoreException("Unsupported shapefile type: " + iShapeType);
}
rf.order(ByteOrder.BIG_ENDIAN);
// read in each Record and Populate the Feature
- // TODO: ignore deleted records
- df.get(); // denotes whether deleted or current
- // read first part of record
-
- for (FieldDescriptor fd: this.FDArray) {
- data = new byte[fd.getLength()];
- df.get(data);
- int length = data.length;
- while (length != 0 && data[length - 1] <= ' ') {
- length--;
- }
- String value = new String(data, 0, length);
- f.setPropertyValue(fd.getName(), value);
- }
+ dbf.loadRowIntoFeature(f);
this.FeatureMap.put(RecordNumber, f);
}
+ }
+
+ /**
+ * Load point feature.
+ * @param rf Byte buffer.
+ * @param feature Feature to fill.
+ */
+ private void loadPointFeature(MappedByteBuffer rf, Feature feature) {
+ double x = rf.getDouble();
+ double y = rf.getDouble();
+ Point pnt = new Point(x, y);
+ feature.setPropertyValue(GEOMETRY_NAME, pnt);
+ }
+
+ /**
+ * Load polygon feature.
+ * @param rf Byte buffer.
+ * @param feature Feature to fill.
+ * @throws DataStoreException if the polygon cannot be handled.
+ */
+ private void loadPolygonFeature(MappedByteBuffer rf, Feature feature) throws DataStoreException {
+ /* double xmin = */rf.getDouble();
+ /* double ymin = */rf.getDouble();
+ /* double xmax = */rf.getDouble();
+ /* double ymax = */rf.getDouble();
+ int NumParts = rf.getInt();
+ int NumPoints = rf.getInt();
+
+ if (NumParts > 1) {
+ throw new DataStoreException("Polygons with multiple linear rings have not implemented yet.");
+ }
- fc.close();
- fc2.close();
- fis.close();
- fis2.close();
+ // read the one part
+ @SuppressWarnings("unused")
+ int Part = rf.getInt();
+ Polygon poly = new Polygon();
+
+ // create a line from the points
+ double xpnt = rf.getDouble();
+ double ypnt = rf.getDouble();
+ // Point oldpnt = new Point(xpnt, ypnt);
+ poly.startPath(xpnt, ypnt);
+
+ for (int j = 0; j < NumPoints - 1; j++) {
+ xpnt = rf.getDouble();
+ ypnt = rf.getDouble();
+ poly.lineTo(xpnt, ypnt);
+ }
+
+ feature.setPropertyValue(GEOMETRY_NAME, poly);
}
+ /**
+ * Load polyline feature.
+ * @param rf Byte buffer.
+ * @param feature Feature to fill.
+ */
+ private void loadPolylineFeature(MappedByteBuffer rf, Feature feature) {
+ /* double xmin = */rf.getDouble();
+ /* double ymin = */rf.getDouble();
+ /* double xmax = */rf.getDouble();
+ /* double ymax = */rf.getDouble();
+
+ int NumParts = rf.getInt();
+ int NumPoints = rf.getInt();
+
+ int[] NumPartArr = new int[NumParts + 1];
+
+ for (int n = 0; n < NumParts; n++) {
+ int idx = rf.getInt();
+ NumPartArr[n] = idx;
+ }
+ NumPartArr[NumParts] = NumPoints;
+
+ double xpnt, ypnt;
+ Polyline ply = new Polyline();
+
+ for (int m = 0; m < NumParts; m++) {
+ xpnt = rf.getDouble();
+ ypnt = rf.getDouble();
+ ply.startPath(xpnt, ypnt);
+
+ for (int j = NumPartArr[m]; j < NumPartArr[m + 1] - 1; j++) {
+ xpnt = rf.getDouble();
+ ypnt = rf.getDouble();
+ ply.lineTo(xpnt, ypnt);
+ }
+ }
+
+ feature.setPropertyValue(GEOMETRY_NAME, ply);
+ }
+
+ /**
+ * Create a feature descriptor.
+ * @param name Name of the field.
+ * @return The feature type.
+ */
private DefaultFeatureType getFeatureType(final String name) {
- final int n = FDArray.size();
+ Objects.requireNonNull(name, "The feature name cannot be null.");
+
+ final int n = dbf.getFieldsDescriptor().size();
final DefaultAttributeType<?>[] attributes = new DefaultAttributeType<?>[n + 1];
- final Map<String,Object> properties = new HashMap<String,Object>(4);
- for (int i=0; i<n; i++) {
- properties.put(DefaultAttributeType.NAME_KEY, FDArray.get(i).getName());
+ final Map<String, Object> properties = new HashMap<String, Object>(4);
+
+ // Load data field.
+ for (int i = 0; i < n; i++) {
+ properties.put(DefaultAttributeType.NAME_KEY, dbf.getFieldsDescriptor().get(i).getName());
attributes[i] = new DefaultAttributeType<String>(properties, String.class, 1, 1, null);
}
+
+ // Add geometry field.
properties.put(DefaultAttributeType.NAME_KEY, GEOMETRY_NAME);
attributes[n] = new DefaultAttributeType<Geometry>(properties, Geometry.class, 1, 1, null);
+
+ // Add name.
properties.put(DefaultAttributeType.NAME_KEY, name);
return new DefaultFeatureType(properties, false, null, attributes);
}
+ /**
+ * @see java.lang.Object#toString()
+ */
@Override
public String toString() {
StringBuilder s = new StringBuilder();
@@ -293,12 +350,7 @@ public class ShapeFile {
s.append("mmin: ").append(mmin).append(lineSeparator);
s.append("mmax: ").append(mmax).append(lineSeparator);
s.append("------------------------").append(lineSeparator);
- s.append("DbaseVersion: ").append(DbaseVersion).append(lineSeparator);
- s.append("DbaseLastUpdate: ").append(new String(DbaseLastUpdate)).append(lineSeparator);
- s.append("FeatureCount: ").append(FeatureCount).append(lineSeparator);
- s.append("DbaseHeaderBytes: ").append(DbaseHeaderBytes).append(lineSeparator);
- s.append("DbaseRecordBytes: ").append(DbaseRecordBytes).append(lineSeparator);
- s.append("DbasePlusLanReserved: ").append(DbasePlusLanReserved).append(lineSeparator);
+ s.append(dbf.toString());
return s.toString();
}
Modified: sis/branches/JDK6/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/ShapeTypeEnum.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/ShapeTypeEnum.java?rev=1634099&r1=1634098&r2=1634099&view=diff
==============================================================================
--- sis/branches/JDK6/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/ShapeTypeEnum.java [UTF-8] (original)
+++ sis/branches/JDK6/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/ShapeTypeEnum.java [UTF-8] Fri Oct 24 17:28:28 2014
@@ -25,8 +25,8 @@ import java.util.Map;
* Provides a ShapefileType Enumeration
*
* @author Travis L. Pinney
- * @since 0.4
- * @version 0.4
+ * @since 0.5
+ * @version 0.5
* @module
*
* @see <a href="http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf">ESRI Shapefile Specification</a>
Modified: sis/branches/JDK6/storage/sis-shapefile/src/test/java/org/apache/sis/storage/shapefile/ShapeFileTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/storage/sis-shapefile/src/test/java/org/apache/sis/storage/shapefile/ShapeFileTest.java?rev=1634099&r1=1634098&r2=1634099&view=diff
==============================================================================
--- sis/branches/JDK6/storage/sis-shapefile/src/test/java/org/apache/sis/storage/shapefile/ShapeFileTest.java [UTF-8] (original)
+++ sis/branches/JDK6/storage/sis-shapefile/src/test/java/org/apache/sis/storage/shapefile/ShapeFileTest.java [UTF-8] Fri Oct 24 17:28:28 2014
@@ -27,32 +27,57 @@ import static org.junit.Assert.*;
/**
+ * Tests the {@link ShapeFile} class.
*
* @author Travis L. Pinney
- * @since 0.4
- * @version 0.4
+ * @since 0.5
+ * @version 0.5
* @module
*/
public final strictfp class ShapeFileTest extends TestCase {
- private static String path(final String name) throws IOException, URISyntaxException {
+ /**
+ * Returns URI path to a resource.
+ * @param name Resource name.
+ * @return URI path.
+ * @throws URISyntaxException if the resource name is incorrect.
+ */
+ private static String path(final String name) throws URISyntaxException {
return new File(ShapeFileTest.class.getResource(name).toURI()).getPath();
}
+ /**
+ * Test polylines count.
+ * @throws URISyntaxException if the resource name is incorrect.
+ * @throws IOException if the shapefile cannot be found or an I/O error occurs.
+ * @throws DataStoreException if the shapefile has a structure problem.
+ */
@Test
public void testPolyineCount() throws URISyntaxException, IOException, DataStoreException {
ShapeFile shp = new ShapeFile(path("SignedBikeRoute_4326_clipped.shp"));
- assertEquals(shp.FeatureMap.size(), shp.FeatureCount);
+ assertEquals(shp.FeatureMap.size(), shp.getFeatureCount());
}
- @Test
- public void testPolygonCount() throws URISyntaxException, IOException, DataStoreException {
+ /**
+ * Test polygon count.
+ * @throws URISyntaxException if the resource name is incorrect.
+ * @throws IOException if the shapefile cannot be found or an I/O error occurs.
+ * @throws DataStoreException if the shapefile has a structure problem.
+ */
+ @Test
+ public void testPolygonCount() throws URISyntaxException, IOException, DataStoreException {
ShapeFile shp = new ShapeFile(path("ANC90Ply_4326.shp"));
- assertEquals(shp.FeatureMap.size(), shp.FeatureCount);
+ assertEquals(shp.FeatureMap.size(), shp.getFeatureCount());
}
- @Test
- public void testPointCount() throws URISyntaxException, IOException, DataStoreException {
+ /**
+ * Test point count.
+ * @throws URISyntaxException if the resource name is incorrect.
+ * @throws IOException if the shapefile cannot be found or an I/O error occurs.
+ * @throws DataStoreException if the shapefile has a structure problem.
+ */
+ @Test
+ public void testPointCount() throws URISyntaxException, IOException, DataStoreException {
ShapeFile shp = new ShapeFile(path("ABRALicenseePt_4326_clipped.shp"));
- assertEquals(shp.FeatureMap.size(), shp.FeatureCount);
+ assertEquals(shp.FeatureMap.size(), shp.getFeatureCount());
}
}
Modified: sis/branches/JDK6/storage/sis-shapefile/src/test/java/org/apache/sis/test/suite/ShapefileTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/storage/sis-shapefile/src/test/java/org/apache/sis/test/suite/ShapefileTestSuite.java?rev=1634099&r1=1634098&r2=1634099&view=diff
==============================================================================
--- sis/branches/JDK6/storage/sis-shapefile/src/test/java/org/apache/sis/test/suite/ShapefileTestSuite.java [UTF-8] (original)
+++ sis/branches/JDK6/storage/sis-shapefile/src/test/java/org/apache/sis/test/suite/ShapefileTestSuite.java [UTF-8] Fri Oct 24 17:28:28 2014
@@ -26,7 +26,7 @@ import org.junit.BeforeClass;
*/
@Suite.SuiteClasses({
org.apache.sis.storage.shapefile.ShapeFileTest.class,
- org.apache.sis.storage.shapefile.CmdLineDriverTest.class
+ org.apache.sis.internal.shapefile.jdbc.DBFResultSetTest.class
})
public final strictfp class ShapefileTestSuite extends TestSuite {
/**
Modified: sis/branches/JDK6/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/xml/XMLStoreTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/xml/XMLStoreTest.java?rev=1634099&r1=1634098&r2=1634099&view=diff
==============================================================================
--- sis/branches/JDK6/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/xml/XMLStoreTest.java [UTF-8] (original)
+++ sis/branches/JDK6/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/xml/XMLStoreTest.java [UTF-8] Fri Oct 24 17:28:28 2014
@@ -19,17 +19,14 @@ package org.apache.sis.internal.storage.
import java.util.Locale;
import java.io.StringReader;
import org.opengis.metadata.Metadata;
-import org.opengis.metadata.citation.Role;
-import org.opengis.metadata.citation.OnLineFunction;
-import org.opengis.metadata.citation.OnlineResource;
-import org.opengis.metadata.citation.ResponsibleParty;
+import org.opengis.metadata.citation.*;
import org.apache.sis.xml.Namespaces;
import org.apache.sis.storage.StorageConnector;
import org.apache.sis.storage.DataStoreException;
import org.apache.sis.test.TestCase;
import org.junit.Test;
-import static org.junit.Assert.*;
+import static org.opengis.test.Assert.*;
import static org.apache.sis.test.TestUtilities.getSingleton;
// Branch-dependent imports
@@ -41,7 +38,7 @@ import org.apache.sis.internal.jdk7.Stan
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.4
- * @version 0.4
+ * @version 0.5
* @module
*/
public final strictfp class XMLStoreTest extends TestCase {
@@ -101,13 +98,16 @@ public final strictfp class XMLStoreTest
} finally {
store.close();
}
- final ResponsibleParty party = (ResponsibleParty) getSingleton(metadata.getContacts());
- final OnlineResource resource = party.getContactInfo().getOnlineResource();
-
- assertEquals(Locale.ENGLISH, metadata.getLanguage());
- assertEquals(StandardCharsets.UTF_8, metadata.getCharacterSet());
- assertEquals(Role.PRINCIPAL_INVESTIGATOR, party.getRole());
- assertEquals("Apache SIS", String.valueOf(party.getOrganisationName()));
+ final Responsibility resp = getSingleton(metadata.getContacts());
+ final Party party = getSingleton(resp.getParties());
+ final Contact contact = getSingleton(party.getContactInfo());
+ final OnlineResource resource = getSingleton(contact.getOnlineResources());
+
+ assertInstanceOf("party", Organisation.class, party);
+ assertEquals(Locale.ENGLISH, getSingleton(metadata.getLanguages()));
+ assertEquals(StandardCharsets.UTF_8, getSingleton(metadata.getCharacterSets()));
+ assertEquals(Role.PRINCIPAL_INVESTIGATOR, resp.getRole());
+ assertEquals("Apache SIS", String.valueOf(party.getName()));
assertEquals("http://sis.apache.org", String.valueOf(resource.getLinkage()));
assertEquals(OnLineFunction.INFORMATION, resource.getFunction());
}