kiwi-postgis  Version 0.1.0.0
LiteralUtils Class Reference

Static Public Member Functions

static Geometry toGeometry (final org.opengis.geometry.Envelope envelope)
 
static Geometry toGeometry (final Envelope envelope)
 
static Geometry toGeometry (final Envelope2D envelope)
 
static Geometry toGeometry (final OctagonalEnvelope envelope)
 
static Geometry toGeometry (final Rectangle envelope)
 
static Geometry createGeometry (Coordinate[] coordinates, String geomtype, Integer srid)
 
static Geometry createGeometryCollection (List< Geometry > geometries, String geomtype, Integer srid)
 
static Geometry createGeometryCollection (Geometry[] geometries, String geomtype, Integer srid)
 
static Geometry createGeometry (List< Coordinate > coordarray, String geomtype, Integer srid)
 
static Geometry transform (Geometry sourcegeom, Geometry targetgeom)
 

Member Function Documentation

◆ createGeometry() [1/2]

static Geometry createGeometry ( Coordinate []  coordinates,
String  geomtype,
Integer  srid 
)
static

Referenced by LineFromText.construct(), LineFromWKB.construct(), Polygon.construct(), GeomFromGeoHash.construct(), LiteralUtils.createGeometry(), LineFromMultiPoint.operation(), LineSelfIntersectionPoint.operation(), ShiftLongitude.operation(), Force2D.operation(), Multi.operation(), Force3D.operation(), FlipCoordinates.operation(), Force3DM.operation(), LineMerge.operation(), ForcePolygonCCW.operation(), ForcePolygonCW.operation(), Force4D.operation(), TWKBDatatype.read(), GeoHashDatatype.read(), ShortestLine.relation(), LongestLine.relation(), RemovePoint.relation(), SetPoint.relation(), ShortestLine3D.relation(), RemoveRepeatedPoints.relation(), AddPoint.relation(), AddZ.relation(), SwapOrdinates.relation(), MultiplyZ.relation(), and LiteralUtils.transform().

104  {
105  GeometryFactory fac=new GeometryFactory();
106  Geometry geom;
107  switch(geomtype) {
108  case "Point":
109  geom= fac.createPoint(coordinates[0]);
110  geom.setSRID(srid);
111  return geom;
112  case "MultiPoint":
113  geom=fac.createMultiPointFromCoords(coordinates);
114  geom.setSRID(srid);
115  return geom;
116  case "LineString":
117  geom= fac.createLineString(coordinates);
118  geom.setSRID(srid);
119  return geom;
120  case "Polygon":
121  geom= fac.createPolygon(coordinates);
122  geom.setSRID(srid);
123  return geom;
124  case "MultiLineString":
125  List<LineString> list=new LinkedList<LineString>();
126  list.add(fac.createLineString(coordinates));
127  geom= fac.createMultiLineString(list.toArray(new LineString[0]));
128  geom.setSRID(srid);
129  return geom;
130  case "MultiPolygon":
131  List<Polygon> plist=new LinkedList<Polygon>();
132  plist.add(fac.createPolygon(coordinates));
133  geom= fac.createMultiPolygon(plist.toArray(new Polygon[0]));
134  geom.setSRID(srid);
135  return geom;
136  default:
137  return null;
138  }
139  }

◆ createGeometry() [2/2]

static Geometry createGeometry ( List< Coordinate coordarray,
String  geomtype,
Integer  srid 
)
static

References LiteralUtils.createGeometry().

150  {
151  return createGeometry(coordarray.toArray(new Coordinate[0]), geomtype,srid);
152  }
static Geometry createGeometry(Coordinate[] coordinates, String geomtype, Integer srid)
Definition: LiteralUtils.java:104

◆ createGeometryCollection() [1/2]

static Geometry createGeometryCollection ( List< Geometry >  geometries,
String  geomtype,
Integer  srid 
)
static

Referenced by SharedPaths.relation().

141  {
142  return createGeometryCollection(geometries.toArray(new Geometry[0]), geomtype, srid);
143  }
static Geometry createGeometryCollection(List< Geometry > geometries, String geomtype, Integer srid)
Definition: LiteralUtils.java:141

◆ createGeometryCollection() [2/2]

static Geometry createGeometryCollection ( Geometry []  geometries,
String  geomtype,
Integer  srid 
)
static
145  {
146  GeometryFactory fac=new GeometryFactory();
147  return fac.createGeometryCollection(geometries);
148  }

◆ toGeometry() [1/5]

static Geometry toGeometry ( final org.opengis.geometry.Envelope  envelope)
static

Referenced by OctogonalEnvelope.operation(), MakeBox2D.relation(), MakeBox3D.relation(), Overlaps.relation(), Contains.relation(), Touches.relation(), Crosses.relation(), Intersects.relation(), Within.relation(), Equals.relation(), Disjoint.relation(), CoveredBy.relation(), Intersection.relation(), and ContainsProperly.relation().

28  {
29 
30  GeometryFactory gf = new GeometryFactory();
31  return gf.createPolygon(gf.createLinearRing(
32  new Coordinate[]{
33  new Coordinate(envelope.getLowerCorner().getDirectPosition().getCoordinate()[0], envelope.getLowerCorner().getDirectPosition().getCoordinate()[1]),
34  new Coordinate(envelope.getUpperCorner().getDirectPosition().getCoordinate()[0], envelope.getLowerCorner().getDirectPosition().getCoordinate()[1]),
35  new Coordinate(envelope.getUpperCorner().getDirectPosition().getCoordinate()[0], envelope.getUpperCorner().getDirectPosition().getCoordinate()[1]),
36  new Coordinate(envelope.getLowerCorner().getDirectPosition().getCoordinate()[0], envelope.getLowerCorner().getDirectPosition().getCoordinate()[1]),
37  new Coordinate(envelope.getLowerCorner().getDirectPosition().getCoordinate()[0], envelope.getLowerCorner().getDirectPosition().getCoordinate()[1])
38  }), null);
39  }

