Class GeometryFactory

  • All Implemented Interfaces:
    Serializable

    public class GeometryFactory
    extends com.vividsolutions.jts.geom.GeometryFactory

    The CPF provides an extended version of the Java Topology Suite (JTS) GeometryFactory to create JTS geometries. The extended version includes support for coordinate system projection, precision model, and controls on the number of axis.

    The GeometryFactory does not provide a public constructor. GeometryFactory instances can be obtained using the getFactory static methods described below.

    See Also:
    Serialized Form
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <G extends com.vividsolutions.jts.geom.Geometry>
      G
      copy​(G geometry)
      Construct a new copy of an existing Geometry.
      <T extends com.vividsolutions.jts.geom.Geometry>
      T
      createGeometry​(String wkt)
      Construct a new Geometry from a WKT or EWKT encoded geometry.
      com.vividsolutions.jts.geom.LinearRing createLinearRing​(double... coordinates)
      Construct a new LinearRing using the array of coordinates.
      com.vividsolutions.jts.geom.LineString createLineString​(double... coordinates)
      Construct a new LineString using the array of coordinates.
      com.vividsolutions.jts.geom.MultiLineString createMultiLineString​(Collection<?> lines)
      Construct a new MultiLineString using the list of lines.
      com.vividsolutions.jts.geom.MultiPoint createMultiPoint​(List<?> points)
      Construct a new MultiPoint using the list of points.
      com.vividsolutions.jts.geom.Point createPoint​(double... coordinates)
      Construct a new point using the array of coordinates.
      com.vividsolutions.jts.geom.Point createPoint​(Object object)  
      com.vividsolutions.jts.geom.Polygon createPolygon​(List<?> rings)
      Construct a new polygon using the list of rings.
      int getAxisCount()  
      static GeometryFactory getFactory()
      Get a GeometryFactory with no coordinate system, 3D axis (x, y & z) and a floating precision model.
      static GeometryFactory getFactory​(double scaleXy)
      Get a GeometryFactory with no coordinate system, 3D axis (x, y & z) and a fixed x, y &anp; floating z precision models.
      static GeometryFactory getFactory​(int srid)
      Get a GeometryFactory with the coordinate system, 3D axis (x, y & z) and a floating precision models.
      static GeometryFactory getFactory​(int srid, double scaleXy)
      Get a GeometryFactory with the coordinate system, 2D axis (x & y) and a fixed x, y precision model.
      static GeometryFactory getFactory​(int srid, double scaleXy, double scaleZ)
      Get a GeometryFactory with no coordinate system, 3D axis (x, y & z) and a fixed x, y & floating z precision models.
      static GeometryFactory getFactory​(int srid, int axisCount)
      Get a GeometryFactory with the coordinate system, number of axis and a floating precision model.
      static GeometryFactory getFactory​(int srid, int axisCount, double scaleXy, double scaleZ)
      Get a GeometryFactory with the coordinate system, number of axis and a fixed x, y & fixed z precision models.
      static GeometryFactory getFactory​(com.vividsolutions.jts.geom.Geometry geometry)
      Get the geometry factory used for an existing geometry.
      int getNumAxis()  
      com.vividsolutions.jts.geom.Polygon[] getPolygonArray​(Collection<?> polygonList)  
      double getScaleXY()  
      double getScaleZ()  
      boolean hasM()  
      boolean hasZ()  
      com.vividsolutions.jts.geom.MultiPolygon multiPolygon​(Collection<?> polygons)
      Construct a new MultiPolygon using the list of points.
      static String toWkt​(com.vividsolutions.jts.geom.Geometry geometry)  
      static String toWkt​(com.vividsolutions.jts.geom.Geometry geometry, boolean writeSrid)  
      • Methods inherited from class com.vividsolutions.jts.geom.GeometryFactory

        buildGeometry, createGeometry, createGeometryCollection, createLinearRing, createLinearRing, createLineString, createLineString, createMultiLineString, createMultiPoint, createMultiPoint, createMultiPoint, createMultiPolygon, createPoint, createPoint, createPointFromInternalCoord, createPolygon, createPolygon, createPolygon, createPolygon, getCoordinateSequenceFactory, getPrecisionModel, getSRID, toGeometry, toGeometryArray, toLinearRingArray, toLineStringArray, toMultiLineStringArray, toMultiPointArray, toMultiPolygonArray, toPointArray, toPolygonArray
    • Method Detail

      • getFactory

        public static GeometryFactory getFactory()

        Get a GeometryFactory with no coordinate system, 3D axis (x, y & z) and a floating precision model.

        Returns:
        The geometry factory.
      • getFactory

        public static GeometryFactory getFactory​(double scaleXy)

        Get a GeometryFactory with no coordinate system, 3D axis (x, y & z) and a fixed x, y &anp; floating z precision models.

        Parameters:
        scaleXy - The scale factor used to round the x, y coordinates. The precision is 1 / scaleXy. A scale factor of 1000 will give a precision of 1 / 1000 = 1mm for projected coordinate systems using metres.
        Returns:
        The geometry factory.
      • getFactory

        public static GeometryFactory getFactory​(com.vividsolutions.jts.geom.Geometry geometry)
        Get the geometry factory used for an existing geometry.
        Parameters:
        geometry - The geometry to get the factory from.
        Returns:
        The geometry factory;
      • getFactory

        public static GeometryFactory getFactory​(int srid)

        Get a GeometryFactory with the coordinate system, 3D axis (x, y & z) and a floating precision models.

        Parameters:
        srid - The EPSG coordinate system id.
        Returns:
        The geometry factory.
      • getFactory

        public static GeometryFactory getFactory​(int srid,
                                                 double scaleXy)

        Get a GeometryFactory with the coordinate system, 2D axis (x & y) and a fixed x, y precision model.

        Parameters:
        srid - The EPSG coordinate system id.
        scaleXy - The scale factor used to round the x, y coordinates. The precision is 1 / scaleXy. A scale factor of 1000 will give a precision of 1 / 1000 = 1mm for projected coordinate systems using metres.
        Returns:
        The geometry factory.
      • getFactory

        public static GeometryFactory getFactory​(int srid,
                                                 double scaleXy,
                                                 double scaleZ)

        Get a GeometryFactory with no coordinate system, 3D axis (x, y & z) and a fixed x, y & floating z precision models.

        Parameters:
        srid - The EPSG coordinate system id.
        scaleXy - The scale factor used to round the x, y coordinates. The precision is 1 / scaleXy. A scale factor of 1000 will give a precision of 1 / 1000 = 1mm for projected coordinate systems using metres.
        scaleZ - The scale factor used to round the z coordinates. The precision is 1 / scaleZ. A scale factor of 1000 will give a precision of 1 / 1000 = 1mm for projected coordinate systems using metres.
        Returns:
        The geometry factory.
      • getFactory

        public static GeometryFactory getFactory​(int srid,
                                                 int axisCount)

        Get a GeometryFactory with the coordinate system, number of axis and a floating precision model.

        Parameters:
        srid - The EPSG coordinate system id.
        axisCount - The number of coordinate axis. 2 for 2D x & y coordinates. 3 for 3D x, y & z coordinates.
        Returns:
        The geometry factory.
      • getFactory

        public static GeometryFactory getFactory​(int srid,
                                                 int axisCount,
                                                 double scaleXy,
                                                 double scaleZ)

        Get a GeometryFactory with the coordinate system, number of axis and a fixed x, y & fixed z precision models.

        Parameters:
        srid - The EPSG coordinate system id.
        axisCount - The number of coordinate axis. 2 for 2D x & y coordinates. 3 for 3D x, y & z coordinates.
        scaleXy - The scale factor used to round the x, y coordinates. The precision is 1 / scaleXy. A scale factor of 1000 will give a precision of 1 / 1000 = 1mm for projected coordinate systems using metres.
        scaleZ - The scale factor used to round the z coordinates. The precision is 1 / scaleZ. A scale factor of 1000 will give a precision of 1 / 1000 = 1mm for projected coordinate systems using metres.
        Returns:
        The geometry factory.
      • toWkt

        public static String toWkt​(com.vividsolutions.jts.geom.Geometry geometry)
      • toWkt

        public static String toWkt​(com.vividsolutions.jts.geom.Geometry geometry,
                                   boolean writeSrid)
      • copy

        public <G extends com.vividsolutions.jts.geom.Geometry> G copy​(G geometry)

        Construct a new copy of an existing Geometry. If the geometry is in a different coordinate system or precision model project the geometry to the coordinate system from this geometry factory and apply the precision model.

        The return type of this method will be auto-casted to the type of the variable the result is assigned to. Use Geometry as the type if it is not possible to guarantee that the geometry is of a specific geometry type.

        Type Parameters:
        G - The class of geometry to cast the result to.
        Parameters:
        geometry - The geometry.
        Returns:
        The copied geometry.
      • createGeometry

        public <T extends com.vividsolutions.jts.geom.Geometry> T createGeometry​(String wkt)

        Construct a new Geometry from a WKT or EWKT encoded geometry. If the EWKT string includes a SRID the geometry will use read using that SRID and then projected to the SRID of the geometry factory. If the SRID was not specified the geometry will be assumed to be in the coordinate system of the geometry factory's SRID. The return type of the WKT to geometry conversion will be auto-casted to the type of the variable the result is assigned to. Use Geometry as the type if it is not possible to guarantee that the WKT is of a specific geometry type.

        The following example shows a WGS84 EWKT polygon converted to a BC Albers polygon.

        GeometryFactory geometryFactory = GeometryFactory.getFactory(3005, 1.0);
          String wkt = "SRID=4326;POLYGON((-122 50,-124 50,-124 51,-122 51,-122 50))";
          Polygon polygon = createGeometry(wkt);
          System.out.println(polygon);
          // POLYGON((1286630 561884,1143372 555809,1140228 667065,1280345 673006,1286630 561884))
        Parameters:
        wkt - The WKT or http://postgis.net/docs/manual-2.0/using_postgis_dbmanagement.html#EWKB_EWKT encoded geometry.
        Returns:
        The created geometry.
      • createLinearRing

        public com.vividsolutions.jts.geom.LinearRing createLinearRing​(double... coordinates)

        Construct a new LinearRing using the array of coordinates. The ring must form a closed loop. The size of the array should be a multiple of the number of axis. For example a 2D geometry will have x1,y1...,xN,yN values and a 3D x1,y1,z1...,xN,yN,zN. Geographic coordinates are always longitude, latitude and projected easting, northing.

        Parameters:
        coordinates - The coordinates.
        Returns:
        The created linear ring.
      • createLineString

        public com.vividsolutions.jts.geom.LineString createLineString​(double... coordinates)

        Construct a new LineString using the array of coordinates. The size of the array should be a multiple of the number of axis. For example a 2D geometry will have x1,y1...,xN,yN values and a 3D x1,y1,z1...,xN,yN,zN. Geographic coordinates are always longitude, latitude and projected easting, northing.

        Parameters:
        coordinates - The coordinates.
        Returns:
        The created linestring.
      • createMultiLineString

        public com.vividsolutions.jts.geom.MultiLineString createMultiLineString​(Collection<?> lines)

        Construct a new MultiLineString using the list of lines. The first ring in the list is the exterior ring and the other rings are the interior rings. The rings in the list can be any of the following types.

        • double[]
        • LineString
        • CoordinateSequence

        For a double[] the size of the array should be a multiple of the number of axis. For example a 2D geometry will have x1,y1...,xN,yN values and a 3D x1,y1,z1...,xN,yN,zN. Geographic coordinates are always longitude, latitude and projected easting, northing.

        Parameters:
        lines - The list of lines.
        Returns:
        The created multi-linestring.
      • createMultiPoint

        public com.vividsolutions.jts.geom.MultiPoint createMultiPoint​(List<?> points)

        Construct a new MultiPoint using the list of points. The points in the list can be any of the following types.

        • double[]
        • Point
        • Coordinate
        • CoordinateSequence

        For a double[] the size of the array should be a multiple of the number of axis. For example a 2D geometry will have x1,y1...,xN,yN values and a 3D x1,y1,z1...,xN,yN,zN. Geographic coordinates are always longitude, latitude and projected easting, northing.

        Parameters:
        points - The list of points.
        Returns:
        The created multi-point.
      • createPoint

        public com.vividsolutions.jts.geom.Point createPoint​(double... coordinates)

        Construct a new point using the array of coordinates. The size of the array should be the same as the number of axis used on this geometry factory. If the size is less then additional axis will be set to 0. If greater then those values will be ignored. For example a 2D geometry will have x,y values and a 3D x,y,z. Geographic coordinates are always longitude, latitude and projected easting, northing.

        Parameters:
        coordinates - The coordinates.
        Returns:
        The created point.
      • createPoint

        public com.vividsolutions.jts.geom.Point createPoint​(Object object)
      • createPolygon

        public com.vividsolutions.jts.geom.Polygon createPolygon​(List<?> rings)

        Construct a new polygon using the list of rings. The first ring in the list is the exterior ring and the other rings are the interior rings. The rings in the list can be any of the following types.

        • double[]
        • LineString
        • LinearRing
        • CoordinateSequence

        For a double[] the size of the array should be a multiple of the number of axis. For example a 2D geometry will have x1,y1...,xN,yN values and a 3D x1,y1,z1...,xN,yN,zN. Geographic coordinates are always longitude, latitude and projected easting, northing.

        Parameters:
        rings - The list of rings.
        Returns:
        The created polygon.
      • getAxisCount

        public int getAxisCount()
      • getNumAxis

        public int getNumAxis()
      • getPolygonArray

        public com.vividsolutions.jts.geom.Polygon[] getPolygonArray​(Collection<?> polygonList)
      • getScaleXY

        public double getScaleXY()
      • getScaleZ

        public double getScaleZ()
      • hasM

        public boolean hasM()
      • hasZ

        public boolean hasZ()
      • multiPolygon

        public com.vividsolutions.jts.geom.MultiPolygon multiPolygon​(Collection<?> polygons)

        Construct a new MultiPolygon using the list of points. The points in the list can be any of the following types.

        For a double[] the size of the array should be a multiple of the number of axis. For example a 2D geometry will have x1,y1...,xN,yN values and a 3D x1,y1,z1...,xN,yN,zN. Geographic coordinates are always longitude, latitude and projected easting, northing.

        Parameters:
        polygons - The list of polygons.
        Returns:
        The created multi-polygon.