Revision 8780

View differences:

org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster.bingmaps/org.gvsig.raster.bingmaps.provider.legend/src/main/java/org/gvsig/raster/bingmaps/provider/legend/BingMapsRasterGetColorInterpretation.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2016 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23

  
24
package org.gvsig.raster.bingmaps.provider.legend;
25

  
26
import org.slf4j.LoggerFactory;
27

  
28
import org.gvsig.fmap.dal.raster.api.RasterStore;
29
import org.gvsig.raster.lib.legend.api.RasterLegendLocator;
30
import org.gvsig.raster.lib.legend.api.RasterLegendManager;
31
import org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation;
32
import org.gvsig.tools.ToolsLocator;
33
import org.gvsig.tools.dynobject.DynClass;
34
import org.gvsig.tools.dynobject.DynMethod;
35
import org.gvsig.tools.dynobject.DynObject;
36
import org.gvsig.tools.dynobject.exception.DynMethodException;
37
import org.gvsig.tools.dynobject.exception.DynMethodNotSupportedException;
38

  
39
/**
40
 * @author dmartinezizquierdo
41
 *
42
 */
43
public class BingMapsRasterGetColorInterpretation implements DynMethod {
44

  
45
    final static private org.slf4j.Logger logger = LoggerFactory.getLogger(BingMapsRasterGetColorInterpretation.class);
46

  
47
    private static Integer code = null;
48

  
49
    static void register(DynClass storeClass) {
50
        if (code != null) {
51
            return;
52
        }
53
        code =
54
            ToolsLocator.getDynObjectManager()
55
                .registerDynMethod(storeClass, new BingMapsRasterGetColorInterpretation());
56

  
57
    }
58

  
59
    @Override
60
    public int getCode() throws DynMethodNotSupportedException {
61
        return code;
62
    }
63

  
64
    @Override
65
    public String getDescription() {
66
        return "BingMaps Color Interpretation";
67
    }
68

  
69
    @Override
70
    public String getName() {
71
        return RasterStore.DYNMETHOD_GETCOLORINTERPRETATION_NAME;
72
    }
73

  
74
    @Override
75
    public Object invoke(DynObject self, Object[] args) throws DynMethodException {
76
        ColorInterpretation colorInterpretation = null;
77

  
78
        RasterLegendManager legendManager = RasterLegendLocator.getRasterLegendManager();
79

  
80
        colorInterpretation = legendManager.createColorInterpretation(ColorInterpretation.RGB);
81

  
82
        return colorInterpretation;
83
    }
84

  
85
    @Override
86
    public Object clone() throws CloneNotSupportedException {
87
        return super.clone();
88
    }
89
}
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster.bingmaps/org.gvsig.raster.bingmaps.provider.legend/src/main/java/org/gvsig/raster/bingmaps/provider/legend/BingMapsRasterGetColorTable.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2016 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23

  
24
package org.gvsig.raster.bingmaps.provider.legend;
25

  
26

  
27
import java.awt.Color;
28
import java.util.ArrayList;
29
import java.util.List;
30

  
31
import org.slf4j.LoggerFactory;
32

  
33
import org.gvsig.fmap.dal.raster.api.RasterStore;
34
import org.gvsig.raster.bingmaps.provider.BingMapsRasterProvider;
35
import org.gvsig.raster.lib.legend.api.RasterLegendLocator;
36
import org.gvsig.raster.lib.legend.api.RasterLegendManager;
37
import org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation;
38
import org.gvsig.raster.lib.legend.api.colortable.ColorTable;
39
import org.gvsig.raster.lib.legend.api.colortable.colortableclass.ColorTableClass;
40
import org.gvsig.tools.ToolsLocator;
41
import org.gvsig.tools.dynobject.DynClass;
42
import org.gvsig.tools.dynobject.DynMethod;
43
import org.gvsig.tools.dynobject.DynObject;
44
import org.gvsig.tools.dynobject.exception.DynMethodException;
45
import org.gvsig.tools.dynobject.exception.DynMethodNotSupportedException;
46

  
47
/**
48
 * Dynamic method to add a get Color Table funcionality
49
 * @author dmartinezizquierdo
50
 *
51
 */
52
public class BingMapsRasterGetColorTable implements DynMethod {
53

  
54
    final static private org.slf4j.Logger logger = LoggerFactory.getLogger(BingMapsRasterGetColorInterpretation.class);
55

  
56
    private static Integer code = null;
57

  
58
    static void register(DynClass storeClass) {
59
        if (code != null) {
60
            return;
61
        }
62
        code = ToolsLocator.getDynObjectManager()
63
                .registerDynMethod(storeClass, new BingMapsRasterGetColorTable());
64

  
65
    }
66

  
67
    @Override
68
    public int getCode() throws DynMethodNotSupportedException {
69
        return code;
70
    }
71

  
72
    @Override
73
    public String getDescription() {
74
        return "BingMaps Color Table";
75
    }
76

  
77
    @Override
78
    public String getName() {
79
        return RasterStore.DYNMETHOD_GETCOLORTABLE_NAME;
80
    }
81

  
82
    @Override
83
    public Object invoke(DynObject self, Object[] args)
84
        throws DynMethodException {
85
        RasterLegendManager rasterLegendManager = RasterLegendLocator.getRasterLegendManager();
86

  
87
        BingMapsRasterProvider provider = (BingMapsRasterProvider)self;
88

  
89
        ColorInterpretation colorInterpretation =(ColorInterpretation)provider.
90
            invokeDynMethod(RasterStore.DYNMETHOD_GETCOLORINTERPRETATION_NAME, null);
91

  
92
        if ( !( colorInterpretation.isBGR() || colorInterpretation.isRGB() || colorInterpretation.isRGBA() ) ){
93
            ColorTable colorTable;
94

  
95
            //FIXME:
96
            List<ColorTableClass> colorTableClasses=new ArrayList<ColorTableClass>();
97
            double[] minMax={0d,255d}; //new double[2];
98

  
99
            Double increment=1.0;
100

  
101
            for (int i=0;i<=255;i++){
102
                String className=i+"";
103
                double value=((minMax[0]+(i*increment)));
104
                double interpolation=50.0;
105
                int intARGB = ((i & 0xFF) << 24) | // alpha
106
                    ((i & 0xFF) << 16) | // red
107
                    ((i & 0xFF) << 8) | // green
108
                    ((i & 0xFF) << 0); // blue
109
                Color color=new Color(intARGB);
110
                ColorTableClass colorTableClass = rasterLegendManager.createColorTableClass(className, value, interpolation, color);
111
                colorTableClasses.add(colorTableClass);
112
            }
113
            colorTable = rasterLegendManager.createColorTable(BingMapsRasterProvider.NAME+"_color_table",
114
                colorTableClasses, true);
115

  
116
            return colorTable;
117
        }
118

  
119
        return null;
120

  
121
    }
122

  
123
    @Override
124
    public Object clone() throws CloneNotSupportedException {
125
        return super.clone();
126
    }
127
}
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster.bingmaps/org.gvsig.raster.bingmaps.provider.legend/src/main/java/org/gvsig/raster/bingmaps/provider/legend/BingMapsRasterGetLegend.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2016 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23

  
24
package org.gvsig.raster.bingmaps.provider.legend;
25

  
26

  
27
import org.slf4j.LoggerFactory;
28

  
29
import org.gvsig.fmap.dal.raster.api.RasterStore;
30
import org.gvsig.raster.bingmaps.provider.BingMapsRasterProvider;
31
import org.gvsig.raster.lib.legend.api.RasterLegend;
32
import org.gvsig.raster.lib.legend.api.RasterLegendLocator;
33
import org.gvsig.raster.lib.legend.api.RasterLegendManager;
34
import org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation;
35
import org.gvsig.tools.ToolsLocator;
36
import org.gvsig.tools.dynobject.DynClass;
37
import org.gvsig.tools.dynobject.DynMethod;
38
import org.gvsig.tools.dynobject.DynObject;
39
import org.gvsig.tools.dynobject.exception.DynMethodException;
40
import org.gvsig.tools.dynobject.exception.DynMethodNotSupportedException;
41

  
42
/**
43
 * Dynamic method to add a get Legend funcionality
44
 * @author dmartinezizquierdo
45
 *
46
 */
