Revision 8954

View differences:

org.gvsig.legend.filteredheatmap/tags/org.gvsig.legend.filteredheatmap-1.0.142/org.gvsig.legend.filteredheatmap.app/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.legend.filteredheatmap</artifactId>
6
    <version>1.0.142</version>
7
  </parent>
8
  <groupId>org.gvsig</groupId>
9
  <artifactId>org.gvsig.legend.filteredheatmap.app</artifactId>
10
  <packaging>pom</packaging>
11
  <name>org.gvsig.legend.filteredheatmap.app</name>
12

  
13
  <modules>
14
    <module>org.gvsig.legend.filteredheatmap.app.mainplugin</module>
15
  </modules>
16

  
17
</project>
org.gvsig.legend.filteredheatmap/tags/org.gvsig.legend.filteredheatmap-1.0.142/org.gvsig.legend.filteredheatmap.app/org.gvsig.legend.filteredheatmap.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml
1
<!-- gvSIG. Desktop Geographic Information System. Copyright (C) 2007-2013 gvSIG
2
  Association. This program is free software; you can redistribute it and/or modify
3
  it under the terms of the GNU General Public License as published by the Free Software
4
  Foundation; either version 3 of the License, or (at your option) any later version.
5
  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
6
  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
7
  PURPOSE. See the GNU General Public License for more details. You should have received
8
  a copy of the GNU General Public License along with this program; if not, write to
9
  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
10
  USA. For any additional information, do not hesitate to contact us at info AT gvsig.com,
11
  or visit our website www.gvsig.com. -->
12
<assembly>
13
  <id>gvsig-plugin-package</id>
14
  <formats>
15
    <format>zip</format>
16
  </formats>
17
  <baseDirectory>${project.artifactId}</baseDirectory>
18
  <includeBaseDirectory>true</includeBaseDirectory>
19
  <files>
20
    <file>
21
      <source>target/${project.artifactId}-${project.version}.jar</source>
22
      <outputDirectory>lib</outputDirectory>
23
    </file>
24
    <file>
25
      <source>target/package.info</source>
26
    </file>
27
  </files>
28

  
29
  <fileSets>
30
    <fileSet>
31
      <directory>src/main/resources-plugin</directory>
32
      <outputDirectory>.</outputDirectory>
33
    </fileSet>
34
  </fileSets>
35

  
36

  
37
  <dependencySets>
38
    <dependencySet>
39
      <useProjectArtifact>false</useProjectArtifact>
40
      <useTransitiveDependencies>false</useTransitiveDependencies>
41
      <outputDirectory>lib</outputDirectory>
42
      <includes>
43
        <include>org.gvsig:org.gvsig.legend.filteredheatmap.lib.api</include>
44
        <include>org.gvsig:org.gvsig.legend.filteredheatmap.lib.impl</include>
45
        <include>org.gvsig:org.gvsig.legend.filteredheatmap.swing.api</include>
46
        <include>org.gvsig:org.gvsig.legend.filteredheatmap.swing.impl</include>
47
      </includes>
48
    </dependencySet>
49
  </dependencySets>
50

  
51
</assembly>
52

  
org.gvsig.legend.filteredheatmap/tags/org.gvsig.legend.filteredheatmap-1.0.142/org.gvsig.legend.filteredheatmap.app/org.gvsig.legend.filteredheatmap.app.mainplugin/src/main/java/org/gvsig/legend/filteredheatmap/app/FilteredHeatmapLegendExtension.java
1

  
2
package org.gvsig.legend.filteredheatmap.app;
3

  
4
import org.gvsig.andami.IconThemeHelper;
5
import org.gvsig.andami.plugins.Extension;
6

  
7

  
8
public class FilteredHeatmapLegendExtension extends Extension {
9

  
10
    @Override
11
    public void initialize() {
12
        IconThemeHelper.registerIcon("legend", "legend-overview-vectorial-filteredheatmap", this);
13
    }
14

  
15
    @Override
16
    public void execute(String string) {
17
    }
18

  
19
    @Override
20
    public boolean isEnabled() {
21
        return true;
22
    }
23

  
24
    @Override
25
    public boolean isVisible() {
26
        return true;
27
    }
28
    
29
}
org.gvsig.legend.filteredheatmap/tags/org.gvsig.legend.filteredheatmap-1.0.142/org.gvsig.legend.filteredheatmap.app/org.gvsig.legend.filteredheatmap.app.mainplugin/src/main/resources-plugin/plugin-persistence.def
1
<?xml version="1.0"?>
2
<!--
3
Definitions of plugin persistence org.gvsig.filteredheatmap.app.mainplugin
4
 -->
5
<definitions>
6
  <version>1.0.0</version>
7
  <classes>
8
    <class name="org.gvsig.legend.filteredheatmap.app.mainplugin">
9
      <extends>
10
      </extends>
11
      <description>Persistence of the legend of aggregate texts</description>
12
      <fields>
13
      </fields>
14
    </class>
15
  </classes>
16
</definitions>  
org.gvsig.legend.filteredheatmap/tags/org.gvsig.legend.filteredheatmap-1.0.142/org.gvsig.legend.filteredheatmap.app/org.gvsig.legend.filteredheatmap.app.mainplugin/src/main/resources-plugin/i18n/text.properties
1
_Filtered_heatmap_legend_description=Mapa de calor con filtrado que representa la densidad de puntos en un mapa.
2
_Filtered_heatmap_legend=Mapa de calor con filtrado
3
_Distance=Distancia
4
pixels=pixels
5
_Use_color_ramp=Usar un gradiente de color
6
_Number_of_colors=Numero de colores
7
_Hot_color=Color caliente
8
Alpha=Alpha
9
_Cold_color=Color frio
10
_Use_color_table=Usar tabla de color
11
_Color_table=Tabla de color
12
_Use_transparency=Usar transparencia
13
_Hot_color_transparency=Transparencia del color caliente
14
_Cold_color_transparency=Transparencia del color frio
15
_Use_a_field_to_weight_the_heat_map=Usar un campo para ponderar el mapa de calor
16
_Filter_values_to_show=Filtrar valores a mostrar
17
_Filter_by_expression=Filtrar por expresi\u00f3n
18
_Kernel_expression=Expresi\u00f3n del Kernel
org.gvsig.legend.filteredheatmap/tags/org.gvsig.legend.filteredheatmap-1.0.142/org.gvsig.legend.filteredheatmap.app/org.gvsig.legend.filteredheatmap.app.mainplugin/src/main/resources-plugin/i18n/text_en.properties
1
_Filtered_heatmap_legend_description=Filtered heat map for representing the density of dots in a map.
2
_Filtered_heatmap_legend=Filtered heat map
3
_Distance=Distance
4
pixels=pixels
5
_Use_color_ramp=Use a color ramp
6
_Number_of_colors=Number of colors
7
_Hot_color=Hot color
8
Alpha=Alpha
9
_Cold_color=Cold color
10
_Use_color_table=Use a color table
11
_Color_table=Color table
12
_Use_transparency=Use transparencia
13
_Hot_color_transparency=Hot color transparency
14
_Cold_color_transparency=Cold color transparency
15
_Use_a_field_to_weight_the_heat_map=Use a field to weight the heat map
16
_Filter_values_to_show=Filter values to show
17
_Filter_by_expression=Filter by expression
18
_Kernel_expression=Kernel expression
org.gvsig.legend.filteredheatmap/tags/org.gvsig.legend.filteredheatmap-1.0.142/org.gvsig.legend.filteredheatmap.app/org.gvsig.legend.filteredheatmap.app.mainplugin/src/main/resources-plugin/config.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<!-- gvSIG. Desktop Geographic Information System. Copyright (C) 2007-2013 gvSIG
3
  Association. This program is free software; you can redistribute it and/or modify
