Permalink
Browse files

Reorganized geometry process.

Refactored package structure, changed JTS namespace to geo and moved ReprojectGeometry to geo:reproject.
  • Loading branch information...
1 parent 5b583ea commit f52bce7a537c19aaf6579c774d03caf212bf1172 jdeolive committed Aug 21, 2012
@@ -15,15 +15,19 @@
* Lesser General Public License for more details.
*
*/
-package org.geotools.process.jts;
+package org.geotools.process.geometry;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import org.geotools.geometry.jts.JTS;
+import org.geotools.process.ProcessException;
import org.geotools.process.factory.DescribeParameter;
import org.geotools.process.factory.DescribeProcess;
import org.geotools.process.factory.DescribeResult;
+import org.geotools.referencing.CRS;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
import com.vividsolutions.jts.densify.Densifier;
import com.vividsolutions.jts.geom.Geometry;
@@ -403,4 +407,22 @@ static public Geometry splitPolygon(
return polygon.getFactory().createGeometryCollection(
GeometryFactory.toGeometryArray(output));
}
+
+ /**
+ * Will reproject a geometry to another CRS.
+ */
+ @DescribeProcess(title = "Reproject Geometry", description = "Reprojects a given geometry into a supplied coordinate reference system.")
+ @DescribeResult(name = "result", description = "Reprojected geometry")
+ static public Geometry reproject(
+ @DescribeParameter(name = "geometry", description = "Input geometry") Geometry geometry,
+ @DescribeParameter(name = "sourceCRS", min = 0, description = "Coordinate reference system of input geometry") CoordinateReferenceSystem sourceCRS,
+ @DescribeParameter(name = "targetCRS", min = 0, description = "Target coordinate reference system to use for reprojection") CoordinateReferenceSystem targetCRS) {
+
+ try {
+ return JTS.transform(geometry, CRS.findMathTransform(sourceCRS, targetCRS, true));
+ }
+ catch (Exception e) {
+ throw new ProcessException("Reprojection faiiled", e);
+ }
+ }
}
@@ -15,7 +15,7 @@
* Lesser General Public License for more details.
*
*/
-package org.geotools.process.jts;
+package org.geotools.process.geometry;
import org.geotools.process.factory.StaticMethodsProcessFactory;
import org.geotools.util.SimpleInternationalString;
@@ -31,8 +31,7 @@
public class GeometryProcessFactory extends StaticMethodsProcessFactory<GeometryFunctions> {
public GeometryProcessFactory() {
- super(new SimpleInternationalString("Simple JTS based spatial analysis methods"), "JTS",
- GeometryFunctions.class);
+ super(new SimpleInternationalString("Geometry processes"), "geo", GeometryFunctions.class);
}
}
@@ -1,50 +0,0 @@
-/*
- * GeoTools - The Open Source Java GIS Toolkit
- * http://geotools.org
- *
- * (C) 2011, Open Source Geospatial Foundation (OSGeo)
- * (C) 2001-2007 TOPP - www.openplans.org.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package org.geotools.process.geometry.gs;
-
-import org.geotools.process.factory.DescribeParameter;
-import org.geotools.process.factory.DescribeProcess;
-import org.geotools.process.factory.DescribeResult;
-import org.geotools.process.gs.GSProcess;
-import org.geotools.geometry.jts.JTS;
-import org.geotools.referencing.CRS;
-import org.opengis.referencing.crs.CoordinateReferenceSystem;
-
-import com.vividsolutions.jts.geom.Geometry;
-
-/**
- * Will reproject a geometry to another CRS.
- *
- * @author Andrea Aime
- *
- * @source $URL$
- */
-@DescribeProcess(title = "Reproject Geometry", description = "Reprojects a given geometry into a supplied coordinate reference system.")
-public class ReprojectGeometry implements GSProcess {
-
- @DescribeResult(name = "result", description = "Reprojected geometry")
- public Geometry execute(
- @DescribeParameter(name = "geometry", description = "Input geometry") Geometry geometry,
- @DescribeParameter(name = "sourceCRS", min = 0, description = "Coordinate reference system of input geometry") CoordinateReferenceSystem sourceCRS,
- @DescribeParameter(name = "targetCRS", min = 0, description = "Target coordinate reference system to use for reprojection") CoordinateReferenceSystem targetCRS)
- throws Exception {
-
- return JTS.transform(geometry, CRS.findMathTransform(sourceCRS, targetCRS, true));
- }
-
-}
@@ -1 +1 @@
-org.geotools.process.jts.GeometryProcessFactory
+org.geotools.process.geometry.GeometryProcessFactory
@@ -14,10 +14,11 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*/
-package org.geotools.process.jts;
+package org.geotools.process.geometry;
import static org.junit.Assert.*;
+import org.geotools.process.geometry.GeometryFunctions;
import org.junit.Test;
import com.vividsolutions.jts.geom.Geometry;
@@ -1,4 +1,4 @@
-package org.geotools.process.jts;
+package org.geotools.process.geometry;
import java.util.ArrayList;
import java.util.HashMap;
@@ -13,6 +13,8 @@
import org.geotools.process.ProcessException;
import org.geotools.process.ProcessFactory;
import org.geotools.process.Processors;
+import org.geotools.process.geometry.GeometryFunctions;
+import org.geotools.process.geometry.GeometryProcessFactory;
import org.opengis.feature.type.Name;
import org.opengis.util.InternationalString;
@@ -38,12 +40,12 @@ public void testNames() {
Set<Name> names = factory.getNames();
assertTrue(names.size() > 0);
// System.out.println(names);
- assertTrue(names.contains(new NameImpl("JTS", "buffer")));
- assertTrue(names.contains(new NameImpl("JTS", "union")));
+ assertTrue(names.contains(new NameImpl("geo", "buffer")));
+ assertTrue(names.contains(new NameImpl("geo", "union")));
}
public void testDescribeBuffer() {
- NameImpl bufferName = new NameImpl("JTS", "buffer");
+ NameImpl bufferName = new NameImpl("geo", "buffer");
InternationalString desc = factory.getDescription(bufferName);
assertNotNull(desc);
@@ -72,7 +74,7 @@ public void testDescribeBuffer() {
}
public void testExecuteBuffer() throws Exception {
- org.geotools.process.Process buffer = factory.create(new NameImpl("JTS", "Buffer"));
+ org.geotools.process.Process buffer = factory.create(new NameImpl("geo", "Buffer"));
// try less than the required params
Map<String, Object> inputs = new HashMap<String, Object>();
@@ -106,7 +108,7 @@ public void testExecuteBuffer() throws Exception {
}
public void testSPI() throws Exception {
- NameImpl bufferName = new NameImpl("JTS", "buffer");
+ NameImpl bufferName = new NameImpl("geo", "buffer");
ProcessFactory factory = Processors.createProcessFactory(bufferName);
assertNotNull(factory);
assertTrue(factory instanceof GeometryProcessFactory);
@@ -116,7 +118,7 @@ public void testSPI() throws Exception {
}
public void testDescribeUnion() {
- NameImpl unionName = new NameImpl("JTS", "union");
+ NameImpl unionName = new NameImpl("geo", "union");
InternationalString desc = factory.getDescription(unionName);
assertNotNull(desc);
@@ -131,7 +133,7 @@ public void testDescribeUnion() {
}
public void testExecuteUnion() throws Exception {
- org.geotools.process.Process union = factory.create(new NameImpl("JTS", "union"));
+ org.geotools.process.Process union = factory.create(new NameImpl("geo", "union"));
// try less than the required params
Map<String, Object> inputs = new HashMap<String, Object>();
@@ -166,7 +168,7 @@ public void testExecuteUnion() throws Exception {
}
public void testExecuteHull() throws Exception {
- NameImpl hullName = new NameImpl("JTS", "convexHull");
+ NameImpl hullName = new NameImpl("geo", "convexHull");
org.geotools.process.Process hull = factory.create(hullName);
Map<String, Object> inputs = new HashMap<String, Object>();

0 comments on commit f52bce7

Please sign in to comment.