47
public class BingMapsRasterGetLegend implements DynMethod {
48

  
49
    final static private org.slf4j.Logger logger = LoggerFactory.getLogger(BingMapsRasterGetLegend.class);
50

  
51
    private static Integer code = null;
52

  
53

  
54
    static void register(DynClass storeClass) {
55
        if (code != null) {
56
            return;
57
        }
58
        code = ToolsLocator.getDynObjectManager()
59
                .registerDynMethod(storeClass, new BingMapsRasterGetLegend());
60

  
61
    }
62

  
63
    @Override
64
    public int getCode() throws DynMethodNotSupportedException {
65
        return code;
66
    }
67

  
68
    @Override
69
    public String getDescription() {
70
        return "Tile Cache Legend";
71
    }
72

  
73
    @Override
74
    public String getName() {
75
        return RasterStore.DYNMETHOD_GETLEGEND_NAME;
76
    }
77

  
78
    @Override
79
    public Object invoke(DynObject self, Object[] args) throws DynMethodException {
80
        RasterLegend legend = null;
81

  
82
        BingMapsRasterProvider provider = (BingMapsRasterProvider) self;
83
        RasterLegendManager legendManager=RasterLegendLocator.getRasterLegendManager();
84

  
85
        ColorInterpretation colorInterpretation =(ColorInterpretation)provider.
86
            invokeDynMethod(RasterStore.DYNMETHOD_GETCOLORINTERPRETATION_NAME, null);
87

  
88
        legend= legendManager.createLegend(colorInterpretation);
89

  
90
        return legend;
91
    }
92

  
93
    @Override
94
    public Object clone() throws CloneNotSupportedException {
95
        return super.clone();
96
    }
97
}
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster.bingmaps/org.gvsig.raster.bingmaps.provider.legend/src/main/java/org/gvsig/raster/bingmaps/provider/legend/BingMapsRasterLegendLibrary.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2016 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23

  
24
package org.gvsig.raster.bingmaps.provider.legend;
25

  
26
import org.gvsig.fmap.dal.DALLibrary;
27
import org.gvsig.metadata.MetadataLibrary;
28
import org.gvsig.metadata.MetadataLocator;
29
import org.gvsig.raster.bingmaps.provider.BingMapsRasterLibrary;
30
import org.gvsig.raster.bingmaps.provider.BingMapsRasterProvider;
31
import org.gvsig.tools.dynobject.DynClass;
32
import org.gvsig.tools.library.AbstractLibrary;
33
import org.gvsig.tools.library.LibraryException;
34

  
35
/**
36
 * @author dmartinez
37
 *
38
 */
39
public class BingMapsRasterLegendLibrary extends AbstractLibrary {
40

  
41
    @Override
42
    public void doRegistration() {
43
        registerAsServiceOf(DALLibrary.class);
44
        require(BingMapsRasterLibrary.class);
45
        require(MetadataLibrary.class);
46
        require(DALLibrary.class);
47
    }
48

  
49
	@Override
50
	protected void doInitialize() throws LibraryException {
51
	}
52

  
53
	@Override
54
	protected void doPostInitialize() throws LibraryException {
55
		DynClass metadataDefinition = (DynClass) MetadataLocator.getMetadataManager()
56
			.getDefinition(BingMapsRasterProvider.METADATA_DEFINITION_NAME);
57
		BingMapsRasterGetLegend.register(metadataDefinition);
58
		BingMapsRasterGetColorInterpretation.register(metadataDefinition);
59
	}
60
}
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster.bingmaps/org.gvsig.raster.bingmaps.provider.legend/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.raster.bingmaps.provider.legend.BingMapsRasterLegendLibrary
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster.bingmaps/org.gvsig.raster.bingmaps.provider.legend/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
  <modelVersion>4.0.0</modelVersion>
3
  <parent>
4
    <groupId>org.gvsig</groupId>
5
    <artifactId>org.gvsig.raster.bingmaps</artifactId>
6
    <version>2.4.1-SNAPSHOT</version>
7
  </parent>
8
  <artifactId>org.gvsig.raster.bingmaps.provider.legend</artifactId>
9
  <name>org.gvsig.raster.bingmaps.provider.legend</name>
10
  <dependencies>
11
    <dependency>
12
      <groupId>org.gvsig</groupId>
13
      <artifactId>org.gvsig.raster.lib.legend.api</artifactId>
14
    </dependency>
15
    <dependency>
16
      <groupId>org.gvsig</groupId>
17
      <artifactId>org.gvsig.raster.bingmaps.provider</artifactId>
18
    </dependency>
19
    <dependency>
20
      <groupId>org.gvsig</groupId>
21
      <artifactId>org.gvsig.fmap.dal.raster.spi</artifactId>
22
    </dependency>
23
  </dependencies>
24
</project>
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster.bingmaps/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3
  <modelVersion>4.0.0</modelVersion>
4
  <parent>
5
    <groupId>org.gvsig</groupId>
6
    <artifactId>org.gvsig.desktop</artifactId>
7
    <version>2.0.218-SNAPSHOT</version>
8
  </parent>
9
  <artifactId>org.gvsig.raster.bingmaps</artifactId>
10
  <packaging>pom</packaging>
11
  <name>org.gvsig.raster.bingmaps</name>
12
  <version>2.4.1-SNAPSHOT</version>
13
  <dependencies>
14
  </dependencies>
15
  <groupId>org.gvsig</groupId>
16

  
17
  <scm>