4
  it under the terms of the GNU General Public License as published by the Free Software
5
  Foundation; either version 3 of the License, or (at your option) any later version.
6
  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
7
  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8
  PURPOSE. See the GNU General Public License for more details. You should have received
9
  a copy of the GNU General Public License along with this program; if not, write to
10
  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
11
  USA. For any additional information, do not hesitate to contact us at info AT gvsig.com,
12
  or visit our website www.gvsig.com. -->
13
<plugin-config>
14
  <depends plugin-name="org.gvsig.app.mainplugin" />
15
  <resourceBundle name="text" />
16
  <libraries library-dir="lib" />
17
  <extensions>
18
    <extension class-name="org.gvsig.legend.filteredheatmap.app.FilteredHeatmapLegendExtension"
19
      description="" active="true" priority="1">
20

  
21
    </extension>
22

  
23
  </extensions>
24
</plugin-config>
org.gvsig.legend.filteredheatmap/tags/org.gvsig.legend.filteredheatmap-1.0.142/org.gvsig.legend.filteredheatmap.app/org.gvsig.legend.filteredheatmap.app.mainplugin/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.legend.filteredheatmap.app</artifactId>
6
    <version>1.0.142</version>
7
  </parent>
8
  <groupId>org.gvsig</groupId>
9
  <artifactId>org.gvsig.legend.filteredheatmap.app.mainplugin</artifactId>
10
  <version>1.0.142</version>
11
  <name>org.gvsig.legend.filteredheatmap.app.mainplugin</name>
12

  
13
    <properties>
14
    <!-- Package info property values -->
15
    <gvsig.package.info.state>testing</gvsig.package.info.state>
16
    <gvsig.package.info.dependencies>required: org.gvsig.app.mainplugin -ge 2.4.0-A</gvsig.package.info.dependencies>
17
    <gvsig.package.info.official>true</gvsig.package.info.official>
18
    <gvsig.package.info.name>Vector legend: filtered heat map</gvsig.package.info.name>
19
    <gvsig.package.info.description>Legend for aggregate text symbols that are near.</gvsig.package.info.description>
20
    <gvsig.package.info.categories>View,Vector,Symbology</gvsig.package.info.categories>
21
    <gvsig.package.info.javaVM>j1_7</gvsig.package.info.javaVM>
22
    <gvsig.package.info.poolURL>https://devel.gvsig.org/download/projects/gvsig-base-legends/pool</gvsig.package.info.poolURL>
23
  </properties>
24

  
25
  <dependencies>
26
    <dependency>
27
      <groupId>org.gvsig</groupId>
28
      <artifactId>org.gvsig.andami</artifactId>
29
      <scope>compile</scope>
30
    </dependency>
31
    <dependency>
32
      <groupId>org.gvsig</groupId>
33
      <artifactId>org.gvsig.legend.filteredheatmap.swing.api</artifactId>
34
      <scope>compile</scope>
35
    </dependency>
36
    <dependency>
37
      <groupId>org.gvsig</groupId>
38
      <artifactId>org.gvsig.legend.filteredheatmap.lib.api</artifactId>
39
      <scope>compile</scope>
40
    </dependency>
41
    <dependency>
42
      <groupId>org.gvsig</groupId>
43
      <artifactId>org.gvsig.legend.filteredheatmap.lib.impl</artifactId>
44
      <scope>runtime</scope>
45
    </dependency>
46
    <dependency>
47
      <groupId>org.gvsig</groupId>
48
      <artifactId>org.gvsig.legend.filteredheatmap.swing.impl</artifactId>
49
      <scope>runtime</scope>
50
    </dependency>
51
    <dependency>
52
      <groupId>org.gvsig</groupId>
53
      <artifactId>org.gvsig.app.mainplugin</artifactId>
54
      <scope>compile</scope>
55
    </dependency>
56
  </dependencies>
57
</project>
org.gvsig.legend.filteredheatmap/tags/org.gvsig.legend.filteredheatmap-1.0.142/org.gvsig.legend.filteredheatmap.app/org.gvsig.legend.filteredheatmap.app.mainplugin/buildNumber.properties
1
#Sat Oct 14 19:19:46 CEST 2023
2
buildNumber=146
org.gvsig.legend.filteredheatmap/tags/org.gvsig.legend.filteredheatmap-1.0.142/org.gvsig.legend.filteredheatmap.lib/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.legend.filteredheatmap</artifactId>
6
    <version>1.0.142</version>
7
  </parent>
8
  <groupId>org.gvsig</groupId>
9
  <artifactId>org.gvsig.legend.filteredheatmap.lib</artifactId>
10
  <packaging>pom</packaging>
11
  <modules>
12
    <module>org.gvsig.legend.filteredheatmap.lib.api</module>
13
    <module>org.gvsig.legend.filteredheatmap.lib.impl</module>
14
  </modules>
