|
22 | 22 |
|
23 | 23 | package com.esri.core.geometry;
|
24 | 24 |
|
25 |
| -import com.esri.core.geometry.ogc.OGCGeometry; |
26 |
| -import com.esri.core.geometry.ogc.OGCPoint; |
27 |
| -import com.esri.core.geometry.ogc.OGCMultiPoint; |
28 |
| -import com.esri.core.geometry.ogc.OGCLineString; |
29 |
| -import com.esri.core.geometry.ogc.OGCPolygon; |
| 25 | +import com.esri.core.geometry.ogc.*; |
30 | 26 | import com.fasterxml.jackson.core.JsonFactory;
|
31 | 27 | import com.fasterxml.jackson.core.JsonParser;
|
32 |
| -import com.esri.core.geometry.ogc.OGCConcreteGeometryCollection; |
33 | 28 | import junit.framework.TestCase;
|
34 | 29 | import org.junit.Test;
|
35 | 30 |
|
@@ -161,6 +156,20 @@ public void testOGCLineString() {
|
161 | 156 | assertEquals("{\"type\":\"LineString\",\"coordinates\":[[100,0],[101,0],[101,1],[100,1]],\"crs\":null}", result);
|
162 | 157 | }
|
163 | 158 |
|
| 159 | + @Test |
| 160 | + public void testOGCMultiLineStringCRS() throws IOException { |
| 161 | + Polyline p = new Polyline(); |
| 162 | + p.startPath(100.0, 0.0); |
| 163 | + p.lineTo(101.0, 0.0); |
| 164 | + p.lineTo(101.0, 1.0); |
| 165 | + p.lineTo(100.0, 1.0); |
| 166 | + |
| 167 | + OGCMultiLineString multiLineString = new OGCMultiLineString(p, SpatialReference.create(4326)); |
| 168 | + |
| 169 | + String result = multiLineString.asGeoJson(); |
| 170 | + assertEquals("{\"type\":\"MultiLineString\",\"coordinates\":[[[100,0],[101,0],[101,1],[100,1]]],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}}", result); |
| 171 | + } |
| 172 | + |
164 | 173 | @Test
|
165 | 174 | public void testPolygon() {
|
166 | 175 | Polygon p = new Polygon();
|
@@ -241,6 +250,24 @@ public void testMultiPolygon() throws IOException {
|
241 | 250 | assertEquals("{\"type\":\"MultiPolygon\",\"coordinates\":[[[[-100,-100],[100,-100],[100,100],[-100,100],[-100,-100]],[[-90,-90],[90,-90],[-90,90],[90,90],[-90,-90]]],[[[-10,-10],[10,-10],[10,10],[-10,10],[-10,-10]]]]}", result);
|
242 | 251 | }
|
243 | 252 |
|
| 253 | + @Test |
| 254 | + public void testOGCMultiPolygonCRS() throws IOException { |
| 255 | + JsonFactory jsonFactory = new JsonFactory(); |
| 256 | + |
| 257 | + String esriJsonPolygon = "{\"rings\": [[[-100, -100], [-100, 100], [100, 100], [100, -100], [-100, -100]], [[-90, -90], [90, 90], [-90, 90], [90, -90], [-90, -90]], [[-10, -10], [-10, 10], [10, 10], [10, -10], [-10, -10]]]}"; |
| 258 | + |
| 259 | + JsonParser parser = jsonFactory.createParser(esriJsonPolygon); |
| 260 | + MapGeometry parsedPoly = GeometryEngine.jsonToGeometry(parser); |
| 261 | + |
| 262 | + parsedPoly.setSpatialReference(SpatialReference.create(4326)); |
| 263 | + Polygon poly = (Polygon) parsedPoly.getGeometry(); |
| 264 | + OGCMultiPolygon multiPolygon = new OGCMultiPolygon(poly, parsedPoly.getSpatialReference()); |
| 265 | + |
| 266 | + |
| 267 | + String result = multiPolygon.asGeoJson(); |
| 268 | + assertEquals("{\"type\":\"MultiPolygon\",\"coordinates\":[[[[-100,-100],[100,-100],[100,100],[-100,100],[-100,-100]],[[-90,-90],[90,-90],[-90,90],[90,90],[-90,-90]]],[[[-10,-10],[10,-10],[10,10],[-10,10],[-10,-10]]]],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}}", result); |
| 269 | + } |
| 270 | + |
244 | 271 |
|
245 | 272 | @Test
|
246 | 273 | public void testEmptyPolygon() {
|
@@ -334,6 +361,29 @@ public void testOGCPolygonWithHole() {
|
334 | 361 | assertEquals("{\"type\":\"Polygon\",\"coordinates\":[[[100,0],[101,0],[101,1],[100,1],[100,0]],[[100.2,0.2],[100.2,0.8],[100.8,0.8],[100.8,0.2],[100.2,0.2]]],\"crs\":null}", result);
|
335 | 362 | }
|
336 | 363 |
|
| 364 | + @Test |
| 365 | + public void testOGCPolygonWithHoleCRS() { |
| 366 | + Polygon p = new Polygon(); |
| 367 | + |
| 368 | + p.startPath(100.0, 0.0); |
| 369 | + p.lineTo(100.0, 1.0); |
| 370 | + p.lineTo(101.0, 1.0); |
| 371 | + p.lineTo(101.0, 0.0); |
| 372 | + p.closePathWithLine(); |
| 373 | + |
| 374 | + p.startPath(100.2, 0.2); |
| 375 | + p.lineTo(100.8, 0.2); |
| 376 | + p.lineTo(100.8, 0.8); |
| 377 | + p.lineTo(100.2, 0.8); |
| 378 | + p.closePathWithLine(); |
| 379 | + |
| 380 | + SpatialReference sr = SpatialReference.create(4326); |
| 381 | + |
| 382 | + OGCPolygon ogcPolygon = new OGCPolygon(p, sr); |
| 383 | + String result = ogcPolygon.asGeoJson(); |
| 384 | + assertEquals("{\"type\":\"Polygon\",\"coordinates\":[[[100,0],[101,0],[101,1],[100,1],[100,0]],[[100.2,0.2],[100.2,0.8],[100.8,0.8],[100.8,0.2],[100.2,0.2]]],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}}", result); |
| 385 | + } |
| 386 | + |
337 | 387 | @Test
|
338 | 388 | public void testGeometryCollection() {
|
339 | 389 | SpatialReference sr = SpatialReference.create(4326);
|
|
0 commit comments