18
    <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-rasterXXX/org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster</connection>
19
    <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-rasterXXX/org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster</developerConnection>
20
    <url>https://devel.gvsig.org/redmine/projects/gvsig-rasterXXX/repository/show/org.gvsig.raster/trunk/org.gvsig.raster</url>
21
  </scm>
22

  
23
   <repositories>
24
  <repository>
25
   <id>gvsig-public-http-repository</id>
26
   <name>gvSIG maven public HTTP repository</name>
27
   <url>http://devel.gvsig.org/m2repo/j2se</url>
28
   <releases>
29
    <enabled>true</enabled>
30
    <updatePolicy>daily</updatePolicy>
31
    <checksumPolicy>warn</checksumPolicy>
32
   </releases>
33
   <snapshots>
34
    <enabled>true</enabled>
35
    <updatePolicy>daily</updatePolicy>
36
    <checksumPolicy>warn</checksumPolicy>
37
   </snapshots>
38
  </repository>
39
 </repositories>
40

  
41

  
42
  <distributionManagement>
43
    <site>
44
      <id>gvsig-repository</id>
45
      <url>dav:https://devel.gvsig.org/sites/${project.artifactId}/${project.version}</url>
46
    </site>
47
  </distributionManagement>
48

  
49
  <build>
50
    <plugins>
51
      <plugin>
52
        <groupId>org.apache.maven.plugins</groupId>
53
        <artifactId>maven-release-plugin</artifactId>
54
        <configuration>
55
          <tagBase>https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster/tags</tagBase>
56
        </configuration>
57
      </plugin>
58
    </plugins>
59
  </build>
60

  
61

  
62
  <dependencyManagement>
63
    <dependencies>
64
      <dependency>
65
        <groupId>org.gvsig</groupId>
66
        <artifactId>org.gvsig.raster</artifactId>
67
        <version>${org.gvsig.raster.version}</version>
68
        <type>pom</type>
69
        <scope>import</scope>
70
      </dependency>
71
      <dependency>
72
        <groupId>org.gvsig</groupId>
73
        <artifactId>org.gvsig.bingmaps</artifactId>
74
        <version>${org.gvsig.bingmaps.version}</version>
75
        <type>pom</type>
76
        <scope>import</scope>
77
      </dependency>
78
      <dependency>
79
        <groupId>org.gvsig</groupId>
80
        <artifactId>org.gvsig.raster.bingmaps.provider</artifactId>
81
        <version>2.4.1-SNAPSHOT</version>
82
      </dependency>
83
      <dependency>
84
        <groupId>org.gvsig</groupId>
85
        <artifactId>org.gvsig.raster.bingmaps.provider.legend</artifactId>
86
        <version>2.4.1-SNAPSHOT</version>
87
      </dependency>
88
    </dependencies>
89
  </dependencyManagement>
90
  <properties>
91
    <org.gvsig.bingmaps.version>1.0.32</org.gvsig.bingmaps.version>
92
    <org.gvsig.raster.version>2.4.1-SNAPSHOT</org.gvsig.raster.version>
93
  </properties>
94

  
95
  <modules>
96
    <module>org.gvsig.raster.bingmaps.app</module>
97
    <module>org.gvsig.raster.bingmaps.provider</module>
98
    <module>org.gvsig.raster.bingmaps.provider.legend</module>
99
  </modules>
100
</project>
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster.bingmaps/org.gvsig.raster.bingmaps.provider/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
  <modelVersion>4.0.0</modelVersion>
3
  <parent>
4
    <groupId>org.gvsig</groupId>
5
    <artifactId>org.gvsig.raster.bingmaps</artifactId>
6
    <version>2.4.1-SNAPSHOT</version>
7
  </parent>
8
  <artifactId>org.gvsig.raster.bingmaps.provider</artifactId>
9
  <name>org.gvsig.raster.bingmaps.provider</name>
10
  <dependencies>
11
    <dependency>
12
      <groupId>org.gvsig</groupId>
13
      <artifactId>org.gvsig.fmap.dal.raster.spi</artifactId>
14
    </dependency>
15
    <dependency>
16
      <groupId>org.gvsig</groupId>
17
      <artifactId>org.gvsig.bingmaps.lib.api</artifactId>
18
      </dependency>
19
    <dependency>
20
      <groupId>org.gvsig</groupId>
21
      <artifactId>org.gvsig.fmap.dal.raster.api</artifactId>
22
    </dependency>
23
    <dependency>
24
      <groupId>org.gvsig</groupId>
25
      <artifactId>org.gvsig.raster.lib.buffer.spi</artifactId>
26
    </dependency>
27
  </dependencies>
28
</project>
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster.bingmaps/org.gvsig.raster.bingmaps.provider/src/main/resources/org/gvsig/raster/bingmaps/provider/BingMapsRasterMetadata.xml
1
<?xml version="1.0"?>
2
<!--
3
Definitions of metadata fields of GoogleMaps.
4
 -->
5
<definitions>
6
  <version>1.0.0</version>
7
  <classes>
8

  
9
    <class name="BingMapsRaster" namespace="Metadata">
10
      <extends>
11
      	<class namespace="Metadata" name="SpatialProvider"/>
12
      </extends>
13
      <description>Metadata of a Bing Maps store</description>
14
      <fields>
15
      </fields>
16
    </class>
17

  
18
  </classes>
19
</definitions>
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster.bingmaps/org.gvsig.raster.bingmaps.provider/src/main/resources/org/gvsig/raster/bingmaps/provider/BingMapsRasterParameters.xml
1
<?xml version="1.0"?>
2
<definitions>
3
  <version>1.0.0</version>
4
  <classes>
5

  
6
    <class name="BingMapsRasterProviderParameters">
7
       <extends>
8
        <class namespace="dal" name="ProviderParameters"/>
9
      </extends>
10
      <description>Store the parameters need to open BingMaps</description>
11
      <fields>
12

  
13
        <field name="mapType" type="string" mandatory="true" group="Basic">
14
          <description>Property given to BingMaps driver to indicate the map type
15
          </description>
16
          <availableValues>
17
            <value label="AERIAL">aerial</value>
18
            <value label="AERIALWITHLABELS">aerialwithlabels</value>
19
            <value label="ROAD">road</value>
20
          </availableValues>
21
        </field>
22
        <field name="hasApiKey" type="boolean" mandatory="true" group="Basic">
23
          <description>Indicates if an API Key must be used
24
          </description>
25
        </field>
26
        <field name="apiKey" type="string" mandatory="false" group="Basic">
27
          <description>Bing key to use its API
28
          </description>
29
        </field>
30
        <field name="language" type="string" mandatory="false" group="Basic">
31
          <description>Language to be shown in the map
32
          </description>
33
        </field>
34
        <!-- <field name="region" type="string" mandatory="false" group="Basic">
35
          <description>Regional politic restrictions to be shown in the map
