sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mlebi...@apache.org
Subject svn commit: r1713851 - in /sis/branches/JDK8/storage/sis-shapefile/src: main/java/org/apache/sis/storage/shapefile/ test/java/org/apache/sis/storage/shapefile/
Date Wed, 11 Nov 2015 14:32:53 GMT
Author: mlebihan
Date: Wed Nov 11 14:32:52 2015
New Revision: 1713851

URL: http://svn.apache.org/viewvc?rev=1713851&view=rev
Log:
Shapefile Features type, descriptor and database fields descriptors are avaiable in the Shapefile
object by calling the methods :
    public DefaultFeatureType getFeaturesType();
    public ShapefileDescriptor getShapefileDescriptor();
    public List<DBase3FieldDescriptor> getDatabaseFieldsDescriptors();

For information : 
new ShapeFile(String filename) 
doesn't do any I/O operation and is just a declaration of a ShapeFile than can be used later.
The descriptors becomes available as soon as a reading attempt is made by a call to the readFeature()
method, or by a call of loadDescriptors() on the ShapeFile. The binary headers of the shapefile
and dbf has to be readen at these times to get the descriptors.

Modified:
    sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/InputFeatureStream.java
    sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/ShapeFile.java
    sis/branches/JDK8/storage/sis-shapefile/src/test/java/org/apache/sis/storage/shapefile/ShapeFileTest.java

Modified: sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/InputFeatureStream.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/InputFeatureStream.java?rev=1713851&r1=1713850&r2=1713851&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/InputFeatureStream.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/InputFeatureStream.java
[UTF-8] Wed Nov 11 14:32:52 2015
@@ -21,10 +21,12 @@ import java.io.InputStream;
 import java.sql.SQLFeatureNotSupportedException;
 import java.text.DecimalFormat;
 import java.text.MessageFormat;
+import java.util.List;
 
 import org.apache.sis.feature.DefaultFeatureType;
 import org.apache.sis.internal.shapefile.SQLShapefileNotFoundException;
 import org.apache.sis.internal.shapefile.ShapefileByteReader;
+import org.apache.sis.internal.shapefile.ShapefileDescriptor;
 import org.apache.sis.internal.shapefile.jdbc.*;
 import org.apache.sis.internal.shapefile.jdbc.connection.DBFConnection;
 import org.apache.sis.internal.shapefile.jdbc.metadata.DBFDatabaseMetaData;
@@ -167,6 +169,33 @@ public class InputFeatureStream extends
     }
     
     /**
+     * Return the features type.
+     * @return Features type.
+     */
+    public DefaultFeatureType getFeaturesType()
+    {
+        return this.featuresType;
+    }
+    
+    /**
+     * Returns the shapefile descriptor.
+     * @return Shapefile descriptor.
+     */
+    public ShapefileDescriptor getShapefileDescriptor()
+    {
+        return this.shapefileReader.getShapefileDescriptor();
+    }
+    
+    /** 
+     * Returns the database fields descriptors.
+     * @return List of fields descriptors. 
+     */
+    public List<DBase3FieldDescriptor> getDatabaseFieldsDescriptors()
+    {
+        return this.shapefileReader.getFieldsDescriptors();
+    }
+    
+    /**
      * Read next feature responding to the SQL query.
      * @return Feature, null if no more feature is available.
      * @throws SQLNotNumericException if a field expected numeric isn't.

Modified: sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/ShapeFile.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/ShapeFile.java?rev=1713851&r1=1713850&r2=1713851&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/ShapeFile.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/ShapeFile.java
[UTF-8] Wed Nov 11 14:32:52 2015
@@ -17,8 +17,13 @@
 package org.apache.sis.storage.shapefile;
 
 import java.io.File;
+import java.util.List;
 import java.util.Objects;
 
+import org.apache.sis.feature.DefaultFeatureType;
+import org.apache.sis.internal.shapefile.ShapefileDescriptor;
+import org.apache.sis.internal.shapefile.jdbc.DBase3FieldDescriptor;
+
 /**
  * Provides a ShapeFile Reader.
  *
@@ -37,6 +42,15 @@ public class ShapeFile {
     /** Database file. */
     private File databaseFile;
 
