svn - r34222 - branches/geometry/spike/geometry/src/main/java/org/osgeo/geometry

1 message Options
Embed this post
Permalink
svn_geotools

svn - r34222 - branches/geometry/spike/geometry/src/main/java/org/osgeo/geometry

Reply Threaded More More options
Print post
Permalink
Author: bencaradocdavies
Date: 2009-10-24 23:09:28 -0400 (Sat, 24 Oct 2009)
New Revision: 34222

Added:
   branches/geometry/spike/geometry/src/main/java/org/osgeo/geometry/EasyGeometryBuilder.java
Log:
Added EasyGeometryBuilder which is like SimpleGeometryBuilder except it takes a CRS in its constructor instead of its arguments.

Added: branches/geometry/spike/geometry/src/main/java/org/osgeo/geometry/EasyGeometryBuilder.java
===================================================================
--- branches/geometry/spike/geometry/src/main/java/org/osgeo/geometry/EasyGeometryBuilder.java                        (rev 0)
+++ branches/geometry/spike/geometry/src/main/java/org/osgeo/geometry/EasyGeometryBuilder.java 2009-10-25 03:09:28 UTC (rev 34222)
@@ -0,0 +1,215 @@
+package org.osgeo.geometry;
+
+import java.util.List;
+
+import org.osgeo.commons.crs.CRS;
+import org.osgeo.geometry.multi.MultiCurve;
+import org.osgeo.geometry.multi.MultiGeometry;
+import org.osgeo.geometry.multi.MultiLineString;
+import org.osgeo.geometry.multi.MultiPoint;
+import org.osgeo.geometry.multi.MultiPolygon;
+import org.osgeo.geometry.points.Points;
+import org.osgeo.geometry.primitive.LineString;
+import org.osgeo.geometry.primitive.Point;
+import org.osgeo.geometry.primitive.Polygon;
+import org.osgeo.geometry.primitive.Ring;
+
+/**
+ * GeometryBuilder that is the same as {@link SimpleGeometryBuilder} but that takes a {@link CRS} in
+ * its constructor and not its methods.
+ *
+ * @author Jody Garnett
+ * @author Ben Caradoc-Davies
+ */
+public class EasyGeometryBuilder {
+
+    private GeometryFactory factory;
+
+    private CRS crs;
+
+    public EasyGeometryBuilder(GeometryFactory factory, CRS crs) {
+        this.factory = factory;
+        this.crs = crs;
+    }
+
+    /**
+     * Creates a {@link Point} in 2D space.
+     *
+     * @param id
+     *            identifier, may be null
+     * @param x
+     *            value for first coordinate
+     * @param y
+     *            value for second coordinate
+     * @return created {@link Point}
+     */
+    public Point createPoint(String id, double x, double y) {
+        // check crs has 2 axis
+        return factory.point(id, new double[] { x, y }, crs);
+    }
+
+    /**
+     * Creates a {@link Point} in 3D space.
+     *
+     * @param id
+     *            identifier, may be null
+     * @param x
+     *            value for first coordinate
+     * @param y
+     *            value for second coordinate
+     * @param z
+     *            value for third coordinate
+     * @return created {@link Point}
+     */
+    public Point createPoint(String id, double x, double y, double z) {
+        return factory.point(id, new double[] { x, y, z }, crs);
+    }
+
+    /**
+     * Creates a {@link Point} with an arbitrary number of coordinates.
+     *
+     * @param id
+     *            identifier, may be null
+     * @param coordinates
+     *            coordinate values
+     * @return created {@link Point}
+     */
+    public Point createPoint(String id, double[] coordinates) {
+        return factory.point(id, coordinates, crs);
+    }
+
+    /**
+     * Creates a {@link Polygon} surface.
+     *
+     * @param id
+     *            identifier of the new geometry instance
+     * @param exteriorRing
+     *            ring that defines the outer boundary, this may be null (see section 9.2.2.5 of GML
+     *            spec)
+     * @param interiorRings
+     *            list of rings that define the inner boundaries, may be empty or null
+     * @return created {@link Polygon}
+     */
+    public Polygon createPolygon(String id, Ring exteriorRing, List<Ring> interiorRings) {
+        return factory.polygon(id, crs, exteriorRing, interiorRings);
+    }
+
+    /**
+     * Creates a {@link LineString} geometry.
+     *
+     * @param id
+     *            identifier, may be null
+     * @param points
+     *            control points
+     * @return created {@link LineString}
+     */
+    public LineString createLineString(String id, Points points) {
+        return factory.lineString(id, crs, points);
+    }
+
+    /**
+     * Creates an {@link Envelope}.
+     *
+     * @param min
+     *            minimum corner coordinates
+     * @param max
+     *            maximum corner coordinates
+     * @return created {@link Envelope}
+     */
+    public Envelope createEnvelope(double[] min, double[] max) {
+        Point lowerCorner = factory.point(null, min, crs);
+        Point upperCorner = factory.point(null, max, crs);
+        return factory.envelope(lowerCorner, upperCorner);
+    }
+
+    /**
+     * Creates an {@link Envelope} in 2D space.
+     *
+     * @param minx
+     *            minimum x corner coordinate
+     * @param miny
+     *            minimum y corner coordinate
+     * @param maxx
+     *            maximum x corner coordinate
+     * @param maxy
+     *            maximum y corner coordinate
+     * @return created {@link Envelope}
+     */
+    public Envelope createEnvelope(double minx, double miny, double maxx, double maxy) {
+        Point lowerCorner = createPoint(null, minx, miny);
+        Point upperCorner = createPoint(null, maxx, maxy);
+        return factory.envelope(lowerCorner, upperCorner);
+    }
+
+    /**
+     * Create an {@link Envelope} from a list of Doubles.
+     *
+     * @param lowerCorner
+     * @param upperCorner
+     * @return the envelope
+     */
+    public Envelope createEnvelope(List<Double> lowerCorner, List<Double> upperCorner) {
+        if (lowerCorner.size() != upperCorner.size()) {
+            throw new IllegalArgumentException(
+                    "LowerCorner must be of same dimension as upperCorner.");
+        }
+        double[] lc = new double[lowerCorner.size()];
+        double[] uc = new double[upperCorner.size()];
+        for (int i = 0; i < lc.length; ++i) {
+            lc[i] = lowerCorner.get(i);
+            uc[i] = upperCorner.get(i);
+        }
+        return createEnvelope(lc, uc);
+    }
+
+    /**
+     * Creates an untyped multi geometry from a list of {@link Geometry}s.
+     *
+     * @param id
+     *            identifier, may be null
+     * @param members
+     * @return created {@link MultiGeometry}
+     */
+    public MultiGeometry<Geometry> createMultiGeometry(String id, List<Geometry> members) {
+        return factory.multiGeometry(id, crs, members);
+    }
+
+    /**
+     * Creates a {@link MultiPoint} from a list of passed {@link Point}s.
+     *
+     * @param id
+     *            identifier, may be null
+     * @param members
+     *            points that constitute the collection
+     * @return created {@link MultiPoint}
+     */
+    public MultiPoint createMultiPoint(String id, List<Point> members) {
+        return factory.multiPoint(id, crs, members);
+    }
+
+    /**
+     * Creates a {@link MultiCurve} from a list of passed {@link LineString}s.
+     *
+     * @param id
+     *            identifier, may be null
+     * @param members
+     *            curves that constitute the collection
+     * @return created {@link MultiLineString}
+     */
+    public MultiLineString createMultiLineString(String id, List<LineString> members) {
+        return factory.multiLineString(id, crs, members);
+    }
+
+    /**
+     * Creates a {@link MultiPolygon} from a list of passed {@link Polygon}s.
+     *
+     * @param id
+     *            identifier, may be null
+     * @param members
+     *            polygons that constitute the collection
+     * @return created {@link MultiPolygon}
+     */
+    public MultiPolygon createMultiPolygon(String id, List<Polygon> members) {
+        return factory.multiPolygon(id, crs, members);
+    }
+}


Property changes on: branches/geometry/spike/geometry/src/main/java/org/osgeo/geometry/EasyGeometryBuilder.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Id URL
Added: svn:eol-style
   + native


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
GeoTools-commits mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-commits