Mercurial > dive4elements > gnv-client
comparison geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/ArcSDEStatement.java @ 544:33f93898cbbf
Added RasterObject for caching the Rastertiles to get a better performance
geo-backend/trunk@508 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Tue, 05 Jan 2010 14:09:53 +0000 |
parents | fac02bf1c685 |
children | 210716612c30 |
comparison
equal
deleted
inserted
replaced
543:fac02bf1c685 | 544:33f93898cbbf |
---|---|
6 import java.sql.Connection; | 6 import java.sql.Connection; |
7 import java.sql.ResultSet; | 7 import java.sql.ResultSet; |
8 import java.sql.SQLException; | 8 import java.sql.SQLException; |
9 import java.sql.SQLWarning; | 9 import java.sql.SQLWarning; |
10 import java.sql.Statement; | 10 import java.sql.Statement; |
11 import java.util.HashMap; | |
12 import java.util.Vector; | |
13 | 11 |
14 import org.apache.log4j.Logger; | 12 import org.apache.log4j.Logger; |
15 | 13 |
16 import com.esri.sde.sdk.client.SDEPoint; | 14 import com.esri.sde.sdk.client.SDEPoint; |
17 import com.esri.sde.sdk.client.SeColumnDefinition; | 15 import com.esri.sde.sdk.client.SeColumnDefinition; |
18 import com.esri.sde.sdk.client.SeConnection; | 16 import com.esri.sde.sdk.client.SeConnection; |
19 import com.esri.sde.sdk.client.SeException; | 17 import com.esri.sde.sdk.client.SeException; |
20 import com.esri.sde.sdk.client.SeExtent; | 18 import com.esri.sde.sdk.client.SeExtent; |
21 import com.esri.sde.sdk.client.SeFilter; | 19 import com.esri.sde.sdk.client.SeFilter; |
22 import com.esri.sde.sdk.client.SeLayer; | 20 import com.esri.sde.sdk.client.SeLayer; |
23 import com.esri.sde.sdk.client.SeObjectId; | |
24 import com.esri.sde.sdk.client.SeQuery; | 21 import com.esri.sde.sdk.client.SeQuery; |
25 import com.esri.sde.sdk.client.SeQueryInfo; | 22 import com.esri.sde.sdk.client.SeQueryInfo; |
26 import com.esri.sde.sdk.client.SeRaster; | 23 import com.esri.sde.sdk.client.SeRaster; |
27 import com.esri.sde.sdk.client.SeRasterAttr; | 24 import com.esri.sde.sdk.client.SeRasterAttr; |
28 import com.esri.sde.sdk.client.SeRasterBand; | 25 import com.esri.sde.sdk.client.SeRasterBand; |
29 import com.esri.sde.sdk.client.SeRasterColumn; | |
30 import com.esri.sde.sdk.client.SeRasterConstraint; | 26 import com.esri.sde.sdk.client.SeRasterConstraint; |
31 import com.esri.sde.sdk.client.SeRasterTile; | 27 import com.esri.sde.sdk.client.SeRasterTile; |
32 import com.esri.sde.sdk.client.SeRow; | 28 import com.esri.sde.sdk.client.SeRow; |
33 import com.esri.sde.sdk.client.SeShape; | 29 import com.esri.sde.sdk.client.SeShape; |
34 import com.esri.sde.sdk.client.SeShapeFilter; | 30 import com.esri.sde.sdk.client.SeShapeFilter; |
35 import com.esri.sde.sdk.client.SeSqlConstruct; | 31 import com.esri.sde.sdk.client.SeSqlConstruct; |
32 import com.vividsolutions.jts.geom.Coordinate; | |
33 import com.vividsolutions.jts.geom.Envelope; | |
36 import com.vividsolutions.jts.geom.Geometry; | 34 import com.vividsolutions.jts.geom.Geometry; |
37 import com.vividsolutions.jts.geom.Point; | 35 import com.vividsolutions.jts.geom.Point; |
38 import com.vividsolutions.jts.geom.Polygon; | 36 import com.vividsolutions.jts.geom.Polygon; |
39 import com.vividsolutions.jts.io.WKTReader; | 37 import com.vividsolutions.jts.io.WKTReader; |
40 | 38 |
47 | 45 |
48 /** | 46 /** |
49 * the logger, used to log exceptions and additonaly information | 47 * the logger, used to log exceptions and additonaly information |
50 */ | 48 */ |
51 private static Logger log = Logger.getLogger(ArcSDEStatement.class); | 49 private static Logger log = Logger.getLogger(ArcSDEStatement.class); |
52 | |
53 private static HashMap<String, double[]> tiles = new HashMap<String, double[]>(); | |
54 | |
55 private static SeRasterBand rasterBand = null; | |
56 | 50 |
57 private ArcSDEConnection connection = null; | 51 private ArcSDEConnection connection = null; |
58 | 52 |
59 /** | 53 /** |
60 * Constructor | 54 * Constructor |
512 lSet.addRow(lBackingRow); | 506 lSet.addRow(lBackingRow); |
513 } | 507 } |
514 }else{ | 508 }else{ |
515 try { | 509 try { |
516 | 510 |
517 if (rasterBand == null){ | 511 int rasterSize = 128; |
518 pSeQuery.execute(); | 512 pSeQuery.execute(); |
519 row = pSeQuery.fetch(); | 513 row = pSeQuery.fetch(); |
520 SeRasterAttr attr = row.getRaster(0); | 514 SeRasterAttr attr = row.getRaster(0); |
521 SeRaster raster = attr.getRasterInfo(); | 515 SeRaster raster = attr.getRasterInfo(); |
522 SeRasterBand[] bands = raster.getBands(); | 516 SeRasterBand[] bands = raster.getBands(); |
523 rasterBand = bands[0]; | 517 SeRasterBand rasterBand = bands[0]; |
524 } | 518 |
525 | 519 |
526 int height = rasterBand.getBandHeight(); | 520 int height = rasterBand.getBandHeight(); |
527 int width = rasterBand.getBandWidth(); | 521 int width = rasterBand.getBandWidth(); |
528 | 522 |
529 SeExtent extent = rasterBand.getExtent(); | 523 SeExtent extent = rasterBand.getExtent(); |
551 log.debug("BAND-ID "+rasterBand.getId().longValue()); | 545 log.debug("BAND-ID "+rasterBand.getId().longValue()); |
552 int maxLevel = 0; | 546 int maxLevel = 0; |
553 log.debug("Maxlevel: "+maxLevel); | 547 log.debug("Maxlevel: "+maxLevel); |
554 | 548 |
555 if (isPointInRaster){ | 549 if (isPointInRaster){ |
556 int columnIndex = pixelX / 128; | 550 |
557 int rowIndex = pixelY / 128; | 551 if (row == null){ |
558 String tileKey = columnIndex + "/"+ rowIndex; | 552 pSeQuery.execute(); |
553 row = pSeQuery.fetch(); | |
554 } | |
555 SeRasterConstraint constraint = new SeRasterConstraint(); | |
556 constraint.setLevel(maxLevel); | |
557 constraint.setBands(bandNumber); | |
558 constraint.setEnvelope(pixelX / rasterSize, pixelY / rasterSize, pixelX / rasterSize, pixelY / rasterSize); | |
559 pSeQuery.queryRasterTile(constraint); | |
560 SeRasterTile tile = row.getRasterTile(); | |
559 | 561 |
560 double[] tileValues = tiles.get(tileKey); | 562 if(tile != null){ |
561 if (tileValues == null){ | 563 log.debug("BAND-ID Tile "+tile.getBandId().longValue()); |
562 if (row == null){ | 564 log.debug("Pixel "+ tile.getNumPixels()); |
563 pSeQuery.execute(); | 565 log.debug("Column / Row "+tile.getColumnIndex()+" / "+tile.getRowIndex()); |
564 row = pSeQuery.fetch(); | 566 |
565 } | 567 |
566 SeRasterConstraint constraint = new SeRasterConstraint(); | 568 double[] tileValues = new double[tile.getNumPixels()]; |
567 constraint.setLevel(maxLevel); | 569 tileValues = tile.getPixels(tileValues); |
568 constraint.setBands(bandNumber); | 570 lSet.addCol(new ColDefinition("tile",ColDefinition.FLOAT64)); |
569 constraint.setEnvelope(pixelX / 128, pixelY / 128, pixelX / 128, pixelY / 128); | 571 Row lBackingRow = new Row(1); |
570 pSeQuery.queryRasterTile(constraint); | 572 Envelope envelope = new Envelope( |
571 SeRasterTile tile = row.getRasterTile(); | 573 new Coordinate(extent.getMinX(), |
572 | 574 extent.getMinY()), |
573 if(tile != null){ | 575 new Coordinate(extent.getMaxX(), |
574 log.debug("BAND-ID Tile "+tile.getBandId().longValue()); | 576 extent.getMaxY())); |
575 log.debug("Pixel "+ tile.getNumPixels()); | 577 RasterObject ro = new RasterObject(envelope, |
576 log.debug("Column / Row "+tile.getColumnIndex()+" / "+tile.getRowIndex()); | 578 tileValues, |
577 int localPixelX = pixelX - (tile.getColumnIndex()*128); | 579 rasterSize, |
578 int localPixelY = pixelY - (tile.getRowIndex()*128); | 580 tile.getRowIndex(), |
579 int pos = localPixelY*128 +localPixelX; | 581 tile.getColumnIndex(), |
580 if (pos < tile.getNumPixels()){ | 582 width, |
581 tileValues = new double[tile.getNumPixels()]; | 583 height); |
582 tileValues = tile.getPixels(tileValues); | 584 lBackingRow.addObject(ro,0); |
583 this.tiles.put(tileKey, tileValues); | 585 lSet.addRow(lBackingRow); |
584 | 586 } |
585 } | |
586 } | |
587 }else{ | |
588 log.debug("Tile kommt aus dem Cache."); | |
589 } | |
590 | 587 |
591 int localPixelX = pixelX - (columnIndex*128); | |
592 int localPixelY = pixelY - (rowIndex*128); | |
593 int pos = localPixelY*128 +localPixelX; | |
594 lSet.addCol(new ColDefinition("height",ColDefinition.FLOAT64)); | |
595 Row lBackingRow = new Row(1); | |
596 lBackingRow.addObject(tileValues[pos], 0); | |
597 lSet.addRow(lBackingRow); | |
598 }else{ | 588 }else{ |
599 log.debug("The Query doesn't deliver any Information because the Point is located outside the Raster."); | 589 log.debug("The Query doesn't deliver any Information because the Point is located outside the Raster."); |
600 } | 590 } |
601 } catch (Exception e) { | 591 } catch (Exception e) { |
602 log.error(e,e); | 592 log.error(e,e); |