1

How do I get the QGIS modeler to recognize and use my USER DEFINED CRS in proj4 format? I have a user defined CRS with the authid USER:100024. Its parameters in proj4 are "+proj=utm +zone=18 +ellps=clrk66 +datum=WGS84 +towgs84=-11.0584,163.8703,190.541,0,0,0,0 +units=m +no_defs +wktext". Manually I can set my user defined CRS on a given layer (right click layer in TOC, 'Set layer CRS' to 100024) and then save to EPSG:2959 (NAD83 UTM18N) and get a valid return of point coordinates. This works fine. The problem I'm running into is in trying to replicate this behaviour with a QGIS model. From the modeler template I first use the "define current projection" on the source layer (where I select USER:100024 from the CRS window). Second, I run a "reproject layer" to EPSG:2959 on the defined projection from step 1. But this does not work, the coordinates area about 4m off what they ought to be. It seems to ignore the defined proj4 layer paramters (unlike when I do it manually). In fact, when I verify the properties on the source layer it defaults to WGS84 (which sort of makes sense because it's not an official EPSG code) instead of 100024.

  • You may be confusing the system by using +datum=wgs84. It can't be on WGS84 because you're giving a transformation for a local datum to WGS84. Plus using Clarke 1966 for the ellipsoid. What's the datum really supposed to be? NAD27? Or ATS77? Try dropping the +datum statement at least. – mkennedy Feb 14 '18 at 19:34
  • to mkennedy : Dropping the +datum statement doesn't seem to do it either, but it still works manually. In answer to your question our source data is all in NAD27 but was given a shift (for reasons still obscure to me) sometime in the mid seventies when the operation began (mining company). The +towgs84=-11.0584,163.8703,190.541 parameters were given to us by a surveyor to compensate for that shift when converting to NAD83. – Frederic Feb 15 '18 at 19:51
1

I solved the issue by using a pyqgis python script in QGIS instead.

Call and exectute the QGIS projection selector within the script.

Assign the User Defined crs number to a variable (important because different QGIS instances will generate their own crs number).

Set the active layer crs to the selected crs.

Reproject the active layer using the QGIS reprojection algorithm.

# https://gis.stackexchange.com/questions/227899/how-can-i-set-the-project-crs-to-an-existing-user-defined-coordinate-system-with
# https://gis.stackexchange.com/questions/109235/how-to-make-crs-transformation-of-a-qgsvectorlayer?rq=1

# following 2 parameters are for script user input window
##myLayer=vector
##outLayer=output vector

# import modules
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from qgis.core import *
from qgis.utils import *
import processing 
from qgis.gui import QgsGenericProjectionSelector

# use the projection selector window to select your User Defined crs
projSelector = QgsGenericProjectionSelector()
# when running the script, open the projection selector window
projSelector.exec_()
# assign the selected crs to the crsID variable
crsId = projSelector.selectedCrsId()

# apply the crsID to the coordinate ref system
target_crs = QgsCoordinateReferenceSystem()
target_crs.createFromId(crsId, QgsCoordinateReferenceSystem.InternalCrsId)

# use following line if you want to set the canvas crs to the target_crs value
#iface.mapCanvas().setDestinationCrs(target_crs)

# select the active layer in canvas TOC and apply the selected crs
myLayer = iface.activeLayer()
myLayer.setCrs(target_crs)

# run the reprojection algorithm
processing.runalg('qgis:reprojectlayer', myLayer, 'EPSG:2959', r"I:/NAD83_transformation/feb16_2018/new_2959_shape_from100024.shp")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.