semanticwfs  Version 0.1.0.0
ReprojectionUtils Class Reference
Collaboration diagram for ReprojectionUtils:

Static Public Member Functions

static String crsURIToEPSG (String uri)
 
static Coordinate reproject (Double x, Double y, String sourceCRS, String targetCRS)
 
static Coordinate[] reproject (Coordinate[] geom, String sourceCRS, String targetCRS)
 
static Geometry reproject (Geometry geom, String sourceCRS, String targetCRS)
 
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 Package Attributes

static CRSFactory csFactory = new CRSFactory()
 
static CoordinateTransformFactory ctFactory = new CoordinateTransformFactory()
 
static GeometryFactory fac =new GeometryFactory()
 

Member Function Documentation

◆ createGeometry() [1/2]

static Geometry createGeometry ( Coordinate[]  coordinates,
String  geomtype,
Integer  srid 
)
static
146  {
147  GeometryFactory fac=new GeometryFactory();
148  Geometry geom;
149  switch(geomtype) {
150  case "Point":
151  geom= fac.createPoint(coordinates[0]);
152  geom.setSRID(srid);
153  return geom;
154  case "MultiPoint":
155  geom=fac.createMultiPointFromCoords(coordinates);
156  geom.setSRID(srid);
157  return geom;
158  case "LineString":
159  geom= fac.createLineString(coordinates);
160  geom.setSRID(srid);
161  return geom;
162  case "Polygon":
163  geom= fac.createPolygon(coordinates);
164  geom.setSRID(srid);
165  return geom;
166  case "MultiLineString":
167  List<LineString> list=new LinkedList<LineString>();
168  list.add(fac.createLineString(coordinates));
169  geom= fac.createMultiLineString(list.toArray(new LineString[0]));
170  geom.setSRID(srid);
171  return geom;
172  case "MultiPolygon":
173  List<Polygon> plist=new LinkedList<Polygon>();
174  plist.add(fac.createPolygon(coordinates));
175  geom= fac.createMultiPolygon(plist.toArray(new Polygon[0]));
176  geom.setSRID(srid);
177  return geom;
178  default:
179  return null;
180  }
181  }
static GeometryFactory fac
Definition: ReprojectionUtils.java:25

References ReprojectionUtils.fac.

Referenced by ReprojectionUtils.createGeometry(), and ReprojectionUtils.reproject().

◆ createGeometry() [2/2]

static Geometry createGeometry ( List< Coordinate >  coordarray,
String  geomtype,
Integer  srid 
)
static
192  {
193  return createGeometry(coordarray.toArray(new Coordinate[0]), geomtype,srid);
194  }
static Geometry createGeometry(Coordinate[] coordinates, String geomtype, Integer srid)
Definition: ReprojectionUtils.java:146

References ReprojectionUtils.createGeometry().

◆ createGeometryCollection() [1/2]

static Geometry createGeometryCollection ( Geometry[]  geometries,
String  geomtype,
Integer  srid 
)
static
187  {
188  GeometryFactory fac=new GeometryFactory();
189  return fac.createGeometryCollection(geometries);
190  }

References ReprojectionUtils.fac.

◆ createGeometryCollection() [2/2]

static Geometry createGeometryCollection ( List< Geometry >  geometries,
String  geomtype,
Integer  srid 
)
static
183  {
184  return createGeometryCollection(geometries.toArray(new Geometry[0]), geomtype, srid);
185  }
static Geometry createGeometryCollection(List< Geometry > geometries, String geomtype, Integer srid)
Definition: ReprojectionUtils.java:183

◆ crsURIToEPSG()

static String crsURIToEPSG ( String  uri)
static
27  {
28  if(uri.startsWith("http")) {
29  uri=uri.replace(">","");
30  return "EPSG:"+uri.substring(uri.lastIndexOf('/')+1);
31  }else if(uri.startsWith("EPSG")) {
32  return uri;
33  }
34  return "";
35  }

Referenced by ReprojectionUtils.reproject().

◆ reproject() [1/3]

static Coordinate [] reproject ( Coordinate[]  geom,
String  sourceCRS,
String  targetCRS 
)
static
56  {
57  if(sourceCRS==null || sourceCRS.isEmpty() || targetCRS==null || targetCRS.isEmpty())
58  return geom;
59  String src=crsURIToEPSG(sourceCRS);
60  String target=crsURIToEPSG(targetCRS);
61  if(src.isEmpty() || target.isEmpty() || src.equals(target)) {
62  return geom;
63  }
64  CoordinateReferenceSystem crs1 = csFactory.createFromName(src);
65  CoordinateReferenceSystem crs2 = csFactory.createFromName(target);
66  CoordinateTransform trans = ctFactory.createTransform(crs1, crs2);
67  Coordinate[] oldcoords=geom;
68  Coordinate[] newcoords=new Coordinate[oldcoords.length];
69  int i=0;
70  for(Coordinate cur:oldcoords) {
71  ProjCoordinate p1 = new ProjCoordinate();
72  ProjCoordinate p2 = new ProjCoordinate();
73  p1.x = cur.x;
74  p1.y = cur.y;
75  trans.transform(p1, p2);
76  newcoords[i]=new Coordinate(p2.x,p2.y);
77  }
78  return newcoords;
79  }
static CRSFactory csFactory
Definition: ReprojectionUtils.java:21
static String crsURIToEPSG(String uri)
Definition: ReprojectionUtils.java:27
static CoordinateTransformFactory ctFactory
Definition: ReprojectionUtils.java:23

