OSGeo / gdal

GDAL is an open source MIT licensed translator library for raster and vector geospatial data formats.
https://gdal.org
Other
4.78k stars 2.5k forks source link

gdal Java API : ogr.Layer GetNextFeature( ) returned incorrect null value in 3.x version #2169

Closed Zhanhaoxin closed 4 years ago

Zhanhaoxin commented 4 years ago

Expected behavior and actual behavior.

I use gdal Java API: a method GetNextFeature () of org.gdal.ogr.Layer to parse the MapInfo format electronic map. But when I use GDAL 2.4.0 version, it can return the normal value. But when I upgrade to version 3.0.1, the GetNextFeature () method will only return a null value. The API interface document of GDAL does not reflect that this interface has changed from version 2.x to version 3.x. I also tried version 3.0.0 and 3.0.2, and found that using the GetNextFeature () method both returned a null value.

Steps to reproduce the problem.

GetNextFeature () of org.gdal.ogr.Layer in GDAL Java API

Operating system

Ubuntu 16.04 64 bit

GDAL version and provenance

2.4.0 version can return expected value 3.0.0 version , 3.0.1 version , 3.0.2 version return null

jratike80 commented 4 years ago

Could it be that there was some other error earlier and you do not have a next feature now?

Zhanhaoxin commented 4 years ago

Could it be that there was some other error earlier and you do not have a next feature now?

There is nothing wrong before calling GetNextFeature () method, because I parse the MapInfo format map in this way:

DataSource tabDataSrc = ogr.Open(filePath);
Layer layerByOGR = tabDataSrc.GetLayer();
Feature feature = layerByOGR.GetNextFeature();

The layerByOGR object here is not empty, because there are a series of empty judgment operations to guarantee, and I can call other methods of the layerByOGR object, such as: GetName (), GetGeomType (), etc. can return normal values.

jratike80 commented 4 years ago

Do you test also with layer.GetFeatureCount()?

rouault commented 4 years ago

I cannot replicate that with the simplified Java version of ogrinfo in the repository

~/gdal/git/gdal/gdal/swig/java$ java -Djava.library.path=. -cp gdal.jar:build/apps ogrinfo -ro -al ../../../autotest/ogr/data/all_geoms.tab

outputs

INFO: Open of `../../../autotest/ogr/data/all_geoms.tab'
      using driver `MapInfo File' successful.

Layer name: all_geoms
Geometry: Unknown (any)
Feature Count: 16
Extent: (-1.0, -1.0) - (5.0, 6.0)
Layer SRS WKT:
LOCAL_CS["Nonearth",
    UNIT["Meter",1]]