+    /** Type of the features contained in this shapefile. */
+    private DefaultFeatureType featuresType;
+
+    /** Shapefile descriptor. */
+    private ShapefileDescriptor shapefileDescriptor;
+    
+    /** Database field descriptors. */
+    private List<DBase3FieldDescriptor> databaseFieldsDescriptors;
+    
     /**
      * Construct a Shapefile from a file.
      * @param shpfile file to read.
@@ -53,6 +67,30 @@ public class ShapeFile {
     }
 
     /**
+     * Return the default feature type.
+     * @return Feature type.
+     */
+    public DefaultFeatureType getFeaturesType() {
+        return this.featuresType;
+    }
+    
+    /**
+     * Returns the shapefile descriptor.
+     * @return Shapefile descriptor.
+     */
+    public ShapefileDescriptor getShapefileDescriptor() {
+        return this.shapefileDescriptor;
+    }
+    
+    /** 
+     * Returns the database fields descriptors.
+     * @return List of fields descriptors. 
+     */
+    public List<DBase3FieldDescriptor> getDatabaseFieldsDescriptors() {
+        return this.databaseFieldsDescriptors;
+    }
+
+    /**
      * Find features corresponding to an SQL request SELECT * FROM database.
      * @return Features
      * @throws DbaseFileNotFoundException if the database file has not been found.
@@ -61,6 +99,25 @@ public class ShapeFile {
      * @throws InvalidShapefileFormatException if the shapefile format is invalid.
      */
     public InputFeatureStream findAll() throws InvalidDbaseFileFormatException, ShapefileNotFoundException,
DbaseFileNotFoundException, InvalidShapefileFormatException {
-        return new InputFeatureStream(shapeFile, databaseFile);
+        InputFeatureStream is = new InputFeatureStream(shapeFile, databaseFile);
+        this.featuresType = is.getFeaturesType();
+        this.shapefileDescriptor = is.getShapefileDescriptor();
+        this.databaseFieldsDescriptors = is.getDatabaseFieldsDescriptors();
+        return is;
+    }
+
+    /**
+     * Load shapefile descriptors : features types, shapefileDescriptor, database field descriptors
:
+     * this is also automatically done when executing a query on it, by findAll.
+     * @throws DbaseFileNotFoundException if the database file has not been found.
+     * @throws ShapefileNotFoundException if the shapefile has not been found.
+     * @throws InvalidDbaseFileFormatException if the database file format is invalid.
+     * @throws InvalidShapefileFormatException if the shapefile format is invalid.
+     */
+    public void loadDescriptors() throws InvalidDbaseFileFormatException, InvalidShapefileFormatException,
ShapefileNotFoundException, DbaseFileNotFoundException {
+        // Doing an simple query will init the internal descriptors.
+        // It prepares a SELECT * FROM <DBase> but don't read a record by itself.
+        try(InputFeatureStream is = findAll()) {
+        }
     }
 }

Modified: sis/branches/JDK8/storage/sis-shapefile/src/test/java/org/apache/sis/storage/shapefile/ShapeFileTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-shapefile/src/test/java/org/apache/sis/storage/shapefile/ShapeFileTest.java?rev=1713851&r1=1713850&r2=1713851&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-shapefile/src/test/java/org/apache/sis/storage/shapefile/ShapeFileTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-shapefile/src/test/java/org/apache/sis/storage/shapefile/ShapeFileTest.java
[UTF-8] Wed Nov 11 14:32:52 2015
@@ -16,8 +16,12 @@
  */
 package org.apache.sis.storage.shapefile;
 
+import static org.junit.Assert.assertNotNull;
+
 import java.io.File;
 import java.net.URISyntaxException;
+import java.text.MessageFormat;
+import java.util.logging.Logger;
 
 import org.apache.sis.storage.DataStoreException;
 import org.apache.sis.test.TestCase;
@@ -77,6 +81,31 @@ public final strictfp class ShapeFileTes
         readAll(shp);
      }
 
+     /**
+      * Test loading of shapefile descriptors. 
+      * @throws URISyntaxException if the resource name is incorrect.
+      * @throws DataStoreException if a general file reading trouble occurs.
+      */
+     @Test
+     public void testDescriptors() throws URISyntaxException, DataStoreException {
+         Logger log = org.apache.sis.util.logging.Logging.getLogger(ShapeFileTest.class.getName());
+         
+         ShapeFile shp = new ShapeFile(path("ABRALicenseePt_4326_clipped.shp"));
+         shp.loadDescriptors();
+         
+         assertNotNull("The features type of the shapefile should have been set.", shp.getFeaturesType());
+         log.info(MessageFormat.format("ABRALicenseePt_4326_clipped.shp features type : {0}",
shp.getFeaturesType()));
+         
+         assertNotNull("The shapefile descriptor of the shapefile should have been set.",
shp.getShapefileDescriptor());
+         log.info(MessageFormat.format("ABRALicenseePt_4326_clipped.shp shapefile descriptor
: {0}", shp.getShapefileDescriptor()));
+
+         assertNotNull("The DBase III fields descriptors of the shapefile should have been
set.", shp.getDatabaseFieldsDescriptors());
+         log.info(MessageFormat.format("ABRALicenseePt_4326_clipped.shp DBase fields descriptors
: {0}", shp.getDatabaseFieldsDescriptors()));
+         
+         // Loading of the descriptor shall not prevent the shapefile from being red again.
+         readAll(shp);
+     }
+     
     /**
      * Read all the shapefile content.
      * @param shp Shapefile to read.



Mime
View raw message