References ReprojectionUtils.crsURIToEPSG(), ReprojectionUtils.csFactory, and ReprojectionUtils.ctFactory.

◆ reproject() [2/3]

static Coordinate reproject ( Double  x,
Double  y,
String  sourceCRS,
String  targetCRS 
)
static
37  {
38  if(sourceCRS==null || sourceCRS.isEmpty() || targetCRS==null || targetCRS.isEmpty())
39  return new Coordinate(x,y);
40  String src=crsURIToEPSG(sourceCRS);
41  String target=crsURIToEPSG(targetCRS);
42  if(src.isEmpty() || target.isEmpty() || src.equals(target)) {
43  return new Coordinate(x,y);
44  }
45  CoordinateReferenceSystem crs1 = csFactory.createFromName(src);
46  CoordinateReferenceSystem crs2 = csFactory.createFromName(target);
47  CoordinateTransform trans = ctFactory.createTransform(crs1, crs2);
48  ProjCoordinate p1 = new ProjCoordinate();
49  ProjCoordinate p2 = new ProjCoordinate();
50  p1.x = x;
51  p1.y = y;
52  trans.transform(p1, p2);
53  return new Coordinate(p2.x,p2.y);
54  }

References ReprojectionUtils.crsURIToEPSG(), ReprojectionUtils.csFactory, and ReprojectionUtils.ctFactory.

Referenced by TripleStoreConnector.CQLfilterStringToSPARQLQuery(), GeoJSONFormatter.formatJSONObject(), GeoJSONFormatter.formatJSONStreaming(), and ResultFormatter.parseVectorLiteral().

◆ reproject() [3/3]

static Geometry reproject ( Geometry  geom,
String  sourceCRS,
String  targetCRS 
)
static
82  {
83  if(sourceCRS==null || sourceCRS.isEmpty() || targetCRS==null || targetCRS.isEmpty() || geom==null)
84  return geom;
85  String src=crsURIToEPSG(sourceCRS);
86  String target=crsURIToEPSG(targetCRS);
87  if(src.isEmpty() || target.isEmpty() || src.equals(target)) {
88  return geom;
89  }
90  CoordinateReferenceSystem crs1 = csFactory.createFromName(src);
91  CoordinateReferenceSystem crs2 = csFactory.createFromName(target);
92  CoordinateTransform trans = ctFactory.createTransform(crs1, crs2);
93  Coordinate[] oldcoords=geom.getCoordinates();
94  Coordinate[] newcoords=new Coordinate[oldcoords.length];
95  int i=0;
96  for(Coordinate cur:oldcoords) {
97  ProjCoordinate p1 = new ProjCoordinate();
98  ProjCoordinate p2 = new ProjCoordinate();
99  p1.x = cur.x;
100  p1.y = cur.y;
101  trans.transform(p1, p2);
102  newcoords[i]=new Coordinate(p2.x,p2.y);
103  }
104  return ReprojectionUtils.createGeometry(newcoords, geom.getGeometryType(), geom.getSRID());
105  }

References ReprojectionUtils.createGeometry(), ReprojectionUtils.crsURIToEPSG(), ReprojectionUtils.csFactory, and ReprojectionUtils.ctFactory.

◆ toGeometry() [1/2]

static Geometry toGeometry ( final OctagonalEnvelope  envelope)
static
107  {
108  GeometryFactory gf = new GeometryFactory();
109  return gf.createPolygon(gf.createLinearRing(
110  new Coordinate[]{
111  new Coordinate(envelope.getMinX(), envelope.getMinY()),
112  new Coordinate(envelope.getMaxX(), envelope.getMinY()),
113  new Coordinate(envelope.getMaxX(), envelope.getMaxY()),
114  new Coordinate(envelope.getMinX(), envelope.getMaxY()),
115  new Coordinate(envelope.getMinX(), envelope.getMinY())
116  }), null);
117  }

◆ toGeometry() [2/2]

static Geometry toGeometry ( final Rectangle  envelope)
static
133  {
134  GeometryFactory gf = new GeometryFactory();
135  return gf.createPolygon(gf.createLinearRing(
136  new Coordinate[]{
137  new Coordinate(envelope.getMinX(), envelope.getMinY()),
138  new Coordinate(envelope.getMaxX(), envelope.getMinY()),
139  new Coordinate(envelope.getMaxX(), envelope.getMaxY()),
140  new Coordinate(envelope.getMinX(), envelope.getMaxY()),
141  new Coordinate(envelope.getMinX(), envelope.getMinY())
142  }), null);
143  }

Member Data Documentation

◆ csFactory

CRSFactory csFactory = new CRSFactory()
staticpackage

◆ ctFactory

CoordinateTransformFactory ctFactory = new CoordinateTransformFactory()
staticpackage

◆ fac

GeometryFactory fac =new GeometryFactory()
staticpackage