private Point makePointValid ( Point point ) { CoordinateSequence sequence = point . getCoordinateSequence ( ) ; GeometryFactory factory = point . getFactory ( ) ; CoordinateSequenceFactory csFactory = factory . getCoordinateSequenceFactory ( ) ; if ( sequence . size ( ) == 0 ) { return point ; } else if ( Double . isNaN ( sequence . getOrdinate ( 0 , 0 ) ) || Double . isNaN ( sequence . getOrdinate ( 0 , 1 ) ) ) { return factory . createPoint ( csFactory . create ( 0 , sequence . getDimension ( ) ) ) ; } else if ( sequence . size ( ) == 1 ) { return point ; } else { throw new RuntimeException ( "JTS cannot create a point from a CoordinateSequence containing several points" ) ; } }
If X or Y is null return an empty Point