Read/Write JTS Geometry/Polygon/Coordinate Sequence using WKTReader and WKTWriter

361 views
Skip to first unread message

Ams Sol

unread,
Oct 9, 2014, 7:30:46 AM10/9/14
to nettopol...@googlegroups.com
Dear all,

All I need is a simple file to hold a set of polygon coordinate information for me. I want to be able to record those coordinates and retrieve them from my database (WKT seems standard).
In my android application I am making use of JTS libraries to draw buffers.
There are examples of reading writing with WKT but I cant help to notice for example this line:
wkt.read("LINESTRING(0 0, 1 1)");
seems useless for me. if i knew the coordinates of my polygon why would I want to read it from a file?
do you see where im going with this?
I need those (0 0) and (1 1) coordinates. I know what to do with them!

to further clarify my point following line (if existed) is more understandable for me:

Geometry[] geometries = wkt.read("path to my local WKT file");

I would highly appreciate any suggestions or alternatives.

many thanks in advance

Diego Guidi

unread,
Oct 9, 2014, 8:12:33 AM10/9/14
to nettopol...@googlegroups.com


On Thursday, October 9, 2014 1:30:46 PM UTC+2, Ams Sol wrote:
Geometry[] geometries = wkt.read("path to my local WKT file");

You can use 
wkt.read(new FileStream("path to my local WKT file") );

Anyway, your file should contains a single geometry, and not a set of geometries.
If your file contains more than one geometry, you can write all data in separate lines and then use a code like
foreach (String line in File.ReadAllLines("path to my local WKT file")
   wkt
.read(line)


Ams Sol

unread,
Oct 9, 2014, 10:06:08 AM10/9/14
to nettopol...@googlegroups.com
perhaps we are talking about different APIs
Vividsolutions JTS java api does not have such an argument support for the read method of WKTReader class.

Diego Guidi

unread,
Oct 9, 2014, 10:46:23 AM10/9/14
to nettopol...@googlegroups.com


On Thursday, October 9, 2014 4:06:08 PM UTC+2, Ams Sol wrote:
perhaps we are talking about different APIs
Vividsolutions JTS java api does not have such an argument support for the read method of WKTReader class.

OPS, sorry :)
This group is for NTS, the C# port of JTS library.
You can ask for specific JTS support here: https://lists.sourceforge.net/lists/listinfo/jts-topo-suite-user
Anyway, I think my suggest is valid.
You should use java to read string lines from your file and then read geometries using WKTReader
Reply all
Reply to author
Forward
0 new messages