Java Code Examples for org.geojson.LineString

The following examples show how to use org.geojson.LineString. These examples are extracted from open source projects. 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 Project: FROST-Server   Source File: GeoTests.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
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 2
Source Project: FROST-Server   Source File: GeoTests.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
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 3
Source Project: FROST-Server   Source File: GeoTests.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
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 4
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 5
@Test
public void testParseFromString2D() {
    final LineString expected = TestHelper.getLine(new Integer[]{30, 10}, new Integer[]{10, 30}, new Integer[]{40, 40});
    String text = "LINESTRING (30 10, 10 30, 40 40)";
    LineStringConstant result = new LineStringConstant(text);
    Assert.assertEquals(expected, result.getValue());

    text = "LINESTRING(30 10,10 30,40 40)";
    result = new LineStringConstant(text);
    Assert.assertEquals(expected, result.getValue());

    text = "LINESTRING  (30 10 , 10 30 , 40 40)";
    result = new LineStringConstant(text);
    Assert.assertEquals(expected, result.getValue());
}
 
Example 6
@Test
public void testParseFromStringDecimal() {
    final LineString expected = TestHelper.getLine(new Double[]{30.1, 10.2}, new Double[]{0.1, .1}, new Double[]{40.0, 40.0});
    String text = "LINESTRING (30.1 10.2, 0.1 .1, 40.0 40.0)";
    LineStringConstant result = new LineStringConstant(text);
    Assert.assertEquals(expected, result.getValue());
}
 
Example 7
@Test
public void testParseFromString3D() {
    final LineString expected = TestHelper.getLine(new Integer[]{30, 10, 10}, new Integer[]{10, 30, 10}, new Integer[]{40, 40, 40});
    String text = "LINESTRING (30 10 10, 10 30 10, 40 40 40)";
    LineStringConstant result = new LineStringConstant(text);
    Assert.assertEquals(expected, result.getValue());

    text = "LINESTRING(30 10 10,10 30 10,40 40 40)";
    result = new LineStringConstant(text);
    Assert.assertEquals(expected, result.getValue());

    text = "LINESTRING  (30 10 10 , 10 30 10 , 40 40 40)";
    result = new LineStringConstant(text);
    Assert.assertEquals(expected, result.getValue());
}
 
Example 8
Source Project: geojson-jackson   Source File: LineStringTest.java    License: Apache License 2.0 5 votes vote down vote up
@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 9
public LineStringConstant(LineString value) {
    super(value);
}
 
Example 10
@Override
protected LineString parse(String value) {
    return GeoHelper.parseLine(value);
}
 
Example 11
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]));
}
 
Example 12
Source Project: geojson-jackson   Source File: LineStringTest.java    License: Apache License 2.0 4 votes vote down vote up
@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));
}