Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added spatial reference into calls to geojson operator for OGCMultiLi… #291

Merged
merged 1 commit into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public String asText() {
public String asGeoJson() {
OperatorExportToGeoJson op = (OperatorExportToGeoJson) OperatorFactoryLocal.getInstance()
.getOperator(Operator.Type.ExportToGeoJson);
return op.execute(GeoJsonExportFlags.geoJsonExportPreferMultiGeometry, null, getEsriGeometry());
return op.execute(GeoJsonExportFlags.geoJsonExportPreferMultiGeometry, esriSR, getEsriGeometry());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public ByteBuffer asBinary() {
public String asGeoJson() {
OperatorExportToGeoJson op = (OperatorExportToGeoJson) OperatorFactoryLocal
.getInstance().getOperator(Operator.Type.ExportToGeoJson);
return op.execute(GeoJsonExportFlags.geoJsonExportPreferMultiGeometry, null, getEsriGeometry());
return op.execute(GeoJsonExportFlags.geoJsonExportPreferMultiGeometry, esriSR, getEsriGeometry());
}
@Override
public int numGeometries() {
Expand Down
62 changes: 56 additions & 6 deletions src/test/java/com/esri/core/geometry/TestGeomToGeoJson.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,9 @@

package com.esri.core.geometry;

import com.esri.core.geometry.ogc.OGCGeometry;
import com.esri.core.geometry.ogc.OGCPoint;
import com.esri.core.geometry.ogc.OGCMultiPoint;
import com.esri.core.geometry.ogc.OGCLineString;
import com.esri.core.geometry.ogc.OGCPolygon;
import com.esri.core.geometry.ogc.*;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.esri.core.geometry.ogc.OGCConcreteGeometryCollection;
import junit.framework.TestCase;
import org.junit.Test;

Expand Down Expand Up @@ -161,6 +156,20 @@ public void testOGCLineString() {
assertEquals("{\"type\":\"LineString\",\"coordinates\":[[100,0],[101,0],[101,1],[100,1]],\"crs\":null}", result);
}

@Test
public void testOGCMultiLineStringCRS() throws IOException {
Polyline p = new Polyline();
p.startPath(100.0, 0.0);
p.lineTo(101.0, 0.0);
p.lineTo(101.0, 1.0);
p.lineTo(100.0, 1.0);

OGCMultiLineString multiLineString = new OGCMultiLineString(p, SpatialReference.create(4326));

String result = multiLineString.asGeoJson();
assertEquals("{\"type\":\"MultiLineString\",\"coordinates\":[[[100,0],[101,0],[101,1],[100,1]]],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}}", result);
}

@Test
public void testPolygon() {
Polygon p = new Polygon();
Expand Down Expand Up @@ -241,6 +250,24 @@ public void testMultiPolygon() throws IOException {
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);
}

@Test
public void testOGCMultiPolygonCRS() throws IOException {
JsonFactory jsonFactory = new JsonFactory();

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]]]}";

JsonParser parser = jsonFactory.createParser(esriJsonPolygon);
MapGeometry parsedPoly = GeometryEngine.jsonToGeometry(parser);

parsedPoly.setSpatialReference(SpatialReference.create(4326));
Polygon poly = (Polygon) parsedPoly.getGeometry();
OGCMultiPolygon multiPolygon = new OGCMultiPolygon(poly, parsedPoly.getSpatialReference());


String result = multiPolygon.asGeoJson();
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);
}


@Test
public void testEmptyPolygon() {
Expand Down Expand Up @@ -334,6 +361,29 @@ public void testOGCPolygonWithHole() {
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);
}

@Test
public void testOGCPolygonWithHoleCRS() {
Polygon p = new Polygon();

p.startPath(100.0, 0.0);
p.lineTo(100.0, 1.0);
p.lineTo(101.0, 1.0);
p.lineTo(101.0, 0.0);
p.closePathWithLine();

p.startPath(100.2, 0.2);
p.lineTo(100.8, 0.2);
p.lineTo(100.8, 0.8);
p.lineTo(100.2, 0.8);
p.closePathWithLine();

SpatialReference sr = SpatialReference.create(4326);

OGCPolygon ogcPolygon = new OGCPolygon(p, sr);
String result = ogcPolygon.asGeoJson();
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);
}

@Test
public void testGeometryCollection() {
SpatialReference sr = SpatialReference.create(4326);
Expand Down