Ticket #2452 (closed patch: fixed)

Opened 3 years ago

Last modified 3 years ago

Save as vector (not only to shapefile)

Reported by: mhugent Owned by: jef
Priority: minor: annoyance Milestone: Version 1.5.0
Component: Vectors Version: Trunk
Keywords: Cc:
Platform Version: Platform: Debian
Must Fix for Release: No Awaiting user input: no

Description

The following patch adds the possibility to save vector to an OGR supported file format (replaces the 'save as shapefile'). Jürgen, could you review it? The part with the OGR drivers is a bit redundant to code that is already in the OGR provider and in the OGR converter plugin. But as far as I could see, that code does not contain the relationship between driver key and filter string. Maybe we could shift that code to a central place in future?

Regards, Marco

Attachments

save_as_vector.diff Download (15.9 KB) - added by mhugent 3 years ago.

Change History

Changed 3 years ago by mhugent

Changed 3 years ago by mhugent

  • type changed from bug to patch

Changed 3 years ago by jctull

I tested the patch on my OS X setup with r12953. It worked very well on a kml export I performed. This is a very useful addition. Thank you, Marco!

Changed 3 years ago by jpalmer

Tested patch on WinXP with Visual studio 2008 build. Compiled and worked well.

Mapinfo and KML export seems to work well with layers and layer selections. However I did notice that table names in the sqlite export were getting the fullpath to the location of the saved sqlite database. Maybe the QGIS layer name would be better?

Changed 3 years ago by jpalmer

I've being doing some more testing with transforming output vector layers. I have found that if the layer transformation fails during the vector writing, the process aborts, no error message is given to the user, and the output file is left in a corrupted state.

Here is the debug log from the failed layer save:

