Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I installed PostgreSQL 9.2.4 and PostGIS 2.0.3 on my Windows 8 machine. Then I created a table using phpPgAdmin and added a geometry column using the following statement.

SELECT AddGeometryColumn('tablename', 'area', -1, 'POLYGON', 2);

That resulted in these table columns.

+------+---------------------+--------+----------------------------------+-----------+
|Column|Type                 |Not Null|Default                           |Constraints|
+------+---------------------+--------+----------------------------------+-----------+
|id    |integer              |NOT NULL|nextval('simple_id_seq'::regclass)|PRIMARY KEY|
|name  |character varying(50)|        |                                  |           |
|area  |geometry(Polygon)    |        |                                  |           |
+------+---------------------+--------+----------------------------------+-----------+

After some simple text queries I tried to play with geometry data. This is the query I tried to execute.

INSERT INTO tablename (name, area)
VALUES (
    'Lake',
    GeometryFromText('POLYGON((84 104, 212 48, 321 122, 243 179, 275 238, 131 240))', -1)
);

Unfortunately, it throws an error message.

ERROR:  function geometryfromtext(unknown, integer) does not exist
LINE 4:     GeometryFromText('POLYGON((84 104, 212 48, 321 122, 243 ...
            ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

Since AddGeometryColumn was successful, I assume that PostGIS is set up properly. How can I insert geometry data in my table? What am I doing wrong?

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

You should use ST_GeomFromText.

The functions without the ST_ are the older functions, and are being phased out; They are deprecated, and shouldn't be used any more.

share|improve this answer
2  
Thanks, moreover I had to close the polygon, thus add the starting point at the end again. –  danijar May 5 '13 at 17:03
add comment

It seems that the value -1 is no longer valid since version 2 of PostGIS.

You can use 0 instead.

share|improve this answer
    
Thanks for the information. Moreover there is an overloaded version of that function with allows you to don't specify the RSID at all. –  danijar May 6 '13 at 11:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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