Reduce some code duplication

git-svn-id: http://svn.osgeo.org/postgis/trunk@12801 b70326c6-7e19-0410-871a-916f4a2858ee