◆ toGeometry() [2/5]

static Geometry toGeometry ( final Envelope  envelope)
static
41  {
42  GeometryFactory gf = new GeometryFactory();
43  return gf.createPolygon(gf.createLinearRing(
44  new Coordinate[]{
45  new Coordinate(envelope.getMinX(), envelope.getMinY()),
46  new Coordinate(envelope.getMaxX(), envelope.getMinY()),
47  new Coordinate(envelope.getMaxX(), envelope.getMaxY()),
48  new Coordinate(envelope.getMinX(), envelope.getMaxY()),
49  new Coordinate(envelope.getMinX(), envelope.getMinY())
50  }), null);
51  }

◆ toGeometry() [3/5]

static Geometry toGeometry ( final Envelope2D  envelope)
static
53  {
54  GeometryFactory gf = new GeometryFactory();
55  return gf.createPolygon(gf.createLinearRing(
56  new Coordinate[]{
57  new Coordinate(envelope.getMinX(), envelope.getMinY()),
58  new Coordinate(envelope.getMaxX(), envelope.getMinY()),
59  new Coordinate(envelope.getMaxX(), envelope.getMaxY()),
60  new Coordinate(envelope.getMinX(), envelope.getMaxY()),
61  new Coordinate(envelope.getMinX(), envelope.getMinY())
62  }), null);
63  }

◆ toGeometry() [4/5]

static Geometry toGeometry ( final OctagonalEnvelope  envelope)
static
65  {
66  GeometryFactory gf = new GeometryFactory();
67  return gf.createPolygon(gf.createLinearRing(
68  new Coordinate[]{
69  new Coordinate(envelope.getMinX(), envelope.getMinY()),
70  new Coordinate(envelope.getMaxX(), envelope.getMinY()),
71  new Coordinate(envelope.getMaxX(), envelope.getMaxY()),
72  new Coordinate(envelope.getMinX(), envelope.getMaxY()),
73  new Coordinate(envelope.getMinX(), envelope.getMinY())
74  }), null);
75  }

◆ toGeometry() [5/5]

static Geometry toGeometry ( final Rectangle  envelope)
static
91  {
92  GeometryFactory gf = new GeometryFactory();
93  return gf.createPolygon(gf.createLinearRing(
94  new Coordinate[]{
95  new Coordinate(envelope.getMinX(), envelope.getMinY()),
96  new Coordinate(envelope.getMaxX(), envelope.getMinY()),
97  new Coordinate(envelope.getMaxX(), envelope.getMaxY()),
98  new Coordinate(envelope.getMinX(), envelope.getMaxY()),
99  new Coordinate(envelope.getMinX(), envelope.getMinY())
100  }), null);
101  }

◆ transform()

static Geometry transform ( Geometry  sourcegeom,
Geometry  targetgeom 
)
static

References LiteralUtils.createGeometry().

Referenced by Difference3D.relation(), BBOXBelow.relation(), BBOXDistance.relation(), BBOXIsContainedBy.relation(), MaxDistance.relation(), BBOXLeftOf.relation(), OrderingEquals.relation(), BBOXEquals.relation(), BBOXOverlapsAbove.relation(), BBOXIntersects.relation(), BBOXRightOf.relation(), BBOXOverlapsRight.relation(), BBOXOverlapsLeft.relation(), BBOXOverlapsBelow.relation(), BBOXAbove.relation(), BBOXFPIntersects.relation(), BBOXContains.relation(), Distance3D.relation(), ShortestLine.relation(), ShortestLine3D.relation(), SetPoint.relation(), SharedPaths.relation(), and MaxDistance3D.relation().

154  {
155 
156  CoordinateReferenceSystem source;
157  try {
158  source = CRS.forCode("EPSG:"+sourcegeom.getSRID());
159  CoordinateReferenceSystem target = CRS.forCode("EPSG:"+targetgeom.getSRID()); // WGS 84 / World Mercator
160  CoordinateOperation operation = CRS.findOperation(source, target, null);
161  if (CRS.getLinearAccuracy(operation) > 100) {
162  // If the accuracy is coarser than 100 metres (or any other threshold at application choice)
163  // maybe the operation is not suitable. Decide here what to do (throw an exception, etc).
164  }
165  MathTransform mt = operation.getMathTransform();
166  List<Coordinate> coords=new LinkedList<Coordinate>();
167  for(Coordinate coord:targetgeom.getCoordinates()) {
168  DirectPosition resposition = new DirectPosition2D(20, 30); // 20°N 30°E (watch out axis order!)
169  mt.transform(new DirectPosition2D(coord.getY(),coord.getY()), resposition);
170  coords.add(new Coordinate(resposition.getCoordinate()[1],resposition.getCoordinate()[0]));
171  }
172  return LiteralUtils.createGeometry(coords, targetgeom.getGeometryType(), targetgeom.getSRID());
173 
174  } catch (FactoryException | MismatchedDimensionException | TransformException e) {
175  // TODO Auto-generated catch block
176  e.printStackTrace();
177  }
178  return null;
179 
180  }