..\..\..\src\gui\qgsprojectionselector.cpp(72) : (QgsProjectionSelector::QgsProj? ectionSelector) Use popular projection list from EPSG/Proj4 saved state ..\..\..\src\core\qgscoordinatereferencesystem.cpp(242) : (QgsCoordinateReferenc? eSystem::loadFromDb) failed : select srs_id,description,projection_acronym,ellip soid_acronym,parameters,srid,epsg,is_geo from tbl_srs where epsg='100000' ..\..\..\src\core\qgscoordinatereferencesystem.cpp(489) : (QgsCoordinateReferenc? eSystem::getRecord) running query: select * from tbl_srs where parameters='+proj =longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +pm=160 +no_defs' ..\..\..\src\core\qgscoordinatereferencesystem.cpp(523) : (QgsCoordinateReferenc? eSystem::getRecord) trying system qgis.db ..\..\..\src\core\qgscoordinatereferencesystem.cpp(558) : (QgsCoordinateReferenc? eSystem::getRecord) failed : select * from tbl_srs where parameters='+proj=long lat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +pm=160 +no_defs' ..\..\..\src\core\qgscoordinatereferencesystem.cpp(566) : (QgsCoordinateReferenc? eSystem::getRecord) retrieved: select * from tbl_srs where parameters='+proj=lo nglat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +pm=160 +no_defs' ..\..\..\src\core\qgscoordinatereferencesystem.cpp(425) : (QgsCoordinateReferenc? eSystem::createFromProj4) globbing search for srsid from this proj string ..\..\..\src\core\qgscoordinatereferencesystem.cpp(777) : (QgsCoordinateReferenc? eSystem::findMatchingProj) entered. ..\..\..\src\core\qgscoordinatereferencesystem.cpp(826) : (QgsCoordinateReferenc? eSystem::findMatchingProj) no match found in srs.db, trying user db now! ..\..\..\src\core\qgscoordinatereferencesystem.cpp(853) : (QgsCoordinateReferenc? eSystem::findMatchingProj) -------> MATCH FOUND in user qgis.db srsid: 100000 ..\..\..\src\core\qgscoordinatereferencesystem.cpp(428) : (QgsCoordinateReferenc? eSystem::createFromProj4) globbing search for srsid returned srsid: 100000 ..\..\..\src\core\qgscoordinatereferencesystem.cpp(739) : (QgsCoordinateReferenc? eSystem::setMapUnits) Projection has linear units of Meter ..\..\..\src\core\qgscoordinatereferencesystem.cpp(739) : (QgsCoordinateReferenc? eSystem::setMapUnits) Projection has linear units of Meter ..\..\..\src\core\qgscoordinatereferencesystem.cpp(242) : (QgsCoordinateReferenc? eSystem::loadFromDb) failed : select srs_id,description,projection_acronym,ellip soid_acronym,parameters,srid,epsg,is_geo from tbl_srs where epsg='0' ..\..\..\src\core\qgscoordinatereferencesystem.cpp(489) : (QgsCoordinateReferenc? eSystem::getRecord) running query: select * from tbl_srs where parameters='+proj =merc +lon_0=0 +lat_ts=0 +x_0=0 +y_0=0 +a=6378137 +b=6378137 +units=m +no_defs' ..\..\..\src\core\qgscoordinatereferencesystem.cpp(523) : (QgsCoordinateReferenc? eSystem::getRecord) trying system qgis.db ..\..\..\src\core\qgscoordinatereferencesystem.cpp(566) : (QgsCoordinateReferenc? eSystem::getRecord) retrieved: select * from tbl_srs where parameters='+proj=me rc +lon_0=0 +lat_ts=0 +x_0=0 +y_0=0 +a=6378137 +b=6378137 +units=m +no_defs' ..\..\..\src\core\qgscoordinatereferencesystem.cpp(369) : (QgsCoordinateReferenc? eSystem::createFromProj4) proj4string match search for srsid returned srsid: 100 002 ..\..\..\src\core\qgscoordinatereferencesystem.cpp(739) : (QgsCoordinateReferenc? eSystem::setMapUnits) Projection has linear units of Meter ..\..\..\src\core\qgscoordinatereferencesystem.cpp(739) : (QgsCoordinateReferenc? eSystem::setMapUnits) Projection has linear units of Meter ..\..\..\src\gui\qgsprojectionselector.cpp(279) : (QgsProjectionSelector::ogcWms CrsFilterAsSqlExpression?) exiting with '1'. ..\..\..\src\gui\qgsprojectionselector.cpp(660) : (QgsProjectionSelector::loadUs erCrsList) Fetching user projection list... ..\..\..\src\gui\qgsprojectionselector.cpp(279) : (QgsProjectionSelector::ogcWms CrsFilterAsSqlExpression?) exiting with '1'. ..\..\..\src\gui\qgsprojectionselector.cpp(465) : (QgsProjectionSelector::select edProj4String) mySrsId = 3452 ..\..\..\src\gui\qgsprojectionselector.cpp(466) : (QgsProjectionSelector::select edProj4String) USER_CRS_START_ID = 100000 ..\..\..\src\gui\qgsprojectionselector.cpp(490) : (QgsProjectionSelector::select edProj4String) db = C:/OSGeo4W/apps/qgis-linz/./resources/srs.db ..\..\..\src\gui\qgsprojectionselector.cpp(507) : (QgsProjectionSelector::select edProj4String) Selection sql: select parameters from tbl_srs where srs_id = 3452

