Feature request #2452

Save as vector (not only to shapefile)

Added by Marco Hugentobler about 14 years ago. Updated about 14 years ago.

Status:Closed
Priority:Low
Assignee:Jürgen Fischer
Category:Vectors
Pull Request or Patch supplied: Resolution:fixed
Easy fix?:No Copied to github as #:12512

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

save_as_vector.diff Magnifier (15.9 KB) Marco Hugentobler, 2010-02-17 10:33 PM

History

#1 Updated by John Tull about 14 years ago

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

#2 Updated by Jeremy Palmer about 14 years ago

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?

#3 Updated by Jeremy Palmer about 14 years ago

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
UMunknown"SPHEROID["GRS80,PRI
MEM[[Greenwich"0]UNIT["degree]],PROJECTION["Transverse_Mer
cator"],PARAMETER[[latitude_of_origin"0]PARAMETER["central_meridian]],PARA
METER[[scale_factor"09996]PARAMETER["false_easting]],PARAMETER["false
_northing",10000000],UNITMeter
..\\..\\..\\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
)

#4 Updated by Chris Crook about 14 years ago

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.

#5 Updated by Marco Hugentobler about 14 years ago

  • Resolution set to fixed
  • Status changed from Open to Closed

Applied in d14a5e64 (SVN r13073). 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.

Also available in: Atom PDF