|
From: Ian T. <ijt...@gm...> - 2025-08-14 09:24:50
|
Does your shapefile actually contain XYM points? Can you share the file or
at least the print out of the schema
Ian
On Thu, 14 Aug 2025 at 08:45, sunish <sun...@gm...> wrote:
> I am getting Invalid ordinate index: 3 Exception while reading a shape
> file.
> Geotools Version: 28.2
>
> I have this code for reading shape file features. Please help.
>
> private void fileDataStoreTest() {
>
> String filePath ="naksha_vadakara_build.shp";
> File file = new File(filePath);
>
>
> try {
> FileDataStore fileDataStore = FileDataStoreFinder.getDataStore(file);
>
>
> Hints hints = new Hints(Hints.JTS_COORDINATE_SEQUENCE_FACTORY,
> PackedCoordinateSequenceFactory.DOUBLE_FACTORY);
>
> System.out.println(fileDataStore.getSchema().getTypeName());
> System.out.println(fileDataStore.getSchema().getAttributeDescriptors());
> System.out.println(fileDataStore.getSchema().getCoordinateReferenceSystem());
> List<AttributeDescriptor> descriptors = fileDataStore.getSchema().getAttributeDescriptors();
> for(AttributeDescriptor disc :descriptors ){
> System.out.println(disc.getLocalName()+" "+disc.getType().getBinding().getSimpleName());
> }
> System.out.println(fileDataStore.getFeatureSource().getBounds());
> System.out.println(CRS.lookupEpsgCode(fileDataStore.getSchema().getCoordinateReferenceSystem(),true));
>
> SimpleFeatureSource src = fileDataStore.getFeatureSource();
> SimpleFeatureCollection col = src.getFeatures();
> SimpleFeatureIterator itr = col.features();
> // while (itr.hasNext()) {
>
> SimpleFeature f = itr.next();
> System.out.println(f.getDefaultGeometry().toString());
>
> // }
> itr.close();
> fileDataStore.dispose();
>
> } catch (IOException e) {
> throw new RuntimeException(e);
> } catch (FactoryException e) {
> throw new RuntimeException(e);
> }
>
> }
>
> It is throwing this error.
>
> Exception in thread "main" java.lang.IllegalArgumentException: Invalid
> ordinate index: 3
> at
> org.locationtech.jts.geom.CoordinateXYM.setOrdinate(CoordinateXYM.java:156)
> at
> org.locationtech.jts.geom.impl.CoordinateArraySequence.setOrdinate(CoordinateArraySequence.java:309)
> at
> org.geotools.data.shapefile.shp.PolygonHandler.readCoordinates(PolygonHandler.java:316)
> at
> org.geotools.data.shapefile.shp.PolygonHandler.read(PolygonHandler.java:142)
> at
> org.geotools.data.shapefile.shp.ShapefileReader$Record.shape(ShapefileReader.java:114)
> at
> org.geotools.data.shapefile.ShapefileFeatureReader.getGeometry(ShapefileFeatureReader.java:239)
> at
> org.geotools.data.shapefile.ShapefileFeatureReader.hasNext(ShapefileFeatureReader.java:182)
> at
> org.geotools.data.shapefile.ShapefileFeatureReader.next(ShapefileFeatureReader.java:151)
> at
> org.geotools.data.shapefile.ShapefileFeatureReader.next(ShapefileFeatureReader.java:48)
> at
> org.geotools.data.store.ContentFeatureCollection$WrappingFeatureIterator.next(ContentFeatureCollection.java:154)
> at
> org.geotools.data.store.ContentFeatureCollection$WrappingFeatureIterator.next(ContentFeatureCollection.java:134)
> _______________________________________________
> GeoTools-GT2-Users mailing list
> Geo...@li...
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>
--
Ian Turton
|