..\..\..\src\gui\qgsprojectionselector.cpp(465) : (QgsProjectionSelector::select edProj4String) mySrsId = 177 ..\..\..\src\gui\qgsprojectionselector.cpp(466) : (QgsProjectionSelector::select edProj4String) USER_CRS_START_ID = 100000 ..\..\..\src\gui\qgsprojectionselector.cpp(490) : (QgsProjectionSelector::select edProj4String) db = C:/OSGeo4W/apps/qgis-linz/./resources/srs.db ..\..\..\src\gui\qgsprojectionselector.cpp(507) : (QgsProjectionSelector::select edProj4String) Selection sql: select parameters from tbl_srs where srs_id = 177 ..\..\..\src\core\qgscoordinatereferencesystem.cpp(739) : (QgsCoordinateReferenc? eSystem::setMapUnits) Projection has linear units of Meter ..\..\..\src\core\qgscoordinatereferencesystem.cpp(739) : (QgsCoordinateReferenc? eSystem::setMapUnits) Projection has linear units of Meter ..\..\..\src\core\qgscoordinatereferencesystem.cpp(739) : (QgsCoordinateReferenc? eSystem::setMapUnits) Projection has linear units of Meter ..\..\..\src\core\qgscoordinatereferencesystem.cpp(739) : (QgsCoordinateReferenc? eSystem::setMapUnits) Projection has linear units of Meter ..\..\..\src\core\qgscoordinatereferencesystem.cpp(739) : (QgsCoordinateReferenc? eSystem::setMapUnits) Projection has linear units of Meter ..\..\..\src\core\qgscoordinatereferencesystem.cpp(739) : (QgsCoordinateReferenc? eSystem::setMapUnits) Projection has linear units of Meter ..\..\..\src\core\qgsvectorfilewriter.cpp(97) : (QgsVectorFileWriter::QgsVectorF ileWriter) Created data source ..\..\..\src\core\qgsvectorfilewriter.cpp(119) : (QgsVectorFileWriter::QgsVector? FileWriter?) WKT to save as is PROJCS["unnamed",GEOGCS["GRS 1980(IUGG, 1980)",DAT UM["unknown",SPHEROID["GRS80",6378137,298.257222101],TOWGS84[0,0,0,0,0,0,0]],PRI MEM["Greenwich",0],UNIT["degree",0.0174532925199433]],PROJECTION["Transverse_Mer cator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",173],PARA METER["scale_factor",0.9996],PARAMETER["false_easting",1600000],PARAMETER["false _northing",10000000],UNIT["Meter",1]] ..\..\..\src\core\qgsvectorfilewriter.cpp(156) : (QgsVectorFileWriter::QgsVector? FileWriter?) created layer ..\..\..\src\core\qgsvectorfilewriter.cpp(159) : (QgsVectorFileWriter::QgsVector? FileWriter?) creating 6 fields ..\..\..\src\core\qgsvectorfilewriter.cpp(221) : (QgsVectorFileWriter::QgsVector? FileWriter?) creating field id type int width 10 precision 0 ..\..\..\src\core\qgsvectorfilewriter.cpp(221) : (QgsVectorFileWriter::QgsVector? FileWriter?) creating field alt_id type int width 10 precision 0 ..\..\..\src\core\qgsvectorfilewriter.cpp(221) : (QgsVectorFileWriter::QgsVector? FileWriter?) creating field name type QString width 255 precision 104 ..\..\..\src\core\qgsvectorfilewriter.cpp(221) : (QgsVectorFileWriter::QgsVector? FileWriter?) creating field location type QString width 255 precision 104 ..\..\..\src\core\qgsvectorfilewriter.cpp(221) : (QgsVectorFileWriter::QgsVector? FileWriter?) creating field status type QString width 255 precision 8 ..\..\..\src\core\qgsvectorfilewriter.cpp(221) : (QgsVectorFileWriter::QgsVector? FileWriter?) creating field audit_id type int width 10 precision 0 ..\..\..\src\core\qgsvectorfilewriter.cpp(235) : (QgsVectorFileWriter::QgsVector? FileWriter?) Done creating fields ..\..\..\..\src\providers\postgres\qgspostgresprovider.cpp(3115) : (QgsPostgresP rovider::Conn::openCursor) Starting read-only transaction ..\..\..\src\core\qgscoordinatetransform.cpp(488) : (QgsCoordinateTransform::tra nsformCoords) Projection failed emitting invalid transform signal: forward trans form of (0.152795, -0.806109)

failed with error: latitude or longitude exceeded limits

..\..\..\src\core\qgscoordinatetransform.cpp(492) : (QgsCoordinateTransform::tra nsformCoords) throwing exception ..\..\..\src\core\qgscoordinatetransform.cpp(306) : (QgsCoordinateTransform::tra nsformInPlace) rethrowing exception Failed to transform a point while drawing a feature of type . Writing stopped.

(Exception: forward transform of

(0.152795, -0.806109)

failed with error: latitude or longitude exceeded limits )

Changed 3 years ago by ccrook

Would it be possible to add a feature so that if the layer is using the non-persistent memory data provider, then when it is saved to a persistent provider, shapefile or other, then the layer is replaced with the persistent version? (This would address the ticket I've just raised #2487). This would make sense from a user point of view - like saving a new document in a word processor. I guess it could be optional, though I can't see any reason not make it the normal behaviour.

Changed 3 years ago by mhugent

  • status changed from new to closed
  • resolution set to fixed

Applied in r13072. The sqlite table name problem is fixed. The coordinate transformation problem is hard for me to reproduce. Maybe it is a case where the transformation class does not throw any exception.

Note: See TracTickets for help on using tickets.