I want to use ST_GeomFromText() to load vector data to PostGIS. However, I don't know how to convert from Geojson type to WKT.

N.B. I know I can use OGR2OGR to upload the GeoJSON directly, but I just want to confirm if there is any way to convert it or not.

  • ogr2ogr could be a way May 20 '13 at 17:39
  • Efficient in what way?
    – R.K.
    May 21 '13 at 4:04
  • 1
    If your PostGIS version >2, you import GeoJSON directly. May 21 '13 at 7:16

why not use

see Creating GeoJSON Feature Collections with JSON and PostGIS functions or ST_GeomFromGeoJSON from OpenGeo.

To convert to WKT, use

  • ST_AsText , the reverse of ST_GeomFromText() which return the Well-Known Text (WKT)
  • ST_AsEWKT same with SRID meta data
  • Hi, Thanks so much. I don't even know this tool. I am still learning from you as a student.
    – Yu Guo
    May 21 '13 at 16:32

If Python is your thing then you can use GeoMet. It's a Python module that converts GeoJSON to WKT/WKB and vice versa. You can install it directly from the github repository using pip

$ pip install git+git://github.com/larsbutler/geomet.git

Here is a sample conversion:

>>> from geomet import wkt
>>> point = {'type': 'Point', 'coordinates': [116.4, 45.2, 11.1]}
>>> wkt.dumps(point, decimals=4)
'POINT (116.4000 45.2000 11.1000)'

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.