idx
int64
0
41.2k
question
stringlengths
83
4.15k
target
stringlengths
5
715
5,900
public static Point createPoint ( double x , double y , double z ) throws SQLException { return GF . createPoint ( new Coordinate ( x , y , z ) ) ; }
Constructs POINT from three doubles .
5,901
public final void setAttribute ( String currentElement , StringBuilder contentBuffer ) { if ( currentElement . equalsIgnoreCase ( GPXTags . TIME ) ) { setTime ( contentBuffer ) ; } else if ( currentElement . equalsIgnoreCase ( GPXTags . MAGVAR ) ) { setMagvar ( contentBuffer ) ; } else if ( currentElement . equalsIgnoreCase ( GPXTags . GEOIDHEIGHT ) ) { setGeoidheight ( contentBuffer ) ; } else if ( currentElement . equalsIgnoreCase ( GPXTags . NAME ) ) { setName ( contentBuffer ) ; } else if ( currentElement . equalsIgnoreCase ( GPXTags . CMT ) ) { setCmt ( contentBuffer ) ; } else if ( currentElement . equalsIgnoreCase ( GPXTags . DESC ) ) { setDesc ( contentBuffer ) ; } else if ( currentElement . equalsIgnoreCase ( GPXTags . SRC ) ) { setSrc ( contentBuffer ) ; } else if ( currentElement . equalsIgnoreCase ( GPXTags . SYM ) ) { setSym ( contentBuffer ) ; } else if ( currentElement . equalsIgnoreCase ( GPXTags . TYPE ) ) { setType ( contentBuffer ) ; } else if ( currentElement . equalsIgnoreCase ( GPXTags . FIX ) ) { setFix ( contentBuffer ) ; } else if ( currentElement . equalsIgnoreCase ( GPXTags . SAT ) ) { setSat ( contentBuffer ) ; } else if ( currentElement . equalsIgnoreCase ( GPXTags . HDOP ) ) { setHdop ( contentBuffer ) ; } else if ( currentElement . equalsIgnoreCase ( GPXTags . VDOP ) ) { setVdop ( contentBuffer ) ; } else if ( currentElement . equalsIgnoreCase ( GPXTags . PDOP ) ) { setPdop ( contentBuffer ) ; } else if ( currentElement . equalsIgnoreCase ( GPXTags . AGEOFDGPSDATA ) ) { setAgeofdgpsdata ( contentBuffer ) ; } else if ( currentElement . equalsIgnoreCase ( GPXTags . DGPSID ) ) { setDgpsid ( contentBuffer ) ; } else if ( currentElement . equalsIgnoreCase ( GPXTags . EXTENSIONS ) ) { setExtensions ( ) ; } }
Set an attribute for a point . The String currentElement gives the information of which attribute have to be setted . The attribute to set is given by the StringBuilder contentBuffer .
5,902
public final void setLink ( Attributes attributes ) { ptValues [ GpxMetadata . PTLINK ] = attributes . getValue ( GPXTags . HREF ) ; }
Set a link to additional information about the point .
5,903
public final void setSat ( StringBuilder contentBuffer ) { ptValues [ GpxMetadata . PTSAT ] = Integer . parseInt ( contentBuffer . toString ( ) ) ; }
Set the number of satellites used to calculate the GPX fix for a point .
5,904
public final void setHdop ( StringBuilder contentBuffer ) { ptValues [ GpxMetadata . PTHDOP ] = Double . parseDouble ( contentBuffer . toString ( ) ) ; }
Set the horizontal dilution of precision of a point .
5,905
public final void setVdop ( StringBuilder contentBuffer ) { ptValues [ GpxMetadata . PTVDOP ] = Double . parseDouble ( contentBuffer . toString ( ) ) ; }
Set the vertical dilution of precision of a point .
5,906
public final void setPdop ( StringBuilder contentBuffer ) { ptValues [ GpxMetadata . PTPDOP ] = Double . parseDouble ( contentBuffer . toString ( ) ) ; }
Set the position dilution of precision of a point .
5,907
public final void setAgeofdgpsdata ( StringBuilder contentBuffer ) { ptValues [ GpxMetadata . PTAGEOFDGPSDATA ] = Double . parseDouble ( contentBuffer . toString ( ) ) ; }
Set number of seconds since last DGPS update for a point .
5,908
public final void setDgpsid ( StringBuilder contentBuffer ) { ptValues [ GpxMetadata . PTDGPSID ] = Integer . parseInt ( contentBuffer . toString ( ) ) ; }
Set ID of DGPS station used in differential correction for a point .
5,909
protected static Orientation parseGlobalOrientation ( String v ) { if ( v == null ) { return null ; } if ( isDirectedString ( v ) ) { return Orientation . DIRECTED ; } else if ( isReversedString ( v ) ) { return Orientation . REVERSED ; } else if ( isUndirectedString ( v ) ) { return Orientation . UNDIRECTED ; } else { throw new IllegalArgumentException ( ORIENTATION_ERROR ) ; } }
Recovers the global orientation from a string .
5,910
protected String parseEdgeOrientation ( String v ) { if ( v == null ) { return null ; } if ( ! v . contains ( SEPARATOR ) ) { throw new IllegalArgumentException ( ORIENTATION_ERROR ) ; } String [ ] s = v . split ( SEPARATOR ) ; if ( s . length == 2 ) { return s [ 1 ] . trim ( ) ; } else { throw new IllegalArgumentException ( ORIENTATION_ERROR ) ; } }
Recovers the edge orientation from a string .
5,911
public static int [ ] parseDestinationsString ( String s ) { if ( ! s . contains ( "," ) ) { return new int [ ] { Integer . valueOf ( s . trim ( ) ) } ; } String [ ] array = s . split ( "," ) ; int [ ] destinations = new int [ array . length ] ; for ( int i = 0 ; i < destinations . length ; i ++ ) { final String stringWithNoWhiteSpaces = array [ i ] . replaceAll ( "\\s" , "" ) ; if ( stringWithNoWhiteSpaces . isEmpty ( ) ) { throw new IllegalArgumentException ( "Empty destination. Too many commas?" ) ; } destinations [ i ] = Integer . valueOf ( stringWithNoWhiteSpaces ) ; } return destinations ; }
Returns an array of destination ids from a comma - separated list of destinations .
5,912
public void initialise ( XMLReader reader , AbstractGpxParserDefault parent ) { setReader ( reader ) ; setParent ( parent ) ; setContentBuffer ( parent . getContentBuffer ( ) ) ; setTrkPreparedStmt ( parent . getTrkPreparedStmt ( ) ) ; setTrkSegmentsPreparedStmt ( parent . getTrkSegmentsPreparedStmt ( ) ) ; setTrkPointsPreparedStmt ( parent . getTrkPointsPreparedStmt ( ) ) ; setElementNames ( parent . getElementNames ( ) ) ; setCurrentLine ( parent . getCurrentLine ( ) ) ; setTrksegList ( new ArrayList < Coordinate > ( ) ) ; setTrkList ( new ArrayList < LineString > ( ) ) ; }
Create a new specific parser . It has in memory the default parser the contentBuffer the elementNames the currentLine and the trkID .
5,913
public static Geometry geomFromGeoJSON ( String geojson ) throws IOException , SQLException { if ( geojson == null ) { return null ; } if ( jsFactory == null ) { jsFactory = new JsonFactory ( ) ; jsFactory . configure ( JsonParser . Feature . ALLOW_COMMENTS , true ) ; jsFactory . configure ( JsonParser . Feature . ALLOW_SINGLE_QUOTES , true ) ; jsFactory . configure ( JsonParser . Feature . ALLOW_NON_NUMERIC_NUMBERS , true ) ; reader = new GJGeometryReader ( new GeometryFactory ( ) ) ; } JsonParser jp = jsFactory . createParser ( geojson ) ; return reader . parseGeometry ( jp ) ; }
Convert a geojson geometry to geometry .
5,914
public static Double perimeter ( Geometry geometry ) { if ( geometry == null ) { return null ; } if ( geometry . getDimension ( ) < 2 ) { return 0d ; } return computePerimeter ( geometry ) ; }
Compute the perimeter of a polygon or a multipolygon .
5,915
private static double computePerimeter ( Geometry geometry ) { double sum = 0 ; for ( int i = 0 ; i < geometry . getNumGeometries ( ) ; i ++ ) { Geometry subGeom = geometry . getGeometryN ( i ) ; if ( subGeom instanceof Polygon ) { sum += ( ( Polygon ) subGeom ) . getExteriorRing ( ) . getLength ( ) ; } } return sum ; }
Compute the perimeter
5,916
public static Double getMinY ( Geometry geom ) { if ( geom != null ) { return geom . getEnvelopeInternal ( ) . getMinY ( ) ; } else { return null ; } }
Returns the minimal y - value of the given geometry .
5,917
public static Geometry simplyPreserve ( Geometry geometry , double distance ) { if ( geometry == null ) { return null ; } return TopologyPreservingSimplifier . simplify ( geometry , distance ) ; }
Simplifies a geometry and ensures that the result is a valid geometry having the same dimension and number of components as the input and with the components having the same topological relationship .
5,918
protected static KeyedGraph prepareGraph ( Connection connection , String inputTable , String orientation , String weight , Class vertexClass , Class edgeClass ) throws SQLException { GraphFunctionParser parser = new GraphFunctionParser ( ) ; parser . parseWeightAndOrientation ( orientation , weight ) ; return new GraphCreator ( connection , inputTable , parser . getGlobalOrientation ( ) , parser . getEdgeOrientation ( ) , parser . getWeightColumn ( ) , vertexClass , edgeClass ) . prepareGraph ( ) ; }
Return a JGraphT graph from the input edges table .
5,919
private Polygon getCellPolygon ( ) { final Coordinate [ ] summits = new Coordinate [ 5 ] ; double x1 = minX + cellI * deltaX ; double y1 = minY + cellJ * deltaY ; double x2 = minX + ( cellI + 1 ) * deltaX ; double y2 = minY + ( cellJ + 1 ) * deltaY ; summits [ 0 ] = new Coordinate ( x1 , y1 ) ; summits [ 1 ] = new Coordinate ( x2 , y1 ) ; summits [ 2 ] = new Coordinate ( x2 , y2 ) ; summits [ 3 ] = new Coordinate ( x1 , y2 ) ; summits [ 4 ] = new Coordinate ( x1 , y1 ) ; final LinearRing g = GF . createLinearRing ( summits ) ; final Polygon gg = GF . createPolygon ( g , null ) ; cellI ++ ; return gg ; }
Compute the polygon corresponding to the cell
5,920
private Point getCellPoint ( ) { double x1 = ( minX + cellI * deltaX ) + ( deltaX / 2d ) ; double y1 = ( minY + cellJ * deltaY ) + ( deltaY / 2d ) ; cellI ++ ; return GF . createPoint ( new Coordinate ( x1 , y1 ) ) ; }
Compute the point of the cell
5,921
private static String getFirstGeometryField ( String tableName , Connection connection ) throws SQLException { List < String > geomFields = SFSUtilities . getGeometryFields ( connection , TableLocation . parse ( tableName , JDBCUtilities . isH2DataBase ( connection . getMetaData ( ) ) ) ) ; if ( ! geomFields . isEmpty ( ) ) { return geomFields . get ( 0 ) ; } else { throw new SQLException ( "The table " + tableName + " does not contain a geometry field" ) ; } }
Return the first spatial geometry field name
5,922
private void initParameters ( ) { this . minX = envelope . getMinX ( ) ; this . minY = envelope . getMinY ( ) ; double cellWidth = envelope . getWidth ( ) ; double cellHeight = envelope . getHeight ( ) ; this . maxI = ( int ) Math . ceil ( cellWidth / deltaX ) ; this . maxJ = ( int ) Math . ceil ( cellHeight / deltaY ) ; }
Compute the parameters need to create each cells
5,923
public ResultSet getResultSet ( ) throws SQLException { SimpleResultSet srs = new SimpleResultSet ( this ) ; srs . addColumn ( "THE_GEOM" , Types . JAVA_OBJECT , "GEOMETRY" , 0 , 0 ) ; srs . addColumn ( "ID" , Types . INTEGER , 10 , 0 ) ; srs . addColumn ( "ID_COL" , Types . INTEGER , 10 , 0 ) ; srs . addColumn ( "ID_ROW" , Types . INTEGER , 10 , 0 ) ; return srs ; }
Give the regular grid
5,924
public static Double azimuth ( Geometry pointA , Geometry pointB ) { if ( pointA == null || pointB == null ) { return null ; } if ( ( pointA instanceof Point ) && ( pointB instanceof Point ) ) { Double angle ; double x0 = ( ( Point ) pointA ) . getX ( ) ; double y0 = ( ( Point ) pointA ) . getY ( ) ; double x1 = ( ( Point ) pointB ) . getX ( ) ; double y1 = ( ( Point ) pointB ) . getY ( ) ; if ( x0 == x1 ) { if ( y0 < y1 ) { angle = 0.0 ; } else if ( y0 > y1 ) { angle = Math . PI ; } else { angle = null ; } } else if ( y0 == y1 ) { if ( x0 < x1 ) { angle = Math . PI / 2 ; } else if ( x0 > x1 ) { angle = Math . PI + ( Math . PI / 2 ) ; } else { angle = null ; } } else if ( x0 < x1 ) { if ( y0 < y1 ) { angle = Math . atan ( Math . abs ( x0 - x1 ) / Math . abs ( y0 - y1 ) ) ; } else { angle = Math . atan ( Math . abs ( y0 - y1 ) / Math . abs ( x0 - x1 ) ) + ( Math . PI / 2 ) ; } } else { if ( y0 > y1 ) { angle = Math . atan ( Math . abs ( x0 - x1 ) / Math . abs ( y0 - y1 ) ) + Math . PI ; } else { angle = Math . atan ( Math . abs ( y0 - y1 ) / Math . abs ( x0 - x1 ) ) + ( Math . PI + ( Math . PI / 2 ) ) ; } } return angle ; } return null ; }
This code compute the angle in radian as postgis does .
5,925
public static Double getMaxY ( Geometry geom ) { if ( geom != null ) { return geom . getEnvelopeInternal ( ) . getMaxY ( ) ; } else { return null ; } }
Returns the maximal y - value of the given geometry .
5,926
private Point parsePoint ( JsonParser jp ) throws IOException , SQLException { jp . nextToken ( ) ; String coordinatesField = jp . getText ( ) ; if ( coordinatesField . equalsIgnoreCase ( GeoJsonField . COORDINATES ) ) { jp . nextToken ( ) ; Point point = GF . createPoint ( parseCoordinate ( jp ) ) ; jp . nextToken ( ) ; return point ; } else { throw new SQLException ( "Malformed GeoJSON file. Expected 'coordinates', found '" + coordinatesField + "'" ) ; } }
Parses one position
5,927
private MultiPoint parseMultiPoint ( JsonParser jp ) throws IOException , SQLException { jp . nextToken ( ) ; String coordinatesField = jp . getText ( ) ; if ( coordinatesField . equalsIgnoreCase ( GeoJsonField . COORDINATES ) ) { jp . nextToken ( ) ; MultiPoint mPoint = GF . createMultiPoint ( parseCoordinates ( jp ) ) ; jp . nextToken ( ) ; return mPoint ; } else { throw new SQLException ( "Malformed GeoJSON file. Expected 'coordinates', found '" + coordinatesField + "'" ) ; } }
Parses an array of positions
5,928
private Coordinate parseCoordinate ( JsonParser jp ) throws IOException { jp . nextToken ( ) ; double x = jp . getDoubleValue ( ) ; jp . nextToken ( ) ; double y = jp . getDoubleValue ( ) ; Coordinate coord ; jp . nextToken ( ) ; if ( jp . getCurrentToken ( ) == JsonToken . END_ARRAY ) { coord = new Coordinate ( x , y ) ; } else { double z = jp . getDoubleValue ( ) ; jp . nextToken ( ) ; coord = new Coordinate ( x , y , z ) ; } jp . nextToken ( ) ; return coord ; }
Parses a GeoJSON coordinate array and returns a JTS coordinate . The first token corresponds to the first X value . The last token correponds to the end of the coordinate array ] .
5,929
public static MultiLineString createMultiLineString ( Geometry geom ) throws SQLException { if ( geom != null ) { if ( geom . getDimension ( ) > 0 ) { final List < LineString > lineStrings = new LinkedList < LineString > ( ) ; toMultiLineString ( geom , lineStrings ) ; return GEOMETRY_FACTORY . createMultiLineString ( lineStrings . toArray ( new LineString [ 0 ] ) ) ; } else { return GEOMETRY_FACTORY . createMultiLineString ( null ) ; } } else { return null ; } }
Constructs a MultiLineString from the given geometry s coordinates .
5,930
public static void readTSV ( Connection connection , String fileName , String tableReference ) throws SQLException , FileNotFoundException , IOException { File file = URIUtilities . fileFromString ( fileName ) ; if ( FileUtil . isFileImportable ( file , "tsv" ) ) { TSVDriverFunction tsvDriver = new TSVDriverFunction ( ) ; tsvDriver . importFile ( connection , tableReference , file , new EmptyProgressVisitor ( ) ) ; } }
Copy data from TSV File into a new table in specified connection .
5,931
public static Geometry translate ( Geometry geom , double x , double y ) { if ( geom == null ) { return null ; } final CoordinateSequenceDimensionFilter filter = new CoordinateSequenceDimensionFilter ( ) ; geom . apply ( filter ) ; checkMixed ( filter ) ; return AffineTransformation . translationInstance ( x , y ) . transform ( geom ) ; }
Translates a geometry using X and Y offsets .
5,932
public static Geometry translate ( Geometry geom , double x , double y , double z ) { if ( geom == null ) { return null ; } final CoordinateSequenceDimensionFilter filter = new CoordinateSequenceDimensionFilter ( ) ; geom . apply ( filter ) ; checkMixed ( filter ) ; if ( filter . is2D ( ) ) { return AffineTransformation . translationInstance ( x , y ) . transform ( geom ) ; } else { final Geometry clone = geom . copy ( ) ; clone . apply ( new ZAffineTransformation ( x , y , z ) ) ; return clone ; } }
Translates a geometry using X Y and Z offsets .
5,933
public static Geometry toGeometry ( byte [ ] bytes , int srid ) throws SQLException { if ( bytes == null ) { return null ; } WKBReader wkbReader = new WKBReader ( ) ; try { Geometry geometry = wkbReader . read ( bytes ) ; geometry . setSRID ( srid ) ; return geometry ; } catch ( ParseException ex ) { throw new SQLException ( "Cannot parse the input bytes" , ex ) ; } }
Convert a WKB representation to a geometry
5,934
public static Double maxDistance ( Geometry geomA , Geometry geomB ) { return new MaxDistanceOp ( geomA , geomB ) . getDistance ( ) ; }
Return the maximum distance
5,935
public void characters ( char [ ] ch , int start , int length ) throws SAXException { contentBuffer . append ( String . copyValueOf ( ch , start , length ) ) ; }
Fires one or more times for each text node encountered . It saves text informations in contentBuffer .
5,936
public static String quoteIdentifier ( String identifier , boolean isH2DataBase ) { if ( ( isH2DataBase && ( Constants . H2_RESERVED_WORDS . contains ( identifier . toUpperCase ( ) ) || ! H2_SPECIAL_NAME_PATTERN . matcher ( identifier ) . find ( ) ) ) || ( ! isH2DataBase && ( Constants . POSTGIS_RESERVED_WORDS . contains ( identifier . toUpperCase ( ) ) || ! POSTGRE_SPECIAL_NAME_PATTERN . matcher ( identifier ) . find ( ) ) ) ) { return quoteIdentifier ( identifier ) ; } else { return identifier ; } }
Quote identifier only if necessary . Require database knowledge .
5,937
public static TableLocation parse ( String concatenatedTableLocation , Boolean isH2Database ) { List < String > parts = new LinkedList < String > ( ) ; String catalog , schema , table ; catalog = table = schema = "" ; StringTokenizer st = new StringTokenizer ( concatenatedTableLocation , ".`\"" , true ) ; boolean openQuote = false ; StringBuilder sb = new StringBuilder ( ) ; while ( st . hasMoreTokens ( ) ) { String token = st . nextToken ( ) ; if ( token . equals ( "`" ) || token . equals ( "\"" ) ) { openQuote = ! openQuote ; } else if ( token . equals ( "." ) ) { if ( openQuote ) { sb . append ( token ) ; } else { parts . add ( sb . toString ( ) ) ; sb = new StringBuilder ( ) ; } } else { if ( ! openQuote && isH2Database != null ) { token = capsIdentifier ( token , isH2Database ) ; } sb . append ( token ) ; } } if ( sb . length ( ) != 0 ) { parts . add ( sb . toString ( ) ) ; } String [ ] values = parts . toArray ( new String [ 0 ] ) ; switch ( values . length ) { case 1 : table = values [ 0 ] . trim ( ) ; break ; case 2 : schema = values [ 0 ] . trim ( ) ; table = values [ 1 ] . trim ( ) ; break ; case 3 : catalog = values [ 0 ] . trim ( ) ; schema = values [ 1 ] . trim ( ) ; table = values [ 2 ] . trim ( ) ; } return new TableLocation ( catalog , schema , table ) ; }
Convert catalog . schema . table schema . table or table into a TableLocation instance . Non - specified schema or catalogs are converted to the empty string .
5,938
public static String capsIdentifier ( String identifier , Boolean isH2Database ) { if ( isH2Database != null ) { if ( isH2Database ) { return identifier . toUpperCase ( ) ; } else { return identifier . toLowerCase ( ) ; } } else { return identifier ; } }
Change case of parameters to make it more user - friendly .
5,939
private static void decompose ( Geometry geometry , Collection < Geometry > list ) { for ( int i = 0 ; i < geometry . getNumGeometries ( ) ; i ++ ) { Geometry component = geometry . getGeometryN ( i ) ; if ( component instanceof GeometryCollection ) { decompose ( component , list ) ; } else { list . add ( component ) ; } } }
Decompose a geometry recursively into simple components .
5,940
private void removeLowerDimension ( Geometry geometry , List < Geometry > result , int dimension ) { for ( int i = 0 ; i < geometry . getNumGeometries ( ) ; i ++ ) { Geometry g = geometry . getGeometryN ( i ) ; if ( g instanceof GeometryCollection ) { removeLowerDimension ( g , result , dimension ) ; } else if ( g . getDimension ( ) >= dimension ) { result . add ( g ) ; } } }
Reursively remove geometries with a dimension less than dimension parameter
5,941
private Collection < Geometry > unionAdjacentPolygons ( Collection < Geometry > list ) { UnaryUnionOp op = new UnaryUnionOp ( list ) ; Geometry result = op . union ( ) ; if ( result . getNumGeometries ( ) < list . size ( ) ) { list . clear ( ) ; for ( int i = 0 ; i < result . getNumGeometries ( ) ; i ++ ) { list . add ( result . getGeometryN ( i ) ) ; } } return list ; }
Union adjacent polygons to make an invalid MultiPolygon valid
5,942
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
5,943
private static CoordinateSequence makeSequenceValid ( CoordinateSequence sequence , boolean preserveDuplicateCoord , boolean close ) { int dim = sequence . getDimension ( ) ; double [ ] array = new double [ ( sequence . size ( ) + 1 ) * sequence . getDimension ( ) ] ; boolean modified = false ; int count = 0 ; for ( int i = 0 ; i < sequence . size ( ) ; i ++ ) { if ( Double . isNaN ( sequence . getOrdinate ( i , 0 ) ) || Double . isNaN ( sequence . getOrdinate ( i , 1 ) ) ) { modified = true ; continue ; } if ( ! preserveDuplicateCoord && count > 0 && sequence . getCoordinate ( i ) . equals ( sequence . getCoordinate ( i - 1 ) ) ) { modified = true ; continue ; } for ( int j = 0 ; j < dim ; j ++ ) { array [ count * dim + j ] = sequence . getOrdinate ( i , j ) ; if ( j == dim - 1 ) { count ++ ; } } } if ( close && count > 2 && ( array [ 0 ] != array [ ( count - 1 ) * dim ] || array [ 1 ] != array [ ( count - 1 ) * dim + 1 ] ) ) { System . arraycopy ( array , 0 , array , count * dim , dim ) ; modified = true ; count ++ ; } if ( close && count > 3 && dim > 2 ) { for ( int d = 2 ; d < dim ; d ++ ) { if ( array [ ( count - 1 ) * dim + d ] != array [ d ] ) { modified = true ; } array [ ( count - 1 ) * dim + d ] = array [ d ] ; } } if ( modified ) { double [ ] shrinkedArray = new double [ count * dim ] ; System . arraycopy ( array , 0 , shrinkedArray , 0 , count * dim ) ; return PackedCoordinateSequenceFactory . DOUBLE_FACTORY . create ( shrinkedArray , dim ) ; } else { return sequence ; } }
Returns a coordinateSequence free of Coordinates with X or Y NaN value and if desired free of duplicated coordinates . makeSequenceValid keeps the original dimension of input sequence .
5,944
private Set < LineString > getSegments ( Collection < LineString > lines ) { Set < LineString > set = new HashSet < > ( ) ; for ( LineString line : lines ) { Coordinate [ ] cc = line . getCoordinates ( ) ; for ( int i = 1 ; i < cc . length ; i ++ ) { if ( ! cc [ i - 1 ] . equals ( cc [ i ] ) ) { LineString segment = line . getFactory ( ) . createLineString ( new Coordinate [ ] { new Coordinate ( cc [ i - 1 ] ) , new Coordinate ( cc [ i ] ) } ) ; set . add ( segment ) ; } } } return set ; }
Return a set of segments from a linestring
5,945
private Collection < Geometry > restoreDim4 ( Collection < Geometry > geoms , Map < Coordinate , Double > map ) { GeometryFactory factory = new GeometryFactory ( new PackedCoordinateSequenceFactory ( PackedCoordinateSequenceFactory . DOUBLE , 4 ) ) ; Collection < Geometry > result = new ArrayList < > ( ) ; for ( Geometry geom : geoms ) { if ( geom instanceof Point ) { result . add ( factory . createPoint ( restoreDim4 ( ( ( Point ) geom ) . getCoordinateSequence ( ) , map ) ) ) ; } else if ( geom instanceof LineString ) { result . add ( factory . createLineString ( restoreDim4 ( ( ( LineString ) geom ) . getCoordinateSequence ( ) , map ) ) ) ; } else if ( geom instanceof Polygon ) { LinearRing outer = factory . createLinearRing ( restoreDim4 ( ( ( Polygon ) geom ) . getExteriorRing ( ) . getCoordinateSequence ( ) , map ) ) ; LinearRing [ ] inner = new LinearRing [ ( ( Polygon ) geom ) . getNumInteriorRing ( ) ] ; for ( int i = 0 ; i < ( ( Polygon ) geom ) . getNumInteriorRing ( ) ; i ++ ) { inner [ i ] = factory . createLinearRing ( restoreDim4 ( ( ( Polygon ) geom ) . getInteriorRingN ( i ) . getCoordinateSequence ( ) , map ) ) ; } result . add ( factory . createPolygon ( outer , inner ) ) ; } else { for ( int i = 0 ; i < geom . getNumGeometries ( ) ; i ++ ) { result . addAll ( restoreDim4 ( Collections . singleton ( geom . getGeometryN ( i ) ) , map ) ) ; } } } return result ; }
Use ring to restore M values on geoms
5,946
private CoordinateSequence restoreDim4 ( CoordinateSequence cs , Map < Coordinate , Double > map ) { CoordinateSequence seq = new PackedCoordinateSequenceFactory ( DOUBLE , 4 ) . create ( cs . size ( ) , 4 ) ; for ( int i = 0 ; i < cs . size ( ) ; i ++ ) { seq . setOrdinate ( i , 0 , cs . getOrdinate ( i , 0 ) ) ; seq . setOrdinate ( i , 1 , cs . getOrdinate ( i , 1 ) ) ; seq . setOrdinate ( i , 2 , cs . getOrdinate ( i , 2 ) ) ; Double d = map . get ( cs . getCoordinate ( i ) ) ; seq . setOrdinate ( i , 3 , d == null ? Double . NaN : d ) ; } return seq ; }
Use map to restore M values on the coordinate array
5,947
public static PreparedStatement createTrackTable ( Connection connection , String trackTableName , boolean isH2 ) throws SQLException { try ( Statement stmt = connection . createStatement ( ) ) { StringBuilder sb = new StringBuilder ( "CREATE TABLE " ) ; sb . append ( trackTableName ) . append ( " (" ) ; if ( isH2 ) { sb . append ( "the_geom MULTILINESTRING CHECK ST_SRID(THE_GEOM) = 4326," ) ; } else { sb . append ( "the_geom GEOMETRY(MULTILINESTRING, 4326)," ) ; } sb . append ( " id INT," ) ; sb . append ( GPXTags . NAME . toLowerCase ( ) ) . append ( " TEXT," ) ; sb . append ( GPXTags . CMT . toLowerCase ( ) ) . append ( " TEXT," ) ; sb . append ( "description" ) . append ( " TEXT," ) ; sb . append ( GPXTags . SRC . toLowerCase ( ) ) . append ( " TEXT," ) ; sb . append ( GPXTags . HREF . toLowerCase ( ) ) . append ( " TEXT," ) ; sb . append ( GPXTags . HREFTITLE . toLowerCase ( ) ) . append ( " TEXT," ) ; sb . append ( GPXTags . NUMBER . toLowerCase ( ) ) . append ( " INT," ) ; sb . append ( GPXTags . TYPE . toLowerCase ( ) ) . append ( " TEXT," ) ; sb . append ( GPXTags . EXTENSIONS . toLowerCase ( ) ) . append ( " TEXT);" ) ; stmt . execute ( sb . toString ( ) ) ; } StringBuilder insert = new StringBuilder ( "INSERT INTO " ) . append ( trackTableName ) . append ( " VALUES ( ?" ) ; for ( int i = 1 ; i < GpxMetadata . RTEFIELDCOUNT ; i ++ ) { insert . append ( ",?" ) ; } insert . append ( ");" ) ; return connection . prepareStatement ( insert . toString ( ) ) ; }
Creat the track table
5,948
public static PreparedStatement createTrackSegmentsTable ( Connection connection , String trackSegementsTableName , boolean isH2 ) throws SQLException { try ( Statement stmt = connection . createStatement ( ) ) { StringBuilder sb = new StringBuilder ( "CREATE TABLE " ) ; sb . append ( trackSegementsTableName ) . append ( " (" ) ; if ( isH2 ) { sb . append ( "the_geom LINESTRING CHECK ST_SRID(THE_GEOM) = 4326," ) ; } else { sb . append ( "the_geom GEOMETRY(LINESTRING, 4326)," ) ; } sb . append ( " id INT," ) ; sb . append ( GPXTags . EXTENSIONS ) . append ( " TEXT," ) ; sb . append ( "id_track INT);" ) ; stmt . execute ( sb . toString ( ) ) ; } StringBuilder insert = new StringBuilder ( "INSERT INTO " ) . append ( trackSegementsTableName ) . append ( " VALUES ( ?" ) ; for ( int i = 1 ; i < GpxMetadata . TRKSEGFIELDCOUNT ; i ++ ) { insert . append ( ",?" ) ; } insert . append ( ");" ) ; return connection . prepareStatement ( insert . toString ( ) ) ; }
Create the track segments table to store the segments of a track
5,949
public static void dropOSMTables ( Connection connection , boolean isH2 , String tablePrefix ) throws SQLException { TableLocation requestedTable = TableLocation . parse ( tablePrefix , isH2 ) ; String gpxTableName = requestedTable . getTable ( ) ; String [ ] gpxTables = new String [ ] { WAYPOINT , ROUTE , ROUTEPOINT , TRACK , TRACKPOINT , TRACKSEGMENT } ; StringBuilder sb = new StringBuilder ( "drop table if exists " ) ; String gpxTableSuffix = gpxTables [ 0 ] ; String gpxTable = TableUtilities . caseIdentifier ( requestedTable , gpxTableName + gpxTableSuffix , isH2 ) ; sb . append ( gpxTable ) ; for ( int i = 1 ; i < gpxTables . length ; i ++ ) { gpxTableSuffix = gpxTables [ i ] ; gpxTable = TableUtilities . caseIdentifier ( requestedTable , gpxTableName + gpxTableSuffix , isH2 ) ; sb . append ( "," ) . append ( gpxTable ) ; } try ( Statement stmt = connection . createStatement ( ) ) { stmt . execute ( sb . toString ( ) ) ; } }
Drop the existing GPX tables used to store the imported OSM GPX
5,950
public static void append ( int altitudeMode , StringBuilder sb ) { switch ( altitudeMode ) { case KML_CLAMPTOGROUND : sb . append ( "<kml:altitudeMode>clampToGround</kml:altitudeMode>" ) ; return ; case KML_RELATIVETOGROUND : sb . append ( "<kml:altitudeMode>relativeToGround</kml:altitudeMode>" ) ; return ; case KML_ABSOLUTE : sb . append ( "<kml:altitudeMode>absolute</kml:altitudeMode>" ) ; return ; case GX_CLAMPTOSEAFLOOR : sb . append ( "<gx:altitudeMode>clampToSeaFloor</gx:altitudeMode>" ) ; return ; case GX_RELATIVETOSEAFLOOR : sb . append ( "<gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode>" ) ; return ; case NONE : return ; default : throw new IllegalArgumentException ( "Supported altitude modes are: \n" + " For KML profils: CLAMPTOGROUND = 1; RELATIVETOGROUND = 2; ABSOLUTE = 4;\n" + "For GX profils: CLAMPTOSEAFLOOR = 8; RELATIVETOSEAFLOOR = 16; \n" + " No altitude: NONE = 0" ) ; } }
Generate a string value corresponding to the altitude mode .
5,951
public static GeometryCollection extrudePolygonAsGeometry ( Polygon polygon , double height ) { GeometryFactory factory = polygon . getFactory ( ) ; Geometry [ ] geometries = new Geometry [ 3 ] ; final LineString shell = getClockWise ( polygon . getExteriorRing ( ) ) ; ArrayList < Polygon > walls = new ArrayList < Polygon > ( ) ; for ( int i = 1 ; i < shell . getNumPoints ( ) ; i ++ ) { walls . add ( extrudeEdge ( shell . getCoordinateN ( i - 1 ) , shell . getCoordinateN ( i ) , height , factory ) ) ; } final int nbOfHoles = polygon . getNumInteriorRing ( ) ; final LinearRing [ ] holes = new LinearRing [ nbOfHoles ] ; for ( int i = 0 ; i < nbOfHoles ; i ++ ) { final LineString hole = getCounterClockWise ( polygon . getInteriorRingN ( i ) ) ; for ( int j = 1 ; j < hole . getNumPoints ( ) ; j ++ ) { walls . add ( extrudeEdge ( hole . getCoordinateN ( j - 1 ) , hole . getCoordinateN ( j ) , height , factory ) ) ; } holes [ i ] = factory . createLinearRing ( hole . getCoordinateSequence ( ) ) ; } geometries [ 0 ] = factory . createPolygon ( factory . createLinearRing ( shell . getCoordinateSequence ( ) ) , holes ) ; geometries [ 1 ] = factory . createMultiPolygon ( walls . toArray ( new Polygon [ 0 ] ) ) ; geometries [ 2 ] = extractRoof ( polygon , height ) ; return polygon . getFactory ( ) . createGeometryCollection ( geometries ) ; }
Extrude the polygon as a collection of geometries The output geometryCollection contains the floor the walls and the roof .
5,952
public static GeometryCollection extrudeLineStringAsGeometry ( LineString lineString , double height ) { Geometry [ ] geometries = new Geometry [ 3 ] ; GeometryFactory factory = lineString . getFactory ( ) ; Coordinate [ ] coords = lineString . getCoordinates ( ) ; Polygon [ ] walls = new Polygon [ coords . length - 1 ] ; for ( int i = 0 ; i < coords . length - 1 ; i ++ ) { walls [ i ] = extrudeEdge ( coords [ i ] , coords [ i + 1 ] , height , factory ) ; } lineString . apply ( new TranslateCoordinateSequenceFilter ( 0 ) ) ; geometries [ 0 ] = lineString ; geometries [ 1 ] = factory . createMultiPolygon ( walls ) ; geometries [ 2 ] = extractRoof ( lineString , height ) ; return factory . createGeometryCollection ( geometries ) ; }
Extrude the linestring as a collection of geometries The output geometryCollection contains the floor the walls and the roof .
5,953
public static Geometry extractRoof ( LineString lineString , double height ) { LineString result = ( LineString ) lineString . copy ( ) ; result . apply ( new TranslateCoordinateSequenceFilter ( height ) ) ; return result ; }
Extract the linestring roof .
5,954
public static MultiPolygon extractWalls ( Polygon polygon , double height ) { GeometryFactory factory = polygon . getFactory ( ) ; final LineString shell = getClockWise ( polygon . getExteriorRing ( ) ) ; ArrayList < Polygon > walls = new ArrayList < Polygon > ( ) ; for ( int i = 1 ; i < shell . getNumPoints ( ) ; i ++ ) { walls . add ( extrudeEdge ( shell . getCoordinateN ( i - 1 ) , shell . getCoordinateN ( i ) , height , factory ) ) ; } int nbOfHoles = polygon . getNumInteriorRing ( ) ; for ( int i = 0 ; i < nbOfHoles ; i ++ ) { final LineString hole = getCounterClockWise ( polygon . getInteriorRingN ( i ) ) ; for ( int j = 1 ; j < hole . getNumPoints ( ) ; j ++ ) { walls . add ( extrudeEdge ( hole . getCoordinateN ( j - 1 ) , hole . getCoordinateN ( j ) , height , factory ) ) ; } } return polygon . getFactory ( ) . createMultiPolygon ( walls . toArray ( new Polygon [ 0 ] ) ) ; }
Extract the walls from a polygon
5,955
public static Polygon extractRoof ( Polygon polygon , double height ) { GeometryFactory factory = polygon . getFactory ( ) ; Polygon roofP = ( Polygon ) polygon . copy ( ) ; roofP . apply ( new TranslateCoordinateSequenceFilter ( height ) ) ; final LinearRing shell = factory . createLinearRing ( getCounterClockWise ( roofP . getExteriorRing ( ) ) . getCoordinates ( ) ) ; final int nbOfHoles = roofP . getNumInteriorRing ( ) ; final LinearRing [ ] holes = new LinearRing [ nbOfHoles ] ; for ( int i = 0 ; i < nbOfHoles ; i ++ ) { holes [ i ] = factory . createLinearRing ( getClockWise ( roofP . getInteriorRingN ( i ) ) . getCoordinates ( ) ) ; } return factory . createPolygon ( shell , holes ) ; }
Extract the roof of a polygon
5,956
public static MultiPolygon extractWalls ( LineString lineString , double height ) { GeometryFactory factory = lineString . getFactory ( ) ; Coordinate [ ] coords = lineString . getCoordinates ( ) ; Polygon [ ] walls = new Polygon [ coords . length - 1 ] ; for ( int i = 0 ; i < coords . length - 1 ; i ++ ) { walls [ i ] = extrudeEdge ( coords [ i ] , coords [ i + 1 ] , height , factory ) ; } return lineString . getFactory ( ) . createMultiPolygon ( walls ) ; }
Extrude the LineString as a set of walls .
5,957
private static LineString getClockWise ( final LineString lineString ) { final Coordinate c0 = lineString . getCoordinateN ( 0 ) ; final Coordinate c1 = lineString . getCoordinateN ( 1 ) ; final Coordinate c2 = lineString . getCoordinateN ( 2 ) ; lineString . apply ( new UpdateZCoordinateSequenceFilter ( 0 , 3 ) ) ; if ( CGAlgorithms . computeOrientation ( c0 , c1 , c2 ) == CGAlgorithms . CLOCKWISE ) { return lineString ; } else { return ( LineString ) lineString . reverse ( ) ; } }
Reverse the LineString to be oriented clockwise . All NaN z values are replaced by a zero value .
5,958
private static LineString getCounterClockWise ( final LineString lineString ) { final Coordinate c0 = lineString . getCoordinateN ( 0 ) ; final Coordinate c1 = lineString . getCoordinateN ( 1 ) ; final Coordinate c2 = lineString . getCoordinateN ( 2 ) ; lineString . apply ( new UpdateZCoordinateSequenceFilter ( 0 , 3 ) ) ; if ( CGAlgorithms . computeOrientation ( c0 , c1 , c2 ) == CGAlgorithms . COUNTERCLOCKWISE ) { return lineString ; } else { return ( LineString ) lineString . reverse ( ) ; } }
Reverse the LineString to be oriented counter - clockwise .
5,959
private static Polygon extractFloor ( final Polygon polygon ) { GeometryFactory factory = polygon . getFactory ( ) ; final LinearRing shell = factory . createLinearRing ( getClockWise ( polygon . getExteriorRing ( ) ) . getCoordinates ( ) ) ; final int nbOfHoles = polygon . getNumInteriorRing ( ) ; final LinearRing [ ] holes = new LinearRing [ nbOfHoles ] ; for ( int i = 0 ; i < nbOfHoles ; i ++ ) { holes [ i ] = factory . createLinearRing ( getCounterClockWise ( polygon . getInteriorRingN ( i ) ) . getCoordinates ( ) ) ; } return factory . createPolygon ( shell , holes ) ; }
Reverse the polygon to be oriented clockwise
5,960
private static Polygon extrudeEdge ( final Coordinate beginPoint , Coordinate endPoint , final double height , GeometryFactory factory ) { beginPoint . z = Double . isNaN ( beginPoint . z ) ? 0 : beginPoint . z ; endPoint . z = Double . isNaN ( endPoint . z ) ? 0 : endPoint . z ; return factory . createPolygon ( new Coordinate [ ] { beginPoint , new Coordinate ( beginPoint . x , beginPoint . y , beginPoint . z + height ) , new Coordinate ( endPoint . x , endPoint . y , endPoint . z + height ) , endPoint , beginPoint } ) ; }
Create a polygon corresponding to the wall .
5,961
public static String fetchConstraint ( Connection connection , String catalogName , String schemaName , String tableName ) throws SQLException { PreparedStatement pst = SFSUtilities . prepareInformationSchemaStatement ( connection , catalogName , schemaName , tableName , "INFORMATION_SCHEMA.CONSTRAINTS" , "" , "TABLE_CATALOG" , "TABLE_SCHEMA" , "TABLE_NAME" ) ; try ( ResultSet rsConstraint = pst . executeQuery ( ) ) { StringBuilder constraint = new StringBuilder ( ) ; while ( rsConstraint . next ( ) ) { String tableConstr = rsConstraint . getString ( "CHECK_EXPRESSION" ) ; if ( tableConstr != null ) { constraint . append ( tableConstr ) ; } } return constraint . toString ( ) ; } finally { pst . close ( ) ; } }
Read table constraints from database metadata .
5,962
public static Properties parse ( String jdbcUrl ) throws IllegalArgumentException { if ( ! jdbcUrl . startsWith ( URL_STARTS ) ) { throw new IllegalArgumentException ( "JDBC Url must start with " + URL_STARTS ) ; } String driverAndURI = jdbcUrl . substring ( URL_STARTS . length ( ) ) ; Properties properties = new Properties ( ) ; URI uri = URI . create ( driverAndURI . substring ( driverAndURI . indexOf ( ':' ) + 1 ) ) ; if ( uri . getHost ( ) != null ) { properties . setProperty ( DataSourceFactory . JDBC_SERVER_NAME , uri . getHost ( ) ) ; } String path = uri . getPath ( ) ; if ( path != null ) { String [ ] paths = path . split ( ";" ) ; if ( uri . getHost ( ) != null && paths [ 0 ] . startsWith ( "/" ) ) { paths [ 0 ] = paths [ 0 ] . substring ( 1 ) ; } properties . setProperty ( DataSourceFactory . JDBC_DATABASE_NAME , paths [ 0 ] ) ; for ( int id = 1 ; id < paths . length ; id ++ ) { String [ ] option = paths [ id ] . split ( "=" ) ; if ( option . length == 2 ) { properties . setProperty ( option [ 0 ] , option [ 1 ] ) ; } } } String query = uri . getQuery ( ) ; if ( query != null ) { try { for ( Map . Entry < String , String > entry : URIUtilities . getQueryKeyValuePairs ( uri ) . entrySet ( ) ) { properties . setProperty ( entry . getKey ( ) , entry . getValue ( ) ) ; } } catch ( UnsupportedEncodingException ex ) { throw new IllegalArgumentException ( "JDBC Url encoding error" , ex ) ; } } if ( uri . getPort ( ) != - 1 ) { properties . setProperty ( DataSourceFactory . JDBC_PORT_NUMBER , String . valueOf ( uri . getPort ( ) ) ) ; } if ( uri . getScheme ( ) != null && ! "file" . equalsIgnoreCase ( uri . getScheme ( ) ) ) { properties . setProperty ( DataSourceFactory . JDBC_NETWORK_PROTOCOL , uri . getScheme ( ) ) ; } return properties ; }
Convert JDBC URL into JDBC Connection properties
5,963
public static Geometry updateZExtremities ( Geometry geometry , double startZ , double endZ , boolean interpolate ) { if ( geometry == null ) { return null ; } if ( geometry instanceof LineString ) { return force3DStartEnd ( ( LineString ) geometry , startZ , endZ , interpolate ) ; } else if ( geometry instanceof MultiLineString ) { int nbGeom = geometry . getNumGeometries ( ) ; LineString [ ] lines = new LineString [ nbGeom ] ; for ( int i = 0 ; i < nbGeom ; i ++ ) { LineString subGeom = ( LineString ) geometry . getGeometryN ( i ) ; lines [ i ] = ( LineString ) force3DStartEnd ( subGeom , startZ , endZ , interpolate ) ; } return FACTORY . createMultiLineString ( lines ) ; } else { return null ; } }
Update the start and end Z values . If the interpolate is true the vertices are interpolated according the start and end z values .
5,964
private static Geometry force3DStartEnd ( LineString lineString , final double startZ , final double endZ , final boolean interpolate ) { final double bigD = lineString . getLength ( ) ; final double z = endZ - startZ ; final Coordinate coordEnd = lineString . getCoordinates ( ) [ lineString . getCoordinates ( ) . length - 1 ] ; lineString . apply ( new CoordinateSequenceFilter ( ) { boolean done = false ; public boolean isGeometryChanged ( ) { return true ; } public boolean isDone ( ) { return done ; } public void filter ( CoordinateSequence seq , int i ) { double x = seq . getX ( i ) ; double y = seq . getY ( i ) ; if ( i == 0 ) { seq . setOrdinate ( i , 0 , x ) ; seq . setOrdinate ( i , 1 , y ) ; seq . setOrdinate ( i , 2 , startZ ) ; } else if ( i == seq . size ( ) - 1 ) { seq . setOrdinate ( i , 0 , x ) ; seq . setOrdinate ( i , 1 , y ) ; seq . setOrdinate ( i , 2 , endZ ) ; } else { if ( interpolate ) { double smallD = seq . getCoordinate ( i ) . distance ( coordEnd ) ; double factor = smallD / bigD ; seq . setOrdinate ( i , 0 , x ) ; seq . setOrdinate ( i , 1 , y ) ; seq . setOrdinate ( i , 2 , startZ + ( factor * z ) ) ; } } if ( i == seq . size ( ) ) { done = true ; } } } ) ; return lineString ; }
Updates all z values by a new value using the specified first and the last coordinates .
5,965
public boolean push ( String newText ) { if ( stackTop < stack . length - 1 ) { stack [ stackTop ++ ] = newText ; return true ; } else { return false ; } }
Puts string in the stack .
5,966
private int getWindowOffset ( long bytePos , int length ) throws IOException { long desiredMax = bytePos + length - 1 ; if ( ( bytePos >= windowStart ) && ( desiredMax < windowStart + buffer . capacity ( ) ) ) { long res = bytePos - windowStart ; if ( res < Integer . MAX_VALUE ) { return ( int ) res ; } else { throw new IOException ( "This buffer is quite large..." ) ; } } else { long bufferCapacity = Math . max ( bufferSize , length ) ; long size = channel . size ( ) ; bufferCapacity = Math . min ( bufferCapacity , size - bytePos ) ; if ( bufferCapacity > Integer . MAX_VALUE ) { throw new IOException ( "Woaw ! You want to have a REALLY LARGE buffer !" ) ; } windowStart = bytePos ; channel . position ( windowStart ) ; if ( buffer . capacity ( ) != bufferCapacity ) { ByteOrder order = buffer . order ( ) ; buffer = ByteBuffer . allocate ( ( int ) bufferCapacity ) ; buffer . order ( order ) ; } else { buffer . clear ( ) ; } channel . read ( buffer ) ; buffer . flip ( ) ; return ( int ) ( bytePos - windowStart ) ; } }
Moves the window if necessary to contain the desired byte and returns the position of the byte in the window
5,967
private static long getJulianCycle ( double J , double lw ) { return Math . round ( J - J2000 - J0 - lw / ( 2 * Math . PI ) ) ; }
general sun calculations
5,968
private static double getApproxTransit ( double Ht , double lw , double n ) { return J2000 + J0 + ( Ht + lw ) / ( 2 * Math . PI ) + n ; }
calculations for sun times
5,969
private static double getRightAscension ( double Ls ) { return Math . atan2 ( Math . sin ( Ls ) * Math . cos ( e ) , Math . cos ( Ls ) ) ; }
calculations for sun position
5,970
public static Coordinate getPosition ( Date date , double lat , double lng ) { if ( isGeographic ( lat , lng ) ) { double lw = rad * - lng ; double phi = rad * lat ; double J = dateToJulianDate ( date ) ; double M = getSolarMeanAnomaly ( J ) ; double C = getEquationOfCenter ( M ) ; double Ls = getEclipticLongitude ( M , C ) ; double d = getSunDeclination ( Ls ) ; double a = getRightAscension ( Ls ) ; double th = getSiderealTime ( J , lw ) ; double H = th - a ; return new Coordinate ( getAzimuth ( H , phi , d ) , getAltitude ( H , phi , d ) ) ; } else { throw new IllegalArgumentException ( "The coordinate of the point must in latitude and longitude." ) ; } }
Returns the sun position as a coordinate with the following properties
5,971
public int getContentLength ( int index ) throws IOException { int ret = - 1 ; if ( this . lastIndex != index ) { this . readRecord ( index ) ; } ret = this . recLen ; return ret ; }
Get the content length of the given record in bytes not 16 bit words .
5,972
public static Geometry reverse ( Geometry geometry ) { if ( geometry == null ) { return null ; } if ( geometry instanceof MultiPoint ) { return reverseMultiPoint ( ( MultiPoint ) geometry ) ; } return geometry . reverse ( ) ; }
Returns the geometry with vertex order reversed .
5,973
public static Geometry reverseMultiPoint ( MultiPoint mp ) { int nPoints = mp . getNumGeometries ( ) ; Point [ ] revPoints = new Point [ nPoints ] ; for ( int i = 0 ; i < nPoints ; i ++ ) { revPoints [ nPoints - 1 - i ] = ( Point ) mp . getGeometryN ( i ) . reverse ( ) ; } return mp . getFactory ( ) . createMultiPoint ( revPoints ) ; }
Returns the MultiPoint with vertex order reversed . We do our own implementation here because JTS does not handle it .
5,974
public static Polygon makeEnvelope ( double xmin , double ymin , double xmax , double ymax ) { Coordinate [ ] coordinates = new Coordinate [ ] { new Coordinate ( xmin , ymin ) , new Coordinate ( xmax , ymin ) , new Coordinate ( xmax , ymax ) , new Coordinate ( xmin , ymax ) , new Coordinate ( xmin , ymin ) } ; return GF . createPolygon ( GF . createLinearRing ( coordinates ) , null ) ; }
Creates a rectangular Polygon formed from the minima and maxima by the given shell .
5,975
public static Polygon makeEnvelope ( double xmin , double ymin , double xmax , double ymax , int srid ) { Polygon geom = makeEnvelope ( xmin , ymin , xmax , ymax ) ; geom . setSRID ( srid ) ; return geom ; }
Creates a rectangular Polygon formed from the minima and maxima by the given shell . The user can set a srid .
5,976
public static Geometry simplify ( Geometry geometry , double distance ) { if ( geometry == null ) { return null ; } return DouglasPeuckerSimplifier . simplify ( geometry , distance ) ; }
Simplify the geometry using the douglad peucker algorithm .
5,977
public static Geometry expand ( Geometry geometry , double deltaX , double deltaY ) { if ( geometry == null ) { return null ; } Envelope env = geometry . getEnvelopeInternal ( ) ; double minX = env . getMinX ( ) - deltaX ; double maxX = env . getMaxX ( ) + deltaX ; double minY = env . getMinY ( ) - deltaY ; double maxY = env . getMaxY ( ) + deltaY ; Envelope expandedEnvelope = new Envelope ( minX < maxX ? minX : ( env . getMaxX ( ) - env . getMinX ( ) ) / 2 + env . getMinX ( ) , minX < maxX ? maxX : ( env . getMaxX ( ) - env . getMinX ( ) ) / 2 + env . getMinX ( ) , minY < maxY ? minY : ( env . getMaxY ( ) - env . getMinY ( ) ) / 2 + env . getMinY ( ) , minY < maxY ? maxY : ( env . getMaxY ( ) - env . getMinY ( ) ) / 2 + env . getMinY ( ) ) ; return geometry . getFactory ( ) . toGeometry ( expandedEnvelope ) ; }
Expands a geometry s envelope by the given delta X and delta Y . Both positive and negative distances are supported .
5,978
public static LineString computeDirection ( Geometry geometry ) throws IllegalArgumentException { if ( geometry == null ) { return null ; } Triangle triangle = TINFeatureFactory . createTriangle ( geometry ) ; Vector3D normal = TriMarkers . getNormalVector ( triangle ) ; Vector3D vector = new Vector3D ( normal . getX ( ) , normal . getY ( ) , 0 ) . normalize ( ) ; Coordinate inCenter = triangle . centroid ( ) ; inCenter . setOrdinate ( 2 , Triangle . interpolateZ ( inCenter , triangle . p0 , triangle . p1 , triangle . p2 ) ) ; final LineSegment [ ] sides = new LineSegment [ ] { new LineSegment ( triangle . p0 , triangle . p1 ) , new LineSegment ( triangle . p1 , triangle . p2 ) , new LineSegment ( triangle . p2 , triangle . p0 ) } ; Coordinate pointIntersection = null ; double nearestIntersection = Double . MAX_VALUE ; for ( LineSegment side : sides ) { Coordinate intersection = CoordinateUtils . vectorIntersection ( inCenter , vector , side . p0 , new Vector3D ( side . p0 , side . p1 ) . normalize ( ) ) ; double distInters = intersection == null ? Double . MAX_VALUE : side . distance ( intersection ) ; if ( intersection != null && distInters < nearestIntersection ) { pointIntersection = new Coordinate ( intersection . x , intersection . y , Triangle . interpolateZ ( intersection , triangle . p0 , triangle . p1 , triangle . p2 ) ) ; nearestIntersection = distInters ; } } if ( pointIntersection != null ) { return gf . createLineString ( new Coordinate [ ] { inCenter , pointIntersection } ) ; } return gf . createLineString ( new Coordinate [ ] { } ) ; }
Compute the main slope direction
5,979
public static Geometry drapePoints ( Geometry pts , Geometry triangles , STRtree sTRtree ) { Geometry geomDrapped = pts . copy ( ) ; CoordinateSequenceFilter drapeFilter = new DrapeFilter ( sTRtree ) ; geomDrapped . apply ( drapeFilter ) ; return geomDrapped ; }
Drape a point or a multipoint geometry to a set of triangles
5,980
public static Geometry drapeLineString ( LineString line , Geometry triangles , STRtree sTRtree ) { GeometryFactory factory = line . getFactory ( ) ; Geometry triangleLines = LinearComponentExtracter . getGeometry ( triangles , true ) ; Geometry diffExt = lineMerge ( line . difference ( triangleLines ) , factory ) ; CoordinateSequenceFilter drapeFilter = new DrapeFilter ( sTRtree ) ; diffExt . apply ( drapeFilter ) ; return diffExt ; }
Drape a linestring to a set of triangles
5,981
public static Geometry drapePolygon ( Polygon p , Geometry triangles , STRtree sTRtree ) { GeometryFactory factory = p . getFactory ( ) ; Geometry triangleLines = LinearComponentExtracter . getGeometry ( triangles , true ) ; Polygon splittedP = processPolygon ( p , triangleLines , factory ) ; CoordinateSequenceFilter drapeFilter = new DrapeFilter ( sTRtree ) ; splittedP . apply ( drapeFilter ) ; return splittedP ; }
Drape a polygon on a set of triangles
5,982
private static Polygon processPolygon ( Polygon p , Geometry triangleLines , GeometryFactory factory ) { Geometry diffExt = p . getExteriorRing ( ) . difference ( triangleLines ) ; final int nbOfHoles = p . getNumInteriorRing ( ) ; final LinearRing [ ] holes = new LinearRing [ nbOfHoles ] ; for ( int i = 0 ; i < nbOfHoles ; i ++ ) { holes [ i ] = factory . createLinearRing ( lineMerge ( p . getInteriorRingN ( i ) . difference ( triangleLines ) , factory ) . getCoordinates ( ) ) ; } return factory . createPolygon ( factory . createLinearRing ( lineMerge ( diffExt , factory ) . getCoordinates ( ) ) , holes ) ; }
Cut the lines of the polygon with the triangles
5,983
public static Geometry lineMerge ( Geometry geom , GeometryFactory factory ) { LineMerger merger = new LineMerger ( ) ; merger . add ( geom ) ; Collection lines = merger . getMergedLineStrings ( ) ; return factory . buildGeometry ( lines ) ; }
A method to merge a geometry to a set of linestring
5,984
public static Geometry precisionReducer ( Geometry geometry , int nbDec ) throws SQLException { if ( geometry == null ) { return null ; } if ( nbDec < 0 ) { throw new SQLException ( "Decimal_places has to be >= 0." ) ; } PrecisionModel pm = new PrecisionModel ( scaleFactorForDecimalPlaces ( nbDec ) ) ; GeometryPrecisionReducer geometryPrecisionReducer = new GeometryPrecisionReducer ( pm ) ; return geometryPrecisionReducer . reduce ( geometry ) ; }
Reduce the geometry precision . Decimal_Place is the number of decimals to keep .
5,985
public static Geometry ringSideBuffer ( Geometry geom , double bufferSize , int numBuffer ) throws SQLException { return ringSideBuffer ( geom , bufferSize , numBuffer , "endcap=flat" ) ; }
Compute a ring buffer on one side of the geometry
5,986
public static Double computeAspect ( Geometry geometry ) throws IllegalArgumentException { if ( geometry == null ) { return null ; } Vector3D vector = TriMarkers . getSteepestVector ( TriMarkers . getNormalVector ( TINFeatureFactory . createTriangle ( geometry ) ) , TINFeatureFactory . EPSILON ) ; if ( vector . length ( ) < TINFeatureFactory . EPSILON ) { return 0d ; } else { Vector2D v = new Vector2D ( vector . getX ( ) , vector . getY ( ) ) ; return measureFromNorth ( Math . toDegrees ( v . angle ( ) ) ) ; } }
Compute the aspect in degree . The geometry must be a triangle .
5,987
public static Double getMinZ ( Geometry geom ) { if ( geom != null ) { return CoordinateUtils . zMinMax ( geom . getCoordinates ( ) ) [ 0 ] ; } else { return null ; } }
Returns the minimal z - value of the given geometry .
5,988
private static LineString reverse3D ( LineString lineString , String order ) { CoordinateSequence seq = lineString . getCoordinateSequence ( ) ; double startZ = seq . getCoordinate ( 0 ) . z ; double endZ = seq . getCoordinate ( seq . size ( ) - 1 ) . z ; if ( order . equalsIgnoreCase ( "desc" ) ) { if ( ! Double . isNaN ( startZ ) && ! Double . isNaN ( endZ ) && startZ < endZ ) { CoordinateSequences . reverse ( seq ) ; return FACTORY . createLineString ( seq ) ; } } else if ( order . equalsIgnoreCase ( "asc" ) ) { if ( ! Double . isNaN ( startZ ) && ! Double . isNaN ( endZ ) && startZ > endZ ) { CoordinateSequences . reverse ( seq ) ; return FACTORY . createLineString ( seq ) ; } } else { throw new IllegalArgumentException ( "Supported order values are asc or desc." ) ; } return lineString ; }
Reverses a LineString according to the z value . The z of the first point must be lower than the z of the end point .
5,989
public static String generateGMLink ( Geometry geom , String layerType , int zoom ) { if ( geom == null ) { return null ; } try { LayerType layer = LayerType . valueOf ( layerType . toLowerCase ( ) ) ; Coordinate centre = geom . getEnvelopeInternal ( ) . centre ( ) ; StringBuilder sb = new StringBuilder ( "https://maps.google.com/maps?ll=" ) ; sb . append ( centre . y ) ; sb . append ( "," ) ; sb . append ( centre . x ) ; sb . append ( "&z=" ) ; sb . append ( zoom ) ; sb . append ( "&t=" ) ; sb . append ( layer . name ( ) ) ; return sb . toString ( ) ; } catch ( IllegalArgumentException ex ) { throw new IllegalArgumentException ( "Layer type supported are m (normal map) , k (satellite), h (hybrid), p (terrain)" , ex ) ; } }
Generate a Google Map link URL based on the center of the bounding box of the input geometry . Set the layer type and the zoom level .
5,990
protected Coordinate [ ] toCoordinateArray ( Stack stack ) { Coordinate [ ] coordinates = new Coordinate [ stack . size ( ) ] ; for ( int i = 0 ; i < stack . size ( ) ; i ++ ) { Coordinate coordinate = ( Coordinate ) stack . get ( i ) ; coordinates [ i ] = coordinate ; } return coordinates ; }
An alternative to Stack . toArray which is not present in earlier versions of Java .
5,991
private Stack grahamScan ( Coordinate [ ] c ) { Coordinate p ; Stack ps = new Stack ( ) ; p = ( Coordinate ) ps . push ( c [ 0 ] ) ; p = ( Coordinate ) ps . push ( c [ 1 ] ) ; p = ( Coordinate ) ps . push ( c [ 2 ] ) ; for ( int i = 3 ; i < c . length ; i ++ ) { p = ( Coordinate ) ps . pop ( ) ; while ( ! ps . empty ( ) && CGAlgorithms . computeOrientation ( ( Coordinate ) ps . peek ( ) , p , c [ i ] ) > 0 ) { p = ( Coordinate ) ps . pop ( ) ; } p = ( Coordinate ) ps . push ( p ) ; p = ( Coordinate ) ps . push ( c [ i ] ) ; } p = ( Coordinate ) ps . push ( c [ 0 ] ) ; return ps ; }
Uses the Graham Scan algorithm to compute the convex hull vertices .
5,992
public static Geometry force3D ( Geometry geom ) { if ( geom == null ) { return null ; } return GeometryCoordinateDimension . force ( geom , 3 ) ; }
Converts a XY geometry to XYZ . If a geometry has no Z component then a 0 Z coordinate is tacked on .
5,993
public static Boolean isWithinDistance ( Geometry geomA , Geometry geomB , Double distance ) { if ( geomA == null || geomB == null ) { return null ; } return geomA . isWithinDistance ( geomB , distance ) ; }
Returns true if the geometries are within the specified distance of one another .
5,994
public static String toGeojson ( Geometry geom ) { StringBuilder sb = new StringBuilder ( ) ; toGeojsonGeometry ( geom , sb ) ; return sb . toString ( ) ; }
Convert the geometry to a GeoJSON representation .
5,995
public static void toGeojsonGeometry ( Geometry geom , StringBuilder sb ) { if ( geom instanceof Point ) { toGeojsonPoint ( ( Point ) geom , sb ) ; } else if ( geom instanceof LineString ) { toGeojsonLineString ( ( LineString ) geom , sb ) ; } else if ( geom instanceof Polygon ) { toGeojsonPolygon ( ( Polygon ) geom , sb ) ; } else if ( geom instanceof MultiPoint ) { toGeojsonMultiPoint ( ( MultiPoint ) geom , sb ) ; } else if ( geom instanceof MultiLineString ) { toGeojsonMultiLineString ( ( MultiLineString ) geom , sb ) ; } else if ( geom instanceof MultiPolygon ) { toGeojsonMultiPolygon ( ( MultiPolygon ) geom , sb ) ; } else { toGeojsonGeometryCollection ( ( GeometryCollection ) geom , sb ) ; } }
Transform a JTS geometry to a GeoJSON representation .
5,996
public static void toGeojsonPoint ( Point point , StringBuilder sb ) { Coordinate coord = point . getCoordinate ( ) ; sb . append ( "{\"type\":\"Point\",\"coordinates\":[" ) ; sb . append ( coord . x ) . append ( "," ) . append ( coord . y ) ; if ( ! Double . isNaN ( coord . z ) ) { sb . append ( "," ) . append ( coord . z ) ; } sb . append ( "]}" ) ; }
For type Point the coordinates member must be a single position .
5,997
public static void toGeojsonMultiPoint ( MultiPoint multiPoint , StringBuilder sb ) { sb . append ( "{\"type\":\"MultiPoint\",\"coordinates\":" ) ; toGeojsonCoordinates ( multiPoint . getCoordinates ( ) , sb ) ; sb . append ( "}" ) ; }
Coordinates of a MultiPoint are an array of positions .
5,998
public static void toGeojsonLineString ( LineString lineString , StringBuilder sb ) { sb . append ( "{\"type\":\"LineString\",\"coordinates\":" ) ; toGeojsonCoordinates ( lineString . getCoordinates ( ) , sb ) ; sb . append ( "}" ) ; }
Coordinates of LineString are an array of positions .
5,999
public static void toGeojsonMultiLineString ( MultiLineString multiLineString , StringBuilder sb ) { sb . append ( "{\"type\":\"MultiLineString\",\"coordinates\":[" ) ; for ( int i = 0 ; i < multiLineString . getNumGeometries ( ) ; i ++ ) { toGeojsonCoordinates ( multiLineString . getGeometryN ( i ) . getCoordinates ( ) , sb ) ; if ( i < multiLineString . getNumGeometries ( ) - 1 ) { sb . append ( "," ) ; } } sb . append ( "]}" ) ; }
Coordinates of a MultiLineString are an array of LineString coordinate arrays .