15
</project>
org.gvsig.legend.filteredheatmap/tags/org.gvsig.legend.filteredheatmap-1.0.142/org.gvsig.legend.filteredheatmap.lib/org.gvsig.legend.filteredheatmap.lib.api/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.legend.filteredheatmap.lib.api.FilteredHeatmapLegendLibrary
org.gvsig.legend.filteredheatmap/tags/org.gvsig.legend.filteredheatmap-1.0.142/org.gvsig.legend.filteredheatmap.lib/org.gvsig.legend.filteredheatmap.lib.api/src/main/java/org/gvsig/legend/filteredheatmap/lib/api/FilteredHeatmapLegend.java
1
package org.gvsig.legend.filteredheatmap.lib.api;
2

  
3
import java.awt.Color;
4
import org.gvsig.expressionevaluator.Expression;
5
import org.gvsig.fmap.geom.Geometry;
6
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend;
7

  
8
public interface FilteredHeatmapLegend extends IVectorLegend {
9

  
10
    public int getDistance();
11

  
12
    public void setDistance(int distance);
13

  
14
    public void setColorTable(Color[] colorTable);
15

  
16
    public void setColorTable(int numColors, Color coldColor, Color hotColor);
17

  
18
    public Color[] getSourceColorTable();
19

  
20
    public Color[] getTargetColorTable();
21
    
22
    public Geometry getROI();
23
    
24
    public void setROI(Geometry roi);
25

  
26
    public boolean useRamp();
27

  
28
    public String getFieldName();
29

  
30
    public void setFieldName(String fieldName);
31

  
32
    public int getColorTableHotColorAlpha();
33

  
34
    public void setColorTableHotColorAlpha(int colorTableHotColorAlpha);
35

  
36
    public int getColorTableColdColorAlpha();
37

  
38
    public void setColorTableColdColorAlpha(int colorTableColdColorAlpha);
39

  
40
    public boolean useAlphaInColorTable();
41

  
42
    public boolean setUseAlphaInColorTable(boolean use);
43

  
44
    public int getRampNumColors();
45

  
46
    public Color getRampColdColor();
47

  
48
    public Color getRampHotColor();
49
    
50
    public int getFilterProportionValue();
51
    public void setFilterProportionValue(int proportionValue);
52
    
53
    public Expression getFilterByExpression();
54
    public void setFilterByExpression(Expression filterExpression);
55
    
56
    public boolean getUseFilterByExpression();
57
    public void setUseFilterByExpression(boolean useFilterExpression);
58
    
59
    public Expression getKernelExpression();
60
    public void setKernelExpression(Expression kernelExpression);
61
    
62
    
63

  
64
}
org.gvsig.legend.filteredheatmap/tags/org.gvsig.legend.filteredheatmap-1.0.142/org.gvsig.legend.filteredheatmap.lib/org.gvsig.legend.filteredheatmap.lib.api/src/main/java/org/gvsig/legend/filteredheatmap/lib/api/FilteredHeatmapLegendLocator.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2015 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.legend.filteredheatmap.lib.api;
24

  
25
import org.gvsig.expressionevaluator.SymbolTable;
26
import org.gvsig.tools.locator.AbstractLocator;
27
import org.gvsig.tools.locator.Locator;
28
import org.gvsig.tools.locator.LocatorException;
29

  
30

  
31
public class FilteredHeatmapLegendLocator extends AbstractLocator {
32

  
33
    /**
34
     * FilteredHeatmapLegend locator name
35
     */
36
    private static final String LOCATOR_NAME = "FilteredHeatmapLegendLocator";
37

  
38
    /**
39
     * HeatmapLegend manager name
40
     */
41
    public static final String MANAGER_NAME = "FilteredHeatmapLegendManager";
42

  
43
    /**
44
     * HeatmapLegend manager description
45
     */
46
    private static final String MANAGER_DESCRIPTION =
47
        "FilteredHeatmapLegend Manager of gvSIG";
48

  
49

  
50
    /**
51
     * Unique instance
52
     */
53
    private static final FilteredHeatmapLegendLocator instance = new FilteredHeatmapLegendLocator();
54

  
55
    @Override
56
    public String getLocatorName() {
57
        return LOCATOR_NAME;
58
    }
59

  
60
    /**
61
     * Registers the Class implementing the FilteredHeatmapLegendManager interface.
62
     *
63
     * @param clazz
64
     *            implementing the FilteredHeatmapLegendManager interface
65
     */
66
    public static void registerFilteredHeatmapLegendManager(Class clazz){
67
        getInstance().register(MANAGER_NAME, MANAGER_DESCRIPTION, clazz);
68
    }
69

  
70
    /**
71
     * Registers the default Class implementing the FilteredHeatmapLegendManager interface
72
     *
73
     * @param clazz
74
     *            implementing the FilteredHeatmapLegendManager interface
75
     */
76
    public static void registerDefaultFilteredHeatmapLegendManager(Class clazz){
77
        getInstance().registerDefault(MANAGER_NAME, MANAGER_DESCRIPTION, clazz);
78
    }
79

  
80
    /**
81
     * Return a reference to FilteredHeatmapLegendManager.
82
     *
83
     * @return a reference to HeatmapLegendManager
84
     * @throws LocatorException
85
     *             if there is no access to the class or the class
86
     *             cannot be instantiated
87
     * @see Locator#get(String)
88
     */
89
    public static FilteredHeatmapLegendManager getFilteredHeatmapLegendManager() throws LocatorException {
90
        return (FilteredHeatmapLegendManager) getInstance().get(MANAGER_NAME);
91
    }
92

  
93
    /**
94
     * @return
95
     */
96
    public static Locator getInstance() {
97
        return instance;
98
    }
99

  
100
}
org.gvsig.legend.filteredheatmap/tags/org.gvsig.legend.filteredheatmap-1.0.142/org.gvsig.legend.filteredheatmap.lib/org.gvsig.legend.filteredheatmap.lib.api/src/main/java/org/gvsig/legend/filteredheatmap/lib/api/FilteredHeatmapLegendLibrary.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2015 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.legend.filteredheatmap.lib.api;
24

  
25
import org.gvsig.fmap.mapcontext.MapContextLocator;
26
import org.gvsig.fmap.mapcontext.MapContextManager;
27
import org.gvsig.fmap.mapcontext.rendering.legend.driver.ILegendWriter;
28
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager;
29
import org.gvsig.symbology.SymbologyLocator;
30
import org.gvsig.symbology.SymbologyManager;
31
import org.gvsig.tools.library.AbstractLibrary;
32
import org.gvsig.tools.library.LibraryException;
33
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
34

  
35

  
36
public class FilteredHeatmapLegendLibrary extends AbstractLibrary {
37

  
38
    @Override
39
    protected void doInitialize() throws LibraryException {
40
        registerAsAPI(FilteredHeatmapLegendLibrary.class);
41
    }
42

  
43
    @Override
44
    protected void doPostInitialize() throws LibraryException {
45
        // Validate there is any implementation registered.
46
        FilteredHeatmapLegendManager manager = FilteredHeatmapLegendLocator.getFilteredHeatmapLegendManager();
47
        if (manager == null) {
48
            throw new ReferenceNotRegisteredException(
49
                FilteredHeatmapLegendLocator.MANAGER_NAME, FilteredHeatmapLegendLocator.getInstance());
50
        }
51

  
52
        SymbologyManager symbolManager = SymbologyLocator.getSymbologyManager();
53
        ILegendWriter legendWriter = symbolManager.getDefaultLegendWriter();
54

  
55
        MapContextManager mcoman = MapContextLocator.getMapContextManager();
56
        mcoman.registerLegendWriter(
57
            FilteredHeatmapLegend.class,
58
            SymbolManager.LEGEND_FILE_EXTENSION.substring(1),
59
            legendWriter.getClass());
60
    }
61

  
62
}
org.gvsig.legend.filteredheatmap/tags/org.gvsig.legend.filteredheatmap-1.0.142/org.gvsig.legend.filteredheatmap.lib/org.gvsig.legend.filteredheatmap.lib.api/src/main/java/org/gvsig/legend/filteredheatmap/lib/api/KernelExpressionAlgorithm.java
1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6
package org.gvsig.legend.filteredheatmap.lib.api;
7

  
8
import java.awt.Color;
9
import java.awt.Graphics2D;
10
import java.awt.image.BufferedImage;
11
import org.gvsig.expressionevaluator.Expression;
12
import org.gvsig.fmap.geom.Geometry;
13
import org.gvsig.tools.task.Cancellable;
14

  
15
/**
16
 *
17
 * @author osc
18
 */