36
          </description>
37
        </field>
38
        <field name="format" type="string" mandatory="false" group="Basic" defaultValue="png32">
39
          <description>Image format to be downloaded
40
          </description>
41
            <availableValues>
42
              <value label="png">png</value>
43
              <value label="png32">png32</value>
44
              <value label="gif">gif</value>
45
              <value label="jpg">jpg</value>
46
              <value label="jpg-baseline">jpg-baseline</value>
47
            </availableValues>
48
        </field> -->
49
        <field name="crs" type="crs" mandatory="true" group="Basic">
50
          <description>The coordinate reference system used in BingMaps</description>
51
        </field>
52
      </fields>
53
    </class>
54

  
55
  </classes>
56
</definitions>
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster.bingmaps/org.gvsig.raster.bingmaps.provider/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.raster.bingmaps.provider.BingMapsRasterLibrary
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster.bingmaps/org.gvsig.raster.bingmaps.provider/src/main/java/org/gvsig/raster/bingmaps/provider/BingMapsImage.java
1
package org.gvsig.raster.bingmaps.provider;
2

  
3
import java.awt.image.BufferedImage;
4

  
5
import org.slf4j.Logger;
6
import org.slf4j.LoggerFactory;
7

  
8
import org.gvsig.bingmaps.lib.api.BingMapsLocator;
9
import org.gvsig.bingmaps.lib.api.BingMapsManager;
10
import org.gvsig.bingmaps.lib.api.BingMapsMapInfo;
11
import org.gvsig.bingmaps.lib.api.BingMapsTileRequest;
12
import org.gvsig.bingmaps.lib.api.BingMapsTileRequestParams;
13
import org.gvsig.bingmaps.lib.api.exceptions.DownloadingException;
14
import org.gvsig.bingmaps.lib.api.exceptions.GettingMapInfoException;
15
import org.gvsig.bingmaps.lib.api.exceptions.URLFormatException;
16
import org.gvsig.fmap.dal.DataStoreParameters;
17
import org.gvsig.fmap.dal.exception.DataException;
18
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
19
import org.gvsig.fmap.geom.Geometry.DIMENSIONS;
20
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
21
import org.gvsig.fmap.geom.GeometryLocator;
22
import org.gvsig.fmap.geom.GeometryManager;
23
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
24
import org.gvsig.fmap.geom.exception.CreateGeometryException;
25
import org.gvsig.fmap.geom.primitive.Envelope;
26
import org.gvsig.raster.lib.buffer.api.Band;
27
import org.gvsig.raster.lib.buffer.api.Buffer;
28
import org.gvsig.raster.lib.buffer.api.BufferLocator;
29
import org.gvsig.raster.lib.buffer.api.TileStruct;
30
import org.gvsig.raster.lib.buffer.api.exceptions.BufferException;
31
import org.gvsig.tools.ToolsLocator;
32
import org.gvsig.tools.dispose.Disposable;
33
import org.gvsig.tools.dispose.DisposeUtils;
34
import org.gvsig.tools.dispose.impl.AbstractDisposable;
35
import org.gvsig.tools.exception.BaseException;
36
import org.gvsig.tools.locator.LocatorException;
37

  
38

  
39
/**
40
 * @author fdiaz
41
 *
42
 */
