org.geojson.LngLatAlt Java Examples
The following examples show how to use
org.geojson.LngLatAlt.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GeoTests.java From FROST-Server with GNU Lesser General Public License v3.0 | 7 votes |
private static void createLocation4() throws ServiceFailureException { // Locations 4 Polygon gjo = new Polygon( new LngLatAlt(8, 53), new LngLatAlt(7, 52), new LngLatAlt(7, 53), new LngLatAlt(8, 53)); Location location = new Location("Location 4", "Location of Thing 4.", "application/vnd.geo+json", gjo); location.getThings().add(THINGS.get(3)); service.create(location); LOCATIONS.add(location); FeatureOfInterest featureOfInterest = new FeatureOfInterest("FoI 4", "This should be FoI #4.", "application/geo+json", gjo); service.create(featureOfInterest); FEATURESOFINTEREST.add(featureOfInterest); }
Example #2
Source File: TestHelper.java From FROST-Server with GNU Lesser General Public License v3.0 | 6 votes |
public static <T extends Number> List<LngLatAlt> getPointList(int dimensions, T... values) { if (dimensions < 2 || dimensions > 3) { throw new IllegalArgumentException("PointList requires 'demensions' to be 2 or 3."); } if (values == null || values.length % dimensions != 0) { throw new IllegalArgumentException("The number of values " + Arrays.toString(values) + " does not fit the dimensions " + dimensions); } List<LngLatAlt> points = new ArrayList<>(values.length / dimensions); for (int i = 0; i < values.length; i += dimensions) { if (dimensions == 2) { points.add(new LngLatAlt(values[i].doubleValue(), values[i + 1].doubleValue())); } else { points.add(new LngLatAlt(values[i].doubleValue(), values[i + 1].doubleValue(), values[i + 2].doubleValue())); } } return points; }
Example #3
Source File: LngLatAltDeserializer.java From geojson-jackson with Apache License 2.0 | 6 votes |
protected LngLatAlt deserializeArray(JsonParser jp, DeserializationContext ctxt) throws IOException { LngLatAlt node = new LngLatAlt(); node.setLongitude(extractDouble(jp, ctxt, false)); node.setLatitude(extractDouble(jp, ctxt, false)); node.setAltitude(extractDouble(jp, ctxt, true)); List<Double> additionalElementsList = new ArrayList<Double>(); while (jp.hasCurrentToken() && jp.getCurrentToken() != JsonToken.END_ARRAY) { double element = extractDouble(jp, ctxt, true); if (!Double.isNaN(element)) { additionalElementsList.add(element); } } double[] additionalElements = new double[additionalElementsList.size()]; for (int i = 0; i < additionalElements.length; i++) { additionalElements[i] = additionalElementsList.get(i); } node.setAdditionalElements(additionalElements); return node; }
Example #4
Source File: LngLatAltDeserializer.java From geojson-jackson with Apache License 2.0 | 5 votes |
@Override public LngLatAlt deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { if (jp.isExpectedStartArrayToken()) { return deserializeArray(jp, ctxt); } throw ctxt.mappingException(LngLatAlt.class); }
Example #5
Source File: MultiPoligonTest.java From geojson-jackson with Apache License 2.0 | 5 votes |
@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)); }
Example #6
Source File: PolygonTest.java From geojson-jackson with Apache License 2.0 | 5 votes |
private void assertListEquals(List<LngLatAlt> expectedList, List<LngLatAlt> actualList) { for (int x = 0; x < actualList.size(); x++) { LngLatAlt expected = expectedList.get(x); LngLatAlt actual = actualList.get(x); PointTest.assertLngLatAlt(expected.getLongitude(), expected.getLatitude(), expected.getAltitude(), actual); } }
Example #7
Source File: PolygonTest.java From geojson-jackson with Apache License 2.0 | 5 votes |
@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()); }
Example #8
Source File: LngLatAltSerializerTest.java From geojson-jackson with Apache License 2.0 | 5 votes |
@Test public void testSerialization() throws Exception { LngLatAlt position = new LngLatAlt(49.43245, 52.42345, 120.34626); String correctJson = "[49.43245,52.42345,120.34626]"; String producedJson = new ObjectMapper().writeValueAsString(position); Assert.assertEquals(correctJson, producedJson); }
Example #9
Source File: MultiLineStringTest.java From geojson-jackson with Apache License 2.0 | 5 votes |
@Test public void itShouldSerialize() throws Exception { MultiLineString multiLineString = new MultiLineString(); multiLineString.add(Arrays.asList(new LngLatAlt(100, 0), new LngLatAlt(101, 1))); multiLineString.add(Arrays.asList(new LngLatAlt(102, 2), new LngLatAlt(103, 3))); assertEquals("{\"type\":\"MultiLineString\",\"coordinates\":" + "[[[100.0,0.0],[101.0,1.0]],[[102.0,2.0],[103.0,3.0]]]}", mapper.writeValueAsString(multiLineString)); }
Example #10
Source File: LngLatAltDeserializerTest.java From geojson-jackson with Apache License 2.0 | 5 votes |
@Test public void deserializeMongoLngLatAlt() throws Exception { LngLatAlt lngLatAlt = new LngLatAlt(10D, 15D, 5); String lngLatAltJson = new ObjectMapper().writeValueAsString(lngLatAlt); lngLatAltJson.replace("10.0", "\"10.0\""); lngLatAltJson.replace("15.0", "\"15.0\""); LngLatAlt lngLatAlt1 = new ObjectMapper().readValue(lngLatAltJson, LngLatAlt.class); Assert.assertTrue(lngLatAlt.equals(lngLatAlt)); }
Example #11
Source File: PointTest.java From geojson-jackson with Apache License 2.0 | 5 votes |
public static void assertLngLatAlt(double expectedLongitude, double expectedLatitude, double expectedAltitude, double[] expectedAdditionalElements, LngLatAlt point) { assertEquals(expectedLongitude, point.getLongitude(), 0.00001); assertEquals(expectedLatitude, point.getLatitude(), 0.00001); if (Double.isNaN(expectedAltitude)) { assertFalse(point.hasAltitude()); } else { assertEquals(expectedAltitude, point.getAltitude(), 0.00001); assertTrue(Arrays.equals(expectedAdditionalElements, point.getAdditionalElements())); } }
Example #12
Source File: MultiPointTest.java From geojson-jackson with Apache License 2.0 | 5 votes |
@Test public void itShouldDeserializeMultiPoint() throws Exception { MultiPoint multiPoint = mapper .readValue("{\"type\":\"MultiPoint\",\"coordinates\":[[100.0,0.0],[101.0,1.0]]}", MultiPoint.class); assertNotNull(multiPoint); List<LngLatAlt> coordinates = multiPoint.getCoordinates(); PointTest.assertLngLatAlt(100, 0, Double.NaN, coordinates.get(0)); PointTest.assertLngLatAlt(101, 1, Double.NaN, coordinates.get(1)); }
Example #13
Source File: LineStringTest.java From geojson-jackson with Apache License 2.0 | 5 votes |
@Test public void itShouldDeserializeLineString() throws Exception { LineString lineString = mapper.readValue("{\"type\":\"LineString\",\"coordinates\":[[100.0,0.0],[101.0,1.0]]}", LineString.class); assertNotNull(lineString); List<LngLatAlt> coordinates = lineString.getCoordinates(); PointTest.assertLngLatAlt(100, 0, Double.NaN, coordinates.get(0)); PointTest.assertLngLatAlt(101, 1, Double.NaN, coordinates.get(1)); }
Example #14
Source File: LngLatAltSerializer.java From geojson-jackson with Apache License 2.0 | 5 votes |
@Override public void serialize(LngLatAlt value, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeStartArray(); jgen.writeNumber(value.getLongitude()); jgen.writeNumber(value.getLatitude()); if (value.hasAltitude()) { jgen.writeNumber(value.getAltitude()); for (double d : value.getAdditionalElements()) { jgen.writeNumber(d); } } jgen.writeEndArray(); }
Example #15
Source File: MentionConverter.java From baleen with Apache License 2.0 | 5 votes |
private Optional<LatLonArea> computeAveragePosition( final List<LngLatAlt> coordinates, final int numberCoordinates) { double lat = 0; double lon = 0; double minLat = 180; double maxLat = -180; double minLon = 180; double maxLon = -180; for (int i = 0; i < numberCoordinates; i++) { final LngLatAlt c = coordinates.get(i); lat += c.getLatitude(); lon += c.getLongitude(); minLat = minLat < c.getLatitude() ? minLat : c.getLatitude(); maxLat = maxLat > c.getLatitude() ? maxLat : c.getLatitude(); minLon = minLon < c.getLongitude() ? minLon : c.getLongitude(); maxLon = maxLon > c.getLongitude() ? maxLon : c.getLongitude(); } final double dLat = Math.abs(maxLat - minLat); final double dLon = Math.abs(maxLon - minLon); // This area is very crude but... final double area = dLat * dLon; return Optional.of(new LatLonArea(lat / numberCoordinates, lon / numberCoordinates, area)); }
Example #16
Source File: MentionConverter.java From baleen with Apache License 2.0 | 5 votes |
private int getNumberOfCoordinates(final List<LngLatAlt> coordinates, final boolean isPolygon) { if (coordinates == null) { return 0; } // If this is a polygon (includeLast=false) the the first and last coordinates are the same // so we drop one to avoid double counting return isPolygon ? coordinates.size() - 1 : coordinates.size(); }
Example #17
Source File: MentionConverter.java From baleen with Apache License 2.0 | 5 votes |
private Optional<LatLonArea> toGeoLocation( final List<LngLatAlt> coordinates, final boolean isPolygon) { final int numberCoordinates = getNumberOfCoordinates(coordinates, isPolygon); if (numberCoordinates == 0) { return Optional.empty(); } else { return computeAveragePosition(coordinates, numberCoordinates); } }
Example #18
Source File: MentionConverter.java From baleen with Apache License 2.0 | 5 votes |
private Optional<LatLon> toGeoLocation(final MultiPolygon mp) { final List<LatLon> pois = new LinkedList<>(); final List<List<List<LngLatAlt>>> coordinates = mp.getCoordinates(); for (final List<List<LngLatAlt>> polygon : coordinates) { final List<LngLatAlt> exteriorRing = polygon.get(0); toGeoLocation(exteriorRing, true).ifPresent(pois::add); } // Take only the largest return pois.stream().sorted().findFirst(); }
Example #19
Source File: GeoHelper.java From FROST-Server with GNU Lesser General Public License v3.0 | 5 votes |
private static LngLatAlt[] stringListToPoints(String value) { return Arrays.asList(value.split("\\s*,\\s*")).stream() .map(x -> Arrays.asList(x.split(" "))) //split each point in coorinates array .map(x -> x.stream().map(Double::parseDouble)) // parse each coordinate to double .map(x -> getPoint(x.toArray(size -> new Double[size])).getCoordinates()) //collect double coordinate into double[] and convert to Point .toArray(size -> new LngLatAlt[size]); }
Example #20
Source File: GeoHelper.java From FROST-Server with GNU Lesser General Public License v3.0 | 5 votes |
public static LineString parseLine(String value) { Matcher matcher = GeoHelper.WKT_LINE_PATTERN.matcher(value.trim()); if (matcher.matches()) { String[] points = matcher.group(1).split("\\s*,\\s*"); return new LineString( Arrays.asList(points).stream() .map(x -> Arrays.asList(x.split(" "))) //split each point in coorinates array .map(x -> x.stream().map(Double::parseDouble)) // parse each coordinate to double .map(x -> getPoint(x.toArray(size -> new Double[size])).getCoordinates()) //collect double coordinate into double[] and convert to Point .toArray(size -> new LngLatAlt[size])); } else { throw new IllegalArgumentException("'" + value + DOES_NOT_MATCH_PATTERN + GeoHelper.WKT_LINE_PATTERN.pattern() + "'"); } }
Example #21
Source File: GeoTests.java From FROST-Server with GNU Lesser General Public License v3.0 | 5 votes |
private static void createLocation7() throws ServiceFailureException { // Locations 7 LineString gjo = new LineString( new LngLatAlt(4, 52), new LngLatAlt(8, 52)); Location location = new Location("Location 7", "The longest line.", "application/vnd.geo+json", gjo); service.create(location); LOCATIONS.add(location); FeatureOfInterest featureOfInterest = new FeatureOfInterest("FoI 7", "This should be FoI #7.", "application/geo+json", gjo); service.create(featureOfInterest); FEATURESOFINTEREST.add(featureOfInterest); }
Example #22
Source File: GeoTests.java From FROST-Server with GNU Lesser General Public License v3.0 | 5 votes |
private static void createLocation6() throws ServiceFailureException { // Locations 6 LineString gjo = new LineString( new LngLatAlt(5, 52), new LngLatAlt(6, 53)); Location location = new Location("Location 6", "A longer line.", "application/vnd.geo+json", gjo); service.create(location); LOCATIONS.add(location); FeatureOfInterest featureOfInterest = new FeatureOfInterest("FoI 6", "This should be FoI #6.", "application/geo+json", gjo); service.create(featureOfInterest); FEATURESOFINTEREST.add(featureOfInterest); }
Example #23
Source File: GeoTests.java From FROST-Server with GNU Lesser General Public License v3.0 | 5 votes |
private static void createLocation5() throws ServiceFailureException { // Locations 5 LineString gjo = new LineString( new LngLatAlt(5, 52), new LngLatAlt(5, 53)); Location location = new Location("Location 5", "A line.", "application/vnd.geo+json", gjo); service.create(location); LOCATIONS.add(location); FeatureOfInterest featureOfInterest = new FeatureOfInterest("FoI 5", "This should be FoI #5.", "application/geo+json", gjo); service.create(featureOfInterest); FEATURESOFINTEREST.add(featureOfInterest); }
Example #24
Source File: MentionConverter.java From baleen with Apache License 2.0 | 4 votes |
private Optional<LatLon> toGeoLocation(final LngLatAlt coordinates) { return Optional.of(new LatLon(coordinates.getLatitude(), coordinates.getLongitude())); }
Example #25
Source File: LineStringTest.java From geojson-jackson with Apache License 2.0 | 4 votes |
@Test public void itShouldSerializeMultiPoint() throws Exception { MultiPoint lineString = new LineString(new LngLatAlt(100, 0), new LngLatAlt(101, 1)); assertEquals("{\"type\":\"LineString\",\"coordinates\":[[100.0,0.0],[101.0,1.0]]}", mapper.writeValueAsString(lineString)); }
Example #26
Source File: MultiPointTest.java From geojson-jackson with Apache License 2.0 | 4 votes |
@Test public void itShouldSerializeMultiPoint() throws Exception { MultiPoint multiPoint = new MultiPoint(new LngLatAlt(100, 0), new LngLatAlt(101, 1)); assertEquals("{\"type\":\"MultiPoint\",\"coordinates\":[[100.0,0.0],[101.0,1.0]]}", mapper.writeValueAsString(multiPoint)); }
Example #27
Source File: PointTest.java From geojson-jackson with Apache License 2.0 | 4 votes |
public static void assertLngLatAlt(double expectedLongitude, double expectedLatitude, double expectedAltitude, LngLatAlt point) { assertLngLatAlt(expectedLongitude, expectedLatitude, expectedAltitude, new double[0], point); }
Example #28
Source File: TestHelper.java From FROST-Server with GNU Lesser General Public License v3.0 | 4 votes |
public static <T extends Number> LineString getLine(T[]... values) { if (values == null || values.length < 2 || values.length > 3) { throw new IllegalArgumentException("values must have a length of 2 or 3."); } return new LineString(Arrays.asList(values).stream().map(x -> getPoint(x).getCoordinates()).toArray(size -> new LngLatAlt[size])); }