19
public interface KernelExpressionAlgorithm {
20

  
21
    public void setDistance(int distance);
22

  
23
    public int getDistance();
24

  
25
    public void init(int with, int height);
26

  
27
    public void add(int px, int py);
28

  
29
    public void add(int px, int py, double value);
30

  
31
    public void drawWithOpaqueColors(BufferedImage img, Graphics2D g, Color[] colorTable, Cancellable cancel, Geometry roi, int limitProportionToDraw);
32

  
33
    public void drawWithAlphaColors(BufferedImage img, Graphics2D g, Color[] colorTable, Cancellable cancel, Geometry roi, int limitProportion);
34

  
35
    public Expression getKernelExpression();
36

  
37
    public void setKernelExpression(Expression kernelExpression);
38
}
org.gvsig.legend.filteredheatmap/tags/org.gvsig.legend.filteredheatmap-1.0.142/org.gvsig.legend.filteredheatmap.lib/org.gvsig.legend.filteredheatmap.lib.api/src/main/java/org/gvsig/legend/filteredheatmap/lib/api/FilteredHeatmapLegendManager.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2015 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 3
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.legend.filteredheatmap.lib.api;
24

  
25
import org.gvsig.expressionevaluator.SymbolTable;
26

  
27

  
28
public interface FilteredHeatmapLegendManager {
29

  
30
    /**
31
     * Creates an aggregate legend
32
     *
33
     * @return the aggregate legend
34
     */
35
    public FilteredHeatmapLegend create();
36

  
37
    public Class<? extends FilteredHeatmapLegend> getLegendClass(); 
38
    
39
    public SymbolTable createKernelSymbolTable(KernelExpressionAlgorithm alg, int x, int y);
40
    
41
    public KernelExpressionAlgorithm createKernelExpressionAlgorithm(int distance);
42
    
43
}
org.gvsig.legend.filteredheatmap/tags/org.gvsig.legend.filteredheatmap-1.0.142/org.gvsig.legend.filteredheatmap.lib/org.gvsig.legend.filteredheatmap.lib.api/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
  <groupId>org.gvsig</groupId>
4
  <artifactId>org.gvsig.legend.filteredheatmap.lib.api</artifactId>
5
  <name>org.gvsig.legend.filteredheatmap.lib.api</name>
6
  <parent>
7
    <groupId>org.gvsig</groupId>
8
    <artifactId>org.gvsig.legend.filteredheatmap.lib</artifactId>
9
    <version>1.0.142</version>
10
  </parent>
11

  
12
  <build>
13
    <plugins>
14
      <plugin>
15
        <groupId>org.apache.maven.plugins</groupId>
16
        <artifactId>maven-jar-plugin</artifactId>
17
        <configuration>
18
        </configuration>
19
        <executions>
20
          <!-- Generates a jar file only with the test classes -->
21
          <execution>
22
            <goals>
23
              <goal>test-jar</goal>
24
            </goals>
25
          </execution>
26
        </executions>
27
      </plugin>
28
    </plugins>
29
  </build>
30

  
31
  <dependencies>
32
    <dependency>
33
      <groupId>org.gvsig</groupId>
34
      <artifactId>org.gvsig.tools.lib</artifactId>
35
      <scope>compile</scope>
36
    </dependency>
37
    <dependency>
38
      <groupId>org.gvsig</groupId>
39
      <artifactId>org.gvsig.fmap.mapcontext.api</artifactId>
40
      <scope>compile</scope>
41
    </dependency>
42
    <dependency>
43
      <groupId>org.gvsig</groupId>
44
      <artifactId>org.gvsig.symbology.lib.api</artifactId>
45
    </dependency>
46
  </dependencies>
47
</project>
org.gvsig.legend.filteredheatmap/tags/org.gvsig.legend.filteredheatmap-1.0.142/org.gvsig.legend.filteredheatmap.lib/org.gvsig.legend.filteredheatmap.lib.impl/src/main/java/org/gvsig/legend/filteredheatmap/lib/impl/DefaultKernelExpressionAlgorithm.java
1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6
package org.gvsig.legend.filteredheatmap.lib.impl;
7

  
8
import java.awt.Color;
9
import java.awt.Graphics2D;
10
import java.awt.image.BufferedImage;
11
import java.util.ArrayList;
12
import java.util.Arrays;
13
import org.gvsig.expressionevaluator.Expression;
14
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator;
15
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager;
16
import org.gvsig.expressionevaluator.MutableSymbolTable;
17
import org.gvsig.fmap.geom.Geometry;
18
import org.gvsig.fmap.geom.GeometryUtils;
19
import org.gvsig.fmap.geom.primitive.Point;
20
import org.gvsig.legend.filteredheatmap.lib.api.KernelExpressionAlgorithm;
21
import org.gvsig.tools.logger.FilteredLogger;
22
import org.gvsig.tools.swing.api.ToolsSwingLocator;
23
import org.gvsig.tools.swing.api.ToolsSwingManager;
24
import org.gvsig.tools.task.Cancellable;
25
import org.slf4j.Logger;
26
import org.slf4j.LoggerFactory;
27

  
28
/**
29
 *
30
 * @author osc
31
 */
