package me.itszooti.geojson.jts;

import me.itszooti.geojson.GeoGeometry;
import me.itszooti.geojson.GeoPoint;
import me.itszooti.geojson.GeoPosition;

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Point;

public class GeoJTSConverter {

	private GeometryFactory geomFactory;
	
	public GeoJTSConverter() {
		geomFactory = new GeometryFactory();
	}
	
	public GeoGeometry fromJTS(Geometry geom) {
		GeoGeometry geoGeom = null;
		
		// check type and convert
		if (geom instanceof Point) {
			geoGeom = fromJTS((Point)geom);
		}
		
		return geoGeom;
	}
	
	public GeoPoint fromJTS(Point point) {
		GeoPosition pos = new GeoPosition(point.getX(), point.getY());
		return new GeoPoint(pos);
	}
	
	public Geometry toJTS(GeoGeometry geoGeom) {
		Geometry geom = null;
		
		// check type and convert
		if (geoGeom instanceof GeoPoint) {
			geom = toJTS((GeoPoint)geoGeom);
		} else {
			// need exception?
		}
		
		return geom;
	}
	
	private Point toJTS(GeoPoint geoPoint) {
		GeoPosition pos = geoPoint.getPosition();
		return geomFactory.createPoint(new Coordinate(pos.getX(), pos.getY()));
	}
	
}

@@ -63,24 +63,66 @@
 eoGeometry;%0A
+import me.itszooti.geojson.GeoLineString;%0A
 import me.it
@@ -327,24 +327,71 @@
 tryFactory;%0A
+import com.vividsolutions.jts.geom.LineString;%0A
 import com.v
@@ -722,16 +722,21 @@
  fromJTS
+Point
 ((Point)
@@ -742,16 +742,142 @@
 )geom);%0A
+%09%09%7D else if (geom instanceof LineString) %7B%0A%09%09%09geoGeom = fromJTSLineString((LineString)geom);%0A%09%09%7D else %7B%0A%09%09%09// need exception?%0A
 %09%09%7D%0A%09%09%0A%09
@@ -896,29 +896,30 @@
 eom;%0A%09%7D%0A%09%0A%09p
-ublic
+rivate
  GeoPoint fr
@@ -923,16 +923,21 @@
  fromJTS
+Point
 (Point p
@@ -1034,32 +1034,364 @@
 oint(pos);%0A%09%7D%0A%09%0A
+%09private GeoLineString fromJTSLineString(LineString lineString) %7B%0A%09%09Coordinate%5B%5D coords = lineString.getCoordinates();%0A%09%09GeoPosition%5B%5D positions = new GeoPosition%5Bcoords.length%5D;%0A%09%09for (int i = 0; i %3C coords.length; i++) %7B%0A%09%09%09positions%5Bi%5D = new GeoPosition(coords%5Bi%5D.x, coords%5Bi%5D.y);%0A%09%09%7D%0A%09%09return new GeoLineString(positions);%0A%09%7D%0A%09%0A
 %09public Geometry
@@ -1527,16 +1527,21 @@
  = toJTS
+Point
 ((GeoPoi
@@ -1549,24 +1549,124 @@
 t)geoGeom);%0A
+%09%09%7D else if (geoGeom instanceof GeoLineString) %7B%0A%09%09%09geom = toJTSLineString((GeoLineString)geoGeom);%0A
 %09%09%7D else %7B%0A%09
@@ -1729,24 +1729,29 @@
  Point toJTS
+Point
 (GeoPoint ge
@@ -1883,10 +1883,369 @@
 );%0A%09%7D%0A%09%0A
+%09private LineString toJTSLineString(GeoLineString geoLineString) %7B%0A%09%09GeoPosition%5B%5D positions = geoLineString.getPositions();%0A%09%09Coordinate%5B%5D coords = new Coordinate%5Bpositions.length%5D;%0A%09%09for (int i = 0; i %3C positions.length; i++) %7B%0A%09%09%09coords%5Bi%5D = new Coordinate(positions%5Bi%5D.getX(), positions%5Bi%5D.getY());%0A%09%09%7D%0A%09%09return geomFactory.createLineString(coords);%0A%09%7D%0A%09%0A
 %7D%0A

Implement LineString conversion