1

I'm trying to work an example from the "PostGIS Cookbook" and I'm getting an error I don't understand. I'm running the example using Postgres.app on a MacBook. Postgres.app is running PostgreSQL 9.1.12 with PostGIS 1.5.3.

Here's the PL/Python function:

-- load.sql
CREATE OR REPLACE FUNCTION Geocode(address text)
    RETURNS geometry(Point, 4326)
AS $$
    from geopy import geocoders
    g = geocoders.GoogleV3()
    place, (lat, lng) = g.geocode(address)
    plpy.info('Geocoded %s for the address: %s' % (place, address))
    plpy.info('Longitude is %s, Latitude is %s.' % (lng, lat))
    plpy.info("SELECT ST_GeomFromText('POINT(%s %s)', 4326)" % (lng, lat))
    result = plpy.execute("SELECT ST_GeomFromText('POINT(%s %s)', 4326) AS point_geocded" % (lng, lat))
    geometry = result[0]["point_geocoded"]
    return geometry
$$ LANGUAGE plpythonu;

When I try to load the function into the database with this command:

psql geodjango < load.sql

I get this error:

ERROR: type modifier is not allowed for type "geometry"

I suspect this error has something to do with the fact that the book example assumes you're using PostGIS 2.0 and I'm using 1.5.3. However, it still doesn't make sense to me. I'm read about the ST_GeomFromText function in the PostGIS 1.5 Manual and this code appears to be correct. What am I doing wrong?

Thanks.

4
  • Is upgrading to postgis 2.0 an option?
    – Mapperz
    Commented Mar 24, 2014 at 20:55
  • Due to other dependencies, no.
    – Jim
    Commented Mar 24, 2014 at 20:56
  • With PostGIS 1.5 you need to set management to True in your Geometry github.com/geoalchemy/geoalchemy2/issues/50
    – Mapperz
    Commented Mar 24, 2014 at 21:00
  • I don't mean to sound dense, but how does one do that? The articles you referred to pertain to GeoAlchemy which I'm not using. I've looked in the PostGIS manual and don't see this mentioned anywhere. Thanks.
    – Jim
    Commented Mar 24, 2014 at 21:11

1 Answer 1

4

Just change the second line

RETURNS geometry(Point, 4326)

to

RETURNS geometry

The "type modifier" is a 2.0 feature. You might have other problems if GeoAlchemy expects PostGIS 2.0+, but for this particular function, just removing the typmod syntax should suffice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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