32
public class DefaultKernelExpressionAlgorithm implements KernelExpressionAlgorithm {
33

  
34
    private double[][] grid;
35
    private double[][] kernel;
36
    private int distance;
37
    private int height;
38
    private int with;
39
    private double maxValue;
40
    private double minValue;
41
    private Expression kernelExpression;
42
    protected static final Logger LOG = LoggerFactory
43
            .getLogger(KernelExpressionAlgorithm.class);
44
    protected static final FilteredLogger LOGF = new FilteredLogger(LOG, "KernelExpressionAlgorithm", 30);
45
    private boolean forceUpdate;
46
    private KernelSymbolTable kSymbolTable;
47
    private MutableSymbolTable kernelsymbolTable;
48

  
49
    public DefaultKernelExpressionAlgorithm(int distance, Expression kernelExpression) {
50
        this.init(distance, distance);
51
        this.setKernelExpression(kernelExpression);
52
        this.setDistance(distance);
53
    }
54

  
55
    @Override
56
    public Expression getKernelExpression() {
57
        return this.kernelExpression;
58
    }
59

  
60
    @Override
61
    public void setDistance(int distance) {
62
        if (forceUpdate) {
63
            forceUpdate = false;
64
        } else {
65
            if (this.distance == distance) {
66
                return;
67
            }
68
        }
69
        if (this.distance == distance) {
70
            return;
71
        }
72
        this.distance = distance;
73

  
74
        this.kernel = new double[2 * this.distance + 1][2 * this.distance + 1];
75
        if (kernelExpression == null || kernelExpression.isEmpty()) {
76
            return;
77
        }
78

  
79
        Object value;
80

  
81
        for (int y = -this.distance; y < this.distance + 1; y++) {
82
            for (int x = -this.distance; x < this.distance + 1; x++) {
83
                final double dDist = Math.sqrt(x * x + y * y);
84
                if (dDist < this.distance) {
85
                    kSymbolTable.setXY(x, y);
86
                    kSymbolTable.setAlgorithm(this);
87
                    try {
88
                        value = this.kernelExpression.execute(kernelsymbolTable);
89
                    } catch (Exception e) {
90
                        LOGF.warn("Problems executing expression.");
91
                        continue;
92
                    }
93
                    String obj = value.toString();
94
                    this.kernel[x + this.distance][y + this.distance] = Double.parseDouble(obj);
95

  
96
                } else {
97
                    this.kernel[x + this.distance][y + this.distance] = 0;
98
                }
99
            }
100
        }
101
    }
102

  
103
    @Override
104
    public int getDistance() {
105
        return this.distance;
106
    }
107

  
108
    @Override
109
    public void init(int with, int height) {
110
        this.with = with;
111
        this.height = height;
112
        this.grid = new double[with][height];
113
        this.maxValue = 0;
114
        this.minValue = 0;
115
    }
116

  
117
    @Override
118
    public void add(int px, int py) {
119
        add(px, py, 1);
120
    }
121

  
122
    @Override
123
    public void add(int px, int py, double value) {
124
        for (int y = -this.distance; y < this.distance + 1; y++) {
125
            for (int x = -this.distance; x < this.distance + 1; x++) {
126
                if (this.kernel[x + this.distance][y + this.distance] != 0) {
127
                    addValue(px + x, py + y, value * this.kernel[x + this.distance][y + this.distance]);
128
                }
129
            }
130
        }
131
    }
132

  
133
    private void addValue(int px, int py, double value) {
134
        if (px < 0 || py < 0 || px >= with || py >= height) {
135
            return;
136
        }
137
        value += this.grid[px][py];
138
        this.grid[px][py] = value;
139
        if (value > this.maxValue) {
140
            this.maxValue = value;
141
        }
142
        if (value < this.minValue) {
143
            this.minValue = value;
144
        }
145
    }
146

  
147
    @Override
148
    public void drawWithOpaqueColors(BufferedImage img, Graphics2D g, Color[] colorTable, Cancellable cancel, Geometry roi, int limitProportion) {
149
        try {
150
            ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager();
151
            Color c;
152
            double valueForLimit;
153
            if (limitProportion == 100) {
154
                return;
155
            } else if (limitProportion > 0 && limitProportion < 100) {
156
                ArrayList<Double> singleArray = new ArrayList<>();
157
                for (double[] ds : this.grid) {
158
                    for (double d : ds) {
159
                        if (d != 0) {
160
                            singleArray.add(d);
161
                        }
162
                    }
163
                }
164
                int size = singleArray.size();
165
                Double[] sd = singleArray.toArray(new Double[singleArray.size()]);
166
                Arrays.sort(sd);
167
                int indexForLimitValue = ((size - 1) * limitProportion) / 100;
168
                valueForLimit = sd[indexForLimitValue];
169
            } else {
170
                valueForLimit = 0.0;
171
            }
172

  
173
            int maxIndexColor = colorTable.length - 1;
174
            //double minValueToDraw = ((maxValue - minValue) * limitProportion) / 100;
175

  
176
            for (int x = 0; x < with; x++) {
177
                for (int y = 0; y < height; y++) {
178
                    if (cancel.isCanceled()) {
179
                        return;
180
                    }
181
                    if (roi != null) {
182
                        Point point = GeometryUtils.createPoint(x, y);
183
                        if (!roi.intersects(point)) {
184
                            continue;
185
                        }
186
                    }
187
                    double value = this.grid[x][y];
188
                    if (value > 0) {
189
                        if (value < valueForLimit) {
190
                            continue;
191
                        }
192
                        int icolor = this.calculateIndexColor(value, valueForLimit, maxIndexColor);
193
//                        int icolor = (int) (value * maxIndexColor / maxValue);
194
                        c = toolsSwingManager.alphaBlendingWithOpaqueBackground(
195
                                new Color(img.getRGB(x, y)),
196
                                colorTable[icolor]
197
                        );
198
                        img.setRGB(x, y, c.getRGB());
199
                    }
200
                }
201
            }
202
        } catch (Exception ex) {
203
            LOGF.warn("Problems drawing heatmap", ex);
204
        }
205
    }
206

  
207
    // Adapt values to the proportion between minValueToDraw and maxValue of the grid
208
    public int calculateIndexColor(double value, double minValueToDraw, int maxIndexColor) {
209

  
210
        double d = maxValue - minValueToDraw;
211
        double dif = value - minValueToDraw;
212

  
213
        int x = (int) ((dif * maxIndexColor) / d);
214
        if (x > maxIndexColor) {
215
            LOGF.warn("Problems drawing heatmap. Index color is bigger than maxIndexColor");
216
            return maxIndexColor;
217
        } else if (x < 0) {
218
            LOGF.warn("Problems drawing heatmap. Index color is bellow 0");
219
            return 0;
220
        }
221
        return x;
222
    }
223

  
224
    @Override
225
    public void drawWithAlphaColors(BufferedImage img, Graphics2D g, Color[] colorTable, Cancellable cancel, Geometry roi, int limitProportion) {
226
        try {
227
            ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager();
228
            Color c;
229
            double valueForLimit;
230
            if (limitProportion == 100) {
231
                return;
232
            } else if (limitProportion > 0 && limitProportion < 100) {
233
                ArrayList<Double> singleArray = new ArrayList<>();
234
                for (double[] ds : this.grid) {
235
                    for (double d : ds) {
236
                        if (d != 0) {
237
                            singleArray.add(d);
238
                        }
239
                    }
240
                }
241
                int size = singleArray.size();
242
                Double[] sd = singleArray.toArray(new Double[singleArray.size()]);
243
                Arrays.sort(sd);
244
                int indexForLimitValue = ((size - 1) * limitProportion) / 100;
245
                valueForLimit = sd[indexForLimitValue];
246
            } else {
247
                valueForLimit = 0.0;
248
            }
249

  
250
            int maxIndexColor = colorTable.length - 1;
251
            //double minValueToDraw = ((maxValue - minValue) * limitProportion) / 100;
252

  
253
            for (int x = 0; x < with; x++) {
254
                for (int y = 0; y < height; y++) {
255
                    if (cancel.isCanceled()) {
256
                        return;
257
                    }
258
                    if (roi != null) {
259
                        Point point = GeometryUtils.createPoint(x, y);
260
                        if (!roi.intersects(point)) {
261
                            continue;
262
                        }
263
                    }
264
                    double value = this.grid[x][y];
265
                    if (value > 0) {
266
                        if (value < valueForLimit) {
267
                            continue;
268
                        }
269
                        int icolor = this.calculateIndexColor(value, valueForLimit, maxIndexColor);
270
                        c = colorTable[icolor];
271
                        img.setRGB(x, y, c.getRGB());
272
                    }
273
                }
274
            }
275
        } catch (Exception ex) {
276
            LOGF.warn("Problems drawing heatmap", ex);
277
        }
278
    }
279

  
280
    @Override
281
    public void setKernelExpression(Expression kernelExpression) {
282
        if (this.kernelExpression != kernelExpression) {
283
            this.kernelExpression = kernelExpression;
284
            this.forceUpdate = true;
285
            this.setDistance(this.distance);
286

  
287
            this.kSymbolTable = new KernelSymbolTable(this, 0, 0);
288
//            kernelExpression.link(kSymbolTable);
289

  
290
            ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager();
291

  
292
            kernelsymbolTable = manager.createSymbolTable();
293
            kernelsymbolTable.addSymbolTable(kSymbolTable);
294

  
295
        }
296
    }
297

  
298
}
org.gvsig.legend.filteredheatmap/tags/org.gvsig.legend.filteredheatmap-1.0.142/org.gvsig.legend.filteredheatmap.lib/org.gvsig.legend.filteredheatmap.lib.impl/src/main/java/org/gvsig/legend/filteredheatmap/lib/impl/DefaultFilteredHeatmapLegendManager.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2015 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.legend.filteredheatmap.lib.impl;
24

  
25
import org.gvsig.expressionevaluator.SymbolTable;
26
import org.gvsig.legend.filteredheatmap.lib.api.FilteredHeatmapLegend;
27
import org.gvsig.legend.filteredheatmap.lib.api.FilteredHeatmapLegendManager;
28
import org.gvsig.legend.filteredheatmap.lib.api.KernelExpressionAlgorithm;
29

  
30

  
31
public class DefaultFilteredHeatmapLegendManager implements FilteredHeatmapLegendManager {
32

  
33
    @Override
34
    public FilteredHeatmapLegend create() {
35
        return new DefaultFilteredHeatmapLegend();
36
    }
37

  
38
    @Override
39
    public Class<? extends FilteredHeatmapLegend> getLegendClass() {
40
        return DefaultFilteredHeatmapLegend.class;
41
    }
42
    
43
        
44
    @Override
45
    public SymbolTable createKernelSymbolTable(KernelExpressionAlgorithm alg, int x, int y) {
46
        return new KernelSymbolTable(alg, x, y);
47
    }
48
    
49
    @Override
50
    public KernelExpressionAlgorithm createKernelExpressionAlgorithm(int distance) {
51
        return new DefaultKernelExpressionAlgorithm(distance, null);
52
    }
53

  
54
}
org.gvsig.legend.filteredheatmap/tags/org.gvsig.legend.filteredheatmap-1.0.142/org.gvsig.legend.filteredheatmap.lib/org.gvsig.legend.filteredheatmap.lib.impl/src/main/java/org/gvsig/legend/filteredheatmap/lib/impl/KernelSymbolTable.java
1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6
package org.gvsig.legend.filteredheatmap.lib.impl;
7

  
8
import org.apache.commons.lang3.Range;
9
import org.gvsig.expressionevaluator.Interpreter;
10
import org.gvsig.expressionevaluator.spi.AbstractFunction;
11
import org.gvsig.expressionevaluator.spi.AbstractSymbolTable;
12
import org.gvsig.fmap.dal.DataManager;
13
import org.gvsig.legend.filteredheatmap.lib.api.KernelExpressionAlgorithm;
14

  
15
/**
16
 *
17
 * @author osc
18
 */
