[Qgis-user] Copy vector layer CRS.

Fernando M. Roxo da Motta petro at roxo.org
Thu Oct 1 14:33:21 PDT 2015



  Hi all,

  I am writing a processing script in which I get a pair of line vector
layer as input and I create a new point vector layer that is a kind of
chainage processing with some constraint.   So far so good, the
algorithm is working like a charm and the output is being generated as
expected.

  I am stumbling on (I think) a simple task.   As the input layers
don't necessarily have the same CRS as the project, I would like to use
for the output the same CRS as the input layers.   My problem is in how
to do it.

  I am getting the reference as:

  CRS = layer.GetSpatialRef()

  When defining the writer I use:

  writer = VectorWriter(Outfile, None, fields,\
           QGis.WKBPoint, \
           CRS)

  And I get the error:

   arguments did not match any overloaded call:
 QgsVectorFileWriter(QString, QString, QgsFields, QGis.WkbType,
 QgsCoordinateReferenceSystem, QString driverName="ESRI Shapefile",
 QStringList datasourceOptions=QStringList(), QStringList
 layerOptions=QStringList(), QString newFilename=None,
 QgsVectorFileWriter.SymbologyExport
 symbologyExport=QgsVectorFileWriter.NoSymbology): argument 5 has
 unexpected type 'SpatialReference'
 QgsVectorFileWriter(QgsVectorFileWriter): argument 1 has unexpected
 type 'unicode' See log for more details 

  The traceback in log is:

Traceback (most recent call last):|  File
"/home/roxo/.qgis2/python/plugins/processing/core/GeoAlgorithm.py",
line 227, in execute|    self.processAlgorithm(progress)|  File
"/home/roxo/.qgis2/python/plugins/processing/script/ScriptAlgorithm.py",
line 271, in processAlgorithm|    exec((script), ns)|  File "<string>",
line 832, in <module>|  File "<string>", line 781, in main|  File
"<string>", line 538, in Creat3D|  File
"/home/roxo/.qgis2/python/plugins/processing/tools/vector.py", line
435, in __init__|    qgsfields, geometryType, crs,
OGRCodes[extension])|TypeError: arguments did not match any overloaded
call:|  QgsVectorFileWriter(QString, QString, QgsFields, QGis.WkbType,
QgsCoordinateReferenceSystem, QString driverName="ESRI Shapefile",
QStringList datasourceOptions=QStringList(), QStringList
layerOptions=QStringList(), QString newFilename=None,
QgsVectorFileWriter.SymbologyExport
symbologyExport=QgsVectorFileWriter.NoSymbology): argument 5 has
unexpected type 'SpatialReference'|
QgsVectorFileWriter(QgsVectorFileWriter): argument 1 has unexpected
type 'unicode'|

  The content of CRS is:

CRS= PROJCS["SIRGAS_2000_UTM_zone_24S",
    GEOGCS["SIRGAS 2000",
        DATUM["Sistema_de_Referencia_Geocentrico_para_las_AmericaS_2000",
            SPHEROID["GRS 1980",6378137,298.257222101,
                AUTHORITY["EPSG","7019"]],
            TOWGS84[0,0,0,0,0,0,0],
            AUTHORITY["EPSG","6674"]],
        PRIMEM["Greenwich",0,
            AUTHORITY["EPSG","8901"]],
        UNIT["degree",0.0174532925199433,
            AUTHORITY["EPSG","9122"]],
        AUTHORITY["EPSG","4674"]],
    PROJECTION["Transverse_Mercator"],
    PARAMETER["latitude_of_origin",0],
    PARAMETER["central_meridian",-39],
    PARAMETER["scale_factor",0.9996],
    PARAMETER["false_easting",500000],
    PARAMETER["false_northing",10000000],
    UNIT["Meter",1]]

  If instead of CRS I use :

  writer = VectorWriter(Outfile, None, fields,\
             QGis.WKBPoint, \
             QgsCoordinateReferenceSystem(31984,
QgsCoordinateReferenceSystem.EpsgCrsId))

  Everything works, so I understand that the format of information is
not correct.

  The CRS is : class 'osgeo.osr.SpatialReference'
  And the convertion above is:  class
'qgis._core.QgsCoordinateReferenceSystem'

  Is there a way to convert from one to the other?

  BTW:  2.10.1-Pisa in Linux [Xu|U]buntu 14.04.3 64bits.

  Thanks in advance.


  Roxo

-- 
---------------- Non luctari, ludare -------------------+ WYSIWYG
Fernando M. Roxo da Motta <petro at roxo.org>              | Editor?
Except where explicitly stated I speak on my own behalf.|  VI !!
      ( Usuário Linux registrado #39505 )               | I see text,
------------ Quis custodiet ipsos custodes?-------------+ I get text!
 



More information about the Qgis-user mailing list