43
public class BingMapsImage extends AbstractDisposable {
44

  
45
    private static final Logger logger = LoggerFactory.getLogger(BingMapsImage.class);
46

  
47
    private TileStruct tileStruct;
48
    private BingMapsRasterProvider provider;
49
    private DownloadedTile tile;
50

  
51
    private BingMapsMapInfo mapInfo;
52

  
53
    /**
54
     * @param provider
55
     * @param query
56
     * @param tileStruct
57
     * @throws GettingMapInfoException
58
     */
59
    public BingMapsImage(TileStruct tileStruct, BingMapsRasterProvider provider) throws GettingMapInfoException {
60
        this.tileStruct = tileStruct;
61
        this.provider = provider;
62
        this.tile = null;
63
    }
64

  
65
    /**
66
     * @param mapInfo
67
     */
68
    public void setMapInfo(BingMapsMapInfo mapInfo){
69
        this.mapInfo = mapInfo;
70
    }
71

  
72
    /**
73
     * @param bandNumber
74
     * @param zoomLevel
75
     * @param structRow
76
     * @param structCol
77
     * @return Band
78
     * @throws CreateEnvelopeException
79
     * @throws CloneNotSupportedException
80
     * @throws ValidateDataParametersException
81
     */
82
    public Band fetchTile(int bandNumber, int zoomLevel, int structRow, int structCol) throws CreateEnvelopeException,
83
        ValidateDataParametersException, CloneNotSupportedException {
84

  
85
        String keyTile = composeKeyForRecentTiles(zoomLevel, structRow, structCol);
86

  
87
        Buffer buffer = null;
88
        if (this.tile != null && this.tile.getKey().equalsIgnoreCase(keyTile) && this.tile.isDownloaded()) {
89
            // Devolver la banda del buffer del tile
90
            logger.info("Devolviendo la banda "+bandNumber+" del buffer del tile "+tile.getKey());
91
            try {
92
                buffer = tile.getBuffer();
93
                Band band = buffer.getBand(bandNumber);
94
                ToolsLocator.getDisposableManager().bind(band);
95
                return band;
96
            } catch (InterruptedException e) {
97
                logger.warn("Can't fetch tile: zoomLevel = " + zoomLevel + ", tileRow = " + structRow
98
                    + ", tileColumn = " + structCol + ", band = " + bandNumber + ".", e);
99
                return null;
100
            }
101
        } else {
102
            this.tile=null;
103
            // Cargar un tile nuevo
104
            Band band = null;
105
            try {
106
                while(this.tile==null || !this.tile.isDownloaded()) {
107
                    tile = requestTile(zoomLevel, structRow, structCol, keyTile);
108
                }
109

  
110
                buffer = tile.getBuffer();
111

  
112
                band = buffer.getBand(bandNumber);
113
                ToolsLocator.getDisposableManager().bind(band);
114
                return band;
115
            } catch (DataException | BufferException | CreateGeometryException | InterruptedException | URLFormatException | DownloadingException e) {
116
                logger.warn("Can't fetch tile: zoomLevel = " + zoomLevel + ", tileRow = " + structRow
117
                    + ", tileColumn = " + structCol + ", band = " + bandNumber + ".", e);
118
                return null;
119
            }
120
        }
121
    }
122

  
123
    private DownloadedTile requestTile(int zoomLevel, int structRow, int structCol, String key) throws CreateEnvelopeException,
124
        CloneNotSupportedException, BufferException, ValidateDataParametersException, DataException, CreateGeometryException, URLFormatException, DownloadingException {
125

  
126
        Double pixelSize = this.tileStruct.getPixelSizePerZoomLevel().get(zoomLevel);
127

  
128
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
129

  
130
        Envelope structExtent = this.tileStruct.getEnvelope();
131
        int rowsPerTile = this.tileStruct.getRowsPerTile();
132
        int columnsPerTile = this.tileStruct.getColumnsPerTile();
133

  
134
        double minX = Math.max(structExtent.getMinimum(DIMENSIONS.X) + (structCol * (pixelSize * columnsPerTile)),structExtent.getMinimum(DIMENSIONS.X));
135
        double minY = Math.max(structExtent.getMaximum(DIMENSIONS.Y) - ((structRow + 1) * (pixelSize * rowsPerTile)),structExtent.getMinimum(DIMENSIONS.Y));
136
        double maxX = Math.min(structExtent.getMinimum(DIMENSIONS.X) + ((structCol + 1) * (pixelSize * columnsPerTile)),structExtent.getMaximum(DIMENSIONS.X));
137
        double maxY = Math.min(structExtent.getMaximum(DIMENSIONS.Y) - (structRow * (pixelSize * rowsPerTile)),structExtent.getMaximum(DIMENSIONS.Y));
138
        Envelope envelope = geomManager.createEnvelope(minX, minY, maxX, maxY, SUBTYPES.GEOM2D);
139

  
140
        BingMapsManager bingMapsManager = BingMapsLocator.getManager();
141
        DataStoreParameters storeParameters = provider.getParameters();
142

  
143
        BingMapsTileRequestParams requestTileParams = bingMapsManager.createTileRequestParams();
144
        requestTileParams.setLanguage((String) storeParameters.getDynValue("language"));
145
        requestTileParams.setMaxZoomLvl(mapInfo.getMaxZoomLvl());
146
        requestTileParams.setSubdomains(mapInfo.getSubdomains());
147
        requestTileParams.setURLTilePattern(mapInfo.getURLTilePattern());
148

  
149
        BingMapsTileRequest bingRequest=bingMapsManager.createTileRequest(requestTileParams);
150
        DownloadedTile downloadedTile = new DownloadedTile(key, envelope);
151
        BufferedImage image = bingRequest.getTile(structCol, structRow, zoomLevel);
152
        downloadedTile.setImage(image);
153

  
154
        return downloadedTile;
155
    }
156

  
157
    private String composeKeyForRecentTiles(int zoomLevel, int structRow, int structCol) {
158
        StringBuilder builder = new StringBuilder();
159
        builder.append(zoomLevel);
160
        builder.append(":");
161
        builder.append(structCol);
162
        builder.append(":");
163
        builder.append(structRow);
164
        return builder.toString();
165
    }
166

  
167
    private class DownloadedTile extends AbstractDisposable { //implements BingMapsRequestListener {
168

  
169
        private org.gvsig.raster.lib.buffer.api.Buffer buffer;
170
        long lastAccess;
171
        private String key;
172
        private Envelope envelope;
173
        private boolean downloaded;
174

  
175
        public DownloadedTile(String key, Envelope envelope) {
176
            this.key = key;
177
            this.envelope = envelope;
178
            lastAccess = System.currentTimeMillis();
179
            this.downloaded = false;
180
        }
181

  
182
        public String getKey() {
183
            return key;
184
        }
185

  
186
        public synchronized org.gvsig.raster.lib.buffer.api.Buffer getBuffer() throws InterruptedException {
187
            lastAccess = System.currentTimeMillis();
188
            while(!isDownloaded()){
189
                this.wait();
190
            }
191
            return buffer;
192
        }
193

  
194
        public long getLastAccess() {
195
            return lastAccess;
196
        }
197

  
198
        @Override
199
        protected void finalize() throws Throwable {
200
            super.finalize();
201
        }
202

  
203
        public synchronized void setImage(BufferedImage img) {
204

  
205
            downloaded = false;
206

  
207
            try {
208

  
209
                this.buffer =
210
                    BufferLocator.getBufferManager().createRGBBuffer(img, BingMapsRasterProvider.BING_MAPS_PROJECTION,
211
                        this.envelope);
212
                this.downloaded = true;
213

  
214
            } catch (LocatorException | BufferException e) {
215
                logger.warn("Can't create buffer to load downloaded image.", e);
216
            }
217

  
218
            this.notify();
219
        }
220

  
221
        @Override
222
        protected void doDispose() throws BaseException {
223
            DisposeUtils.dispose(buffer);
224
            buffer = null;
225
        }
226

  
227

  
228
        public boolean isDownloaded(){
229
            return this.downloaded;
230
        }
231
    }
232

  
233
    @Override
234
    protected void doDispose() throws BaseException {
235
        if(this.tile != null) {
236
            DisposeUtils.dispose(this.tile);
237
        }
238
        DisposeUtils.dispose((Disposable) tileStruct);
239
        tileStruct = null;
240
    }
241

  
242
}
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster.bingmaps/org.gvsig.raster.bingmaps.provider/src/main/java/org/gvsig/raster/bingmaps/provider/BingMapsRasterProviderFactory.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2016 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.raster.bingmaps.provider;
24

  
25
import org.slf4j.Logger;
26
import org.slf4j.LoggerFactory;
27

  
28
import org.gvsig.fmap.dal.DataParameters;
29
import org.gvsig.fmap.dal.DataStoreParameters;
30
import org.gvsig.fmap.dal.DataStoreProvider;
31
import org.gvsig.fmap.dal.exception.InitializeException;
32
import org.gvsig.fmap.dal.raster.spi.AbstractRasterStoreProviderFactory;
33
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
34
import org.gvsig.tools.dynobject.DynObject;
35

  
36
/**
37
 * Factory for BingMaps provider
38
 * @author dmartinezizquierdo
39
 *
40
 */
41
public class BingMapsRasterProviderFactory extends AbstractRasterStoreProviderFactory {
42

  
43
    private static final Logger logger = LoggerFactory.getLogger(BingMapsRasterProviderFactory.class);
44

  
45
    protected BingMapsRasterProviderFactory(String name, String description) {
46
        super(name, description);
47
    }
48

  
49
    @Override
50
    public DataStoreProvider createProvider(DataParameters parameters,
51
        DataStoreProviderServices providerServices) throws InitializeException {
52
        return (DataStoreProvider) new BingMapsRasterProvider((DataStoreParameters) parameters,providerServices);
53
    }
54

  
55
    @Override
56
    public DynObject createParameters() {
57
        return new BingMapsRasterProviderParameters();
58
    }
59
}
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster.bingmaps/org.gvsig.raster.bingmaps.provider/src/main/java/org/gvsig/raster/bingmaps/provider/BingMapsRasterLibrary.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2016 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23

  
24
package org.gvsig.raster.bingmaps.provider;
25

  
26
import java.util.ArrayList;
27
import java.util.List;
28

  
29
import org.gvsig.fmap.dal.DALFileLibrary;
30
import org.gvsig.fmap.dal.DALLibrary;
31
import org.gvsig.fmap.dal.FileHelper;
32
import org.gvsig.fmap.dal.spi.DALSPILocator;
33
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
34
import org.gvsig.bingmaps.lib.api.BingMapsLibrary;
35
import org.gvsig.metadata.exceptions.MetadataException;
36
import org.gvsig.tools.library.AbstractLibrary;
37
import org.gvsig.tools.library.LibraryException;
38

  
39
/**
40
 * BingMaps Library to register provider commponents
41
 * @author fdiaz
42
 *
43
 */
