I am trying to create a polygon using Lat/long's of community districts. Here is my query below:

SELECT ST_MakePolygon(ST_GeomFromText(
'LINESTRING (40.665535 -73.9933, 40.665535 -73.969749, 40.7245 73.9419, 40.6773 74.0094,40.6795 73.9992, 40.6733 -73.9903, 40.7081  -73.9571, 40.6872 -73.9418, 40.6849 -73.9845, 40.665535 -73.9933)'), 4326);

Whenever I try to run this query I get an error message:

HINT: No function matches the given name and argument types. You might need to add explicit type casts.

Can someone guide me in the right direction?

2 Answers 2


If you are using Well Known Text (WKT) you probably want to describe it as a polygon.

It would look like:

SELECT ST_GeomFromText('POLYGON((40.665535 -73.9933, 40.665535 -73.969749, 40.7245 73.9419, 40.6773 74.0094, 40.6795 73.9992, 40.6733 -73.9903, 40.7081 -73.9571, 40.6872 -73.9418, 40.6849 -73.9845, 40.665535 -73.9933))', 4326);

The reason why there are two brackets (rather than one for the LINESTRING case) is that polygons can have interior regions excluded - it would then have "holes".

Also, I've done the same order of coordinates as your question. However you might be surprised by the results, because that area is not in the USA. It is somewhere in Antarctica, south of the Indian Ocean. For your case, WKT is longitude, latitude rather than latitude, longitude. Think Cartesian plane (X, then Y).

  • Hey man thanks for the answer. I'm a little confused with your last comment. You're saying I should do longitude latitude rather than latitude longitude(which is what I did )?
    – Micheal C.
    Commented Dec 3, 2016 at 23:03
  • 1
    See en.wikipedia.org/wiki/Well-known_text - whether it is longitude then latitude or easting then northing or some other interpretation depends on the spatial reference system. I suggest thinking X then Y.
    – BradHards
    Commented Dec 3, 2016 at 23:05

You have your brackets all mixed up. Put the SRID inside the st_geomfromtext bracket and you should be set

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.