19
public class KernelSymbolTable extends AbstractSymbolTable {
20

  
21
    private KernelExpressionAlgorithm algorithm;
22
    private int pixely;
23
    private int pixelx;
24
    private double pixeldistance;
25

  
26
    public KernelSymbolTable(KernelExpressionAlgorithm algorithm, int x, int y) {
27
        super(DataManager.DAL_SYMBOL_TABLE);
28
        this.algorithm = algorithm;
29
        this.pixelx = x;
30
        this.pixely = y;
31
        this.pixeldistance = 15;
32
        this.addFunction(new KernelDistanceFunc());
33
        this.addFunction(new PixelDistanceFunc());
34
        this.addFunction(new PixelXFunc());
35
        this.addFunction(new PixelYFunc());
36

  
37
    }
38
    @Override
39
    public KernelSymbolTable clone() throws CloneNotSupportedException {
40
        KernelSymbolTable other = (KernelSymbolTable) super.clone();
41
        return other;
42
    }
43
    
44
    public void setAlgorithm(KernelExpressionAlgorithm algorithm) {
45
        this.algorithm = algorithm;
46
    }
47

  
48
    public void setXY(int x, int y) {
49
        this.pixelx = x;
50
        this.pixely = y;
51
        this.pixeldistance = Math.sqrt(pixelx * pixelx + pixely * pixely);
52
    }
53

  
54
    public class KernelDistanceFunc extends AbstractFunction {
55

  
56
        public KernelDistanceFunc() {
57
            super(
58
                    "Kernel Algorithm",
59
                    "kerneldistance",
60
                    Range.is(0),
61
                    "Return the distance",
62
                    "kerneldistance()",
63
                    null,
64
                    "Integer"
65
            );
66
        }
67

  
68
        @Override
69
        public Object call(Interpreter interpreter, Object[] args) throws Exception {
70
            return algorithm.getDistance();
71
        }
72

  
73
    }
74

  
75
    public class PixelDistanceFunc extends AbstractFunction {
76

  
77
        public PixelDistanceFunc() {
78
            super(
79
                    "Kernel Algorithm",
80
                    "pixeldistance",
81
                    Range.is(0),
82
                    "Return the distance to the pixel",
83
                    "pixeldistance()",
84
                    null,
85
                    "Double"
86
            );
87
        }
88

  
89
        @Override
90
        public Object call(Interpreter interpreter, Object[] args) throws Exception {
91
            return pixeldistance;
92
        }
93

  
94
    }
95

  
96
    public class PixelXFunc extends AbstractFunction {
97

  
98
        public PixelXFunc() {
99
            super(
100
                    "Kernel Algorithm",
101
                    "pixelx",
102
                    Range.is(0),
103
                    "Return the pixel coordinate x",
104
                    "pixelx()",
105
                    null,
106
                    "Double"
107
            );
108
        }
109

  
110
        @Override
111
        public Object call(Interpreter interpreter, Object[] args) throws Exception {
112
            return pixelx;
113
        }
114

  
115
    }
116

  
117
    public class PixelYFunc extends AbstractFunction {
118

  
119
        public PixelYFunc() {
120
            super(
121
                    "Kernel Algorithm",
122
                    "pixely",
123
                    Range.is(0),
124
                    "Return the pixel coordinate y",
125
                    "pixely()",
126
                    null,
127
                    "Double"
128
            );
129
        }
130

  
131
        @Override
132
        public Object call(Interpreter interpreter, Object[] args) throws Exception {
133
            return pixely;
134
        }
135

  
136
    }
137
}
org.gvsig.legend.filteredheatmap/tags/org.gvsig.legend.filteredheatmap-1.0.142/org.gvsig.legend.filteredheatmap.lib/org.gvsig.legend.filteredheatmap.lib.impl/src/main/java/org/gvsig/legend/filteredheatmap/lib/impl/DefaultFilteredHeatmapLegend.java
1
package org.gvsig.legend.filteredheatmap.lib.impl;
2

  
3
import java.awt.Color;
4
import java.awt.Graphics2D;
5
import java.awt.Image;
6
import java.awt.image.BufferedImage;
7
import java.util.ArrayList;
8
import java.util.Map;
9

  
10
import org.apache.commons.lang3.StringUtils;
11
import org.cresques.cts.ICoordTrans;
12
import org.gvsig.compat.print.PrintAttributes;
13
import org.gvsig.expressionevaluator.Expression;
14
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator;
15
import org.gvsig.expressionevaluator.MutableSymbolTable;
16
import org.gvsig.fmap.dal.DALLocator;
17

  
18
import org.gvsig.fmap.dal.exception.DataException;
19
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable;
20
import org.gvsig.fmap.dal.feature.Feature;
21
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
22
import org.gvsig.fmap.dal.feature.FeatureQuery;
23
import org.gvsig.fmap.dal.feature.FeatureSelection;
24
import org.gvsig.fmap.dal.feature.FeatureSet;
25
import org.gvsig.fmap.dal.feature.FeatureStore;
26
import org.gvsig.fmap.dal.feature.FeatureType;
27
import org.gvsig.fmap.geom.Geometry;
28
import org.gvsig.fmap.geom.primitive.Point;
29
import org.gvsig.fmap.mapcontext.MapContextException;
30
import org.gvsig.fmap.mapcontext.ViewPort;
31
import org.gvsig.fmap.mapcontext.layers.operations.IHasImageLegend;
32
import org.gvsig.fmap.mapcontext.rendering.legend.LegendException;
33
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent;
34
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
35
import org.gvsig.gui.ColorTablePainter;
36
import org.gvsig.gui.DefaultColorTablePainter;
37
import org.gvsig.legend.filteredheatmap.lib.api.FilteredHeatmapLegend;
38
import org.gvsig.legend.filteredheatmap.lib.api.KernelExpressionAlgorithm;
39
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractVectorialLegend;
40
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.DefaultFeatureDrawnNotification;
41
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.text.impl.SimpleTextSymbol;
42
import org.gvsig.tools.exception.BaseException;
43
import org.gvsig.tools.persistence.PersistentState;
44
import org.gvsig.tools.persistence.exception.PersistenceException;
45
import org.gvsig.tools.task.Cancellable;
46
import org.gvsig.tools.visitor.VisitCanceledException;
47
import org.gvsig.tools.visitor.Visitor;
48

  
49
public class DefaultFilteredHeatmapLegend extends AbstractVectorialLegend implements FilteredHeatmapLegend, IHasImageLegend {
50

  
51
    private ISymbol defaultSymbol;
52
    private KernelExpressionAlgorithm algorithm;
53
    private boolean isRamp;
54
    private Color[] sourceColorTable;
55
    private int colorTableHotColorAlpha;
56
    private int colorTableColdColorAlpha;
57
    private boolean useAlphaInColorTable;
58
    private String fieldName;
59
    private Image imageLegend;
60
    private HeatmapColorTable hmColorTable;
61
    private Color rampColdColor;
62
    private Color rampHotColor;
63
    private int rampNumColors;
64
    private Geometry roi;
65
    private int proportionValue;
66
    private Expression filterExpression;
67
    private boolean useFilterExpression;
68

  
69
    public DefaultFilteredHeatmapLegend() {
70

  
71
        this.defaultSymbol = new SimpleTextSymbol();
72
        Expression kernelPowExp = ExpressionEvaluatorLocator.getExpressionEvaluatorManager().createExpression();
73
        kernelPowExp.setPhrase("power(1-(power(pixeldistance(), 2)/power(kerneldistance(), 2)),2)");
74
        this.algorithm = new DefaultKernelExpressionAlgorithm(30, kernelPowExp);
75
        this.colorTableHotColorAlpha = 255;
76
        this.colorTableColdColorAlpha = 0;
77
        this.useAlphaInColorTable = false;
78
        this.setColorTable(100, new Color(0, 0, 255, 0), new Color(255, 0, 0, 255));
79
        this.imageLegend = null;
80
        this.hmColorTable = null;
81
        this.fieldName = null;
82
        
83
        
84
    }
85

  
86
    @Override
87
    public Expression getKernelExpression() {
88
        return this.algorithm.getKernelExpression();
89
    }
90

  
91
    @Override
92
    public void setKernelExpression(Expression kernelExpression) {
93
        this.algorithm.setKernelExpression(kernelExpression);
94
    }
95

  
96
    @Override
97
    public int getFilterProportionValue() {
98
        return this.proportionValue;
99
    }
100

  
101
    @Override
102
    public void setFilterProportionValue(int proportionValue) {
103
        this.proportionValue = proportionValue;
104
    }
105

  
106
    @Override
107
    public Expression getFilterByExpression() {
108
        return this.filterExpression;
109
    }
110

  
111
    @Override
112
    public void setFilterByExpression(Expression filterExpression) {
113
        this.filterExpression = filterExpression;
114
    }
115

  
116
    @Override
117
    public boolean getUseFilterByExpression() {
118
        return this.useFilterExpression;
119
    }
120

  
121
    @Override
122
    public void setUseFilterByExpression(boolean useFilterExpression) {
123
        this.useFilterExpression = useFilterExpression;
124
    }
125

  
126
    @Override
127
    protected String[] getRequiredFeatureAttributeNames(FeatureStore featureStore) throws DataException {
128
        FeatureType ftype = featureStore.getDefaultFeatureType();
129
//        String[] allAttributes = new String[ftype.getAttributeDescriptors().length];
130
        ArrayList<String> arrayAttributes = new ArrayList<>();
131
        for (FeatureAttributeDescriptor attributeDescriptor : ftype.getAttributeDescriptors()) {
132
            arrayAttributes.add(attributeDescriptor.getName());
133
        }
134
        String[] a = arrayAttributes.toArray(new String[arrayAttributes.size()]);
135
        return a;
136
    }
137

  
138
    @Override
139
    public ISymbol getDefaultSymbol() {
140
        return this.defaultSymbol;
141
    }
142

  
143
    @Override
144
    public void setDefaultSymbol(ISymbol is) {
145
    }
146

  
147
    @Override
148
    public ISymbol getSymbolByFeature(Feature ftr) throws MapContextException {
149
        return this.defaultSymbol;
150
    }
151

  
152
    @Override
153
    public int getShapeType() {
154
        return Geometry.TYPES.GEOMETRY;
155
    }
156

  
157
    @Override
158
    public void setShapeType(int i) {
159
    }
160

  
161
    @Override
162
    public boolean isUseDefaultSymbol() {
163
        return true;
164
    }
165

  
166
    @Override
167
    public void useDefaultSymbol(boolean bln) {
168
    }
169

  
170
    @Override
171
    public boolean isSuitableForShapeType(int shapeType) {
172
        return true;
173
    }
174

  
175
    @Override
176
    protected void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, Map queryParameters, ICoordTrans coordTrans, FeatureStore featureStore, FeatureQuery featureQuery, double dpi) throws LegendException {
177
        int saved_distance = this.algorithm.getDistance();
178
        try {
179
            int distance = (int) (this.algorithm.getDistance() * (dpi / 72));
180
            Geometry theROI = null;
181
            if (this.roi != null) {
182
                theROI = this.roi.cloneGeometry();
183
                theROI.transform(viewPort.getAffineTransform());
184
            }
185
            this.algorithm.init(image.getWidth(), image.getHeight());
186
            this.algorithm.setDistance(distance);
187
            super.draw(image, g, viewPort, cancel, scale, queryParameters, coordTrans, featureStore, featureQuery, dpi);
188
            if (!cancel.isCanceled()) {
189
                this.algorithm.drawWithOpaqueColors(image, g, this.getHeatMapColorTable().getColorTable(), cancel, theROI, this.getFilterProportionValue());
190
            }
191
        } finally {
192
            this.algorithm.setDistance(saved_distance);
193

  
194
        }
195
    }