44
public class BingMapsRasterLibrary extends AbstractLibrary {
45

  
46
    static int BING_MAPS_TILE_SIZE = 256;
47
    static int TILE_SIZE = 256;
48
    static int MAX_ZOOM_LEVEL = 23;
49

  
50
    @Override
51
    public void doRegistration() {
52
        registerAsServiceOf(DALLibrary.class);
53
        require(DALFileLibrary.class);
54
        require(BingMapsLibrary.class);
55
    }
56

  
57
	@Override
58
	protected void doInitialize() throws LibraryException {
59
	}
60

  
61
	@Override
62
	protected void doPostInitialize() throws LibraryException {
63
		List<Throwable> exs = new ArrayList<Throwable>();
64

  
65
		FileHelper.registerParametersDefinition(
66
				BingMapsRasterProviderParameters.PARAMETERS_DEFINITION_NAME,
67
				BingMapsRasterProviderParameters.class, "BingMapsRasterParameters.xml");
68
		try {
69
			FileHelper.registerMetadataDefinition(
70
			    BingMapsRasterProvider.METADATA_DEFINITION_NAME,
71
			    BingMapsRasterProvider.class, "BingMapsRasterMetadata.xml");
72
		} catch (MetadataException e) {
73
			exs.add(e);
74
		}
75

  
76
		DataManagerProviderServices dataman = DALSPILocator.getDataManagerProviderServices();
77

  
78

  
79
		try {
80
            if (!dataman.getStoreProviders()
81
                .contains(BingMapsRasterProvider.NAME)) {
82
                dataman.registerStoreProviderFactory(
83
                    new BingMapsRasterProviderFactory(
84
                        BingMapsRasterProvider.NAME,
85
                        BingMapsRasterProvider.DESCRIPTION));
86
            }
87
		} catch (RuntimeException e) {
88
			exs.add(e);
89
		}
90

  
91
		if (exs.size() > 0) {
92
			throw new LibraryException(this.getClass(), exs);
93
		}
94
	}
95
}
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster.bingmaps/org.gvsig.raster.bingmaps.provider/src/main/java/org/gvsig/raster/bingmaps/provider/BingMapsRasterProvider.java
1
package org.gvsig.raster.bingmaps.provider;
2

  
3
import java.util.ArrayList;
4
import java.util.HashMap;
5
import java.util.List;
6
import java.util.Map;
7

  
8
import org.cresques.cts.IProjection;
9
import org.slf4j.Logger;
10
import org.slf4j.LoggerFactory;
11

  
12
import org.gvsig.bingmaps.lib.api.BingMapsLocator;
13
import org.gvsig.bingmaps.lib.api.BingMapsManager;
14
import org.gvsig.bingmaps.lib.api.BingMapsMapInfo;
15
import org.gvsig.bingmaps.lib.api.BingMapsMapRequest;
16
import org.gvsig.bingmaps.lib.api.BingMapsMapRequestParams;
17
import org.gvsig.bingmaps.lib.api.exceptions.GettingMapInfoException;
18
import org.gvsig.fmap.crs.CRSFactory;
19
import org.gvsig.fmap.dal.DataServerExplorer;
20
import org.gvsig.fmap.dal.DataStore;
21
import org.gvsig.fmap.dal.DataStoreParameters;
22
import org.gvsig.fmap.dal.FileHelper;
23
import org.gvsig.fmap.dal.exception.DataException;
24
import org.gvsig.fmap.dal.exception.InitializeException;
25
import org.gvsig.fmap.dal.exception.OpenException;
26
import org.gvsig.fmap.dal.exception.ReadException;
27
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
28
import org.gvsig.fmap.dal.raster.api.BandQuery;
29
import org.gvsig.fmap.dal.raster.api.RasterQuery;
30
import org.gvsig.fmap.dal.raster.spi.AbstractRasterStoreProvider;
31
import org.gvsig.fmap.dal.raster.spi.BandDescriptorServices;
32
import org.gvsig.fmap.dal.resource.spi.ResourceProvider;
33
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
34
import org.gvsig.fmap.geom.Geometry.DIMENSIONS;
35
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
36
import org.gvsig.fmap.geom.GeometryLocator;
37
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
38
import org.gvsig.fmap.geom.primitive.Envelope;
39
import org.gvsig.metadata.MetadataLocator;
40
import org.gvsig.metadata.MetadataManager;
41
import org.gvsig.metadata.exceptions.MetadataException;
42
import org.gvsig.raster.lib.buffer.api.Buffer;
43
import org.gvsig.raster.lib.buffer.api.BufferDimensions;
44
import org.gvsig.raster.lib.buffer.api.BufferLocator;
45
import org.gvsig.raster.lib.buffer.api.BufferManager;
46
import org.gvsig.raster.lib.buffer.api.NoData;
47
import org.gvsig.raster.lib.buffer.api.PageManager;
48
import org.gvsig.raster.lib.buffer.api.TileStruct;
49
import org.gvsig.raster.lib.buffer.api.exceptions.BufferException;
50
import org.gvsig.raster.lib.buffer.spi.DefaultTileStruct;
51
import org.gvsig.tools.dataTypes.DataTypes;
52
import org.gvsig.tools.dispose.DisposeUtils;
53
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException;
54
import org.gvsig.tools.locator.LocatorException;
55

  
56

  
57
/**
58
 * @author fdiaz
59
 *
60
 */
