idx
int64
0
165k
question
stringlengths
73
4.15k
target
stringlengths
5
918
len_question
int64
21
890
len_target
int64
3
255
17,100
public static Envelope scaleToWidth ( Envelope original , double newWidth ) { double width = original . getWidth ( ) ; double factor = newWidth / width ; double newHeight = original . getHeight ( ) * factor ; return new Envelope ( original . getMinX ( ) , original . getMinX ( ) + newWidth , original . getMinY ( ) , original . getMinY ( ) + newHeight ) ; }
Scale an envelope to have a given width .
96
9
17,101
public static int getDayOfYear ( Calendar cal , int type ) { int jday = cal . get ( Calendar . DAY_OF_YEAR ) ; int mo = cal . get ( java . util . Calendar . MONTH ) + 1 ; if ( type == CALENDAR_YEAR ) { return jday ; } else if ( type == SOLAR_YEAR ) { int day = cal . get ( Calendar . DAY_OF_MONTH ) ; return ( mo == 12 && day > 21 ) ? ( day - 21 ) : ( jday + 10 ) ; } else if ( type == WATER_YEAR ) { return ( mo > 9 ) ? ( jday - ( isLeapYear ( cal . get ( Calendar . YEAR ) ) ? 274 : 273 ) ) : ( jday + 92 ) ; } throw new IllegalArgumentException ( "getDayOfYear() type argument unknown" ) ; }
Get the Day of the year in WATER SOLAR or CALENDAR year .
196
17
17,102
public static double deltaHours ( int calUnit , int increments ) { if ( calUnit == Calendar . DATE ) { return 24 * increments ; } else if ( calUnit == Calendar . HOUR ) { return increments ; } else if ( calUnit == Calendar . MINUTE ) { return increments / 60 ; } else if ( calUnit == Calendar . SECOND ) { return increments / 3600 ; } return - 1 ; }
This used to be deltim in MMS .
89
10
17,103
protected ValidationMessage < Origin > reportError ( Origin origin , String messageKey , Object ... params ) { return reportMessage ( Severity . ERROR , origin , messageKey , params ) ; }
Creates an error validation message for the feature and adds it to the validation result .
40
17
17,104
protected ValidationMessage < Origin > reportFeatureError ( Origin origin , String messageKey , Feature feature , Object ... params ) { ValidationMessage < Origin > message = reportMessage ( Severity . ERROR , origin , messageKey , params ) ; appendLocusTadAndGeneIDToMessage ( feature , message ) ; return message ; }
Creates an error validation message for the feature and adds it to the validation result . If there are locus_tag or gene qualifiers the values of these will be added to the message as a curator comment .
70
42
17,105
public static void appendLocusTadAndGeneIDToMessage ( Feature feature , ValidationMessage < Origin > message ) { if ( SequenceEntryUtils . isQualifierAvailable ( Qualifier . LOCUS_TAG_QUALIFIER_NAME , feature ) ) { Qualifier locusTag = SequenceEntryUtils . getQualifier ( Qualifier . LOCUS_TAG_QUALIFIER_NAME , feature ) ; if ( locusTag . isValue ( ) ) { message . appendCuratorMessage ( "locus tag = " + locusTag . getValue ( ) ) ; } } if ( SequenceEntryUtils . isQualifierAvailable ( Qualifier . GENE_QUALIFIER_NAME , feature ) ) { Qualifier geneName = SequenceEntryUtils . getQualifier ( Qualifier . GENE_QUALIFIER_NAME , feature ) ; if ( geneName . isValue ( ) ) { message . appendCuratorMessage ( "gene = " + geneName . getValue ( ) ) ; } } }
If a feature had locus_tag or gene qualifiers - appends the value of these to the message as a curator comment . Useful for some submitters who want more of a handle on the origin than just a line number .
223
46
17,106
protected ValidationMessage < Origin > reportWarning ( Origin origin , String messageKey , Object ... params ) { return reportMessage ( Severity . WARNING , origin , messageKey , params ) ; }
Creates a warning validation message for the feature and adds it to the validation result .
40
17
17,107
protected ValidationMessage < Origin > reportMessage ( Severity severity , Origin origin , String messageKey , Object ... params ) { ValidationMessage < Origin > message = EntryValidations . createMessage ( origin , severity , messageKey , params ) ; message . getMessage ( ) ; // System.out.println("message = " + message.getMessage()); result . append ( message ) ; return message ; }
Creates a validation message for the feature and adds it to the validation result .
85
16
17,108
private boolean isAlone ( Geometry geometryN ) { Coordinate [ ] coordinates = geometryN . getCoordinates ( ) ; if ( coordinates . length > 1 ) { Coordinate first = coordinates [ 0 ] ; Coordinate last = coordinates [ coordinates . length - 1 ] ; for ( SimpleFeature line : linesList ) { Geometry lineGeom = ( Geometry ) line . getDefaultGeometry ( ) ; int numGeometries = lineGeom . getNumGeometries ( ) ; for ( int i = 0 ; i < numGeometries ; i ++ ) { Geometry subGeom = lineGeom . getGeometryN ( i ) ; Coordinate [ ] lineCoordinates = subGeom . getCoordinates ( ) ; if ( lineCoordinates . length < 2 ) { continue ; } else { Coordinate tmpFirst = lineCoordinates [ 0 ] ; Coordinate tmpLast = lineCoordinates [ lineCoordinates . length - 1 ] ; if ( tmpFirst . distance ( first ) < SAMEPOINTTHRESHOLD || tmpFirst . distance ( last ) < SAMEPOINTTHRESHOLD || tmpLast . distance ( first ) < SAMEPOINTTHRESHOLD || tmpLast . distance ( last ) < SAMEPOINTTHRESHOLD ) { return false ; } } } } } // 1 point line or no connection, mark it as alone for removal return true ; }
Checks if the given geometry is connected to any other line .
309
13
17,109
public static void defaultSmoothShapefile ( String shapePath , String outPath ) throws Exception { PrintStreamProgressMonitor pm = new PrintStreamProgressMonitor ( System . out , System . err ) ; SimpleFeatureCollection initialFC = OmsShapefileFeatureReader . readShapefile ( shapePath ) ; OmsLineSmootherMcMaster smoother = new OmsLineSmootherMcMaster ( ) ; smoother . pm = pm ; smoother . pLimit = 10 ; smoother . inVector = initialFC ; smoother . pLookahead = 13 ; // smoother.pSlide = 1; smoother . pDensify = 0.2 ; smoother . pSimplify = 0.01 ; smoother . process ( ) ; SimpleFeatureCollection smoothedFeatures = smoother . outVector ; OmsShapefileFeatureWriter . writeShapefile ( outPath , smoothedFeatures , pm ) ; }
An utility method to use the module with default values and shapefiles .
184
14
17,110
@ Override public double magnitudeSqr ( Object pt ) { double sum = 0.0 ; double [ ] coords = coords ( pt ) ; for ( int i = 0 ; i < dimensions ; i ++ ) { double c = coords [ i ] ; sum += c * c ; } return sum ; }
space point operations
68
3
17,111
public static byte [ ] generateSecretKey ( ) { final byte [ ] k = new byte [ KEY_LEN ] ; final SecureRandom random = new SecureRandom ( ) ; random . nextBytes ( k ) ; return k ; }
Generates a 32 - byte secret key .
49
9
17,112
private static void initialize ( ) { for ( int i = 0 ; i < 256 ; ++ i ) { long crc = i ; for ( int j = 8 ; j > 0 ; j -- ) { if ( ( crc & 1 ) == 1 ) crc = ( crc >>> 1 ) ^ polynomial ; else crc >>>= 1 ; } values [ i ] = crc ; } init_done = true ; }
Calculates a CRC value for a byte to be used by CRC calculation functions .
92
17
17,113
public static long calculateCRC32 ( byte [ ] buffer , int offset , int length ) { if ( ! init_done ) { initialize ( ) ; } for ( int i = offset ; i < offset + length ; i ++ ) { long tmp1 = ( crc >>> 8 ) & 0x00FFFFFF L ; long tmp2 = values [ ( int ) ( ( crc ^ Character . toUpperCase ( ( char ) buffer [ i ] ) ) & 0xff ) ] ; crc = tmp1 ^ tmp2 ; // System.out.println("CRC: "+crc); } return crc ; }
Calculates the CRC - 32 of a block of data all at once
133
15
17,114
private synchronized URLClassLoader getClassLoader ( ) { if ( modelClassLoader == null ) { List < File > jars = res . filterFiles ( "jar" ) ; // jars as defined in List < File > cli_jars = getExtraResources ( ) ; // cli extra jars List < File > dirs = res . filterDirectories ( ) ; // testing List < URL > urls = new ArrayList < URL > ( ) ; try { for ( int i = 0 ; i < jars . size ( ) ; i ++ ) { urls . add ( jars . get ( i ) . toURI ( ) . toURL ( ) ) ; if ( log . isLoggable ( Level . CONFIG ) ) { log . config ( "classpath entry from simulation: " + jars . get ( i ) ) ; } } for ( int i = 0 ; i < dirs . size ( ) ; i ++ ) { urls . add ( dirs . get ( i ) . toURI ( ) . toURL ( ) ) ; if ( log . isLoggable ( Level . CONFIG ) ) { log . config ( "dir entry: " + dirs . get ( i ) ) ; } } for ( int i = 0 ; i < cli_jars . size ( ) ; i ++ ) { urls . add ( cli_jars . get ( i ) . toURI ( ) . toURL ( ) ) ; if ( log . isLoggable ( Level . CONFIG ) ) { log . config ( "classpath entry from CLI: " + cli_jars . get ( i ) ) ; } } urls . add ( new URL ( "file:" + System . getProperty ( "oms.prj" ) + "/dist/" ) ) ; if ( log . isLoggable ( Level . CONFIG ) ) { log . config ( "Sim loading classpath : " + "file:" + System . getProperty ( "oms.prj" ) + "/dist/" ) ; } } catch ( MalformedURLException ex ) { throw new ComponentException ( "Illegal resource:" + ex . getMessage ( ) ) ; } modelClassLoader = new URLClassLoader ( urls . toArray ( new URL [ 0 ] ) , Thread . currentThread ( ) . getContextClassLoader ( ) ) ; } return modelClassLoader ; }
get the URL class loader for all the resources ( just for jar files
506
14
17,115
public static double getDistanceBetween ( IHMConnection connection , Coordinate p1 , Coordinate p2 , int srid ) throws Exception { if ( srid < 0 ) { srid = 4326 ; } GeometryFactory gf = new GeometryFactory ( ) ; LineString lineString = gf . createLineString ( new Coordinate [ ] { p1 , p2 } ) ; String sql = "select GeodesicLength(LineFromText(\"" + lineString . toText ( ) + "\"," + srid + "));" ; try ( IHMStatement stmt = connection . createStatement ( ) ; IHMResultSet rs = stmt . executeQuery ( sql ) ; ) { if ( rs . next ( ) ) { double length = rs . getDouble ( 1 ) ; return length ; } throw new RuntimeException ( "Could not calculate distance." ) ; } }
Calculates the GeodesicLength between to points .
189
12
17,116
private boolean moveToNextTriggerpoint ( RandomIter triggerIter , RandomIter flowIter , int [ ] flowDirColRow ) { double tmpFlowValue = flowIter . getSampleDouble ( flowDirColRow [ 0 ] , flowDirColRow [ 1 ] , 0 ) ; if ( tmpFlowValue == 10 ) { return false ; } if ( ! ModelsEngine . go_downstream ( flowDirColRow , tmpFlowValue ) ) throw new ModelsIllegalargumentException ( "Unable to go downstream: " + flowDirColRow [ 0 ] + "/" + flowDirColRow [ 1 ] , this , pm ) ; while ( isNovalue ( triggerIter . getSampleDouble ( flowDirColRow [ 0 ] , flowDirColRow [ 1 ] , 0 ) ) ) { tmpFlowValue = flowIter . getSampleDouble ( flowDirColRow [ 0 ] , flowDirColRow [ 1 ] , 0 ) ; if ( tmpFlowValue == 10 ) { return false ; } if ( ! ModelsEngine . go_downstream ( flowDirColRow , tmpFlowValue ) ) throw new ModelsIllegalargumentException ( "Unable to go downstream: " + flowDirColRow [ 0 ] + "/" + flowDirColRow [ 1 ] , this , pm ) ; } return true ; }
Moves the flowDirColRow variable to the next trigger point .
278
14
17,117
public static void memclr ( byte [ ] array , int offset , int length ) { for ( int i = 0 ; i < length ; ++ i , ++ offset ) array [ offset ] = 0 ; }
Fill the given array with zeros .
44
8
17,118
public static byte [ ] zero_pad ( byte [ ] original , int block_size ) { if ( ( original . length % block_size ) == 0 ) { return original ; } byte [ ] result = new byte [ round_up ( original . length , block_size ) ] ; memcpy ( result , 0 , original , 0 , original . length ) ; // Unnecessary - jvm sets bytes to 0. // memclr (result, original.length, result.length - original.length); return result ; }
Return a new array equal to original except zero - padded to an integral mulitple of blocks . If the original is already an integral multiple of blocks just return it .
112
34
17,119
public static boolean isSupportedVectorExtension ( String name ) { for ( String ext : supportedVectors ) { if ( name . toLowerCase ( ) . endsWith ( ext ) ) { return true ; } } return false ; }
Checks a given name of a file if it is a supported vector extension .
50
16
17,120
public static boolean isSupportedRasterExtension ( String name ) { for ( String ext : supportedRasters ) { if ( name . toLowerCase ( ) . endsWith ( ext ) ) { return true ; } } return false ; }
Checks a given name of a file if it is a supported raster extension .
50
17
17,121
public static GridCoverage2D readRaster ( String path ) throws Exception { OmsRasterReader reader = new OmsRasterReader ( ) ; reader . file = path ; reader . process ( ) ; GridCoverage2D geodata = reader . outRaster ; return geodata ; }
Utility method to quickly read a grid in default mode .
66
12
17,122
private void swap ( int i , int j ) { double [ ] temp = data [ i ] ; data [ i ] = data [ j ] ; data [ j ] = temp ; }
swap rows i and j
39
6
17,123
public Matrix transpose ( ) { Matrix A = new Matrix ( N , M ) ; for ( int i = 0 ; i < M ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { A . data [ j ] [ i ] = data [ i ] [ j ] ; } } return A ; }
create and return the transpose of the invoking matrix
72
10
17,124
public Matrix solve ( Matrix rhs ) { if ( M != N || rhs . M != N || rhs . N != 1 ) { throw new RuntimeException ( "Illegal matrix dimensions." ) ; } // create copies of the data Matrix A = new Matrix ( this ) ; Matrix b = new Matrix ( rhs ) ; // Gaussian elimination with partial pivoting for ( int i = 0 ; i < N ; i ++ ) { // find pivot row and swap int max = i ; for ( int j = i + 1 ; j < N ; j ++ ) { if ( Math . abs ( A . data [ j ] [ i ] ) > Math . abs ( A . data [ max ] [ i ] ) ) { max = j ; } } A . swap ( i , max ) ; b . swap ( i , max ) ; // singular if ( A . data [ i ] [ i ] == 0.0 ) { throw new RuntimeException ( "Matrix is singular." ) ; } // pivot within b for ( int j = i + 1 ; j < N ; j ++ ) { b . data [ j ] [ 0 ] -= b . data [ i ] [ 0 ] * A . data [ j ] [ i ] / A . data [ i ] [ i ] ; } // pivot within A for ( int j = i + 1 ; j < N ; j ++ ) { double m = A . data [ j ] [ i ] / A . data [ i ] [ i ] ; for ( int k = i + 1 ; k < N ; k ++ ) { A . data [ j ] [ k ] -= A . data [ i ] [ k ] * m ; } A . data [ j ] [ i ] = 0.0 ; } } // back substitution Matrix x = new Matrix ( N , 1 ) ; for ( int j = N - 1 ; j >= 0 ; j -- ) { double t = 0.0 ; for ( int k = j + 1 ; k < N ; k ++ ) { t += A . data [ j ] [ k ] * x . data [ k ] [ 0 ] ; } x . data [ j ] [ 0 ] = ( b . data [ j ] [ 0 ] - t ) / A . data [ j ] [ j ] ; } return x ; }
return x = A^ - 1 b assuming A is square and has full rank
488
16
17,125
public void print ( ) { for ( int i = 0 ; i < M ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { System . out . printf ( "%9.4f " , data [ i ] [ j ] ) ; } System . out . println ( ) ; } }
print matrix to standard output
69
5
17,126
public void createTables ( boolean makeIndexes ) throws Exception { database . executeInsertUpdateDeleteSql ( "DROP TABLE IF EXISTS " + TABLE_TILES ) ; database . executeInsertUpdateDeleteSql ( "DROP TABLE IF EXISTS " + TABLE_METADATA ) ; database . executeInsertUpdateDeleteSql ( CREATE_TILES ) ; database . executeInsertUpdateDeleteSql ( CREATE_METADATA ) ; if ( makeIndexes ) { createIndexes ( ) ; } }
Create the mbtiles tables in the db .
115
10
17,127
public void fillMetadata ( float n , float s , float w , float e , String name , String format , int minZoom , int maxZoom ) throws Exception { // type = baselayer // version = 1.1 // descritpion = name String query = toMetadataQuery ( "name" , name ) ; database . executeInsertUpdateDeleteSql ( query ) ; query = toMetadataQuery ( "description" , name ) ; database . executeInsertUpdateDeleteSql ( query ) ; query = toMetadataQuery ( "format" , format ) ; database . executeInsertUpdateDeleteSql ( query ) ; query = toMetadataQuery ( "minZoom" , minZoom + "" ) ; database . executeInsertUpdateDeleteSql ( query ) ; query = toMetadataQuery ( "maxZoom" , maxZoom + "" ) ; database . executeInsertUpdateDeleteSql ( query ) ; query = toMetadataQuery ( "type" , "baselayer" ) ; database . executeInsertUpdateDeleteSql ( query ) ; query = toMetadataQuery ( "version" , "1.1" ) ; database . executeInsertUpdateDeleteSql ( query ) ; // left, bottom, right, top query = toMetadataQuery ( "bounds" , w + "," + s + "," + e + "," + n ) ; database . executeInsertUpdateDeleteSql ( query ) ; }
Populate the metadata table .
310
6
17,128
public synchronized void addTile ( int x , int y , int z , byte [ ] imageBytes ) throws Exception { database . execOnConnection ( connection -> { try ( IHMPreparedStatement pstmt = connection . prepareStatement ( insertTileSql ) ; ) { pstmt . setInt ( 1 , z ) ; pstmt . setInt ( 2 , x ) ; pstmt . setInt ( 3 , y ) ; pstmt . setBytes ( 4 , imageBytes ) ; pstmt . executeUpdate ( ) ; return "" ; } } ) ; }
Add a single tile .
123
5
17,129
public synchronized void addTilesInBatch ( List < Tile > tilesList ) throws Exception { database . execOnConnection ( connection -> { boolean autoCommit = connection . getAutoCommit ( ) ; connection . setAutoCommit ( false ) ; try ( IHMPreparedStatement pstmt = connection . prepareStatement ( insertTileSql ) ; ) { for ( Tile tile : tilesList ) { pstmt . setInt ( 1 , tile . z ) ; pstmt . setInt ( 2 , tile . x ) ; pstmt . setInt ( 3 , tile . y ) ; pstmt . setBytes ( 4 , tile . imageBytes ) ; pstmt . addBatch ( ) ; } pstmt . executeBatch ( ) ; return "" ; } finally { connection . setAutoCommit ( autoCommit ) ; } } ) ; }
Add a list of tiles in batch mode .
187
9
17,130
public byte [ ] getTile ( int tx , int tyOsm , int zoom ) throws Exception { int ty = tyOsm ; if ( tileRowType . equals ( "tms" ) ) { int [ ] tmsTileXY = MercatorUtils . osmTile2TmsTile ( tx , tyOsm , zoom ) ; ty = tmsTileXY [ 1 ] ; } int _ty = ty ; return database . execOnConnection ( connection -> { try ( IHMPreparedStatement statement = connection . prepareStatement ( SELECTQUERY ) ) { statement . setInt ( 1 , zoom ) ; statement . setInt ( 2 , tx ) ; statement . setInt ( 3 , _ty ) ; IHMResultSet resultSet = statement . executeQuery ( ) ; if ( resultSet . next ( ) ) { byte [ ] imageBytes = resultSet . getBytes ( 1 ) ; return imageBytes ; } } return null ; } ) ; }
Get a Tile s image bytes from the database .
203
10
17,131
public Envelope getBounds ( ) throws Exception { checkMetadata ( ) ; String boundsWSEN = metadataMap . get ( "bounds" ) ; String [ ] split = boundsWSEN . split ( "," ) ; double w = Double . parseDouble ( split [ 0 ] ) ; double s = Double . parseDouble ( split [ 1 ] ) ; double e = Double . parseDouble ( split [ 2 ] ) ; double n = Double . parseDouble ( split [ 3 ] ) ; return new Envelope ( w , e , s , n ) ; }
Get the db envelope .
121
5
17,132
public int [ ] getBoundsInTileIndex ( int zoomlevel ) throws Exception { String sql = "select min(tile_column), max(tile_column), min(tile_row), max(tile_row) from tiles where zoom_level=" + zoomlevel ; return database . execOnConnection ( connection -> { try ( IHMStatement statement = connection . createStatement ( ) ; IHMResultSet resultSet = statement . executeQuery ( sql ) ; ) { if ( resultSet . next ( ) ) { int minTx = resultSet . getInt ( 1 ) ; int maxTx = resultSet . getInt ( 2 ) ; int minTy = resultSet . getInt ( 3 ) ; int maxTy = resultSet . getInt ( 4 ) ; return new int [ ] { minTx , maxTx , minTy , maxTy } ; } } return null ; } ) ; }
Get the bounds of a zoomlevel in tile indexes .
189
11
17,133
public void out2in ( Object from , String from_out , Object ... tos ) { for ( Object co : tos ) { out2in ( from , from_out , co , from_out ) ; } }
Connects field1 of cmd1 with the same named fields in cmds
48
15
17,134
public void in2in ( String in , Object to , String to_in ) { controller . mapIn ( in , to , to_in ) ; }
Maps a Compound Input field to a internal simple input field .
33
13
17,135
public void in2in ( String in , Object ... to ) { for ( Object cmd : to ) { in2in ( in , cmd , in ) ; } }
Maps a compound input to an internal simple input field . Both fields have the same name .
35
18
17,136
public void field2in ( Object o , String field , Object to , String to_in ) { controller . mapInField ( o , field , to , to_in ) ; }
Maps a object s field to an In field
39
9
17,137
public void field2in ( Object o , String field , Object to ) { field = field . trim ( ) ; if ( field . indexOf ( ' ' ) > 0 ) { // maybe multiple field names given String [ ] fields = field . split ( "\\s+" ) ; for ( String f : fields ) { field2in ( o , f , to , f ) ; } } else { field2in ( o , field , to , field ) ; } }
Maps an object s field to a component s In field with the same name
100
15
17,138
public void out2field ( Object from , String from_out , Object o , String field ) { controller . mapOutField ( from , from_out , o , field ) ; }
Maps a component s Out field to an object field .
39
11
17,139
public void out2field ( Object from , String from_out , Object o ) { out2field ( from , from_out , o , from_out ) ; }
Maps a component Out field to an object s field . Both field have the same name .
36
18
17,140
public void out2out ( String out , Object to , String to_out ) { controller . mapOut ( out , to , to_out ) ; }
Maps a Compound Output field to a internal simple output field .
33
13
17,141
@ Deprecated public void connect ( Object from , String from_out , Object to , String to_in ) { controller . connect ( from , from_out , to , to_in ) ; }
deprecated methods starting here .
42
6
17,142
protected void reportError ( ValidationResult result , String messageKey , Object ... params ) { reportMessage ( result , Severity . ERROR , messageKey , params ) ; }
Creates an error validation message for the sequence and adds it to the validation result .
36
17
17,143
protected void reportWarning ( ValidationResult result , String messageKey , Object ... params ) { reportMessage ( result , Severity . WARNING , messageKey , params ) ; }
Creates a warning validation message for the sequence and adds it to the validation result .
36
17
17,144
protected void reportMessage ( ValidationResult result , Severity severity , String messageKey , Object ... params ) { result . append ( EntryValidations . createMessage ( origin , severity , messageKey , params ) ) ; }
Creates a validation message for the sequence and adds it to the validation result .
46
16
17,145
private void calcInsolation ( double lambda , WritableRaster demWR , WritableRaster gradientWR , WritableRaster insolationWR , int day , double dx ) { // calculating the day angle // double dayang = 2 * Math.PI * (day - 1) / 365.0; double dayangb = ( 360 / 365.25 ) * ( day - 79.436 ) ; dayangb = Math . toRadians ( dayangb ) ; // Evaluate the declination of the sun. delta = getDeclination ( dayangb ) ; // Evaluate the radiation in this day. double ss = Math . acos ( - Math . tan ( delta ) * Math . tan ( lambda ) ) ; double hour = - ss + ( Math . PI / 48.0 ) ; while ( hour <= ss - ( Math . PI / 48 ) ) { omega = hour ; // calculating the vector related to the sun double sunVector [ ] = calcSunVector ( ) ; double zenith = calcZenith ( sunVector [ 2 ] ) ; double [ ] inverseSunVector = calcInverseSunVector ( sunVector ) ; double [ ] normalSunVector = calcNormalSunVector ( sunVector ) ; int height = demWR . getHeight ( ) ; int width = demWR . getWidth ( ) ; WritableRaster sOmbraWR = calculateFactor ( height , width , sunVector , inverseSunVector , normalSunVector , demWR , dx ) ; double mr = 1 / ( sunVector [ 2 ] + 0.15 * Math . pow ( ( 93.885 - zenith ) , ( - 1.253 ) ) ) ; for ( int j = 0 ; j < height ; j ++ ) { for ( int i = 0 ; i < width ; i ++ ) { // evaluate the radiation. calcRadiation ( i , j , demWR , sOmbraWR , insolationWR , sunVector , gradientWR , mr ) ; } } hour = hour + Math . PI / 24.0 ; } }
Evaluate the radiation .
436
6
17,146
public static boolean isCrsValid ( CoordinateReferenceSystem crs ) { if ( crs instanceof AbstractSingleCRS ) { AbstractSingleCRS aCrs = ( AbstractSingleCRS ) crs ; Datum datum = aCrs . getDatum ( ) ; ReferenceIdentifier name = datum . getName ( ) ; String code = name . getCode ( ) ; if ( code . equalsIgnoreCase ( "Unknown" ) ) { return false ; } } return true ; }
Checks if a crs is valid i . e . if it is not a wildcard default one .
107
22
17,147
@ SuppressWarnings ( "nls" ) public static void writeProjectionFile ( String filePath , String extention , CoordinateReferenceSystem crs ) throws IOException { /* * fill a prj file */ String prjPath = null ; if ( extention != null && filePath . toLowerCase ( ) . endsWith ( "." + extention ) ) { int dotLoc = filePath . lastIndexOf ( "." ) ; prjPath = filePath . substring ( 0 , dotLoc ) ; prjPath = prjPath + ".prj" ; } else { if ( ! filePath . endsWith ( ".prj" ) ) { prjPath = filePath + ".prj" ; } else { prjPath = filePath ; } } try ( BufferedWriter bufferedWriter = new BufferedWriter ( new FileWriter ( prjPath ) ) ) { bufferedWriter . write ( crs . toWKT ( ) ) ; } }
Fill the prj file with the actual map projection .
211
11
17,148
public static void reproject ( CoordinateReferenceSystem from , CoordinateReferenceSystem to , Object [ ] geometries ) throws Exception { MathTransform mathTransform = CRS . findMathTransform ( from , to ) ; for ( int i = 0 ; i < geometries . length ; i ++ ) { geometries [ i ] = JTS . transform ( ( Geometry ) geometries [ i ] , mathTransform ) ; } }
Reproject a set of geometries
93
9
17,149
public static void reproject ( CoordinateReferenceSystem from , CoordinateReferenceSystem to , Coordinate [ ] coordinates ) throws Exception { MathTransform mathTransform = CRS . findMathTransform ( from , to ) ; for ( int i = 0 ; i < coordinates . length ; i ++ ) { coordinates [ i ] = JTS . transform ( coordinates [ i ] , coordinates [ i ] , mathTransform ) ; } }
Reproject a set of coordinates .
87
8
17,150
public static double getMetersAsWGS84 ( double meters , Coordinate c ) { GeodeticCalculator gc = new GeodeticCalculator ( DefaultGeographicCRS . WGS84 ) ; gc . setStartingGeographicPoint ( c . x , c . y ) ; gc . setDirection ( 90 , meters ) ; Point2D destinationGeographicPoint = gc . getDestinationGeographicPoint ( ) ; double degrees = Math . abs ( destinationGeographicPoint . getX ( ) - c . x ) ; return degrees ; }
Converts meters to degrees based on a given coordinate in 90 degrees direction .
123
15
17,151
private void createHoughPixels ( double [ ] [ ] [ ] houghValues , byte houghPixels [ ] ) { double d = - 1D ; for ( int j = 0 ; j < height ; j ++ ) { for ( int k = 0 ; k < width ; k ++ ) { if ( houghValues [ k ] [ j ] [ 0 ] > d ) { d = houghValues [ k ] [ j ] [ 0 ] ; } } } for ( int l = 0 ; l < height ; l ++ ) { for ( int i = 0 ; i < width ; i ++ ) { houghPixels [ i + l * width ] = ( byte ) Math . round ( ( houghValues [ i ] [ l ] [ 0 ] * 255D ) / d ) ; } } }
Convert Values in Hough Space to an 8 - Bit Image Space .
174
15
17,152
public void drawCircles ( double [ ] [ ] [ ] houghValues , byte [ ] circlespixels ) { // Copy original input pixels into output // circle location display image and // combine with saturation at 100 int roiaddr = 0 ; for ( int y = offy ; y < offy + height ; y ++ ) { for ( int x = offx ; x < offx + width ; x ++ ) { // Copy; circlespixels [ roiaddr ] = imageValues [ x + offset * y ] ; // Saturate if ( circlespixels [ roiaddr ] != 0 ) circlespixels [ roiaddr ] = 100 ; else circlespixels [ roiaddr ] = 0 ; roiaddr ++ ; } } // Copy original image to the circlespixels image. // Changing pixels values to 100, so that the marked // circles appears more clear. Must be improved in // the future to show the resuls in a colored image. // for(int i = 0; i < width*height ;++i ) { // if(imageValues[i] != 0 ) // if(circlespixels[i] != 0 ) // circlespixels[i] = 100; // else // circlespixels[i] = 0; // } // if (centerPoints == null) { // if (useThreshold) // getCenterPointsByThreshold(threshold); // else Coordinate [ ] centerPoints = getCenterPoints ( houghValues , maxCircles ) ; // } byte cor = - 1 ; // Redefine these so refer to ROI coordinates exclusively int offset = width ; int offx = 0 ; int offy = 0 ; for ( int l = 0 ; l < maxCircles ; l ++ ) { int i = ( int ) centerPoints [ l ] . x ; int j = ( int ) centerPoints [ l ] . y ; // Draw a gray cross marking the center of each circle. for ( int k = - 10 ; k <= 10 ; ++ k ) { int p = ( j + k + offy ) * offset + ( i + offx ) ; if ( ! outOfBounds ( j + k + offy , i + offx ) ) circlespixels [ ( j + k + offy ) * offset + ( i + offx ) ] = cor ; if ( ! outOfBounds ( j + offy , i + k + offx ) ) circlespixels [ ( j + offy ) * offset + ( i + k + offx ) ] = cor ; } for ( int k = - 2 ; k <= 2 ; ++ k ) { if ( ! outOfBounds ( j - 2 + offy , i + k + offx ) ) circlespixels [ ( j - 2 + offy ) * offset + ( i + k + offx ) ] = cor ; if ( ! outOfBounds ( j + 2 + offy , i + k + offx ) ) circlespixels [ ( j + 2 + offy ) * offset + ( i + k + offx ) ] = cor ; if ( ! outOfBounds ( j + k + offy , i - 2 + offx ) ) circlespixels [ ( j + k + offy ) * offset + ( i - 2 + offx ) ] = cor ; if ( ! outOfBounds ( j + k + offy , i + 2 + offx ) ) circlespixels [ ( j + k + offy ) * offset + ( i + 2 + offx ) ] = cor ; } } }
Draw the circles found in the original image .
765
9
17,153
public String getSequence ( Long beginPosition , Long endPosition ) { byte [ ] sequenceByte = getSequenceByte ( beginPosition , endPosition ) ; if ( sequenceByte != null ) return new String ( sequenceByte ) ; return null ; }
Returns a subsequence string or null if the location is not valid .
52
14
17,154
private void set ( Matrix m ) { this . nRows = this . nCols = Math . min ( m . nRows , m . nCols ) ; this . values = m . values ; }
Set this square matrix from another matrix . Note that this matrix will reference the values of the argument matrix . If the values are not square only the upper left square is used .
46
35
17,155
protected void set ( double values [ ] [ ] ) { super . set ( values ) ; nRows = nCols = Math . min ( nRows , nCols ) ; }
Set this square matrix from a 2 - d array of values . If the values are not square only the upper left square is used .
41
27
17,156
public static void printMatrixData ( double [ ] [ ] matrix ) { int cols = matrix [ 0 ] . length ; int rows = matrix . length ; for ( int r = 0 ; r < rows ; r ++ ) { for ( int c = 0 ; c < cols ; c ++ ) { printer . print ( matrix [ r ] [ c ] ) ; printer . print ( separator ) ; } printer . println ( ) ; } }
Print data from a matrix .
94
6
17,157
public static String envelope2WKT ( org . locationtech . jts . geom . Envelope env ) { GeometryFactory gf = GeometryUtilities . gf ( ) ; Geometry geometry = gf . toGeometry ( env ) ; return geometry . toText ( ) ; }
Print the envelope as WKT .
64
7
17,158
public int read ( ) throws IOException { int b = 0 ; // Byte to be read is already in out buffer, simply returning it if ( fOffset < fLength ) { return fData [ fOffset ++ ] & 0xff ; } /* * End of the stream is reached. * I also believe that in certain cases fOffset can point to the * position after the end of stream, for example, after invalid * `setStartOffset()` call followed by `rewind()`. * This situation is not handled currently. */ if ( fOffset == fEndOffset ) { return - 1 ; } /* * Ok, we should actually read data from underlying stream, but * first it will be good to check if buffer array should be * expanded. Each time buffer size is doubled. */ if ( fOffset == fData . length ) { byte [ ] newData = new byte [ fOffset << 1 ] ; System . arraycopy ( fData , 0 , newData , 0 , fOffset ) ; fData = newData ; } // Reading byte from the underlying stream, storing it in buffer and // then returning it. b = fInputStream . read ( ) ; if ( b == - 1 ) { fEndOffset = fOffset ; return - 1 ; } fData [ fLength ++ ] = ( byte ) b ; fOffset ++ ; return b & 0xff ; }
Reads next byte from this stream . This byte is either being read from underlying InputStream or taken from the internal buffer in case it was already read at some point before .
287
35
17,159
public void close ( ) throws IOException { if ( fInputStream != null ) { fInputStream . close ( ) ; fInputStream = null ; fData = null ; } }
Closes underlying byte stream .
39
6
17,160
public String getTranslation ( ) { if ( codons == null ) { return "" ; } StringBuilder translation = new StringBuilder ( ) ; for ( Codon codon : codons ) { translation . append ( codon . getAminoAcid ( ) ) ; } return translation . toString ( ) ; }
Returns the translation including stop codons and trailing bases .
67
11
17,161
public String getConceptualTranslation ( ) { if ( codons == null ) { return "" ; } StringBuilder translation = new StringBuilder ( ) ; for ( int i = 0 ; i < conceptualTranslationCodons ; ++ i ) { Codon codon = codons . get ( i ) ; translation . append ( codon . getAminoAcid ( ) ) ; } return translation . toString ( ) ; }
Returns the translation excluding stop codons and trailing bases .
90
11
17,162
public static double [ ] gaussianSmooth ( double [ ] values , int kernelRadius ) throws Exception { int size = values . length ; double [ ] newValues = new double [ values . length ] ; double [ ] kernelData2D = makeGaussianKernel ( kernelRadius ) ; for ( int i = 0 ; i < kernelRadius ; i ++ ) { newValues [ i ] = values [ i ] ; } for ( int r = kernelRadius ; r < size - kernelRadius ; r ++ ) { double kernelSum = 0.0 ; double outputValue = 0.0 ; int k = 0 ; for ( int kc = - kernelRadius ; kc <= kernelRadius ; kc ++ , k ++ ) { double value = values [ r + kc ] ; if ( ! isNovalue ( value ) ) { outputValue = outputValue + value * kernelData2D [ k ] ; kernelSum = kernelSum + kernelData2D [ k ] ; } } newValues [ r ] = outputValue / kernelSum ; } for ( int i = size - kernelRadius ; i < size ; i ++ ) { newValues [ i ] = values [ i ] ; } return newValues ; }
Smooth an array of values with a gaussian blur .
264
12
17,163
public static double [ ] averageSmooth ( double [ ] values , int lookAhead ) throws Exception { int size = values . length ; double [ ] newValues = new double [ values . length ] ; for ( int i = 0 ; i < lookAhead ; i ++ ) { newValues [ i ] = values [ i ] ; } for ( int i = lookAhead ; i < size - lookAhead ; i ++ ) { double sum = 0.0 ; int k = 0 ; for ( int l = - lookAhead ; l <= lookAhead ; l ++ ) { double value = values [ i + l ] ; if ( ! isNovalue ( value ) ) { sum = sum + value ; k ++ ; } } newValues [ i ] = sum / k ; } for ( int i = size - lookAhead ; i < size ; i ++ ) { newValues [ i ] = values [ i ] ; } return newValues ; }
Smooth an array of values with an averaging moving window .
205
12
17,164
public Coordinate wgs84ToEnu ( Coordinate cLL ) { checkZ ( cLL ) ; Coordinate cEcef = wgs84ToEcef ( cLL ) ; Coordinate enu = ecefToEnu ( cEcef ) ; return enu ; }
Converts the wgs84 coordinate to ENU .
65
11
17,165
public Coordinate enuToWgs84 ( Coordinate enu ) { checkZ ( enu ) ; Coordinate cEcef = enuToEcef ( enu ) ; Coordinate wgs84 = ecefToWgs84 ( cEcef ) ; return wgs84 ; }
Converts the ENU coordinate to wgs84 .
67
11
17,166
public void convertGeometryFromEnuToWgs84 ( Geometry geometryEnu ) { Coordinate [ ] coordinates = geometryEnu . getCoordinates ( ) ; for ( int i = 0 ; i < coordinates . length ; i ++ ) { Coordinate wgs84 = enuToWgs84 ( coordinates [ i ] ) ; coordinates [ i ] . x = wgs84 . x ; coordinates [ i ] . y = wgs84 . y ; coordinates [ i ] . z = wgs84 . z ; } }
Converts a geometry from ENU to WGS .
114
11
17,167
public void convertGeometryFromWgsToEnu ( Geometry geometryWgs ) { Coordinate [ ] coordinates = geometryWgs . getCoordinates ( ) ; for ( int i = 0 ; i < coordinates . length ; i ++ ) { Coordinate enu = wgs84ToEnu ( coordinates [ i ] ) ; coordinates [ i ] . x = enu . x ; coordinates [ i ] . y = enu . y ; coordinates [ i ] . z = enu . z ; } }
Converts a geometry from WGS to ENU .
109
11
17,168
public Envelope convertEnvelopeFromWgsToEnu ( Envelope envelopeWgs ) { Polygon polygonEnu = GeometryUtilities . createPolygonFromEnvelope ( envelopeWgs ) ; convertGeometryFromWgsToEnu ( polygonEnu ) ; Envelope envelopeEnu = polygonEnu . getEnvelopeInternal ( ) ; return envelopeEnu ; }
Converts an envelope from WGS to ENU .
90
11
17,169
public synchronized Position goTo ( Double lon , Double lat , Double elev , Double azimuth , boolean animate ) { View view = getWwd ( ) . getView ( ) ; view . stopAnimations ( ) ; view . stopMovement ( ) ; Position eyePosition ; if ( lon == null || lat == null ) { Position currentEyePosition = wwd . getView ( ) . getCurrentEyePosition ( ) ; if ( currentEyePosition != null ) { lat = currentEyePosition . latitude . degrees ; lon = currentEyePosition . longitude . degrees ; } else { return null ; } } if ( elev == null ) { // use the current elev = wwd . getView ( ) . getCurrentEyePosition ( ) . getAltitude ( ) ; } if ( Double . isNaN ( elev ) ) { if ( ! Double . isNaN ( lastElevation ) ) { elev = lastElevation ; } else { elev = NwwUtilities . DEFAULT_ELEV ; } } eyePosition = NwwUtilities . toPosition ( lat , lon , elev ) ; if ( animate ) { view . goTo ( eyePosition , elev ) ; } else { view . setEyePosition ( eyePosition ) ; } if ( azimuth != null ) { Angle heading = Angle . fromDegrees ( azimuth ) ; view . setHeading ( heading ) ; } lastElevation = elev ; return eyePosition ; }
Move to a given location .
314
6
17,170
public void goTo ( Sector sector , boolean animate ) { View view = getWwd ( ) . getView ( ) ; view . stopAnimations ( ) ; view . stopMovement ( ) ; if ( sector == null ) { return ; } // Create a bounding box for the specified sector in order to estimate // its size in model coordinates. Box extent = Sector . computeBoundingBox ( getWwd ( ) . getModel ( ) . getGlobe ( ) , getWwd ( ) . getSceneController ( ) . getVerticalExaggeration ( ) , sector ) ; // Estimate the distance between the center position and the eye // position that is necessary to cause the sector to // fill a viewport with the specified field of view. Note that we change // the distance between the center and eye // position here, and leave the field of view constant. Angle fov = view . getFieldOfView ( ) ; double zoom = extent . getRadius ( ) / fov . cosHalfAngle ( ) / fov . tanHalfAngle ( ) ; // Configure OrbitView to look at the center of the sector from our // estimated distance. This causes OrbitView to // animate to the specified position over several seconds. To affect // this change immediately use the following: if ( animate ) { view . goTo ( new Position ( sector . getCentroid ( ) , 0d ) , zoom ) ; } else { ( ( OrbitView ) wwd . getView ( ) ) . setCenterPosition ( new Position ( sector . getCentroid ( ) , 0d ) ) ; ( ( OrbitView ) wwd . getView ( ) ) . setZoom ( zoom ) ; } }
Move to see a given sector .
358
7
17,171
public void setFlatGlobe ( boolean doMercator ) { EarthFlat globe = new EarthFlat ( ) ; globe . setElevationModel ( new ZeroElevationModel ( ) ) ; wwd . getModel ( ) . setGlobe ( globe ) ; wwd . getView ( ) . stopMovement ( ) ; GeographicProjection projection ; if ( doMercator ) { projection = new ProjectionMercator ( ) ; } else { projection = new ProjectionEquirectangular ( ) ; } globe . setProjection ( projection ) ; wwd . redraw ( ) ; }
Set the globe as flat .
128
6
17,172
public void setSphereGlobe ( ) { Earth globe = new Earth ( ) ; wwd . getModel ( ) . setGlobe ( globe ) ; wwd . getView ( ) . stopMovement ( ) ; wwd . redraw ( ) ; }
Set the globe as sphere .
55
6
17,173
public void setFlatSphereGlobe ( ) { Earth globe = new Earth ( ) ; globe . setElevationModel ( new ZeroElevationModel ( ) ) ; wwd . getModel ( ) . setGlobe ( globe ) ; wwd . getView ( ) . stopMovement ( ) ; wwd . redraw ( ) ; }
Set the globe as flat sphere .
75
7
17,174
public List < Message > getFilteredList ( EMessageType messageType , Long fromTsMillis , Long toTsMillis , long limit ) throws Exception { String tableName = TABLE_MESSAGES ; String sql = "select " + getQueryFieldsString ( ) + " from " + tableName ; List < String > wheresList = new ArrayList <> ( ) ; if ( messageType != null && messageType != EMessageType . ALL ) { String where = type_NAME + "=" + messageType . getCode ( ) ; wheresList . add ( where ) ; } if ( fromTsMillis != null ) { String where = TimeStamp_NAME + ">" + fromTsMillis ; wheresList . add ( where ) ; } if ( toTsMillis != null ) { String where = TimeStamp_NAME + "<" + toTsMillis ; wheresList . add ( where ) ; } if ( wheresList . size ( ) > 0 ) { sql += " WHERE " ; for ( int i = 0 ; i < wheresList . size ( ) ; i ++ ) { if ( i > 0 ) { sql += " AND " ; } sql += wheresList . get ( i ) ; } } sql += " order by " + ID_NAME + " desc" ; if ( limit > 0 ) { sql += " limit " + limit ; } String _sql = sql ; List < Message > messages = new ArrayList < Message > ( ) ; logDb . execOnConnection ( connection -> { try ( IHMStatement stmt = connection . createStatement ( ) ; IHMResultSet rs = stmt . executeQuery ( _sql ) ; ) { while ( rs . next ( ) ) { Message event = resultSetToItem ( rs ) ; messages . add ( event ) ; } } return null ; } ) ; return messages ; }
Get the list of messages filtered .
403
7
17,175
@ Override public boolean accept ( File file ) { String name = file . getName ( ) ; if ( FilenameUtils . wildcardMatch ( name , wildcards , caseSensitivity ) ) { return true ; } return false ; }
Checks to see if the filename matches one of the wildcards .
51
14
17,176
public SimpleFeature convertDwgAttribute ( String typeName , String layerName , DwgAttrib attribute , int id ) { Point2D pto = attribute . getInsertionPoint ( ) ; Coordinate coord = new Coordinate ( pto . getX ( ) , pto . getY ( ) , attribute . getElevation ( ) ) ; String textString = attribute . getText ( ) ; return createPointTextFeature ( typeName , layerName , id , coord , textString ) ; }
Builds a point feature from a dwg attribute .
108
11
17,177
public SimpleFeature convertDwgPolyline2D ( String typeName , String layerName , DwgPolyline2D polyline2d , int id ) { Point2D [ ] ptos = polyline2d . getPts ( ) ; CoordinateList coordList = new CoordinateList ( ) ; if ( ptos != null ) { for ( int j = 0 ; j < ptos . length ; j ++ ) { Coordinate coord = new Coordinate ( ptos [ j ] . getX ( ) , ptos [ j ] . getY ( ) , 0.0 ) ; coordList . add ( coord ) ; } SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder ( ) ; b . setName ( typeName ) ; b . setCRS ( crs ) ; b . add ( THE_GEOM , LineString . class ) ; b . add ( LAYER , String . class ) ; SimpleFeatureType type = b . buildFeatureType ( ) ; SimpleFeatureBuilder builder = new SimpleFeatureBuilder ( type ) ; Geometry lineString = gF . createLineString ( coordList . toCoordinateArray ( ) ) ; Object [ ] values = new Object [ ] { lineString , layerName } ; builder . addAll ( values ) ; return builder . buildFeature ( typeName + "." + id ) ; } return null ; }
Builds a line feature from a dwg polyline 2D .
292
14
17,178
public SimpleFeature convertDwgPoint ( String typeName , String layerName , DwgPoint point , int id ) { double [ ] p = point . getPoint ( ) ; Point2D pto = new Point2D . Double ( p [ 0 ] , p [ 1 ] ) ; CoordinateList coordList = new CoordinateList ( ) ; Coordinate coord = new Coordinate ( pto . getX ( ) , pto . getY ( ) , 0.0 ) ; coordList . add ( coord ) ; SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder ( ) ; b . setName ( typeName ) ; b . setCRS ( crs ) ; b . add ( THE_GEOM , MultiPoint . class ) ; b . add ( LAYER , String . class ) ; SimpleFeatureType type = b . buildFeatureType ( ) ; SimpleFeatureBuilder builder = new SimpleFeatureBuilder ( type ) ; Geometry points = gF . createMultiPoint ( coordList . toCoordinateArray ( ) ) ; Object [ ] values = new Object [ ] { points , layerName } ; builder . addAll ( values ) ; return builder . buildFeature ( typeName + "." + id ) ; }
Builds a point feature from a dwg point .
261
11
17,179
public SimpleFeature convertDwgLine ( String typeName , String layerName , DwgLine line , int id ) { double [ ] p1 = line . getP1 ( ) ; double [ ] p2 = line . getP2 ( ) ; Point2D [ ] ptos = new Point2D [ ] { new Point2D . Double ( p1 [ 0 ] , p1 [ 1 ] ) , new Point2D . Double ( p2 [ 0 ] , p2 [ 1 ] ) } ; CoordinateList coordList = new CoordinateList ( ) ; for ( int j = 0 ; j < ptos . length ; j ++ ) { Coordinate coord = new Coordinate ( ptos [ j ] . getX ( ) , ptos [ j ] . getY ( ) , 0.0 ) ; coordList . add ( coord ) ; } SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder ( ) ; b . setName ( typeName ) ; b . setCRS ( crs ) ; b . add ( THE_GEOM , LineString . class ) ; b . add ( LAYER , String . class ) ; SimpleFeatureType type = b . buildFeatureType ( ) ; SimpleFeatureBuilder builder = new SimpleFeatureBuilder ( type ) ; Geometry lineString = gF . createLineString ( coordList . toCoordinateArray ( ) ) ; Object [ ] values = new Object [ ] { lineString , layerName } ; builder . addAll ( values ) ; return builder . buildFeature ( typeName + "." + id ) ; }
Builds a line feature from a dwg line .
336
11
17,180
public SimpleFeature convertDwgCircle ( String typeName , String layerName , DwgCircle circle , int id ) { double [ ] center = circle . getCenter ( ) ; double radius = circle . getRadius ( ) ; Point2D [ ] ptos = GisModelCurveCalculator . calculateGisModelCircle ( new Point2D . Double ( center [ 0 ] , center [ 1 ] ) , radius ) ; CoordinateList coordList = new CoordinateList ( ) ; for ( int j = 0 ; j < ptos . length ; j ++ ) { Coordinate coord = new Coordinate ( ptos [ j ] . getX ( ) , ptos [ j ] . getY ( ) , 0.0 ) ; coordList . add ( coord ) ; } // close to create a polygon if ( ( ptos [ ptos . length - 1 ] . getX ( ) != ptos [ 0 ] . getX ( ) ) || ( ptos [ ptos . length - 1 ] . getY ( ) != ptos [ 0 ] . getY ( ) ) ) { Coordinate coord = new Coordinate ( ptos [ 0 ] . getX ( ) , ptos [ 0 ] . getY ( ) , 0.0 ) ; coordList . add ( coord ) ; } SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder ( ) ; b . setName ( typeName ) ; b . setCRS ( crs ) ; b . add ( THE_GEOM , Polygon . class ) ; b . add ( LAYER , String . class ) ; SimpleFeatureType type = b . buildFeatureType ( ) ; SimpleFeatureBuilder builder = new SimpleFeatureBuilder ( type ) ; LinearRing linearRing = gF . createLinearRing ( coordList . toCoordinateArray ( ) ) ; Geometry polygon = gF . createPolygon ( linearRing , null ) ; Object [ ] values = new Object [ ] { polygon , layerName } ; builder . addAll ( values ) ; return builder . buildFeature ( typeName + "." + id ) ; }
Builds a polygon feature from a dwg circle .
453
12
17,181
public SimpleFeature convertDwgSolid ( String typeName , String layerName , DwgSolid solid , int id ) { double [ ] p1 = solid . getCorner1 ( ) ; double [ ] p2 = solid . getCorner2 ( ) ; double [ ] p3 = solid . getCorner3 ( ) ; double [ ] p4 = solid . getCorner4 ( ) ; Point2D [ ] ptos = new Point2D [ ] { new Point2D . Double ( p1 [ 0 ] , p1 [ 1 ] ) , new Point2D . Double ( p2 [ 0 ] , p2 [ 1 ] ) , new Point2D . Double ( p3 [ 0 ] , p3 [ 1 ] ) , new Point2D . Double ( p4 [ 0 ] , p4 [ 1 ] ) } ; CoordinateList coordList = new CoordinateList ( ) ; for ( int j = 0 ; j < ptos . length ; j ++ ) { Coordinate coord = new Coordinate ( ptos [ j ] . getX ( ) , ptos [ j ] . getY ( ) ) ; coordList . add ( coord ) ; } coordList . closeRing ( ) ; SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder ( ) ; b . setName ( typeName ) ; b . setCRS ( crs ) ; b . add ( THE_GEOM , Polygon . class ) ; b . add ( LAYER , String . class ) ; SimpleFeatureType type = b . buildFeatureType ( ) ; SimpleFeatureBuilder builder = new SimpleFeatureBuilder ( type ) ; LinearRing linearRing = gF . createLinearRing ( coordList . toCoordinateArray ( ) ) ; Geometry polygon = gF . createPolygon ( linearRing , null ) ; Object [ ] values = new Object [ ] { polygon , layerName } ; builder . addAll ( values ) ; return builder . buildFeature ( typeName + "." + id ) ; }
Builds a polygon feature from a dwg solid .
431
12
17,182
public SimpleFeature convertDwgArc ( String typeName , String layerName , DwgArc arc , int id ) { double [ ] c = arc . getCenter ( ) ; Point2D center = new Point2D . Double ( c [ 0 ] , c [ 1 ] ) ; double radius = ( arc ) . getRadius ( ) ; double initAngle = Math . toDegrees ( ( arc ) . getInitAngle ( ) ) ; double endAngle = Math . toDegrees ( ( arc ) . getEndAngle ( ) ) ; Point2D [ ] ptos = GisModelCurveCalculator . calculateGisModelArc ( center , radius , initAngle , endAngle ) ; CoordinateList coordList = new CoordinateList ( ) ; for ( int j = 0 ; j < ptos . length ; j ++ ) { Coordinate coord = new Coordinate ( ptos [ j ] . getX ( ) , ptos [ j ] . getY ( ) , 0.0 ) ; coordList . add ( coord ) ; } SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder ( ) ; b . setName ( typeName ) ; b . setCRS ( crs ) ; b . add ( THE_GEOM , LineString . class ) ; b . add ( LAYER , String . class ) ; SimpleFeatureType type = b . buildFeatureType ( ) ; SimpleFeatureBuilder builder = new SimpleFeatureBuilder ( type ) ; Geometry lineString = gF . createLineString ( coordList . toCoordinateArray ( ) ) ; Object [ ] values = new Object [ ] { lineString , layerName } ; builder . addAll ( values ) ; return builder . buildFeature ( typeName + "." + id ) ; }
Builds a line feature from a dwg arc .
384
11
17,183
public static double norm_vec ( double x , double y , double z ) { return Math . sqrt ( x * x + y * y + z * z ) ; }
Normalized Vector .
37
4
17,184
public static double lag1 ( double [ ] vals ) { double mean = mean ( vals ) ; int size = vals . length ; double r1 ; double q = 0 ; double v = ( vals [ 0 ] - mean ) * ( vals [ 0 ] - mean ) ; for ( int i = 1 ; i < size ; i ++ ) { double delta0 = ( vals [ i - 1 ] - mean ) ; double delta1 = ( vals [ i ] - mean ) ; q += ( delta0 * delta1 - q ) / ( i + 1 ) ; v += ( delta1 * delta1 - v ) / ( i + 1 ) ; } r1 = q / v ; return r1 ; }
Returns the lag - 1 autocorrelation of a dataset ;
156
13
17,185
public static double round ( double val , int places ) { long factor = ( long ) Math . pow ( 10 , places ) ; // Shift the decimal the correct number of places // to the right. val = val * factor ; // Round to the nearest integer. long tmp = Math . round ( val ) ; // Shift the decimal the correct number of places // back to the left. return ( double ) tmp / factor ; }
Round a double value to a specified number of decimal places .
88
12
17,186
public static double random ( double min , double max ) { assert max > min ; return min + Math . random ( ) * ( max - min ) ; }
Generate a random number in a range .
33
9
17,187
private boolean checkStructure ( ) { File ds ; ds = new File ( mapsetPath + File . separator + GrassLegacyConstans . CATS + File . separator ) ; if ( ! ds . exists ( ) ) if ( ! ds . mkdir ( ) ) return false ; ds = new File ( mapsetPath + File . separator + GrassLegacyConstans . CELL + File . separator ) ; if ( ! ds . exists ( ) ) if ( ! ds . mkdir ( ) ) return false ; ds = new File ( mapsetPath + File . separator + GrassLegacyConstans . CELL_MISC + File . separator ) ; if ( ! ds . exists ( ) ) if ( ! ds . mkdir ( ) ) return false ; ds = new File ( mapsetPath + File . separator + GrassLegacyConstans . CELL_MISC + File . separator + name ) ; if ( ! ds . exists ( ) ) if ( ! ds . mkdir ( ) ) return false ; ds = new File ( mapsetPath + File . separator + GrassLegacyConstans . FCELL + File . separator ) ; if ( ! ds . exists ( ) ) if ( ! ds . mkdir ( ) ) return false ; ds = new File ( mapsetPath + File . separator + GrassLegacyConstans . CELLHD + File . separator ) ; if ( ! ds . exists ( ) ) if ( ! ds . mkdir ( ) ) return false ; ds = new File ( mapsetPath + File . separator + GrassLegacyConstans . COLR + File . separator ) ; if ( ! ds . exists ( ) ) if ( ! ds . mkdir ( ) ) return false ; ds = new File ( mapsetPath + File . separator + GrassLegacyConstans . HIST + File . separator ) ; if ( ! ds . exists ( ) ) if ( ! ds . mkdir ( ) ) return false ; return true ; }
check if the needed folders are there ( they could be missing if the mapset has just been created and this is the first file that gets into it
458
30
17,188
private boolean createEmptyHeader ( String filePath , int rows ) { try { RandomAccessFile theCreatedFile = new RandomAccessFile ( filePath , "rw" ) ; rowaddresses = new long [ rows + 1 ] ; // the size of a long theCreatedFile . write ( 4 ) ; // write the addresses of the row begins. Since we don't know how // much // they will be compressed, they will be filled after the // compression for ( int i = 0 ; i < rows + 1 ; i ++ ) { theCreatedFile . writeInt ( 0 ) ; } pointerInFilePosition = theCreatedFile . getFilePointer ( ) ; rowaddresses [ 0 ] = pointerInFilePosition ; theCreatedFile . close ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; return false ; } return true ; }
creates the space for the header of the rasterfile filling the spaces with zeroes . After the compression the values will be rewritten
182
28
17,189
private void createCellhd ( int chproj , int chzone , double chn , double chs , double che , double chw , int chcols , int chrows , double chnsres , double chewres , int chformat , int chcompressed ) throws Exception { StringBuffer data = new StringBuffer ( 512 ) ; data . append ( "proj: " + chproj + "\n" ) . append ( "zone: " + chzone + "\n" ) . append ( "north: " + chn + "\n" ) . append ( "south: " + chs + "\n" ) . append ( "east: " + che + "\n" ) . append ( "west: " + chw + "\n" ) . append ( "cols: " + chcols + "\n" ) . append ( "rows: " + chrows + "\n" ) . append ( "n-s resol: " + chnsres + "\n" ) . append ( "e-w resol: " + chewres + "\n" ) . append ( "format: " + chformat + "\n" ) . append ( "compressed: " + chcompressed ) ; File ds = new File ( mapsetPath + File . separator + GrassLegacyConstans . CELLHD + File . separator + name ) ; OutputStreamWriter windFile = new OutputStreamWriter ( new FileOutputStream ( ds ) ) ; windFile . write ( data . toString ( ) ) ; windFile . close ( ) ; }
changes the cellhd file inserting the new values obtained from the environment
339
13
17,190
public boolean compressAndWriteObj ( RandomAccessFile theCreatedFile , RandomAccessFile theCreatedNullFile , Object dataObject ) throws RasterWritingFailureException { if ( dataObject instanceof double [ ] [ ] ) { compressAndWrite ( theCreatedFile , theCreatedNullFile , ( double [ ] [ ] ) dataObject ) ; } else { throw new RasterWritingFailureException ( "Raster type not supported." ) ; }
Passing the object after defining the type of data that will be written
91
14
17,191
public String getStyle ( StyleType type , Color color , String colorName , String layerName ) { throw new UnsupportedOperationException ( ) ; }
Generates a style from a template using the provided substitutions .
31
13
17,192
protected Reader toReader ( Object input ) throws IOException { if ( input instanceof Reader ) { return ( Reader ) input ; } if ( input instanceof InputStream ) { return new InputStreamReader ( ( InputStream ) input ) ; } if ( input instanceof String ) { return new StringReader ( ( String ) input ) ; } if ( input instanceof URL ) { return new InputStreamReader ( ( ( URL ) input ) . openStream ( ) ) ; } if ( input instanceof File ) { return new FileReader ( ( File ) input ) ; } throw new IllegalArgumentException ( "Unable to turn " + input + " into reader" ) ; }
Turns input into a Reader .
141
7
17,193
public static boolean supportsNative ( ) { if ( ! testedLibLoading ) { LiblasJNALibrary wrapper = LiblasWrapper . getWrapper ( ) ; if ( wrapper != null ) { isNativeLibAvailable = true ; } testedLibLoading = true ; } return isNativeLibAvailable ; }
Checks of nativ libs are available .
64
10
17,194
public static ALasReader getReader ( File lasFile , CoordinateReferenceSystem crs ) throws Exception { if ( supportsNative ( ) ) { return new LiblasReader ( lasFile , crs ) ; } else { return new LasReaderBuffered ( lasFile , crs ) ; } }
Get a las reader .
62
5
17,195
public static ALasWriter getWriter ( File lasFile , CoordinateReferenceSystem crs ) throws Exception { if ( supportsNative ( ) ) { return new LiblasWriter ( lasFile , crs ) ; } else { return new LasWriterBuffered ( lasFile , crs ) ; } }
Get a las writer .
62
5
17,196
public void setRoot ( DbLevel v ) { DbLevel oldRoot = v ; root = v ; fireTreeStructureChanged ( oldRoot ) ; }
Sets the root to a given variable .
34
9
17,197
public void onError ( Exception e ) { e . printStackTrace ( ) ; String localizedMessage = e . getLocalizedMessage ( ) ; if ( localizedMessage == null ) { localizedMessage = e . getMessage ( ) ; } if ( localizedMessage == null || localizedMessage . trim ( ) . length ( ) == 0 ) { localizedMessage = "An undefined error was thrown. Please send the below trace to your technical contact:\n" ; localizedMessage += ExceptionUtils . getStackTrace ( e ) ; } String _localizedMessage = localizedMessage ; SwingUtilities . invokeLater ( new Runnable ( ) { public void run ( ) { JOptionPane . showMessageDialog ( parent , _localizedMessage , "ERROR" , JOptionPane . ERROR_MESSAGE ) ; } } ) ; }
Called if an error occurrs . Can be overridden . SHows dialog by default .
177
19
17,198
public static boolean tcaMax ( FlowNode flowNode , RandomIter tcaIter , RandomIter hacklengthIter , double maxTca , double maxDistance ) { List < FlowNode > enteringNodes = flowNode . getEnteringNodes ( ) ; for ( Node node : enteringNodes ) { double tca = node . getValueFromMap ( tcaIter ) ; if ( tca >= maxTca ) { if ( NumericsUtilities . dEq ( tca , maxTca ) ) { if ( node . getValueFromMap ( hacklengthIter ) > maxDistance ) return false ; } else return false ; } } return true ; }
Compare two value of tca and distance .
142
9
17,199
public static boolean isCircularBoundary ( CompoundLocation < Location > location , long sequenceLength ) { if ( location . getLocations ( ) . size ( ) == 1 ) { return false ; // cant be if there is only 1 location element } boolean lastLocation = false ; List < Location > locationList = location . getLocations ( ) ; for ( int i = 0 ; i < locationList . size ( ) ; i ++ ) { if ( i == locationList . size ( ) - 1 ) { lastLocation = true ; } Long position = location . getLocations ( ) . get ( i ) . getEndPosition ( ) ; if ( position == sequenceLength && ! lastLocation ) { return true ; } } return false ; }
Checks to see if a feature s location spans a circular boundary - assumes the genome the feature is coming from is circular .
157
25