Example usage for org.springframework.data.mongodb.core.geo GeoJsonPolygon GeoJsonPolygon

List of usage examples for org.springframework.data.mongodb.core.geo GeoJsonPolygon GeoJsonPolygon

Introduction

In this page you can find the example usage for org.springframework.data.mongodb.core.geo GeoJsonPolygon GeoJsonPolygon.

Prototype

public GeoJsonPolygon(List<Point> points) 

Source Link

Document

Creates new GeoJsonPolygon from the given Point s.

Usage

From source file:org.springframework.data.mongodb.core.geo.GeoJsonModuleUnitTests.java

/**
 * @see DATAMONGO-1181/*from w  w  w  .  j a v  a2 s.  c o  m*/
 */
@Test
public void shouldDeserializeGeoJsonPolygonCorrectly()
        throws JsonParseException, JsonMappingException, IOException {

    String json = "{ \"type\": \"Polygon\", \"coordinates\": [ [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ] ]}";

    assertThat(mapper.readValue(json, GeoJsonPolygon.class),
            is(new GeoJsonPolygon(Arrays.asList(new Point(100, 0), new Point(101, 0), new Point(101, 1),
                    new Point(100, 1), new Point(100, 0)))));
}

From source file:org.springframework.data.mongodb.core.geo.GeoJsonModuleUnitTests.java

/**
 * @see DATAMONGO-1181/*from w ww  . j  av a  2  s .  c  om*/
 */
@Test
public void shouldDeserializeGeoJsonMultiPolygonCorrectly()
        throws JsonParseException, JsonMappingException, IOException {

    String json = "{ \"type\": \"Polygon\", \"coordinates\": ["
            + "[[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]]],"
            + "[[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]],"
            + "[[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]]"//
            + "]}";

    assertThat(mapper.readValue(json, GeoJsonMultiPolygon.class),
            is(new GeoJsonMultiPolygon(Arrays.asList(
                    new GeoJsonPolygon(Arrays.asList(new Point(102, 2), new Point(103, 2), new Point(103, 3),
                            new Point(102, 3), new Point(102, 2))),
                    new GeoJsonPolygon(Arrays.asList(new Point(100, 0), new Point(101, 0), new Point(101, 1),
                            new Point(100, 1), new Point(100, 0))),
                    new GeoJsonPolygon(Arrays.asList(new Point(100.2, 0.2), new Point(100.8, 0.2),
                            new Point(100.8, 0.8), new Point(100.2, 0.8), new Point(100.2, 0.2)))))));

}