61
public class BingMapsRasterProvider extends AbstractRasterStoreProvider {
62

  
63
    private static final Logger logger =
64
        LoggerFactory.getLogger(BingMapsRasterProvider.class);
65

  
66
    public static String NAME = "BingMapsRaster";
67
    public static String DESCRIPTION = "Bing Maps Raster Provider";
68
    public static final String METADATA_DEFINITION_NAME = "BingMapsRaster";
69
    static IProjection BING_MAPS_PROJECTION = CRSFactory.getCRS("EPSG:3857");
70

  
71

  
72
    private BingMapsImage image;
73
    TileStruct tileStruct = null;
74
    Map<Integer,List<PageManager>> pageManagersPerZoomLevel = null;
75

  
76
    private Envelope worldExtent;
77

  
78
    private BingMapsMapInfo mapInfo = null;
79
    private Integer maxZoomLevel = null;
80

  
81
    protected static void registerMetadataDefinition() throws MetadataException {
82
        MetadataManager manager = MetadataLocator.getMetadataManager();
83
        if (manager.getDefinition(METADATA_DEFINITION_NAME) == null) {
84
            manager.addDefinition(METADATA_DEFINITION_NAME,
85
                BingMapsRasterProviderParameters.class.getResourceAsStream("BingMapsRasterMetadata.xml"),
86
                BingMapsRasterProviderParameters.class.getClassLoader());
87
        }
88
    }
89

  
90

  
91
    protected BingMapsRasterProvider(DataStoreParameters params, DataStoreProviderServices storeServices) {
92
        super(params, storeServices, FileHelper.newMetadataContainer(METADATA_DEFINITION_NAME));
93
        pageManagersPerZoomLevel = new HashMap<Integer, List<PageManager>>();
94
    }
95

  
96
    @Override
97
    public Buffer createBuffer(RasterQuery rasterQuery) throws BufferException {
98

  
99
        BufferManager bufferManager = BufferLocator.getBufferManager();
100
        int[] bandDataTypes;
101
        List<PageManager> pageManagers = new ArrayList<PageManager>();
102
        NoData[] bandNoData;
103
        Envelope envelope = getTileStruct().getEnvelope();
104
        double pixelSize = rasterQuery.getPixelSize();
105
        int zoomLevel;
106
        if(pixelSize == 0){
107
            zoomLevel = 1;
108
        } else {
109
            zoomLevel = getZoomLvlForPixelSize(pixelSize);
110
        }
111

  
112
            if (!rasterQuery.getBands().isEmpty()) {
113
                List<BandQuery> bands;
114
                bands = rasterQuery.getBands();
115
                bandDataTypes = new int[bands.size()];
116
                bandNoData = new NoData[bands.size()];
117

  
118
                for (BandQuery bandQuery : bands) {
119
                    int band = bandQuery.getBand();
120
                    bandDataTypes[band] = this.getBandDescriptor(band).getDataType();
121
                    bandNoData[band] = this.getNoData(rasterQuery, band);
122
                    try {
123
                        pageManagers.add(getPageManagersInZoom(zoomLevel).get(band));
124
                    } catch (ValidateDataParametersException | CreateEnvelopeException | DataException
125
                        | CloneNotSupportedException | GettingMapInfoException e) {
126
                        throw new BufferException(e);
127
                    }
128
                }
129
            } else {
130
                int bands = getBands();
131
                bandDataTypes = new int[bands];
132
                bandNoData = new NoData[bands];
133
                for (int i = 0; i < bands; i++) {
134
                    bandDataTypes[i] = this.getBandDescriptor(i).getDataType();
135
                    bandNoData[i] = this.getNoData(rasterQuery, i);
136
                    try {
137
                        pageManagers.add(getPageManagersInZoom(zoomLevel).get(i));
138
                    } catch (ValidateDataParametersException | CreateEnvelopeException | DataException
139
                        | CloneNotSupportedException | GettingMapInfoException e) {
140
                        throw new BufferException(e);
141
                    }
142
                }
143
            }
144

  
145
        Buffer buffer =
146
            bufferManager.createBuffer(getRows(zoomLevel), getColumns(zoomLevel), bandDataTypes, bandNoData,
147
                BING_MAPS_PROJECTION, envelope, pageManagers);
148

  
149
        if(rasterQuery.getClip()!=null){
150
            Buffer completeBuffer = buffer;
151
            envelope  = rasterQuery.getClip();
152
            buffer = bufferManager.createClippedBuffer(completeBuffer, envelope);
153
            DisposeUtils.dispose(completeBuffer);
154
        }
155

  
156
        return buffer;
157
    }
158

  
159
    @Override
160
    public BandDescriptorServices getBandDescriptor(int band) {
161
        BandDescriptorServices descriptor = super.getBandDescriptor(band);
162
      switch (band) {
163
      case 0:
164
          descriptor.setName("RED");
165
          descriptor.setDescription("RED");
166
          descriptor.setDataType(BufferManager.TYPE_BYTE);
167
      case 1:
168
          descriptor.setName("GREEN");
169
          descriptor.setDescription("GREEN");
170
          descriptor.setDataType(BufferManager.TYPE_BYTE);
171
      case 2:
172
          descriptor.setName("BLUE");
173
          descriptor.setDescription("BLUE");
174
          descriptor.setDataType(BufferManager.TYPE_BYTE);
175
      case 3:
176
          descriptor.setName("ALPHA");
177
          descriptor.setDescription("ALPHA");
178
          descriptor.setDataType(BufferManager.TYPE_BYTE);
179
      }
180
      return descriptor;
181

  
182
    }
183

  
184
    @Override
185
    public int getBands() {
186
        return 3;
187
    }
188

  
189
    @Override
190
    public DataServerExplorer getExplorer() throws ReadException, ValidateDataParametersException {
191
        // TODO Auto-generated method stub
192
        return null;
193
    }
194

  
195
    @Override
196
    public void open() throws OpenException {
197
        for(int i=0; i<getBands(); i++){
198
            this.getBandDescriptor(i).setDataType(DataTypes.BYTE);
199
        }
200
    }
201

  
202
    @Override
203
    public ResourceProvider getResource() {
204
        return null;
205
    }
206

  
207
    @Override
208
    public Object getSourceId() {
209
        return NAME+"-"+getParameters().getDynValue("mapType");
210
    }
211

  
212
    @Override
213
    public String getProviderName() {
214
        return NAME;
215
    }
216

  
217
    @Override
218
    public String getName() {
219
        return NAME;
220
    }
221

  
222
    @Override
223
    public String getFullName() {
224
        return NAME+"-"+getParameters().getDynValue("mapType");
225
    }
226

  
227
    @Override
228
    public TileStruct getTileStruct() {
229
        if(tileStruct == null){
230
            autoOpen();
231

  
232
            tileStruct = new DefaultTileStruct();
233
            tileStruct.setColumnsPerTile(BingMapsRasterLibrary.TILE_SIZE);
234
            tileStruct.setRowsPerTile(BingMapsRasterLibrary.TILE_SIZE);
235

  
236
            //FIXME: ??
237
//            tileStruct.setProviderName("GTIFF");
238

  
239
            try {
240
                worldExtent = GeometryLocator.getGeometryManager().createEnvelope(-20037508, -20037508, 20037508, 20037508, SUBTYPES.GEOM2D);
241
                tileStruct.setEnvelope(worldExtent);
242

  
243
                Map<Integer, Double> zoomLevels = new HashMap<Integer, Double>();
244

  
245
                double pixelSize = worldExtent.getLength(DIMENSIONS.X)/BingMapsRasterLibrary.BING_MAPS_TILE_SIZE;
246
                for (int zoomLevel = 0; zoomLevel <= getMaxZoomLevel(); zoomLevel++) {
247
                    if(zoomLevel>0) {
248
                        zoomLevels.put(zoomLevel, pixelSize);
249
                    }
250
                    pixelSize = pixelSize / 2;
251
                }
252

  
253
                tileStruct.setPixelSizePerZoomLevel(zoomLevels);
254
            } catch (LocatorException | CreateEnvelopeException e) {
255
                logger.warn("Can't create world extent of BingMaps", e);
256
            }
257
        }
258
        return this.tileStruct;
259
    }
260

  
261
    private BingMapsImage getBingMapsImage() throws GettingMapInfoException {
262
        if(this.image == null){
263
            this.image = new BingMapsImage(getTileStruct(), this);
264
            this.image.setMapInfo(getMapInfo());
265
        }
266
        return this.image;
267
    }
268

  
269
    private BingMapsMapInfo getMapInfo() throws GettingMapInfoException {
270
        if (this.mapInfo == null) {
271
            BingMapsManager bingMapsManager = BingMapsLocator.getManager();
272
            BingMapsMapRequestParams requestParams = bingMapsManager.createMapRequestParams();
273

  
274
            DataStoreParameters storeParameters = getParameters();
275
            requestParams.setHasApiKey((Boolean) storeParameters.getDynValue("hasApiKey"));
276
            requestParams.setApiKey((String) storeParameters.getDynValue("apiKey"));
277
            requestParams.setLanguage((String) storeParameters.getDynValue("language"));
278
            requestParams.setMapType((String) storeParameters.getDynValue("mapType"));
279

  
280
            requestParams
281
                .setURLMapPattern("http://dev.virtualearth.net/REST/V1/Imagery/Metadata/{MAPTYPE}?mapVersion=v1&format=jpeg&output=xml&key={KEY}");
282

  
283
            BingMapsMapRequest mapRequest = bingMapsManager.createMapRequest(requestParams);
284
            this.mapInfo = mapRequest.getMapInfo();
285

  
286
        }
287
        return this.mapInfo;
288
    }
289

  
290

  
291
    /**
292
     * @param pixelSize
293
     * @return The appropriate zoom level for the pizelSize
294
     */
295
    private int getZoomLvlForPixelSize(double pixelSize) {
296
        int zoom = 0;
297
        Map<Integer, Double> pixelSizePerZoomLevel = getTileStruct().getPixelSizePerZoomLevel();
298
        for (int i : pixelSizePerZoomLevel.keySet()) {
299
            zoom = i;
300
            double levelPixelSize = pixelSizePerZoomLevel.get(zoom);
301
            if (pixelSize >= levelPixelSize) {
302
                return zoom;
303
            }
304
        }
305
        if(zoom<1){
306
            zoom=1;
307
        }
308
        return zoom;
309
    }
310

  
311
    private List<PageManager> getPageManagersInZoom(int zoomLevel) throws ValidateDataParametersException, CreateEnvelopeException, BufferException, DataException, CloneNotSupportedException, GettingMapInfoException {
312
        List<PageManager> pageManagersInZoom = this.pageManagersPerZoomLevel.get(zoomLevel);
313
        if (pageManagersInZoom == null) {
314
            pageManagersInZoom = new ArrayList<PageManager>();
315
            for (int i = 0; i < getBands(); i++) {
316
                pageManagersInZoom.add(new BingMapsBandTileManager(getTileStruct(), this.getBingMapsImage(), zoomLevel, i, this));
317
            }
318
            this.pageManagersPerZoomLevel.put(zoomLevel, pageManagersInZoom);
319
        }
320
        return pageManagersInZoom;
321
    }
322

  
323
    /**
324
     * @param zoomLevel
325
     * @return rows per zoom level
326
     */
327
    public int getRows(int zoomLevel) {
328
        return (int) (Math.round(getTileStruct().getEnvelope().getLength(DIMENSIONS.Y) / this.getTileStruct().getPixelSizePerZoomLevel().get(zoomLevel)));
329
    }
330

  
331
    /**
332
     * @param zoomLevel
333
     * @return columns per zoom level
334
     */
335
    public int getColumns(int zoomLevel) {
336
        return (int) (Math.round(getTileStruct().getEnvelope().getLength(DIMENSIONS.X) / this.getTileStruct().getPixelSizePerZoomLevel().get(zoomLevel)));
337
    }
338

  
339
    @Override
340
    public Object getDynValue(String name) throws DynFieldNotFoundException {
341
        if (DataStore.METADATA_ENVELOPE.equalsIgnoreCase(name)) {
342
            return this.getTileStruct().getEnvelope(); //.worldExtent;
343
        } else if (DataStore.METADATA_CRS.equalsIgnoreCase(name)) {
344
            return BING_MAPS_PROJECTION;
345
        }
346
        return super.getDynValue(name);
347
    }
348

  
349
    @Override
350
    public BufferDimensions getDimensions() throws InitializeException {
351
        if(this.dimensions==null){;
352
            Double pixelSize = getTileStruct().getPixelSizePerZoomLevel().get(getMaxZoomLevel());
353
            Envelope envelope = getTileStruct().getEnvelope();
354
            int rows = (int)Math.round(envelope.getLength(DIMENSIONS.Y)/pixelSize);
355
            int columns = rows;
356
            this.dimensions = BufferLocator.getBufferManager().createBufferDimensions(rows, columns, envelope);
357
        }
358
        return this.dimensions;
359
    }
360

  
361
    private int getMaxZoomLevel() {
362
        if (maxZoomLevel == null) {
363
            try {
364
                maxZoomLevel = getMapInfo().getMaxZoomLvl();
365
            } catch (GettingMapInfoException e) {
366
                logger.warn("Can't get BingMaps map info", e);
367
                return BingMapsRasterLibrary.MAX_ZOOM_LEVEL;
368
            }
369
        }
370
        return maxZoomLevel.intValue();
371
    }
372
}
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster.bingmaps/org.gvsig.raster.bingmaps.provider/src/main/java/org/gvsig/raster/bingmaps/provider/BingMapsBandTileManager.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2016 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.raster.bingmaps.provider;
24

  
25
import java.io.IOException;
26
import java.nio.Buffer;
27

  
28
import org.slf4j.Logger;
29
import org.slf4j.LoggerFactory;
30

  
31
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
32
import org.gvsig.fmap.dal.raster.spi.RasterStoreProvider;
33
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
34
import org.gvsig.raster.lib.buffer.api.Band;
35
import org.gvsig.raster.lib.buffer.api.BandInfo;
36
import org.gvsig.raster.lib.buffer.api.BandTileManager;
37
import org.gvsig.raster.lib.buffer.api.TileStruct;
38

  
39

  
40
/**
41
 * @author fdiaz
42
 *
43
 */
44
public class BingMapsBandTileManager implements BandTileManager {
45

  
46
    private static final Logger logger = LoggerFactory.getLogger(BingMapsBandTileManager.class);
47

  
48
    private int bandNumber;
49
    private int zoomLevel;
50

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff