Search in sources :

Example 6 with Polygon

use of org.geojson.Polygon in project geojson-jackson by opendatalab-de.

the class MultiPoligonTest method itShouldSerialize.

@Test
public void itShouldSerialize() throws Exception {
    MultiPolygon multiPolygon = new MultiPolygon();
    multiPolygon.add(new Polygon(new LngLatAlt(102, 2), new LngLatAlt(103, 2), new LngLatAlt(103, 3), new LngLatAlt(102, 3), new LngLatAlt(102, 2)));
    Polygon polygon = new Polygon(MockData.EXTERNAL);
    polygon.addInteriorRing(MockData.INTERNAL);
    multiPolygon.add(polygon);
    assertEquals("{\"type\":\"MultiPolygon\",\"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]]]]}", mapper.writeValueAsString(multiPolygon));
}
Also used : MultiPolygon(org.geojson.MultiPolygon) MultiPolygon(org.geojson.MultiPolygon) Polygon(org.geojson.Polygon) LngLatAlt(org.geojson.LngLatAlt) Test(org.junit.Test)

Example 7 with Polygon

use of org.geojson.Polygon in project geojson-jackson by opendatalab-de.

the class PolygonTest method itShouldFailOnAddInteriorRingWithoutExteriorRing.

@Test(expected = RuntimeException.class)
public void itShouldFailOnAddInteriorRingWithoutExteriorRing() throws Exception {
    Polygon polygon = new Polygon();
    polygon.addInteriorRing(MockData.EXTERNAL);
}
Also used : Polygon(org.geojson.Polygon) Test(org.junit.Test)

Example 8 with Polygon

use of org.geojson.Polygon in project geojson-jackson by opendatalab-de.

the class PolygonTest method itShouldSerializeWithHole.

@Test
public void itShouldSerializeWithHole() throws Exception {
    Polygon polygon = new Polygon(MockData.EXTERNAL);
    polygon.addInteriorRing(MockData.INTERNAL);
    assertEquals("{\"type\":\"Polygon\",\"coordinates\":" + "[[[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]]]}", mapper.writeValueAsString(polygon));
}
Also used : Polygon(org.geojson.Polygon) Test(org.junit.Test)

Example 9 with Polygon

use of org.geojson.Polygon in project geojson-jackson by opendatalab-de.

the class PolygonTest method itShouldReplaceExteriorRing.

@Test
public void itShouldReplaceExteriorRing() throws Exception {
    Polygon polygon = new Polygon(Arrays.asList(new LngLatAlt(0, 0), new LngLatAlt(1, 0), new LngLatAlt(1, 1), new LngLatAlt(0, 1), new LngLatAlt(0, 0)));
    polygon.setExteriorRing(MockData.EXTERNAL);
    assertEquals(MockData.EXTERNAL, polygon.getExteriorRing());
    assertEquals(0, polygon.getInteriorRings().size());
}
Also used : Polygon(org.geojson.Polygon) LngLatAlt(org.geojson.LngLatAlt) Test(org.junit.Test)

Example 10 with Polygon

use of org.geojson.Polygon in project dhis2-core by dhis2.

the class MetadataImportExportControllerTest method testPostInValidGeoJsonAttribute.

@Test
void testPostInValidGeoJsonAttribute() {
    JsonWebMessage message = POST("/metadata", "{\"organisationUnits\": [ {\"id\":\"rXnqqH2Pu6N\",\"name\": \"My Unit 2\",\"shortName\": \"OU2\",\"openingDate\": \"2020-01-01\"," + "\"attributeValues\": [{\"value\":  \"{\\\"type\\\": \\\"Polygon\\\"}\"," + "\"attribute\": {\"id\": \"RRH9IFiZZYN\"}}]}]," + "\"attributes\":[{\"id\":\"RRH9IFiZZYN\",\"valueType\":\"GEOJSON\",\"organisationUnitAttribute\":true,\"name\":\"testgeojson\"}]}").content(HttpStatus.CONFLICT).as(JsonWebMessage.class);
    assertNotNull(message.find(JsonErrorReport.class, report -> report.getErrorCode() == ErrorCode.E6004));
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) JsonAttributeValue(org.hisp.dhis.webapi.json.domain.JsonAttributeValue) ContentType(org.hisp.dhis.webapi.WebClient.ContentType) Body(org.hisp.dhis.webapi.WebClient.Body) GeoJsonObject(org.geojson.GeoJsonObject) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) JsonWebMessage(org.hisp.dhis.webapi.json.domain.JsonWebMessage) JsonIdentifiableObject(org.hisp.dhis.webapi.json.domain.JsonIdentifiableObject) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test) HttpStatus(org.springframework.http.HttpStatus) JsonObject(org.hisp.dhis.jsontree.JsonObject) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ErrorCode(org.hisp.dhis.feedback.ErrorCode) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) JsonImportSummary(org.hisp.dhis.webapi.json.domain.JsonImportSummary) JsonErrorReport(org.hisp.dhis.webapi.json.domain.JsonErrorReport) Polygon(org.geojson.Polygon) JsonWebMessage(org.hisp.dhis.webapi.json.domain.JsonWebMessage) JsonErrorReport(org.hisp.dhis.webapi.json.domain.JsonErrorReport) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Aggregations

Polygon (org.geojson.Polygon)10 Test (org.junit.Test)8 LngLatAlt (org.geojson.LngLatAlt)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 GeoJsonObject (org.geojson.GeoJsonObject)2 DhisControllerConvenienceTest (org.hisp.dhis.webapi.DhisControllerConvenienceTest)2 JsonAttributeValue (org.hisp.dhis.webapi.json.domain.JsonAttributeValue)2 JsonIdentifiableObject (org.hisp.dhis.webapi.json.domain.JsonIdentifiableObject)2 Test (org.junit.jupiter.api.Test)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 MultiPolygon (org.geojson.MultiPolygon)1 ErrorCode (org.hisp.dhis.feedback.ErrorCode)1 JsonObject (org.hisp.dhis.jsontree.JsonObject)1 Body (org.hisp.dhis.webapi.WebClient.Body)1 ContentType (org.hisp.dhis.webapi.WebClient.ContentType)1 JsonErrorReport (org.hisp.dhis.webapi.json.domain.JsonErrorReport)1 JsonImportSummary (org.hisp.dhis.webapi.json.domain.JsonImportSummary)1 JsonWebMessage (org.hisp.dhis.webapi.json.domain.JsonWebMessage)1