196

  
197
    @Override
198
    public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
199
            double scale, Map queryParameters, ICoordTrans coordTrans,
200
            FeatureStore featureStore, FeatureQuery featureQuery, PrintAttributes properties)
201
            throws LegendException {
202
        int saved_distance = this.algorithm.getDistance();
203
        try {
204
            double dpi = viewPort.getDPI();
205
            // Ver CartographicSupportToolkit.getCartographicLength
206
            int distance = (int) (this.algorithm.getDistance() * (dpi / 72));
207
            Geometry theROI = null;
208
            if (this.roi != null) {
209
                theROI = this.roi.cloneGeometry();
210
                theROI.transform(viewPort.getAffineTransform());
211
            }
212
            this.algorithm.init(viewPort.getImageWidth(), viewPort.getImageHeight());
213
            this.algorithm.setDistance(distance);
214
            BufferedImage image = new BufferedImage(viewPort.getImageWidth(), viewPort.getImageHeight(), BufferedImage.TYPE_INT_ARGB);
215
            super.draw(image, g, viewPort, cancel, scale, queryParameters, coordTrans, featureStore, featureQuery, dpi);
216
            if (!cancel.isCanceled()) {
217
                this.algorithm.drawWithAlphaColors(image, g, this.getHeatMapColorTable().getColorTable(), cancel, theROI, this.getFilterProportionValue());
218
                g.drawImage(image, 0, 0, null);
219
            }
220
        } finally {
221
            this.algorithm.setDistance(saved_distance);
222

  
223
        }
224
    }
