-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GeoPackage: Fix handling of invalid SRS ID when writing #3302
Comments
I've not checked but I suspect that if you run those cases, instead of using SRID = 0 or -1, it will add a new entry in the gpkg_spatial_ref_sys table. This is not a huge deal, but it would be more in the spirit of the spec to just use the special SRID values. |
Yes, new SRS is inserted, because srs = osr.SpatialReference()
srs.ImportFromWkt('GEOGCS["Undefined geographic SRS",DATUM["unknown",SPHEROID["unknown",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST]]') No authority is found, so it falls-back to
ProblemI don't really know how to change the Python TestHere is my current Python sample that exercises the situation: def dump_gpkg_spatial_ref_sys(ds, tag):
print('--- {0} ------------'.format(tag))
lyr = ds.ExecuteSQL('SELECT * FROM gpkg_spatial_ref_sys ORDER BY srs_id')
f = lyr.GetNextFeature()
i = 1
while f:
print('{0}:'.format(i), f.GetField('srs_name'), '|', f.GetField('srs_id'), '|', f.GetField('organization_coordsys_id'), '|', f.GetField('definition'), '|', f.GetField('description'))
f = lyr.GetNextFeature()
i = i + 1
def test_gpkg_write_srs_undefined():
if gdaltest.gpkg_dr is None:
pytest.skip()
gdal.Unlink('/vsimem/tmp.gpkg')
ds = gdaltest.gpkg_dr.Create('/vsimem/tmp.gpkg', 1, 1)
ds.SetGeoTransform([0, 1, 0, 0, 0, -1])
dump_gpkg_spatial_ref_sys(ds, 'BEFORE')
srs = osr.SpatialReference()
srs.ImportFromWkt('GEOGCS["Undefined geographic SRS",DATUM["unknown",SPHEROID["unknown",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST]]')
ret = ds.SetSpatialRef(srs)
dump_gpkg_spatial_ref_sys(ds, 'AFTER ') Output:
|
I would likely add an early test in the method for the nature of the CRS with OGRSpatialReference::IsGeographic() / OGRSpatialReference::IsLocal() and on its name with OGRSpatialReference::GetName() |
Okey. Seeing the This does seem to do the job: if (poSRS->IsGeographic() || poSRS->IsLocal())
{
const char* pszName = poSRS->GetName();
if ( pszName != nullptr && strlen(pszName) > 0 )
{
if (EQUAL(pszName, "Undefined cartesian SRS"))
return -1;
if (EQUAL(pszName, "Undefined geographic SRS"))
return 0;
}
} I'll prepare PR. |
that's a good point, but without testing the name, we have no way of deciding since we have no concept of SRID in OGRSpatialReference. My idea was that a ogr2ogr of a source GeoPackage with SRID=0 or -1 to a target GeoPackage would result in 0 and -1 being used in the target dataset. |
Improves OSGeo#3286 Closes OSGeo#3302 (cherry picked from master commit 69aebed)
This issue is dedicated to discuss further improvements to PR #3286 suggested by @rouault in #3286 (comment), quoting:
@rouault I admit I'm having hard time trying to find an anchor for the 'writing side' in the GeoPackage driver - I have very little experience with the format.
Do you mean the driver is lacking as not accepting any of the two possible undefined SRS when new dataset/layer is created?
Putting it differently, what new test cases are expected to be covered (and any required implementation on the drivier added/changed, of course). Here is what I have just been scratching out:
I'll appreciate any hints or bearings where the driver is lacking.
The text was updated successfully, but these errors were encountered: