Search in sources :

Example 1 with Polygon

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

the class PolygonTest method itShouldSetExteriorRing.

@Test
public void itShouldSetExteriorRing() throws Exception {
    Polygon polygon = new Polygon();
    polygon.setExteriorRing(MockData.EXTERNAL);
    assertEquals(MockData.EXTERNAL, polygon.getExteriorRing());
}
Also used : Polygon(org.geojson.Polygon) Test(org.junit.Test)

Example 2 with Polygon

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

the class PolygonTest method itShouldSerialize.

@Test
public void itShouldSerialize() throws Exception {
    Polygon polygon = new Polygon(MockData.EXTERNAL);
    assertEquals("{\"type\":\"Polygon\",\"coordinates\":" + "[[[100.0,0.0],[101.0,0.0],[101.0,1.0],[100.0,1.0],[100.0,0.0]]]}", mapper.writeValueAsString(polygon));
}
Also used : Polygon(org.geojson.Polygon) Test(org.junit.Test)

Example 3 with Polygon

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

the class PolygonTest method itShouldDeserialize.

@Test
public void itShouldDeserialize() throws Exception {
    Polygon polygon = mapper.readValue("{\"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]]]}", Polygon.class);
    assertListEquals(MockData.EXTERNAL, polygon.getExteriorRing());
    assertListEquals(MockData.INTERNAL, polygon.getInteriorRing(0));
    assertListEquals(MockData.INTERNAL, polygon.getInteriorRings().get(0));
}
Also used : Polygon(org.geojson.Polygon) Test(org.junit.Test)

Example 4 with Polygon

use of org.geojson.Polygon in project onebusaway-gtfs-modules by OneBusAway.

the class LocationsGeoJSONReaderTest method read.

@Test
public void read() throws IOException {
    Collection<Location> locations = new LocationsGeoJSONReader(new InputStreamReader(new FileInputStream(GtfsTestData.getLocationsGeojson())), "").read();
    assertEquals(locations.size(), 1);
    Location location = locations.iterator().next();
    assertEquals("si_Wendenschlossstrasse", location.getId().getId());
    assertEquals("Wendenschlossstrasse", location.getName());
    assertEquals("A nice description", location.getDescription());
    assertTrue(location.getGeometry() instanceof Polygon);
    assertEquals(new Polygon(new LngLatAlt(13.576526641845703, 52.44413508398945), new LngLatAlt(13.575839996337889, 52.429169943434495), new LngLatAlt(13.590774536132812, 52.4105872618342), new LngLatAlt(13.60879898071289, 52.43225757383383), new LngLatAlt(13.576526641845703, 52.44413508398945)), location.getGeometry());
    assertEquals("fare-zone-A", location.getZoneId());
    assertEquals("http://example.com", location.getUrl());
}
Also used : InputStreamReader(java.io.InputStreamReader) Polygon(org.geojson.Polygon) FileInputStream(java.io.FileInputStream) LngLatAlt(org.geojson.LngLatAlt) Location(org.onebusaway.gtfs.model.Location) Test(org.junit.Test)

Example 5 with Polygon

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

the class MetadataImportExportControllerTest method testPostValidGeoJsonAttribute.

@Test
void testPostValidGeoJsonAttribute() throws IOException {
    POST("/metadata", "{\"organisationUnits\": [ {\"id\":\"rXnqqH2Pu6N\",\"name\": \"My Unit 2\",\"shortName\": \"OU2\",\"openingDate\": \"2020-01-01\"," + "\"attributeValues\": [{\"value\":  \"{\\\"type\\\": \\\"Polygon\\\"," + "\\\"coordinates\\\":  [[[100,0],[101,0],[101,1],[100,1],[100,0]]] }\"," + "\"attribute\": {\"id\": \"RRH9IFiZZYN\"}}]}]," + "\"attributes\":[{\"id\":\"RRH9IFiZZYN\",\"valueType\":\"GEOJSON\",\"organisationUnitAttribute\":true,\"name\":\"testgeojson\"}]}").content(HttpStatus.OK);
    JsonIdentifiableObject organisationUnit = GET("/organisationUnits/{id}", "rXnqqH2Pu6N").content().asObject(JsonIdentifiableObject.class);
    assertEquals(1, organisationUnit.getAttributeValues().size());
    JsonAttributeValue attributeValue = organisationUnit.getAttributeValues().get(0);
    GeoJsonObject geoJSON = new ObjectMapper().readValue(attributeValue.getValue(), GeoJsonObject.class);
    assertTrue(geoJSON instanceof Polygon);
    Polygon polygon = (Polygon) geoJSON;
    assertEquals(100, polygon.getCoordinates().get(0).get(0).getLongitude());
}
Also used : JsonIdentifiableObject(org.hisp.dhis.webapi.json.domain.JsonIdentifiableObject) JsonAttributeValue(org.hisp.dhis.webapi.json.domain.JsonAttributeValue) GeoJsonObject(org.geojson.GeoJsonObject) Polygon(org.geojson.Polygon) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) 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