225

  
226
    @Override
227
    protected void drawFeatures(
228
            BufferedImage image,
229
            Graphics2D g,
230
            final ViewPort viewPort,
231
            final Cancellable cancel,
232
            final ICoordTrans coordTrans,
233
            double dpi,
234
            DefaultFeatureDrawnNotification drawnNotification,
235
            FeatureSet featureSet,
236
            FeatureSelection selection
237
    ) throws BaseException {
238
        int x = -1;
239
        if (!StringUtils.isEmpty(this.fieldName)) {
240
            x = featureSet.getDefaultFeatureType().getIndex(this.fieldName);
241
        }
242
        final int n = x;
243

  
244
        MutableSymbolTable symbolTable = ExpressionEvaluatorLocator.getManager().createSymbolTable();
245
        FeatureSymbolTable fst = DALLocator.getDataManager().createFeatureSymbolTable();
246
        symbolTable.addSymbolTable(fst);
247

  
248
        featureSet.accept(new Visitor() {
249
            @Override
250
            public void visit(Object o) throws VisitCanceledException, BaseException {
251
                if (cancel.isCanceled()) {
252
                    throw new VisitCanceledException();
253
                }
254
                Feature feature = (Feature) o;
255
                Geometry geom = feature.getDefaultGeometry();
256
                if (geom != null) {
257
                    Point pointGeo = geom.centroid();
258
                    if (coordTrans != null) {
259
                        pointGeo.reProject(coordTrans);
260
                    }
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff