Ok, I have the Unit Test showing two problems, but I can't commit it at the moment. What the way to push them ? I think you have to set some rights for me first ?


Here is the unit test I added in the sis-shapefile project (in the branch JDK 8 I'm using at the moment) :


package org.apache.sis.storage.shapefile;

import static org.junit.Assert.*;

import java.io.*;

import org.apache.sis.storage.*;
import org.junit.*;
import org.opengis.feature.*;
import org.opengis.test.*;

/**
* Issues with features.
* @author Marc LE BIHAN
*/
public class IssuesWithFeaturesTest extends TestCase
{
  /**
   * Issue : the first property red by DenseFeature is null.
   * @throws DataStoreException if unable to find or read the shapefile.
   * @throws IOException if unable to find or read the shapefile.
   */
@Test public void issueFirstPropertyNull() throws IOException, DataStoreException { ShapeFile shapefile = new ShapeFile("src/test/resources/org/apache/sis/storage/shapefile/92-Hauts-de-Seine.shp");

Feature feature = shapefile.FeatureMap.values().iterator().next(); // The shapefile has 36 features, take the first one. String city = (String)feature.getProperty("COMMUNE\0\0\0\0").getValue(); String refInsee = (String)feature.getProperty("REF_INSEE\0\0").getValue(); String zipCode = (String)feature.getProperty("CODE_POSTA\0").getValue();

// The first feature property you read (city here) will return a null value.
     assertNotNull("The city should have an INSEE reference.", refInsee);
     assertNotNull("The city should have a zip code.", zipCode);
     assertNotNull("The city should have a name.", city);
  }

  /**
* Issue : when features are loaded from a Shapefile, the DBF file may load its properties with fields padded oddly. * When comes the times to query the feature content, the getProperty(..) find nothing if the name is not padded.
   * @throws DataStoreException if unable to find or read the shapefile.
   * @throws IOException if unable to find or read the shapefile.
   */
@Test public void featureIsTrickedByZerosChar() throws IOException, DataStoreException
  {
ShapeFile shapefile = new ShapeFile("src/test/resources/org/apache/sis/storage/shapefile/92-Hauts-de-Seine.shp");

Feature feature = shapefile.FeatureMap.values().iterator().next(); // The shapefile has 36 features, take the first one. feature.getProperty("COMMUNE\0\0\0\0"); // The field name currently set in the DBF. feature.getProperty("COMMUNE"); // fails because the DBF describes this field as "COMMUNE\0\0\0\0".
  }
}

I added for test resources the shapefile contained in this Openstreetmap tar.gz : http://export.openstreetmap.fr/contours-administratifs/communes/92-Hauts-de-Seine.shp.tar.gz

Regards,

Marc.

-----Message d'origine----- From: Martin Desruisseaux
Sent: Monday, September 29, 2014 12:53 AM
To: dev@sis.apache.org
Subject: Re: Shapefile / DenseFeature : first name searched for returns a null value.

Hello Marc

Thanks for signalling that bug! I don't think that we need to create a
branch for such fixes. It would be nice if we could have a JUnit test
reproducing the bug, ideally without sis-shapefile dependency so we
could keep the test in the sis-feature module. The JUnit test and (if
you wish) the fix could be either attached in a JIRA task, or committed
directly if you wish (ideally on the JDK8 branch for making the merges
easier, but other branches or trunk are fine too).

   Regards,

       Martin


Le 28/09/14 20:07, Marc Le Bihan a écrit :
Hello,

I’ve just downloaded 0.5-SNAPSHOT version Friday, and I managed to make it works rather well by reading a shapefile from Openstreetmap.

I encounter a trouble, however. The first value asked in a DenseFeature is always returning a null value.


If I attempt to query the values of a Feature this way :
"REF_INSEE", "COMMUNE",  "CODE_POSTA",
I will receive  : null, “a city name”, “a zip code”.

If I try to query this way :
"CODE_POSTA", "REF_INSEE", "COMMUNE",
I will receive : null, “an INSEE code”, “a city name”.


after the init call of
        wrapValuesInProperties();
the method assumes that it has done the same work it would have done with
        final Property property = ((Property[]) properties)[index];
but it’s not the case.


Involved method :

@Override
public Property getProperty(final String name) throws IllegalArgumentException {
    ArgumentChecks.ensureNonNull("name", name);
    final int index = getIndex(name);
    if (properties instanceof Property[]) {
        final Property property = ((Property[]) properties)[index];
        if (property != null) {
            return property;
        }
    } else {
        wrapValuesInProperties();
    }
    final Property property = createProperty(name);
    properties[index] = property;
    return property;
}

I may  :
- Attempt to correct the bug and send a branch somewhere with an unit test.
- or Open a JIRA entry.

what is the best ?

Regards,

M. Le Bihan


Reply via email to