[GeoTools 11.2] Un chargement de shapefile me montre un problème de dépendances ?
Bonjour,
Après pas mal de temps sur d'autres sujets, j'ai téléchargé GeoTools 11.2 : la dernière version stable.
J'ai mis en premier lieu deux dépendances Maven recommandées pour l'utiliser, puis rapidement, j'en suis venu à toutes les mettre pensant que le problème que je vais décrire ici a sa source dedans.
Avec jai.core=1.1.3 et geotools.version=11.2 :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| <!-- Interface GeoAPI -->
<dependency>
<groupId>org.opengis</groupId>
<artifactId>geoapi</artifactId>
<version>${geoapi.version}</version>
</dependency>
<dependency>
<groupId>javax.media</groupId>
<artifactId>jai_core</artifactId>
<version>${jai.core}</version>
</dependency>
<!-- GeoTools -->
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-api</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-coverage</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-cql</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-data</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-main</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-metadata</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-opengis</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-referencing</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-render</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-shapefile</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-swing</artifactId>
<version>${geotools.version}</version>
</dependency> |
J'exécute alors le code de test suivant :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| @Test public void lireShapefile() throws IOException
{
// Récupération des paramètres du test.
Ressources rsc = new Ressources(TestShapeFile.class);
File file = new File(rsc.chaine("fichier.shp")); //$NON-NLS-1$
assertTrue("Le fichier shapefile source n'existe pas.", file.exists()); //$NON-NLS-1$
String couche = rsc.chaine("couche"); //$NON-NLS-1$
// Lecture du shapefile.
DataStore datastore = new LoadShapefile().load(file);
assertNotNull("Le datastore n'a pas pu être obtenu.", datastore); //$NON-NLS-1$
// Obtention d'une de ses couches.
SimpleFeatureSource feature = datastore.getFeatureSource(couche);
assertNotNull("La couche désirée n'a pas pu être lue.", feature); //$NON-NLS-1$
rsc.info("log.nom_info_shapefile", couche, file, feature.getName(), feature.getInfo()); //$NON-NLS-1$
} |
Avec :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
public class LoadShapefile
{
public DataStore load(File shapefile) throws IOException
{
return(load(shapefile.toURI().toURL()));
}
public DataStore load(URL shapefile) throws IOException
{
Map<String, String> chargement = new HashMap<>();
chargement.put("url", shapefile.toString()); //$NON-NLS-1$
DataStore datastore = DataStoreFinder.getDataStore(chargement);
return datastore;
}
} |
Et pour paramètres du test :
- Les fichiers :
92-Hauts-de-Seine.dbf
92-Hauts-de-Seine.prj
92-Hauts-de-Seine.shp
92-Hauts-de-Seine.shx
que j'ai pris sur ce lien (export.openstreetmap.fr),
- La couche 92-Hauts-de-Seine, comme je l'ai trouvée nommée en ouvrant le shapefile dans QGis.
Mon problème :
Lorsque j'exécute ce test, j'obtiens cette erreur :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| Running utils.gis.TestShapeFile
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.359 sec <<< FAILURE! - in utils.gis.TestShapeFile
lireShapefile(utils.gis.TestShapeFile) Time elapsed: 0.312 sec <<< ERROR!
java.lang.AbstractMethodError: org.geotools.metadata.iso.citation.ContactImpl.getOnlineResource()Lorg/opengis/metadata/citation/OnlineResource;
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.geotools.metadata.PropertyAccessor.get(PropertyAccessor.java:474)
at org.geotools.metadata.PropertyAccessor.hashCode(PropertyAccessor.java:789)
at org.geotools.metadata.MetadataStandard.hashCode(MetadataStandard.java:323)
at org.geotools.metadata.AbstractMetadata.hashCode(AbstractMetadata.java:215)
at org.geotools.metadata.PropertyAccessor.hashCode(PropertyAccessor.java:791)
at org.geotools.metadata.MetadataStandard.hashCode(MetadataStandard.java:323)
at org.geotools.metadata.AbstractMetadata.hashCode(AbstractMetadata.java:215)
at java.util.HashMap.hash(HashMap.java:338)
at java.util.HashMap.put(HashMap.java:611)
at java.util.HashSet.add(HashSet.java:219)
at org.geotools.util.CheckedHashSet.add(CheckedHashSet.java:216)
at org.geotools.metadata.iso.citation.CitationImpl.<init>(CitationImpl.java:177)
at org.geotools.metadata.iso.citation.Citations.<clinit>(Citations.java:86)
at org.geotools.referencing.wkt.Parser.parseAuthority(Parser.java:352)
at org.geotools.referencing.wkt.Parser.parseGeoGCS(Parser.java:864)
at org.geotools.referencing.wkt.Parser.parseCoordinateReferenceSystem(Parser.java:224)
at org.geotools.referencing.wkt.Parser.parseCoordinateReferenceSystem(Parser.java:204)
at org.geotools.referencing.factory.ReferencingObjectFactory.createFromWKT(ReferencingObjectFactory.java:1090)
at org.geotools.data.PrjFileReader.<init>(PrjFileReader.java:89)
at org.geotools.data.PrjFileReader.<init>(PrjFileReader.java:63)
at org.geotools.data.shapefile.ShapefileSetManager.openPrjReader(ShapefileSetManager.java:106)
at org.geotools.data.shapefile.ShapefileFeatureSource.readAttributes(ShapefileFeatureSource.java:420)
at org.geotools.data.shapefile.ShapefileFeatureSource.buildFeatureType(ShapefileFeatureSource.java:376)
at org.geotools.data.store.ContentFeatureSource.getAbsoluteSchema(ContentFeatureSource.java:340)
at org.geotools.data.store.ContentFeatureSource.getSchema(ContentFeatureSource.java:309)
at org.geotools.data.store.ContentFeatureSource.getName(ContentFeatureSource.java:291)
at org.geotools.data.shapefile.ShapefileFeatureStore.getName(ShapefileFeatureStore.java:141)
at utils.gis.TestShapeFile.lireShapefile(TestShapeFile.java:37) |
qui me fait suspecter qu'il lui manque une dépendance.
Et je le suspecte très fortement, parce que si j'ajoute (dans un autre but, pour d'autres tests qui n'ont rien à voir dans mon projet) les dépendances GeotoolKit 3.20-geoapi-3.0 dans mon pom.xml,
c'est cette exception qui est levée :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| lireShapefile(utils.gis.TestShapeFile) Time elapsed: 0.46 sec <<< ERROR!
java.lang.ClassCastException: org.geotoolkit.referencing.factory.ReferencingObjectFactory cannot be cast to org.opengis.referencing.Factory
at org.geotools.referencing.ReferencingFactoryFinder.getFactory(ReferencingFactoryFinder.java:197)
at org.geotools.referencing.ReferencingFactoryFinder.getCRSFactory(ReferencingFactoryFinder.java:288)
at org.geotools.data.PrjFileReader.<init>(PrjFileReader.java:89)
at org.geotools.data.PrjFileReader.<init>(PrjFileReader.java:63)
at org.geotools.data.shapefile.ShapefileSetManager.openPrjReader(ShapefileSetManager.java:106)
at org.geotools.data.shapefile.ShapefileFeatureSource.readAttributes(ShapefileFeatureSource.java:420)
at org.geotools.data.shapefile.ShapefileFeatureSource.buildFeatureType(ShapefileFeatureSource.java:376)
at org.geotools.data.store.ContentFeatureSource.getAbsoluteSchema(ContentFeatureSource.java:340)
at org.geotools.data.store.ContentFeatureSource.getSchema(ContentFeatureSource.java:309)
at org.geotools.data.store.ContentFeatureSource.getName(ContentFeatureSource.java:291)
at org.geotools.data.shapefile.ShapefileFeatureStore.getName(ShapefileFeatureStore.java:141)
at utils.gis.TestShapeFile.lireShapefile(TestShapeFile.java:37) |
Visiblement, geotools essaie de trouver une Factory GeoApi (org.opengis) n'importe où il la trouve. Est-ce parce qu'il n'a pas su trouver la sienne propre via les onze dépendances que je lui ai mises ? Ou bien que celle qu'il a chargée pour lui-même ne lui suffisait pas ?
Mystère. Mais il me manque quelque-chose quelque-part... Qu'est-ce que ça pourrait bien être ?
EDIT : Décidément, tout m'échappe ! En essayant de faire l'opération équivalente via Geotoolkit 3.20-geoapi-3.0, je ne parviens pas à trouver le package org.geotoolkit.data dans ses dépendances, et je ne peux pas utiliser les objets de chargement correspondants. Je suis très humilié de faire autant fausse route !!!
Merci
!
Grunt.
(Geotools échoue -> Geotoolkit -> Annoncé deprecated -> Apache SIS) : c'est le bon cette fois ?
Après plusieurs tentatives infructueuses, j'ai abandonné Geotools.
Je suis parvenu à charger mon Shapefile avec Geotoolkit, mais en utilisant une version 4.x-SNAPSHOT car je ne trouvais pas le package org.geotoolkit.data en version 3.20.
Au moment où j'essayais d'installer manuellement la javadoc derrière les 30 dépendances que cette api réclame pour compiler pour pouvoir m'en sortir (un mvn install -DdownloadJavadocs=true n'aspire rien), j'ai lu sur leur site : "Large part of Geotoolkit.org code is moving to the Apache SIS project. This migration results in deprecation of massive amount of classes in the Geotk project, which will be replaced by the SIS equivalent."
Alors, je suis entrain de migrer vers ce projet.
Mais j'espère que cette fois, ce projet là, ils ne l'abandonneront pas en cours de route.