Hi, I'm dealing with a problem in the geotools shapefile store
regarding null geometries. With this code[1] I write a shapefile with
a null geometry. Then, when I read it, a POINT(NaN, NaN) is obtained
[2].

This is the case with 2.7.2 and 8.0-M1 versions.

I think it is a bug because null geometries are supported in shapefile
format and they are also meaningful values. It can be easily solved by
including an "if" in the ShapefileReader.Record.shape() method and
keeping the handler to deal with the null geometry.

Are you interested in a patch with the fix and a test case? In any
case, I'd like to know the way to proceed.

Thanks.

[1]
        public static void main(String[] args) throws Exception {
                Map<String, Serializable> params = new HashMap<String, 
Serializable>();
                params.put("url", new File("/tmp/test.shp").toURI().toURL());
                ShapefileDataStore ds = (ShapefileDataStore) new 
ShapefileDataStoreFactory()
                                .createNewDataStore(params);

                SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
                tb.setName("shapefile");
                tb.add("the_geom", Point.class);
                tb.add("id", Integer.class);
                ds.createSchema(tb.buildFeatureType());

                Transaction transaction = Transaction.AUTO_COMMIT;
                FeatureWriter<SimpleFeatureType, SimpleFeature> writer = ds
                                .getFeatureWriter(transaction);

                SimpleFeature feature = writer.next();
                feature.setAttribute(0, null);
                feature.setAttribute(1, 0);

                writer.close();
                transaction.commit();
                ds.dispose();
        }


[2]
                ShpFiles shpFiles = new ShpFiles(new File("/tmp/test.shp"));
                ShapefileReader reader = new ShapefileReader(shpFiles, false, 
true,
                                ValueFactory.getGeometryFactory(), false);
                long t1 = System.currentTimeMillis();
                while (reader.hasNext()) {
                        System.out.println(reader.nextRecord().shape());
                }
                reader.close();

------------------------------------------------------------------------------
Magic Quadrant for Content-Aware Data Loss Prevention
Research study explores the data loss prevention market. Includes in-depth
analysis on the changes within the DLP market, and the criteria used to
evaluate the strengths and weaknesses of these DLP solutions.
http://www.accelacomm.com/jaw/sfnl/114/51385063/
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to