public static PointValue parse( CharSequence text ) { return PointValue.parse( text, null ); }
@Test void shouldBeAbleToParseIncompletePointWithHeaderInformation() { String headerInformation = "{latitude: 40.7128}"; String data = "{longitude: -74.0060, height: 567.8, crs:wgs-84-3D}"; assertThrows( InvalidValuesArgumentException.class, () -> PointValue.parse( data ) ); // this should work PointValue.parse( data, PointValue.parseHeaderInformation( headerInformation ) ); }
@Test void shouldBeAbleToParsePointThatOverridesHeaderInformation() { String headerInformation = "{crs:wgs-84}"; String data = "{latitude: 40.7128, longitude: -74.0060, height: 567.8, crs:wgs-84-3D}"; PointValue expected = PointValue.parse( data ); PointValue actual = PointValue.parse( data, PointValue.parseHeaderInformation( headerInformation ) ); assertEqual( expected, actual ); assertEquals( "wgs-84-3d", actual.getCoordinateReferenceSystem().getName().toLowerCase() ); }
@Override protected boolean extract0( char[] data, int offset, int length, CSVHeaderInformation optionalData ) { value = PointValue.parse( CharBuffer.wrap( data, offset, length ), optionalData ); return true; }
private InvalidValuesArgumentException assertCannotParse( String text ) { return assertThrows( InvalidValuesArgumentException.class, () -> PointValue.parse( text ) ); } }
@Test void shouldBeAbleToParseWeirdlyFormattedPoints() { assertEqual( pointValue( WGS84, 1.0, 2.0 ), PointValue.parse( " \t\n { latitude : 2.0 ,longitude :1.0 } \t" ) ); // TODO: Should some/all of these fail? assertEqual( pointValue( WGS84, 1.0, 2.0 ), PointValue.parse( " \t\n { latitude : 2.0 ,longitude :1.0 , } \t" ) ); assertEqual( pointValue( Cartesian, 2.0E-8, -1.0E7 ), PointValue.parse( " \t\n { x :+.2e-7,y: -1.0E07 , } \t" ) ); assertEqual( pointValue( Cartesian, 2.0E-8, -1.0E7 ), PointValue.parse( " \t\n { x :+.2e-7,y: -1.0E07 , garbage} \t" ) ); assertEqual( pointValue( Cartesian, 2.0E-8, -1.0E7 ), PointValue.parse( " \t\n { gar ba ge,x :+.2e-7,y: -1.0E07} \t" ) ); }
@Test void shouldBeAbleToParsePointWithUnquotedCrs() { assertEqual( pointValue( WGS84_3D, -74.0060, 40.7128, 567.8 ), PointValue.parse( "{latitude: 40.7128, longitude: -74.0060, height: 567.8, crs:wgs-84-3D}" ) ); // - explicitly WGS84-3D, without quotes }
@Test void shouldBeAbleToParsePoints() { assertEqual( pointValue( WGS84, 13.2, 56.7 ), PointValue.parse( "{latitude: 56.7, longitude: 13.2}" ) ); assertEqual( pointValue( WGS84, -74.0060, 40.7128 ), PointValue.parse( "{latitude: 40.7128, longitude: -74.0060, crs: 'wgs-84'}" ) ); // - explicitly WGS84 assertEqual( pointValue( Cartesian, -21, -45.3 ), PointValue.parse( "{x: -21, y: -45.3}" ) ); // - default to cartesian 2D assertEqual( pointValue( WGS84, -21, -45.3 ), PointValue.parse( "{x: -21, y: -45.3, srid: 4326}" ) ); // - explicitly set WGS84 by SRID assertEqual( pointValue( Cartesian, 17, -52.8 ), PointValue.parse( "{x: 17, y: -52.8, crs: 'cartesian'}" ) ); // - explicit cartesian 2D assertEqual( pointValue( WGS84_3D, 13.2, 56.7, 123.4 ), PointValue.parse( "{latitude: 56.7, longitude: 13.2, height: 123.4}" ) ); // - defaults to WGS84-3D assertEqual( pointValue( WGS84_3D, 13.2, 56.7, 123.4 ), PointValue.parse( "{latitude: 56.7, longitude: 13.2, z: 123.4}" ) ); // - defaults to WGS84-3D assertEqual( pointValue( WGS84_3D, -74.0060, 40.7128, 567.8 ), PointValue.parse( "{latitude: 40.7128, longitude: -74.0060, height: 567.8, crs: 'wgs-84-3D'}" ) ); // - explicitly WGS84-3D assertEqual( pointValue( Cartesian_3D, -21, -45.3, 7.2 ), PointValue.parse( "{x: -21, y: -45.3, z: 7.2}" ) ); // - default to cartesian 3D assertEqual( pointValue( Cartesian_3D, 17, -52.8, -83.1 ), PointValue.parse( "{x: 17, y: -52.8, z: -83.1, crs: 'cartesian-3D'}" ) ); // - explicit cartesian 3D }
public static PointValue parse( CharSequence text ) { return PointValue.parse( text, null ); }
@Override protected boolean extract0( char[] data, int offset, int length, CSVHeaderInformation optionalData ) { value = PointValue.parse( CharBuffer.wrap( data, offset, length ), optionalData ); return true; }