polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nic...@apache.org
Subject [40/50] [abbrv] zest-qi4j git commit: Final cleanup
Date Fri, 17 Apr 2015 16:46:27 GMT
http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/503532e9/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/to/ToHelper.java
----------------------------------------------------------------------
diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/to/ToHelper.java
b/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/to/ToHelper.java
deleted file mode 100644
index ae9916b..0000000
--- a/libraries/spatial/src/main/java/org/qi4j/library/spatial/conversions/to/ToHelper.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright 2014 Jiri Jetmar.
- *
- * Licensed  under the  Apache License,  Version 2.0  (the "License");
- * you may not use  this file  except in  compliance with the License.
- * You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed  under the  License is distributed on an "AS IS" BASIS,
- * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
- * implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.qi4j.library.spatial.conversions.to;
-
-import org.geojson.GeoJsonObject;
-import org.qi4j.api.geometry.internal.TGeometry;
-import org.qi4j.api.structure.Module;
-
-import static org.qi4j.library.spatial.projection.transformations.TTransformations.Transform;
-
-/**
- * Created by jj on 04.12.14.
- */
-public class ToHelper {
-
-    private Module module;
-    private TGeometry intermediate;
-
-    public ToHelper(Module module, TGeometry intermediate)
-    {
-        this.module = module;
-        this.intermediate = intermediate;
-    }
-
-    public TGeometry toTGeometry()
-    {
-        return new TGeometryToConverter(module).convert(intermediate);
-    }
-
-    public TGeometry toTGeometry(String CRS) throws Exception
-    {
-        if (!intermediate.getCRS().equalsIgnoreCase(CRS))
-                Transform(module).from(intermediate).to(CRS) ;
-
-        return new TGeometryToConverter(module).convert(intermediate, CRS);
-    }
-
-
-
-    public GeoJsonObject toGeoJson()
-    {
-        return new GeoJsonToConverter(module).convert(intermediate);
-    }
-
-    private ToHelper() {}
-}

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/503532e9/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/from/FromHelper.java
----------------------------------------------------------------------
diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/from/FromHelper.java
b/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/from/FromHelper.java
new file mode 100644
index 0000000..68ab3d9
--- /dev/null
+++ b/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/from/FromHelper.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2014 Jiri Jetmar.
+ *
+ * Licensed  under the  Apache License,  Version 2.0  (the "License");
+ * you may not use  this file  except in  compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed  under the  License is distributed on an "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.qi4j.library.spatial.formats.conversions.from;
+
+import org.geojson.GeoJsonObject;
+import org.qi4j.api.geometry.internal.TGeometry;
+import org.qi4j.api.structure.Module;
+import org.qi4j.library.spatial.formats.conversions.to.ToHelper;
+
+
+public class FromHelper
+{
+
+    private Module module;
+
+    public FromHelper(Module module)
+    {
+        this.module = module;
+    }
+
+    private FromHelper()
+    {
+    }
+
+    public ToHelper from(TGeometry tGeometry)
+    {
+        return new ToHelper(module, new TGeometryFromConverter(module).convert(tGeometry));
+    }
+
+    public ToHelper from(GeoJsonObject geoJsonObject)
+    {
+        return new ToHelper(module, new GeoJsonFromConverter(module).convert(geoJsonObject));
+
+    }
+
+    public ToHelper from(String wkt) throws Exception
+    {
+        return new ToHelper(module, new WKTFromConverter(module).convert(wkt, null));
+    }
+
+    public ToHelper from(String wkt, String crs) throws Exception
+    {
+        return new ToHelper(module, new WKTFromConverter(module).convert(wkt, crs));
+    }
+}

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/503532e9/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/from/GeoJsonFromConverter.java
----------------------------------------------------------------------
diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/from/GeoJsonFromConverter.java
b/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/from/GeoJsonFromConverter.java
new file mode 100644
index 0000000..70bbdb0
--- /dev/null
+++ b/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/from/GeoJsonFromConverter.java
@@ -0,0 +1,200 @@
+/*
+ * Copyright 2014 Jiri Jetmar.
+ *
+ * Licensed  under the  Apache License,  Version 2.0  (the "License");
+ * you may not use  this file  except in  compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed  under the  License is distributed on an "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.qi4j.library.spatial.formats.conversions.from;
+
+import org.geojson.*;
+import org.qi4j.api.geometry.*;
+import org.qi4j.api.geometry.internal.TGeometry;
+import org.qi4j.api.geometry.internal.TLinearRing;
+import org.qi4j.api.structure.Module;
+
+import java.util.List;
+
+import static org.qi4j.api.geometry.TGeometryFactory.*;
+
+
+public class GeoJsonFromConverter
+{
+
+    private Module module;
+
+    public GeoJsonFromConverter(Module module)
+    {
+        this.module = module;
+    }
+
+    public TGeometry convert(GeoJsonObject geojson)
+
+    {
+        return transform(geojson);
+    }
+
+    private TGeometry transform(GeoJsonObject geojson)
+    {
+        if (geojson instanceof Point)
+        {
+            return createTPoint((Point) geojson);
+        } else if ((geojson instanceof MultiPoint) && !(geojson instanceof LineString))
+        {
+            return createTMultiPoint((MultiPoint) geojson);
+        } else if (geojson instanceof LineString)
+        {
+            return createTLineString((LineString) geojson);
+        } else if (geojson instanceof MultiLineString)
+        {
+            return createTMultiLineString((MultiLineString) geojson);
+        } else if (geojson instanceof Polygon)
+        {
+            return createTPolygon((Polygon) geojson);
+        } else if (geojson instanceof MultiPolygon)
+        {
+            return createTMultiPolygon((MultiPolygon) geojson);
+        } else if (geojson instanceof Feature)
+        {
+            return createTFeature((Feature) geojson);
+        } else if (geojson instanceof FeatureCollection)
+        {
+            return createTFeatureCollection((FeatureCollection) geojson);
+        } else throw new RuntimeException("Unknown GeoJSON type - " + geojson);
+    }
+
+
+    private TGeometry createTPoint(Point point)
+    {
+        return TPoint(module)
+                .x(point.getCoordinates().getLatitude())
+                .y(point.getCoordinates().getLongitude())
+                .z(point.getCoordinates().getAltitude())
+                .geometry();
+    }
+
+    private TGeometry createTMultiPoint(MultiPoint multiPoint)
+    {
+        TMultiPoint tMultiPoint = TMultiPoint(module).geometry();
+        for (LngLatAlt xyz : multiPoint.getCoordinates())
+        {
+            tMultiPoint.of
+                    (
+                            TPoint(module)
+                                    .x(xyz.getLatitude())
+                                    .y(xyz.getLongitude())
+                                    .z(xyz.getAltitude())
+                                    .geometry()
+                    );
+        }
+        return tMultiPoint;
+    }
+
+    private TGeometry createTLineString(LineString lineString)
+    {
+        TLineString tLineString = TLineString(module).of().geometry();
+
+        for (LngLatAlt xyz : lineString.getCoordinates())
+        {
+            tLineString.of(
+                    TPoint(module)
+                            .x(xyz.getLatitude())
+                            .y(xyz.getLongitude())
+                            .z(xyz.getAltitude())
+                            .geometry()
+            );
+        }
+        return tLineString;
+    }
+
+    private TGeometry createTMultiLineString(MultiLineString multiLineString)
+    {
+        TMultiLineString tMultiLineString = TMultiLineString(module).of().geometry();
+        for (List<LngLatAlt> coordinates : multiLineString.getCoordinates())
+        {
+            tMultiLineString.of(getLine(coordinates));
+        }
+        return tMultiLineString;
+    }
+
+    private TGeometry createTPolygon(Polygon polygon)
+    {
+        TPolygon tPolygon;
+        TLinearRing ring = getRing((polygon).getExteriorRing());
+        if (!ring.isValid())
+            throw new RuntimeException("Polygon shell not valid");
+        else
+            tPolygon = TPolygon(module).shell(ring).geometry();
+        for (int i = 0; i < (polygon).getInteriorRings().size(); i++)
+        {
+            tPolygon.withHoles(getRing((polygon).getInteriorRings().get(i)));
+        }
+        return tPolygon;
+    }
+
+    private TGeometry createTMultiPolygon(MultiPolygon multiPolygon)
+    {
+        TMultiPolygon tMultiPolygon = TMultiPolygon(module).of().geometry();
+        for (List<List<LngLatAlt>> polygons : multiPolygon.getCoordinates())
+        {
+            for (List<LngLatAlt> polygon : polygons)
+            {
+                tMultiPolygon.of(TPolygon(module).shell(getRing(polygon)).geometry());
+            }
+        }
+        return tMultiPolygon;
+    }
+
+    private TGeometry createTFeature(Feature feature)
+    {
+        return TFeature(module).of(new GeoJsonFromConverter(module).transform(feature.getGeometry())).geometry();
+    }
+
+    private TGeometry createTFeatureCollection(FeatureCollection featurecollection)
+    {
+        TFeatureCollection tFeatureCollection = TFeatureCollection(module).of().geometry();
+        for (Feature feature : featurecollection.getFeatures())
+        {
+            tFeatureCollection.of((TFeature) createTFeature(feature));
+        }
+        return tFeatureCollection;
+    }
+
+    private TLineString getLine(List<LngLatAlt> coordinates)
+    {
+        TLineString tLineString = TLineString(module).of().geometry();
+        for (LngLatAlt xyz : coordinates)
+        {
+            tLineString.yx(xyz.getLatitude(), xyz.getLongitude());
+        }
+        return tLineString;
+    }
+
+    private TLinearRing getRing(List<LngLatAlt> coordinates)
+    {
+
+        TLinearRing tLinearRing = TLinearRing(module).of().geometry();
+        for (LngLatAlt xyz : coordinates)
+        {
+            tLinearRing.yx(xyz.getLatitude(), xyz.getLongitude());
+        }
+
+        if (!tLinearRing.isClosed())
+        {
+            tLinearRing.of(tLinearRing.getStartPoint()); // hack here - we are closing the
ring, of not closed.
+        }
+
+        return tLinearRing;
+    }
+}

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/503532e9/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/to/GeoJsonToConverter.java
----------------------------------------------------------------------
diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/to/GeoJsonToConverter.java
b/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/to/GeoJsonToConverter.java
new file mode 100644
index 0000000..366c98f
--- /dev/null
+++ b/libraries/spatial/src/main/java/org/qi4j/library/spatial/formats/conversions/to/GeoJsonToConverter.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2014 Jiri Jetmar.
+ *
+ * Licensed  under the  Apache License,  Version 2.0  (the "License");
+ * you may not use  this file  except in  compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed  under the  License is distributed on an "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.qi4j.library.spatial.formats.conversions.to;
+
+import org.geojson.GeoJsonObject;
+import org.geojson.Point;
+import org.qi4j.api.geometry.TPoint;
+import org.qi4j.api.geometry.internal.TGeometry;
+import org.qi4j.api.structure.Module;
+
+
+public class GeoJsonToConverter
+{
+
+
+    private Module module;
+
+    public GeoJsonToConverter(Module module)
+    {
+        this.module = module;
+    }
+
+    public GeoJsonObject convert(TGeometry intemediate)
+    {
+        return transform(intemediate);
+    }
+
+    private GeoJsonObject transform(TGeometry intemediate)
+    {
+
+        switch (intemediate.getType())
+        {
+            case POINT:
+                return buildPoint((TPoint) intemediate);
+            case MULTIPOINT:
+                return null;
+            case LINESTRING:
+                return null;
+            case MULTILINESTRING:
+                return null;
+            case POLYGON:
+                return null;
+            case MULTIPOLYGON:
+                return null;
+            case FEATURE:
+                return null;
+            case FEATURECOLLECTION:
+                return null;
+            default:
+                throw new RuntimeException("Unknown TGeometry Type.");
+        }
+
+    }
+
+    private Point buildPoint(TPoint point)
+    {
+        return new Point(point.x(), point.y());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/503532e9/libraries/spatial/src/main/java/org/qi4j/library/spatial/projection/ProjectionsRegistry.java
----------------------------------------------------------------------
diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/projection/ProjectionsRegistry.java
b/libraries/spatial/src/main/java/org/qi4j/library/spatial/projection/ProjectionsRegistry.java
deleted file mode 100644
index e82592f..0000000
--- a/libraries/spatial/src/main/java/org/qi4j/library/spatial/projection/ProjectionsRegistry.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright 2014 Jiri Jetmar.
- *
- * Licensed  under the  Apache License,  Version 2.0  (the "License");
- * you may not use  this file  except in  compliance with the License.
- * You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed  under the  License is distributed on an "AS IS" BASIS,
- * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
- * implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.qi4j.library.spatial.projection;
-
-import org.cts.CRSFactory;
-import org.cts.crs.CRSException;
-import org.cts.crs.CoordinateReferenceSystem;
-import org.cts.registry.*;
-
-import java.util.Set;
-
-
-public class ProjectionsRegistry {
-
-    protected static CRSFactory cRSFactory = new CRSFactory();
-
-
-    static {
-        RegistryManager registryManager = cRSFactory.getRegistryManager();
-        registryManager.addRegistry(new IGNFRegistry());
-        registryManager.addRegistry(new EPSGRegistry());
-        registryManager.addRegistry(new ESRIRegistry());
-        registryManager.addRegistry(new Nad27Registry());
-        registryManager.addRegistry(new Nad83Registry());
-        registryManager.addRegistry(new worldRegistry());
-    }
-
-
-    public Set<String> getSupportedSRID(String registryName) throws RegistryException
-    {
-        return cRSFactory.getSupportedCodes(registryName);
-    }
-
-    // EPSG, IGNF, ESRI
-    public Set<String> getSupportedRegistryCodes(String registryName) throws RegistryException
{
-        return cRSFactory.getRegistryManager().getRegistry(registryName).getSupportedCodes();
-    }
-
-    public String[] dumpRegistries() {
-        return cRSFactory.getRegistryManager().getRegistryNames();
-    }
-
-    public CoordinateReferenceSystem getCRS(String wkt)  {
-        try {
-            return cRSFactory.getCRS(wkt);
-        } catch(CRSException _ex)
-        {
-            _ex.printStackTrace();
-            return null;
-        }
-    }
-
-
-        public CoordinateReferenceSystem getReferenceSystem(String csName) throws CRSException
-    {
-        return cRSFactory.getCRS(csName);
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/503532e9/libraries/spatial/src/main/java/org/qi4j/library/spatial/projection/transformations/TTransformations.java
----------------------------------------------------------------------
diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/projection/transformations/TTransformations.java
b/libraries/spatial/src/main/java/org/qi4j/library/spatial/projection/transformations/TTransformations.java
deleted file mode 100644
index 1235a27..0000000
--- a/libraries/spatial/src/main/java/org/qi4j/library/spatial/projection/transformations/TTransformations.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright 2014 Jiri Jetmar.
- *
- * Licensed  under the  Apache License,  Version 2.0  (the "License");
- * you may not use  this file  except in  compliance with the License.
- * You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed  under the  License is distributed on an "AS IS" BASIS,
- * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
- * implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.qi4j.library.spatial.projection.transformations;
-
-import org.qi4j.api.structure.Module;
-import org.qi4j.library.spatial.projection.transformations.fromto.FromHelper;
-
-
-public class TTransformations {
-
-    public static FromHelper Transform(Module module)
-    {
-        return new FromHelper(module);
-    }
-}

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/503532e9/libraries/spatial/src/main/java/org/qi4j/library/spatial/projection/transformations/fromto/FromHelper.java
----------------------------------------------------------------------
diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/projection/transformations/fromto/FromHelper.java
b/libraries/spatial/src/main/java/org/qi4j/library/spatial/projection/transformations/fromto/FromHelper.java
deleted file mode 100644
index e1fa78a..0000000
--- a/libraries/spatial/src/main/java/org/qi4j/library/spatial/projection/transformations/fromto/FromHelper.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 2014 Jiri Jetmar.
- *
- * Licensed  under the  Apache License,  Version 2.0  (the "License");
- * you may not use  this file  except in  compliance with the License.
- * You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed  under the  License is distributed on an "AS IS" BASIS,
- * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
- * implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.qi4j.library.spatial.projection.transformations.fromto;
-
-import org.qi4j.api.geometry.internal.TGeometry;
-import org.qi4j.api.structure.Module;
-import org.qi4j.library.spatial.conversions.from.TGeometryFromConverter;
-
-
-public class FromHelper {
-
-    private Module module;
-
-    public FromHelper(Module module)
-    {
-        this.module = module;
-    }
-
-    private FromHelper() {}
-
-    public ToHelper from(TGeometry tGeometry)
-    {
-        return new ToHelper(module, new TGeometryFromConverter(module).convert(tGeometry));
-    }
-}

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/503532e9/libraries/spatial/src/main/java/org/qi4j/library/spatial/projections/ProjectionsRegistry.java
----------------------------------------------------------------------
diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/projections/ProjectionsRegistry.java
b/libraries/spatial/src/main/java/org/qi4j/library/spatial/projections/ProjectionsRegistry.java
new file mode 100644
index 0000000..119022b
--- /dev/null
+++ b/libraries/spatial/src/main/java/org/qi4j/library/spatial/projections/ProjectionsRegistry.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2014 Jiri Jetmar.
+ *
+ * Licensed  under the  Apache License,  Version 2.0  (the "License");
+ * you may not use  this file  except in  compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed  under the  License is distributed on an "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.qi4j.library.spatial.projections;
+
+import org.cts.CRSFactory;
+import org.cts.crs.CRSException;
+import org.cts.crs.CoordinateReferenceSystem;
+import org.cts.registry.*;
+
+import java.util.Set;
+
+
+public class ProjectionsRegistry
+{
+
+    protected static CRSFactory cRSFactory = new CRSFactory();
+
+    static
+    {
+        RegistryManager registryManager = cRSFactory.getRegistryManager();
+        registryManager.addRegistry(new IGNFRegistry());
+        registryManager.addRegistry(new EPSGRegistry());
+        registryManager.addRegistry(new ESRIRegistry());
+        registryManager.addRegistry(new Nad27Registry());
+        registryManager.addRegistry(new Nad83Registry());
+        registryManager.addRegistry(new worldRegistry());
+    }
+
+
+    public Set<String> getSupportedSRID(String registryName) throws RegistryException
+    {
+        return cRSFactory.getSupportedCodes(registryName);
+    }
+
+    // EPSG, IGNF, ESRI
+    public Set<String> getSupportedRegistryCodes(String registryName) throws RegistryException
+    {
+        return cRSFactory.getRegistryManager().getRegistry(registryName).getSupportedCodes();
+    }
+
+    public String[] dumpRegistries()
+    {
+        return cRSFactory.getRegistryManager().getRegistryNames();
+    }
+
+    public CoordinateReferenceSystem getCRS(String wkt)
+    {
+        try
+        {
+            return cRSFactory.getCRS(wkt);
+        } catch (CRSException _ex)
+        {
+            throw new RuntimeException(_ex);
+        }
+    }
+
+
+    public CoordinateReferenceSystem getReferenceSystem(String csName) throws CRSException
+    {
+        return cRSFactory.getCRS(csName);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/503532e9/libraries/spatial/src/main/java/org/qi4j/library/spatial/projections/transformations/fromto/FromHelper.java
----------------------------------------------------------------------
diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/projections/transformations/fromto/FromHelper.java
b/libraries/spatial/src/main/java/org/qi4j/library/spatial/projections/transformations/fromto/FromHelper.java
new file mode 100644
index 0000000..f3ebe56
--- /dev/null
+++ b/libraries/spatial/src/main/java/org/qi4j/library/spatial/projections/transformations/fromto/FromHelper.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2014 Jiri Jetmar.
+ *
+ * Licensed  under the  Apache License,  Version 2.0  (the "License");
+ * you may not use  this file  except in  compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed  under the  License is distributed on an "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.qi4j.library.spatial.projections.transformations.fromto;
+
+import org.qi4j.api.geometry.internal.TGeometry;
+import org.qi4j.api.structure.Module;
+import org.qi4j.library.spatial.formats.conversions.from.TGeometryFromConverter;
+
+
+public class FromHelper
+{
+
+    private Module module;
+
+    public FromHelper(Module module)
+    {
+        this.module = module;
+    }
+
+    private FromHelper()
+    {
+    }
+
+    public ToHelper from(TGeometry tGeometry)
+    {
+        return new ToHelper(module, new TGeometryFromConverter(module).convert(tGeometry));
+    }
+}

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/503532e9/libraries/spatial/src/main/java/org/qi4j/library/spatial/projections/transformations/fromto/ToHelper.java
----------------------------------------------------------------------
diff --git a/libraries/spatial/src/main/java/org/qi4j/library/spatial/projections/transformations/fromto/ToHelper.java
b/libraries/spatial/src/main/java/org/qi4j/library/spatial/projections/transformations/fromto/ToHelper.java
new file mode 100644
index 0000000..eb49068
--- /dev/null
+++ b/libraries/spatial/src/main/java/org/qi4j/library/spatial/projections/transformations/fromto/ToHelper.java
@@ -0,0 +1,158 @@
+/*
+ * Copyright 2014 Jiri Jetmar.
+ *
+ * Licensed  under the  Apache License,  Version 2.0  (the "License");
+ * you may not use  this file  except in  compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed  under the  License is distributed on an "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.qi4j.library.spatial.projections.transformations.fromto;
+
+import org.cts.IllegalCoordinateException;
+import org.cts.crs.GeodeticCRS;
+import org.cts.op.CoordinateOperation;
+import org.cts.op.CoordinateOperationFactory;
+import org.qi4j.api.geometry.*;
+import org.qi4j.api.geometry.internal.Coordinate;
+import org.qi4j.api.geometry.internal.TGeometry;
+import org.qi4j.api.structure.Module;
+import org.qi4j.library.spatial.projections.ProjectionsRegistry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+
+
+public class ToHelper
+{
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(ToHelper.class);
+
+
+    private Module module;
+    private TGeometry intermediate;
+    private double maxPrecisionMeanConversionError = Double.MAX_VALUE;
+
+    public ToHelper(Module module, TGeometry intermediate)
+    {
+        this.module = module;
+        this.intermediate = intermediate;
+    }
+
+    private ToHelper()
+    {
+    }
+
+
+    public void to(String CRS, double maxPrecisionMeanConversionError) throws RuntimeException
+    {
+        this.maxPrecisionMeanConversionError = maxPrecisionMeanConversionError;
+        to(CRS);
+    }
+
+    public void to(String CRS) throws RuntimeException
+    {
+        try
+        {
+            GeodeticCRS sourceCRS = (GeodeticCRS) new ProjectionsRegistry().getCRS(intermediate.getCRS());
+            GeodeticCRS targetCRS = (GeodeticCRS) new ProjectionsRegistry().getCRS(CRS);
+
+            if (sourceCRS.equals(targetCRS))
+            {
+                return;
+            }
+            switch (intermediate.getType())
+            {
+                case POINT:
+                    transform(sourceCRS, targetCRS, new Coordinate[]{((TPoint) intermediate).getCoordinate()});
+                    break;
+                case MULTIPOINT:
+                    transform(sourceCRS, targetCRS, ((TMultiPoint) intermediate).getCoordinates());
+                    break;
+                case LINESTRING:
+                    transform(sourceCRS, targetCRS, ((TLineString) intermediate).getCoordinates());
+                    break;
+                case MULTILINESTRING:
+                    transform(sourceCRS, targetCRS, ((TMultiLineString) intermediate).getCoordinates());
+                    break;
+                case POLYGON:
+                    transform(sourceCRS, targetCRS, ((TPolygon) intermediate).getCoordinates());
+                    break;
+                case MULTIPOLYGON:
+                    transform(sourceCRS, targetCRS, ((TMultiPolygon) intermediate).getCoordinates());
+                    break;
+                case FEATURE:
+                    transform(sourceCRS, targetCRS, ((TFeature) intermediate).getCoordinates());
+                    break;
+                case FEATURECOLLECTION:
+                    transform(sourceCRS, targetCRS, ((TFeatureCollection) intermediate).getCoordinates());
+                    break;
+            }
+
+            // JJ TODO - Set nested TGeometries CRSs as well
+            intermediate.setCRS(targetCRS.getCode());
+        } catch (Exception _ex)
+        {
+            throw new RuntimeException(_ex);
+        }
+    }
+
+
+    private void transformTPoint(GeodeticCRS sourceCRS, GeodeticCRS targetCRS, TPoint tPoint)
throws Exception
+    {
+        transform(sourceCRS, targetCRS, new Coordinate[]{tPoint.getCoordinate()});
+        tPoint.setCRS(targetCRS.getCode());
+    }
+
+    private void transformTMultiPoint(GeodeticCRS sourceCRS, GeodeticCRS targetCRS, TMultiPoint
tMultiPoint) throws Exception
+    {
+        transform(sourceCRS, targetCRS, tMultiPoint.getCoordinates());
+        tMultiPoint.setCRS(targetCRS.getCode());
+        // tMultiPoint.
+    }
+
+    private void transformTLineString(GeodeticCRS sourceCRS, GeodeticCRS targetCRS, TLineString
tLineString) throws Exception
+    {
+
+        transform(sourceCRS, targetCRS, tLineString.getCoordinates());
+        tLineString.setCRS(targetCRS.getCode());
+        // tMultiPoint.
+    }
+
+
+    private void transform(GeodeticCRS sourceCRS, GeodeticCRS targetCRS, Coordinate... coordinates)
throws IllegalCoordinateException
+    {
+        List<CoordinateOperation> ops;
+        ops = CoordinateOperationFactory.createCoordinateOperations(sourceCRS, targetCRS);
+
+        if (!ops.isEmpty())
+        {
+            if (true)
+            {
+                LOGGER.trace("Projection conversion operations", ops.get(0));
+                LOGGER.trace("Projection precision", ops.get(0).getPrecision(), " m.");
+            }
+
+            if (maxPrecisionMeanConversionError < Double.MAX_VALUE && maxPrecisionMeanConversionError
< ops.get(0).getPrecision())
+                throw new RuntimeException("Transformation from " + sourceCRS.getCode() +
" to " + targetCRS.getCode() +
+                        " can not be done with the requested precision of " + maxPrecisionMeanConversionError
+ " meters." +
+                        " Current precision mean conversion error is " + ops.get(0).getPrecision()
+ " meters.");
+
+            for (Coordinate coordinate : coordinates)
+            {
+                double[] c = ops.get(0).transform(new double[]{coordinate.y(), coordinate.x()
/** z */});
+                coordinate.y(c[1]).x(c[0]);
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/503532e9/libraries/spatial/src/test/java/org/qi4j/library/spatial/conversions/ConversionsFromWktTest.java
----------------------------------------------------------------------
diff --git a/libraries/spatial/src/test/java/org/qi4j/library/spatial/conversions/ConversionsFromWktTest.java
b/libraries/spatial/src/test/java/org/qi4j/library/spatial/conversions/ConversionsFromWktTest.java
deleted file mode 100644
index 82f7455..0000000
--- a/libraries/spatial/src/test/java/org/qi4j/library/spatial/conversions/ConversionsFromWktTest.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package org.qi4j.library.spatial.conversions;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.Test;
-import org.qi4j.api.geometry.TPoint;
-import org.qi4j.bootstrap.AssemblyException;
-import org.qi4j.bootstrap.ModuleAssembly;
-import org.qi4j.library.spatial.assembly.TGeometryAssembler;
-import org.qi4j.test.AbstractQi4jTest;
-
-
-/**
- * Created by jj on 04.12.14.
- */
-public class ConversionsFromWktTest extends AbstractQi4jTest {
-
-    private final String CRS_EPSG_4326 = "EPSG:4326";
-    private final String CRS_EPSG_27572 = "EPSG:27572";
-    private ObjectMapper GeoJsonMapper = new ObjectMapper();
-
-    @Override
-    public void assemble(ModuleAssembly module)
-            throws AssemblyException {
-        new TGeometryAssembler().assemble(module);
-    }
-
-    @Test
-    public void WhenConvertFromWktToTGeometry() throws Exception {
-        TPoint tPoint = (TPoint) TConversions.Convert(module).from("POINT(11.57958981111
48.13905780941111 )", CRS_EPSG_27572).toTGeometry();
-    }
-
-
-}

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/503532e9/libraries/spatial/src/test/java/org/qi4j/library/spatial/conversions/ConversionsWithProjectionsTest.java
----------------------------------------------------------------------
diff --git a/libraries/spatial/src/test/java/org/qi4j/library/spatial/conversions/ConversionsWithProjectionsTest.java
b/libraries/spatial/src/test/java/org/qi4j/library/spatial/conversions/ConversionsWithProjectionsTest.java
deleted file mode 100644
index ddcde72..0000000
--- a/libraries/spatial/src/test/java/org/qi4j/library/spatial/conversions/ConversionsWithProjectionsTest.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright 2014 Jiri Jetmar.
- *
- * Licensed  under the  Apache License,  Version 2.0  (the "License");
- * you may not use  this file  except in  compliance with the License.
- * You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed  under the  License is distributed on an "AS IS" BASIS,
- * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
- * implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.qi4j.library.spatial.conversions;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.geojson.FeatureCollection;
-import org.junit.Test;
-import org.qi4j.api.geometry.TFeatureCollection;
-import org.qi4j.api.geometry.TPoint;
-import org.qi4j.bootstrap.AssemblyException;
-import org.qi4j.bootstrap.ModuleAssembly;
-import org.qi4j.library.spatial.assembly.TGeometryAssembler;
-import org.qi4j.library.spatial.topo.GeoJSONSwissLakes2013;
-import org.qi4j.library.spatial.projection.transformations.TTransformations;
-import org.qi4j.test.AbstractQi4jTest;
-
-import static org.junit.Assert.assertTrue;
-import static org.qi4j.api.geometry.TGeometryFactory.TPoint;
-import static org.qi4j.library.spatial.conversions.TConversions.Convert;
-
-
-public class ConversionsWithProjectionsTest extends AbstractQi4jTest {
-
-    private final String CRS1 = "EPSG:4326";
-    private ObjectMapper geoJsonMapper = new ObjectMapper();
-
-
-    @Override
-    public void assemble(ModuleAssembly module)
-            throws AssemblyException {
-        new TGeometryAssembler().assemble(module);
-    }
-
-    @Test
-    public void whenConvertFromTGeometryToTGeometryConvertProjections() throws Exception
{
-        TPoint tPoint1 = TPoint(module).x(11.57958981111).y(48.13905780941111).geometry();
-        TPoint tPoint2 = (TPoint) Convert(module).from(tPoint1).toTGeometry(CRS1);
-        assertTrue(tPoint1.compareTo(tPoint2) == 0);
-    }
-
-
-    @Test
-    public void whenConvertSwissLakesTranslateProjection() throws Exception
-    {
-        // convert from CH1903 (EPSG:21781) to EPSG:4326
-//        TFeatureCollection swisslakes =  (TFeatureCollection)Convert(module).from(geoJsonMapper.readValue(GeoJSONSwissLakes2013.SWISS_LAKES,
FeatureCollection.class))
-//         .toTGeometry("EPSG:21781");
-
-        FeatureCollection featureCollection = geoJsonMapper.readValue(GeoJSONSwissLakes2013.SWISS_LAKES,
FeatureCollection.class);
-        TFeatureCollection tFeatureCollection = (TFeatureCollection)Convert(module).from(featureCollection).toTGeometry();
-        tFeatureCollection.setCRS("EPSG:21781");
-        System.out.println(tFeatureCollection.getCoordinates().length);
-        System.out.println(tFeatureCollection.getNumPoints());
-
-        TTransformations.Transform(module).from(tFeatureCollection).to("EPSG:4326");
-
-        System.out.println("tFeatureCollection " + tFeatureCollection);
-
-        // tFeatureCollection.getCoordinates();
-
-
- /**
-        TFeatureCollection tFeatureCollection = (TFeatureCollection)Convert(module).from(featureCollection).toTGeometry("EPSG:21781");
-        System.out.println(tFeatureCollection);
-        TTransformations.Transform(module).from(tFeatureCollection).to("EPSG:4326");
-        System.out.println(tFeatureCollection);
-  */
-    }
-
-}


Mime
View raw message