NAME: String (1.0)
OGRFeature(all_geoms):1
  NAME (String) = 
  Style = SYMBOL(a:0,c:#000000,s:12pt,id:"mapinfo-sym-35,ogr-sym-10")
  POINT (0 1)

OGRFeature(all_geoms):2
  NAME (String) = 
  Style = SYMBOL(a:0,c:#000000,s:1pt,id:"mapinfo-sym-35,ogr-sym-10")
  POINT (2 3)
[snip]
Zhanhaoxin commented 4 years ago

Do you test also with layer.GetFeatureCount()?

I re-verified that in version 3.0.2, when I parse an electronic map in MapInfo format, when parsing a .TAB file, the return value of layer.GetFeatureCount () is also a null value, but in version 2.4.0 it is Can return a non-empty value, except for the inconsistent version of GDAL, other codes including electronic maps are consistent.

jratike80 commented 4 years ago

It means that the problem is not in the GetNextFeature() but something happens before that. I suggest to make test with ogrinfo of GDAL 3.0.2. If it can't find and list features from your MapInfo file then there may be some bug in the MITAB driver. In that case we need test data.

If ogrinfo does find features then it means that there is not a bug in the driver but something else has changed between GDAL versions 2.4 and 3.0. Read the migration guide https://github.com/OSGeo/gdal/blob/release/3.0/gdal/MIGRATION_GUIDE.TXT and check if there is something for you. If that does not help, write mail to gdal-dev mailing list and ask for help. Include relevant parts of your code in your question.

Zhanhaoxin commented 4 years ago

I cannot replicate that with the simplified Java version of ogrinfo in the repository

~/gdal/git/gdal/gdal/swig/java$ java -Djava.library.path=. -cp gdal.jar:build/apps ogrinfo -ro -al ../../../autotest/ogr/data/all_geoms.tab

outputs

INFO: Open of `../../../autotest/ogr/data/all_geoms.tab'
      using driver `MapInfo File' successful.

Layer name: all_geoms
Geometry: Unknown (any)
Feature Count: 16
Extent: (-1.0, -1.0) - (5.0, 6.0)
Layer SRS WKT:
LOCAL_CS["Nonearth",
    UNIT["Meter",1]]
NAME: String (1.0)
OGRFeature(all_geoms):1
  NAME (String) = 
  Style = SYMBOL(a:0,c:#000000,s:12pt,id:"mapinfo-sym-35,ogr-sym-10")
  POINT (0 1)

OGRFeature(all_geoms):2
  NAME (String) = 
  Style = SYMBOL(a:0,c:#000000,s:1pt,id:"mapinfo-sym-35,ogr-sym-10")
  POINT (2 3)
[snip]

I cannot replicate that with the simplified Java version of ogrinfo in the repository

~/gdal/git/gdal/gdal/swig/java$ java -Djava.library.path=. -cp gdal.jar:build/apps ogrinfo -ro -al ../../../autotest/ogr/data/all_geoms.tab

outputs

INFO: Open of `../../../autotest/ogr/data/all_geoms.tab'
      using driver `MapInfo File' successful.

Layer name: all_geoms
Geometry: Unknown (any)
Feature Count: 16
Extent: (-1.0, -1.0) - (5.0, 6.0)
Layer SRS WKT:
LOCAL_CS["Nonearth",
    UNIT["Meter",1]]
NAME: String (1.0)
OGRFeature(all_geoms):1
  NAME (String) = 
  Style = SYMBOL(a:0,c:#000000,s:12pt,id:"mapinfo-sym-35,ogr-sym-10")
  POINT (0 1)

OGRFeature(all_geoms):2
  NAME (String) = 
  Style = SYMBOL(a:0,c:#000000,s:1pt,id:"mapinfo-sym-35,ogr-sym-10")
  POINT (2 3)
[snip]

I used the jars compiled by GDAL 2.40 and the jars compiled by GDAL 3.2.0 to verify that the .TAB file was loaded through ogrinfo.

2.4.0 output:

INFO: Open of `Urban_trunk_road_label.TAB'
      using driver `MapInfo File' successful.
 Layer name: Urban_trunk_road_label
 Geometry: Point
 Feature Count: 1441
 Extent: (120.582297, 27.845912) - (120.850769, 28.078711)
 Layer SRS WKT:
GEOGCS["unnamed",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563],
        TOWGS84[0,0,0,0,0,0,0]],
    PRIMEM["Greenwich",0],
    UNIT["degree",0.0174532925199433]]
 ID: Integer (10.0)
 NAME: String (254.0)
 CODE: String (50.0)
 TYPE: Integer (5.0)
 PROPERTY: Integer (5.0)
 MAXSPEED: Integer (5.0)
 TRAVEL: Integer (5.0)
 WIDTH: String (19.0)
 ISO: String (50.0)
 ORDATE: String (10.0)
 CHDATE: String (10.0)
 WORKAREAID: String (50.0)
 SHAPE_LEN: String (19.0)

3.2.0 output:

FAILURE:
Unable to open datasource `Urban_trunk_road_label.TAB' with the following drivers.

   -> PCIDSK
   -> PDS4
   -> PDF
   -> ESRI Shapefile
   -> MapInfo File
   -> UK .NTF
   -> OGR_SDTS
   -> S57
   -> DGN
   -> OGR_VRT
   -> REC
   -> Memory
   -> BNA
   -> CSV
   -> GML
   -> GPX
   -> KML
   -> GeoJSON
   -> GeoJSONSeq
   -> ESRIJSON
   -> TopoJSON
   -> OGR_GMT
   -> WAsP
   -> OpenFileGDB
   -> XPlane
   -> DXF
   -> CAD
   -> Geoconcept
   -> GeoRSS
   -> GPSTrackMaker
   -> PGDUMP
   -> GPSBabel
   -> SUA
   -> OpenAir
   -> OGR_PDS
   -> HTF
   -> AeronavFAA
   -> EDIGEO
   -> SVG
   -> Idrisi
   -> ARCGEN
   -> SEGUKOOA
   -> SEGY
   -> ODS
   -> XLSX
   -> SXF
   -> Selafin
   -> JML
   -> VDV
   -> MVT
   -> TIGER
   -> AVCBin
   -> AVCE00
rouault commented 4 years ago

Please attach the dataset (zip the .tab, .dat, .id, .map) with which you reproduce the issue

Zhanhaoxin commented 4 years ago

Please attach the dataset (zip the .tab, .dat, .id, .map) with which you reproduce the issue

GuangZhou_MapInfo.zip

rouault commented 4 years ago

The GuangZhou_MapInfo.zip file doesn't contain Urban_trunk_road_label.TAB, but many other layers. That said I was able to read them with GDAL 3.0.x and the Java version of ogrinfo

Zhanhaoxin commented 4 years ago

GuangZhou_MapInfo.zip文件不包含Urban_trunk_road_label.TAB,但包含许多其他层。就是说,我能够使用GDAL 3.0.x和Java版本的ogrinfo来阅读它们

The jar I use is built using C ++. I think what might be missing in the 3.0.x build?

rouault commented 4 years ago

I'm afraid we cannot really help you. There must be something specific to your setup that I can't reproduce here

jratike80 commented 4 years ago

Tests on Windows with ogrinfo after renaming the first file set in the zip into test1.* GDAL 3.0.2 from OSGeo4W reads the data GDAL 2.4.2 from gisinternals reads the data GDAL 3.1.0dev from gisinternals.com does not read the data

Debug does not give a hint what makes the gisinternals version to fail.

I believe that like the GetNextFeature() had nothing to do with the issue nor does Java API.

All three versions I have come with iconv files but I would still make some test with all ASCII data, and then again with data having Chinese characters.

jratike80 commented 4 years ago

I must have done something wrong with my previous test. Now I cannot repeat the error with any builds and versions. With my Windows set to use codepage 936 this works as it should:

ogrinfo -al 四级道路.TAB
INFO: Open of `鍥涚骇閬撹矾.TAB'
      using driver `MapInfo File' successful.

Layer name: 鍥涚骇閬撹矾
Geometry: Line String
Feature Count: 434
Extent: (113.306430, 23.113710) - (113.402490, 23.192300)
Layer SRS WKT:
GEOGCRS["unnamed",
    DATUM["World Geodetic System 1984",
        ELLIPSOID["WGS 84",6378137,298.257223563,
            LENGTHUNIT["metre",1,
                ID["EPSG",9001]]]],
    PRIMEM["Greenwich",0,
        ANGLEUNIT["degree",0.0174532925199433,
            ID["EPSG",9122]]],
    CS[ellipsoidal,2],
        AXIS["latitude",north,
            ORDER[1],
            ANGLEUNIT["degree",0.0174532925199433,
                ID["EPSG",9122]]],
        AXIS["longitude",east,
            ORDER[2],
            ANGLEUNIT["degree",0.0174532925199433,
                ID["EPSG",9122]]]]
Data axis to CRS axis mapping: 2,1
NAME: String (56.0)
OGRFeature(鍥涚骇閬撹矾):1
  NAME (String) = 澶╂渤鍖楄矾
  Style = PEN(w:1px,c:#ff8000,id:"mapinfo-pen-2,ogr-pen-0")
  LINESTRING (113.31085 23.14341,113.31303 23.14349)

OGRFeature(鍥涚骇閬撹矾):2
  NAME (String) = 澶╂渤鍖楄矾
  Style = PEN(w:1px,c:#ff8000,id:"mapinfo-pen-2,ogr-pen-0")
  LINESTRING (113.31483 23.14366,113.31303 23.14358)

OGRFeature(鍥涚骇閬撹矾):3
  NAME (String) = 澶╂渤鍖楄矾
  Style = PEN(w:1px,c:#ff8000,id:"mapinfo-pen-2,ogr-pen-0")
  LINESTRING (113.31303 23.14349,113.31483 23.14358)

OGRFeature(鍥涚骇閬撹矾):4
  NAME (String) = 澶╂渤鍖楄矾
  Style = PEN(w:1px,c:#ff8000,id:"mapinfo-pen-2,ogr-pen-0")
  LINESTRING (113.31303 23.14358,113.31085 23.14354)
Zhanhaoxin commented 4 years ago

I'm afraid we cannot really help you. There must be something specific to your setup that I can't reproduce here

When compiling the GDAL 3.0.x version, the parameters used are the same as those in the 2.0.4 version. Both versions use PROJ 6.1.1. The following are the parameters used in my makefile. What special parameters need to be added for the compilation of the 3.0.x version?

--with-java=${JAVA_HOME} \
--with-png=$(COMPONENT_DIR)/../libpng/target \
--with-jpeg=$(COMPONENT_DIR)/../jpeg/target \
--with-xml2=$(COMPONENT_DIR)/../libxml2/target \
--with-proj=$(COMPONENT_DIR)/../proj/target \
--with-libz=$(ROOT)/3rdTools/zlib \
--with-crypto=$(ROOT)/3rdTools/openssl \
--without-jasper --without-sqlite3\
jratike80 commented 4 years ago

Did you ever test ogrinfo with the same data that Even used, the all_geoms files from https://github.com/OSGeo/gdal/tree/master/autotest/ogr/data? Did you test also with the Windows or Linux binary version of ogrinfo?

rouault commented 4 years ago

Closing due to lack of feedback