3

Lets say I just wanted to turn WKT to GeoJSON on the command line I could do this:

/opt/gdal-custom/bin/ogr2ogr -f CSV /vsistdout/ foo.sqlite \
-dialect sqlite \
-sql "SELECT AsGeoJSON(GeomFromText('POLYGON ((-94.1748 26.90248,-94.1748 27.60567,-93.07617 27.60567,-93.07617 26.90248,-94.1748 26.90248))', 4326)) AS wktIntersection"

However I don't actually need the sqlite file. Is there some sort of null datasource I could use? I tried replacing foo.sqlite with /dev/null and /vsimemory/. Its just a minor annoyance.

asked Jul 9, 2015 at 16:07

2 Answers 2

6

Use the SQLite in-memory database: :memory:

ogr2ogr -f CSV /vsistdout/ ":memory:" -dialect sqlite \
-sql "SELECT AsGeoJSON(GeomFromText('POLYGON ((-94.1748 26.90248,-94.1748 27.60567,-93.07617 27.60567,-93.07617 26.90248,-94.1748 26.90248))', 4326)) AS wktIntersection"
answered Jul 10, 2015 at 2:02
1
  • Ok that seems to be the cleanest way to do it. Commented Jul 10, 2015 at 13:06
2

You could make a tiny Python script, e.g. wkt2json.py

#!/usr/bin/env python
import sys
from osgeo import ogr
ogr.UseExceptions()
print(ogr.CreateGeometryFromWkt(sys.argv[1]).ExportToJson())

And use it with the WKT in double quotes as the first and only argument:

$ python wkt2json.py "POINT(4 5)"
{ "type": "Point", "coordinates": [ 4.0, 5.0 ] }
answered Jul 10, 2015 at 2:44
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.