Opened 14 years ago

Closed 14 years ago

#2123 closed patch (fixed)

wrong projection information when creating a new shapefile

Reported by: cmoe Owned by: jef
Priority: major: does not work as expected Milestone: Version 1.4.0
Component: Data Provider Version: Trunk
Keywords: create shapefile; Cc:
Must Fix for Release: Yes Platform: RedHat
Platform Version: Awaiting user input: no

Description

(This bug may be related to #1943 and also to #1889, if it isn't even the same.)

Im working with crs epsg 21781. If I create a new shapefile with the "new vecotr layer" tool, the shapefile is missing the towgs84 part in its crs parameters.

  1. Open Qgis
  2. in project properties set tht crs to epsg 21781/CH1903 (Enable 'on the fly' is also set).
  3. in the settings->options->crs set "project wide default crs will be used"
  4. with the "new vector layer"-button create a new shapefile and save it.
  5. load the created shapefile into qgis
  6. open the properties of the new shapefile -> the crs of the shapefile is missing the towgs84 parameter and therefore it displays on a wrong place in the canvas.

I attach the debug output from the console when creating a new shapefile in this way. You will see that from line 1 to 14 all output concering crs has the towgs84 information. As from line 41 on the towgs84 part is missing. So it seems to be a problem of the qgsvectorprovider or ogr.

The crs in the srs.db is ok, also the epsg file of proj. Currently I'm running r12143.

regards Cedric

Attachments (2)

debugoutput_new_shapfile.txt (33.0 KB ) - added by cmoe 14 years ago.
debug output when creating a new shapefile in epsg 21781
fix_wrong_prj_files.diff (1.0 KB ) - added by cmoe 14 years ago.
patch to correct wrong prj files when creating an empty data source. Added a test if its really a shapefile

Download all attachments as: .zip

Change History (8)

by cmoe, 14 years ago

debug output when creating a new shapefile in epsg 21781

comment:1 by cmoe, 14 years ago

I stripped the problem down to the call of OGR_DS_CreateLayer of the createEmptyDataSource method in qgsogrprovider.cpp (around linie 1525).

The reference (OGRSpatialReferenceH) we are passing seems to be ok, but the returning layer (OGRLayerH) is missing the towgs84 part in his srs. This seems to be intentional of ogr because OGR_DS_CreateLayer calls morphToESRI() for the srs (line 568 in gdal/ogr/ogrsf_frmts/shape/ogrshapedatasource.cpp). morphToESRI() removes the towgs84 parameter.

This does not happen, if I export a postgis layer as shapefile or an existing shapefile. But this is done in different way by the QgsVectorFileWriter::writeAsShapefile(). qgsvectorfilewriter.cpp says at line 397, that it doesn't strip the towgs84 parameter.

Would it be possible, to use the QgsVectorFileWriter in the createEmptyDataSource method? According to comment qgsvectorfilewriter.cpp we are already broken with relying on ESRI style prj-files.

comment:2 by cmoe, 14 years ago

I understand the follwing now: If we do writeAsShapefile() ogr responds also with a wrong prj file. But afer the ogr call qgis just overwrites the prj file with a correct version.

So we may do the same for creating an empty data source. A patch is provided in the attachments. Please may someone have a look at it, and, if appropriate, apply it.

comment:3 by cmoe, 14 years ago

Type: bugpatch

comment:4 by mhugent, 14 years ago

Owner: changed from nobody to jef

Hi Cedric

Thank you for the patch. It might be good to test if format is shapefile, since the method could also be used for other formats (even if this is not the case at the moment). Otherwise +1 for me to apply the patch.

I'm assigining the ticket to Jürgen, since he is the OGR guru in the dev team.

Regards, Marco

comment:5 by cmoe, 14 years ago

Hi Marco

I added a test if it's a ESRI Shapefile to the patch. I'm not sure if this the right way to do it, but it works :-) I added also a little more robustnes to the writing of the new file.

by cmoe, 14 years ago

Attachment: fix_wrong_prj_files.diff added

patch to correct wrong prj files when creating an empty data source. Added a test if its really a shapefile

comment:6 by jef, 14 years ago

Resolution: fixed
Status: newclosed

"applied" in r12259.

Note: See TracTickets for help on using tickets.