├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── gs-web-elasticsearch
├── LICENSE
├── doc
│ ├── images
│ │ ├── elasticsearch_configuration.png
│ │ ├── elasticsearch_fieldlist.png
│ │ ├── elasticsearch_fieldlist_edit.png
│ │ ├── elasticsearch_logging.png
│ │ └── elasticsearch_store.png
│ └── index.rst
├── pom.xml
└── src
│ ├── assembly
│ └── dist.xml
│ └── main
│ ├── java
│ ├── applicationContext.xml
│ └── mil
│ │ └── nga
│ │ └── giat
│ │ └── elasticsearch
│ │ ├── ElasticAttributeProvider.java
│ │ ├── ElasticConfigurationPage.html
│ │ ├── ElasticConfigurationPage.java
│ │ ├── ElasticConfigurationPanel.html
│ │ ├── ElasticConfigurationPanel.java
│ │ ├── ElasticConfigurationPanelInfo.java
│ │ ├── ElasticFeatureTypeCallback.java
│ │ ├── ElasticXStreamInitializer.java
│ │ └── ElasticXStreamPersisterInitializer.java
│ └── resources
│ └── GeoServerApplication.properties
├── gt-elasticsearch-process
├── LGPL
├── LICENSE
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── mil
│ │ │ └── nga
│ │ │ └── giat
│ │ │ └── process
│ │ │ └── elasticsearch
│ │ │ ├── BBOXRemovingFilterVisitor.java
│ │ │ ├── BasicGeoHashGrid.java
│ │ │ ├── GeoHashGrid.java
│ │ │ ├── GeoHashGridProcess.java
│ │ │ ├── GridCell.java
│ │ │ ├── GridCoverageUtil.java
│ │ │ ├── MetricGeoHashGrid.java
│ │ │ ├── NestedAggGeoHashGrid.java
│ │ │ └── RasterScale.java
│ └── resources
│ │ └── META-INF
│ │ └── services
│ │ ├── org.geotools.process.ProcessFactory
│ │ └── org.geotools.process.vector.VectorProcess
│ └── test
│ └── java
│ └── mil
│ └── nga
│ └── giat
│ └── process
│ └── elasticsearch
│ ├── GeoHashGridProcessTest.java
│ ├── GeoHashGridTest.java
│ ├── GridCoverageUtilTest.java
│ ├── MetricGeoHashGridTest.java
│ ├── NestedAggGeoHashGridTest.java
│ ├── RasterScaleTest.java
│ └── TestUtil.java
├── gt-elasticsearch
├── LGPL
├── LICENSE
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── mil
│ │ │ └── nga
│ │ │ └── giat
│ │ │ └── data
│ │ │ └── elasticsearch
│ │ │ ├── ElasticAggregation.java
│ │ │ ├── ElasticAttribute.java
│ │ │ ├── ElasticCapabilities.java
│ │ │ ├── ElasticClient.java
│ │ │ ├── ElasticConstants.java
│ │ │ ├── ElasticDataStore.java
│ │ │ ├── ElasticDataStoreFactory.java
│ │ │ ├── ElasticFeatureReader.java
│ │ │ ├── ElasticFeatureReaderScroll.java
│ │ │ ├── ElasticFeatureSource.java
│ │ │ ├── ElasticFeatureTypeBuilder.java
│ │ │ ├── ElasticHit.java
│ │ │ ├── ElasticLayerConfiguration.java
│ │ │ ├── ElasticMappings.java
│ │ │ ├── ElasticParserUtil.java
│ │ │ ├── ElasticRequest.java
│ │ │ ├── ElasticResponse.java
│ │ │ ├── ElasticResults.java
│ │ │ ├── FilterToElastic.java
│ │ │ ├── FilterToElasticException.java
│ │ │ ├── FilterToElasticHelper.java
│ │ │ ├── GeohashUtil.java
│ │ │ ├── RestElasticClient.java
│ │ │ └── TotalDeserializer.java
│ └── resources
│ │ └── META-INF
│ │ └── services
│ │ └── org.geotools.data.DataStoreFactorySpi
│ └── test
│ ├── java
│ └── mil
│ │ └── nga
│ │ └── giat
│ │ └── data
│ │ └── elasticsearch
│ │ ├── ElasticAggregationReaderTest.java
│ │ ├── ElasticAttributeTest.java
│ │ ├── ElasticDataStoreFinderIT.java
│ │ ├── ElasticDataStoreIT.java
│ │ ├── ElasticDatastoreFactoryTest.java
│ │ ├── ElasticFeatureFilterIT.java
│ │ ├── ElasticFilterTest.java
│ │ ├── ElasticGeometryFilterIT.java
│ │ ├── ElasticParserUtilTest.java
│ │ ├── ElasticResponseTest.java
│ │ ├── ElasticTemporalFilterIT.java
│ │ ├── ElasticTestSupport.java
│ │ ├── ElasticViewParametersFilterIT.java
│ │ ├── GeohashUtilTest.java
│ │ ├── RandomGeometryBuilder.java
│ │ └── RestElasticClientTest.java
│ └── resources
│ ├── README.md
│ ├── active_mappings.json
│ ├── active_mappings_legacy.json
│ ├── active_mappings_ng.json
│ ├── log4j.properties
│ ├── logging.properties
│ ├── mockito-extensions
│ └── org.mockito.plugins.MockMaker
│ ├── requirements.txt
│ ├── test_index.py
│ └── wifiAccessPoint.json
├── joda-shaded
├── LICENSE.txt
├── NOTICE.txt
├── pom.xml
└── src
│ └── main
│ └── java
│ └── org
│ └── elasticsearch
│ └── common
│ └── Strings.java
└── pom.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | **target/
2 | **.settings/
3 | **.project
4 | **.classpath
5 | *.prefs
6 | *.log
7 | *.iml
8 | **idea/
9 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: true
2 | services:
3 | - docker
4 | language: java
5 | jdk:
6 | - openjdk8
7 | env:
8 | matrix:
9 | - GEOTOOLS_VERSION='22.0' GEOSERVER_VERSION='2.16.0' ES_VERSION='7.4.0'
10 | - GEOTOOLS_VERSION='22.0' GEOSERVER_VERSION='2.16.0' ES_VERSION='6.8.3'
11 | - GEOTOOLS_VERSION='22.0' GEOSERVER_VERSION='2.16.0' ES_VERSION='5.6.16'
12 | - GEOTOOLS_VERSION='22.0' GEOSERVER_VERSION='2.16.0' ES_VERSION='2.4.5' ARGS='-Ddocker.image=elasticsearch'
13 | - GEOTOOLS_VERSION='21.3' GEOSERVER_VERSION='2.15.3' ES_VERSION='7.4.0'
14 | - GEOTOOLS_VERSION='21.3' GEOSERVER_VERSION='2.15.3' ES_VERSION='6.8.3'
15 | - GEOTOOLS_VERSION='21.3' GEOSERVER_VERSION='2.15.3' ES_VERSION='5.6.16'
16 | - GEOTOOLS_VERSION='21.3' GEOSERVER_VERSION='2.15.3' ES_VERSION='2.4.5' ARGS='-Ddocker.image=elasticsearch'
17 | cache:
18 | directories:
19 | - "$HOME/.m2"
20 | install:
21 | - mvn --version
22 | - travis_retry mvn install -DskipTests=true -Dskip.integration.tests=true -B -Dgeotools.version=${GEOTOOLS_VERSION} -Dgeoserver.version=${GEOSERVER_VERSION} -Des.test.version=${ES_VERSION} ${ARGS}
23 | script:
24 | - sudo sysctl -w vm.max_map_count=262144
25 | - travis_retry mvn verify -Dgeotools.version=${GEOTOOLS_VERSION} -Dgeoserver.version=${GEOSERVER_VERSION} -Des.test.version=${ES_VERSION} ${ARGS}
26 | after_success:
27 | - mvn coveralls:report
28 | before_deploy:
29 | - mvn assembly:assembly -pl gs-web-elasticsearch
30 | - export PLUGIN_FILE="$(ls gs-web-elasticsearch/target/elasticgeo*.zip)";
31 | - echo "Deploying $PLUGIN_FILE to GitHub releases"
32 | deploy:
33 | provider: releases
34 | api_key:
35 | secure: UiMZusRpTSbs3BQWZxououT1VPj8LzUN4UYH8H+PcPdEEZfx/lDNCxlaj1YG8eVCflJL1TItPdU8jIEU435weP4v3cnSyUjq/3Oc4ey9CK/iuphoqvkqfCgRxpVsj9wuZkJqLobi9+9JFLz6NziCnX9ME5WxRgMPlfRU2jot/GM=
36 | file_glob: true
37 | skip_cleanup: true
38 | file: "$PLUGIN_FILE"
39 | on:
40 | tags: true
41 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ElasticGeo
2 |
3 |
4 |
6 |
7 |
8 |
9 |
11 |
12 |
13 | ElasticGeo provides a GeoTools data store that allows geospatial features from an Elasticsearch index to be published via OGC services using GeoServer.
14 |
15 | ### Pull Request
16 |
17 | If you'd like to contribute to this project, please make a pull request. We'll review the pull request and discuss the changes. All pull request contributions to this project will be released under the appropriate license conditions discussed below.
18 |
19 | Software source code previously released under an open source license and then modified by NGA staff is considered a "joint work" (see 17 USC 101); it is partially copyrighted, partially public domain, and as a whole is protected by the copyrights of the non-government authors and must be released according to the terms of the original open source license.
20 |
21 | ### Project relies upon:
22 |
23 | GeoTools under [LGPL v 2.1](http://geotools.org/about.html)
24 |
25 | GeoServer under [GPL v 2 with later option](http://geoserver.org/license/)
26 |
27 | ElasticGeo under [LGPL v 2.1](https://github.com/matsjg/elasticgeo)
28 |
29 | Elasticsearch under [Apache License v 2.0](https://github.com/elastic/elasticsearch/blob/master/LICENSE.txt)
30 |
31 | ### Documentation
32 |
33 | [Read more](gs-web-elasticsearch/doc/index.rst)
34 |
35 |
36 |
--------------------------------------------------------------------------------
/gs-web-elasticsearch/doc/images/elasticsearch_configuration.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ngageoint/elasticgeo/91c2a99ccea6988cc5d0f96a108c690b7b9c6ea2/gs-web-elasticsearch/doc/images/elasticsearch_configuration.png
--------------------------------------------------------------------------------
/gs-web-elasticsearch/doc/images/elasticsearch_fieldlist.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ngageoint/elasticgeo/91c2a99ccea6988cc5d0f96a108c690b7b9c6ea2/gs-web-elasticsearch/doc/images/elasticsearch_fieldlist.png
--------------------------------------------------------------------------------
/gs-web-elasticsearch/doc/images/elasticsearch_fieldlist_edit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ngageoint/elasticgeo/91c2a99ccea6988cc5d0f96a108c690b7b9c6ea2/gs-web-elasticsearch/doc/images/elasticsearch_fieldlist_edit.png
--------------------------------------------------------------------------------
/gs-web-elasticsearch/doc/images/elasticsearch_logging.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ngageoint/elasticgeo/91c2a99ccea6988cc5d0f96a108c690b7b9c6ea2/gs-web-elasticsearch/doc/images/elasticsearch_logging.png
--------------------------------------------------------------------------------
/gs-web-elasticsearch/doc/images/elasticsearch_store.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ngageoint/elasticgeo/91c2a99ccea6988cc5d0f96a108c690b7b9c6ea2/gs-web-elasticsearch/doc/images/elasticsearch_store.png
--------------------------------------------------------------------------------
/gs-web-elasticsearch/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | 4.0.0
7 |
8 | elasticgeo
9 | mil.nga.giat
10 | 2.16-SNAPSHOT
11 |
12 | gs-web-elasticsearch
13 | 2.16-SNAPSHOT
14 | jar
15 | GeoServer Elasticsearch Module
16 |
17 |
18 | mil.nga.giat
19 | gt-elasticsearch
20 | ${project.version}
21 |
22 |
23 | mil.nga.giat
24 | gt-elasticsearch-process
25 | ${project.version}
26 |
27 |
28 |
29 | org.geoserver
30 | gs-main
31 | ${geoserver.version}
32 | provided
33 |
34 |
35 | org.geoserver.web
36 | gs-web-core
37 | ${geoserver.version}
38 | provided
39 |
40 |
41 | org.geotools
42 | gt-main
43 | ${geotools.version}
44 | provided
45 |
46 |
47 | org.geoserver.web
48 | gs-web-core
49 | ${geoserver.version}
50 | test-jar
51 | test
52 |
53 |
54 | org.geoserver
55 | gs-main
56 | ${geoserver.version}
57 | test-jar
58 | test
59 |
60 |
61 | com.mockrunner
62 | mockrunner
63 | 0.3.6
64 | test
65 |
66 |
67 | junit
68 | junit
69 | 4.11
70 | test
71 |
72 |
73 |
74 |
75 |
76 | ${basedir}/src/main/java
77 |
78 | applicationContext.xml
79 | **/*.html
80 |
81 |
82 |
83 | ${basedir}/src/main/resources
84 |
85 | **/*
86 |
87 |
88 |
89 |
90 |
91 | maven-assembly-plugin
92 | 2.4
93 |
94 | src/assembly/dist.xml
95 | false
96 | elasticgeo-${project.version}
97 |
98 |
99 |
100 | org.apache.maven.plugins
101 | maven-shade-plugin
102 | 2.2
103 |
104 |
105 | package
106 |
107 | shade
108 |
109 |
110 |
111 |
112 | *:pom:*
113 | *:maven*:*
114 | commons-codec
115 | commons-collections
116 | commons-httpclient
117 | commons-logging
118 | *:guava:*
119 | javax.media:jai*:*
120 | *:jts:*
121 | *:*:jsr305
122 | log4j:log4j
123 |
124 |
125 |
126 |
127 | *:*
128 |
129 | META-INF/maven/**
130 | META-INF/*.SF
131 | META-INF/*.DSA
132 | META-INF/*.RSA
133 | META-INF/DEPENDENCIES
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 | META-INF/LICENSE
142 | LICENSE
143 |
144 |
145 | false
146 |
147 |
148 | false
149 | false
150 | elasticgeo-${project.version}
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
--------------------------------------------------------------------------------
/gs-web-elasticsearch/src/assembly/dist.xml:
--------------------------------------------------------------------------------
1 |
4 | bin
5 |
6 | zip
7 |
8 | false
9 |
10 |
11 | ${project.build.directory}
12 | /
13 |
14 | elasticgeo*.jar
15 |
16 |
17 |
18 | .
19 | /
20 |
21 | LICENSE
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/gs-web-elasticsearch/src/main/java/applicationContext.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | Elasticsearch
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/gs-web-elasticsearch/src/main/java/mil/nga/giat/elasticsearch/ElasticAttributeProvider.java:
--------------------------------------------------------------------------------
1 | /* (c) 2014 Open Source Geospatial Foundation - all rights reserved
2 | * This code is licensed under the GPL 2.0 license, available at the root
3 | * application directory.
4 | */
5 |
6 | package mil.nga.giat.elasticsearch;
7 |
8 | import java.util.Arrays;
9 | import java.util.List;
10 |
11 | import mil.nga.giat.data.elasticsearch.ElasticAttribute;
12 |
13 | import org.geoserver.web.wicket.GeoServerDataProvider;
14 |
15 | /**
16 | *
17 | * Provide attributes from Elasticsearch fields.
18 | *
19 | */
20 | class ElasticAttributeProvider extends GeoServerDataProvider {
21 |
22 | private static final long serialVersionUID = -1021780286733349153L;
23 |
24 | private final List attributes;
25 |
26 | /**
27 | * Name of field
28 | */
29 | static final Property NAME = new BeanProperty<>("name",
30 | "displayName");
31 |
32 | /**
33 | * Class type of field
34 | */
35 | static final Property TYPE = new AbstractProperty(
36 | "type") {
37 |
38 | private static final long serialVersionUID = 4454312983828267130L;
39 |
40 | @Override
41 | public Object getPropertyValue(ElasticAttribute item) {
42 | if (item.getType() != null) {
43 | return item.getType().getSimpleName();
44 | }
45 | return null;
46 | }
47 |
48 | };
49 |
50 | /**
51 | * Mark as the default geometry
52 | */
53 | static final Property DEFAULT_GEOMETRY = new BeanProperty<>(
54 | "defaultGeometry", "defaultGeometry");
55 |
56 | /**
57 | * SRID of geometric field
58 | */
59 | static final Property SRID = new BeanProperty<>("srid", "srid");
60 |
61 | /**
62 | * Use field in datastore
63 | */
64 | static final Property USE = new BeanProperty<>("use", "use");
65 |
66 | /**
67 | * Store if the field is in use in datastore
68 | */
69 | static final Property DATE_FORMAT = new BeanProperty<>("dateFormat", "dateFormat");
70 |
71 | /**
72 | * If field is analyzed
73 | */
74 | static final Property ANALYZED = new BeanProperty<>("analyzed", "analyzed");
75 |
76 | /**
77 | * If field is stored
78 | */
79 | static final Property STORED = new BeanProperty<>("stored", "stored");
80 |
81 | /**
82 | * Order of the field
83 | */
84 | static final Property ORDER = new BeanProperty<>("order", "order");
85 |
86 | /**
87 | * Custom name of the field
88 | */
89 | static final Property CUSTOM_NAME = new BeanProperty<>("customName", "customName");
90 |
91 | /**
92 | * Build attribute provider
93 | *
94 | * @param attributes list to use as source for provider
95 | */
96 | public ElasticAttributeProvider(List attributes) {
97 | this.attributes = attributes;
98 | }
99 |
100 | @Override
101 | protected List> getProperties() {
102 | return Arrays.asList(USE, NAME, TYPE, ORDER, CUSTOM_NAME, DEFAULT_GEOMETRY, STORED, ANALYZED, SRID, DATE_FORMAT);
103 | }
104 |
105 | @Override
106 | protected List getItems() {
107 | return attributes;
108 | }
109 |
110 | }
111 |
--------------------------------------------------------------------------------
/gs-web-elasticsearch/src/main/java/mil/nga/giat/elasticsearch/ElasticConfigurationPage.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Elasticsearch fields configuration
5 |
6 |
7 |
8 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/gs-web-elasticsearch/src/main/java/mil/nga/giat/elasticsearch/ElasticConfigurationPanel.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/gs-web-elasticsearch/src/main/java/mil/nga/giat/elasticsearch/ElasticConfigurationPanel.java:
--------------------------------------------------------------------------------
1 | /* (c) 2014 Open Source Geospatial Foundation - all rights reserved
2 | * This code is licensed under the GPL 2.0 license, available at the root
3 | * application directory.
4 | */
5 |
6 | package mil.nga.giat.elasticsearch;
7 |
8 | import java.io.IOException;
9 | import java.util.List;
10 | import java.util.logging.Level;
11 |
12 | import mil.nga.giat.data.elasticsearch.ElasticAttribute;
13 | import mil.nga.giat.data.elasticsearch.ElasticDataStore;
14 | import mil.nga.giat.data.elasticsearch.ElasticLayerConfiguration;
15 |
16 | import org.apache.wicket.Component;
17 | import org.apache.wicket.MarkupContainer;
18 | import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;
19 | import org.apache.wicket.ajax.AjaxRequestTarget;
20 | import org.apache.wicket.ajax.markup.html.AjaxLink;
21 | import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
22 | import org.apache.wicket.markup.head.IHeaderResponse;
23 | import org.apache.wicket.markup.head.OnLoadHeaderItem;
24 | import org.apache.wicket.markup.html.panel.Fragment;
25 | import org.apache.wicket.model.IModel;
26 | import org.geoserver.catalog.Catalog;
27 | import org.geoserver.catalog.CatalogBuilder;
28 | import org.geoserver.catalog.DataStoreInfo;
29 | import org.geoserver.catalog.FeatureTypeInfo;
30 | import org.geoserver.catalog.LayerInfo;
31 | import org.geoserver.catalog.ResourceInfo;
32 | import org.geoserver.web.GeoServerApplication;
33 | import org.geoserver.web.data.resource.ResourceConfigurationPage;
34 | import org.geoserver.web.data.resource.ResourceConfigurationPanel;
35 | import org.geoserver.web.wicket.ParamResourceModel;
36 | import org.geotools.feature.NameImpl;
37 | import org.opengis.feature.type.Name;
38 |
39 | /**
40 | * Resource configuration panel to show a link to open Elasticsearch attribute
41 | * modal dialog
If the Elasticsearch attribute are not configured for
42 | * current layer, the modal dialog will be open at first resource configuration
43 | * window opening
After modal dialog is closed the resource page is
44 | * reloaded and feature configuration table updated
45 | *
46 | */
47 | @SuppressWarnings("WeakerAccess")
48 | public class ElasticConfigurationPanel extends ResourceConfigurationPanel {
49 |
50 | private static final long serialVersionUID = 3382530429105288433L;
51 |
52 | private LayerInfo _layerInfo;
53 |
54 | private ElasticLayerConfiguration _layerConfig;
55 |
56 | /**
57 | * Adds Elasticsearch configuration panel link, configure modal dialog and
58 | * implements modal callback.
59 | *
60 | * @see ElasticConfigurationPage#done
61 | */
62 |
63 | public ElasticConfigurationPanel(final String panelId, final IModel> model) {
64 | super(panelId, model);
65 | final FeatureTypeInfo fti = (FeatureTypeInfo) model.getObject();
66 |
67 | final ModalWindow modal = new ModalWindow("modal");
68 | modal.setInitialWidth(800);
69 | modal.setTitle(new ParamResourceModel("modalTitle", ElasticConfigurationPanel.this));
70 |
71 | if (fti.getMetadata().get(ElasticLayerConfiguration.KEY) == null) {
72 | modal.add(new OpenWindowOnLoadBehavior());
73 | }
74 |
75 | modal.setContent(new ElasticConfigurationPage(panelId, model) {
76 | @Override
77 | void done(AjaxRequestTarget target, LayerInfo layerInfo,
78 | ElasticLayerConfiguration layerConfig) {
79 | _layerInfo = layerInfo;
80 | _layerConfig = layerConfig;
81 |
82 | try {
83 | saveLayer((FeatureTypeInfo) getResourceInfo());
84 | } catch (IOException e) {
85 | LOGGER.log(Level.SEVERE, e.getMessage(), e);
86 | error(new ParamResourceModel("creationFailure", this, e).getString());
87 | }
88 |
89 | MarkupContainer parent = ElasticConfigurationPanel.this.getParent();
90 | while (!(parent == null || parent instanceof ResourceConfigurationPage)) {
91 | parent = parent.getParent();
92 | }
93 |
94 | if (parent != null) {
95 | ResourceInfo ri = ElasticConfigurationPanel.this.getResourceInfo();
96 | ((ResourceConfigurationPage) parent).updateResource(ri, target);
97 | }
98 |
99 | modal.close(target);
100 | }
101 | });
102 | add(modal);
103 |
104 | AjaxLink> findLink = new AjaxLink("edit") {
105 | @Override
106 | public void onClick(AjaxRequestTarget target) {
107 | modal.show(target);
108 | }
109 | };
110 | final Fragment attributePanel = new Fragment("esPanel", "esPanelFragment", this);
111 | attributePanel.setOutputMarkupId(true);
112 | add(attributePanel);
113 | attributePanel.add(findLink);
114 | }
115 |
116 | /*
117 | * Open modal dialog on window load
118 | */
119 | private class OpenWindowOnLoadBehavior extends AbstractDefaultAjaxBehavior {
120 | @Override
121 | protected void respond(AjaxRequestTarget target) {
122 | ModalWindow window = (ModalWindow) getComponent();
123 | window.show(target);
124 | }
125 |
126 | @Override
127 | public void renderHead(Component component, IHeaderResponse response) {
128 | response.render(OnLoadHeaderItem.forScript(getCallbackScript().toString()));
129 | }
130 | }
131 |
132 | private void saveLayer(FeatureTypeInfo ft) throws IOException {
133 | GeoServerApplication app = (GeoServerApplication) getApplication();
134 | Catalog catalog = app.getCatalog();
135 |
136 | String namespace = ft.getNamespace().getURI();
137 | Name qualifiedName = new NameImpl(namespace, _layerInfo.getName());
138 | LayerInfo layerInfo = catalog.getLayerByName(qualifiedName);
139 |
140 | boolean isNew = ft.getId() == null || app.getCatalog().getResource(ft.getId(),ResourceInfo.class) == null;
141 |
142 | FeatureTypeInfo typeInfo;
143 | if (layerInfo == null || isNew) {
144 | // New
145 | DataStoreInfo dsInfo;
146 | dsInfo = catalog.getStore(ft.getStore().getId(), DataStoreInfo.class);
147 | ElasticDataStore ds = (ElasticDataStore) dsInfo.getDataStore(null);
148 | CatalogBuilder builder = new CatalogBuilder(catalog);
149 | builder.setStore(dsInfo);
150 | ElasticLayerConfiguration layerConfig;
151 | layerConfig = new ElasticLayerConfiguration(_layerConfig);
152 | layerConfig.setLayerName(_layerInfo.getName());
153 | layerConfig.getAttributes().clear();
154 | List attributes = _layerConfig.getAttributes();
155 | layerConfig.getAttributes().addAll(attributes);
156 | ds.setLayerConfiguration(layerConfig);
157 |
158 | FeatureTypeInfo _typeInfo = (FeatureTypeInfo) _layerInfo.getResource();
159 | typeInfo = builder.buildFeatureType(ds.getFeatureSource(qualifiedName));
160 | typeInfo.setName(_layerInfo.getName());
161 | typeInfo.getMetadata().put(ElasticLayerConfiguration.KEY, layerConfig);
162 | typeInfo.setEnabled(_typeInfo.isEnabled());
163 | typeInfo.setAdvertised(_typeInfo.isAdvertised());
164 | typeInfo.setTitle(_typeInfo.getTitle());
165 | typeInfo.setDescription(_typeInfo.getDescription());
166 | typeInfo.setAbstract(_typeInfo.getAbstract());
167 | typeInfo.getKeywords().addAll(_typeInfo.getKeywords());
168 | typeInfo.getMetadataLinks().addAll(_typeInfo.getMetadataLinks());
169 | typeInfo.getDataLinks().addAll(_typeInfo.getDataLinks());
170 | typeInfo.setSRS(_typeInfo.getSRS());
171 | typeInfo.setProjectionPolicy(_typeInfo.getProjectionPolicy());
172 | typeInfo.setNativeBoundingBox(_typeInfo.getNativeBoundingBox());
173 | typeInfo.setLatLonBoundingBox(_typeInfo.getLatLonBoundingBox());
174 | typeInfo.setCircularArcPresent(_typeInfo.isCircularArcPresent());
175 | typeInfo.setLinearizationTolerance(_typeInfo.getLinearizationTolerance());
176 |
177 | layerInfo = builder.buildLayer(typeInfo);
178 | builder.updateLayer(layerInfo, _layerInfo);
179 | layerInfo.setName(_layerInfo.getName());
180 | layerInfo.setResource(typeInfo);
181 | } else {
182 | // Update
183 | typeInfo = (FeatureTypeInfo) layerInfo.getResource();
184 | typeInfo.getMetadata().put(ElasticLayerConfiguration.KEY, _layerConfig);
185 | }
186 | }
187 |
188 | }
189 |
--------------------------------------------------------------------------------
/gs-web-elasticsearch/src/main/java/mil/nga/giat/elasticsearch/ElasticConfigurationPanelInfo.java:
--------------------------------------------------------------------------------
1 | /* (c) 2014 Open Source Geospatial Foundation - all rights reserved
2 | * This code is licensed under the GPL 2.0 license, available at the root
3 | * application directory.
4 | */
5 |
6 | package mil.nga.giat.elasticsearch;
7 |
8 | import org.geoserver.catalog.FeatureTypeInfo;
9 | import org.geoserver.platform.ExtensionPriority;
10 | import org.geoserver.web.data.resource.ResourceConfigurationPanelInfo;
11 |
12 | /**
13 | *
14 | * Implements ResourceConfigurationPanelInfo extension point to add Elasticsearch
15 | * attribute configuration link on resource page.
16 | * Priority is reduced under standard {@link ExtensionPriority#LOWEST} to shows
17 | * the Elasticsearch link after other panels.
18 | *
19 | */
20 | class ElasticConfigurationPanelInfo extends ResourceConfigurationPanelInfo implements ExtensionPriority {
21 |
22 | private static final long serialVersionUID = 1485404586629946126L;
23 |
24 | @Override
25 | public boolean canHandle(Object obj) {
26 | boolean canHandle = false;
27 | if (obj instanceof FeatureTypeInfo) {
28 | FeatureTypeInfo fti = (FeatureTypeInfo) obj;
29 | for (String st : getSupportedTypes()) {
30 | if (fti.getStore().getType().equals(st)) {
31 | canHandle = true;
32 | break;
33 | }
34 | }
35 | }
36 | return canHandle;
37 | }
38 |
39 | @Override
40 | public int getPriority() {
41 | return ExtensionPriority.LOWEST + 1;
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/gs-web-elasticsearch/src/main/java/mil/nga/giat/elasticsearch/ElasticFeatureTypeCallback.java:
--------------------------------------------------------------------------------
1 | /* (c) 2014 Open Source Geospatial Foundation - all rights reserved
2 | * This code is licensed under the GPL 2.0 license, available at the root
3 | * application directory.
4 | */
5 | package mil.nga.giat.elasticsearch;
6 |
7 | import mil.nga.giat.data.elasticsearch.ElasticDataStore;
8 | import mil.nga.giat.data.elasticsearch.ElasticLayerConfiguration;
9 | import static mil.nga.giat.data.elasticsearch.ElasticLayerConfiguration.KEY;
10 |
11 | import org.geoserver.catalog.FeatureTypeInfo;
12 | import org.geoserver.catalog.FeatureTypeCallback;
13 | import org.geotools.data.DataAccess;
14 | import org.opengis.feature.Feature;
15 | import org.opengis.feature.type.FeatureType;
16 | import org.opengis.feature.type.Name;
17 |
18 | /**
19 | *
20 | * Implementation of FeatureTypeInitializer extension point to initialize
21 | * Elasticsearch datastore.
22 | *
23 | * @see FeatureTypeCallback
24 | *
25 | */
26 | class ElasticFeatureTypeCallback implements FeatureTypeCallback {
27 |
28 | @Override
29 | public boolean canHandle(FeatureTypeInfo info,
30 | DataAccess extends FeatureType, ? extends Feature> dataAccess) {
31 | return dataAccess instanceof ElasticDataStore;
32 | }
33 |
34 | @Override
35 | public boolean initialize(FeatureTypeInfo info,
36 | DataAccess extends FeatureType, ? extends Feature> dataAccess, Name temporaryName) {
37 |
38 | ElasticLayerConfiguration layerConfig;
39 | layerConfig = (ElasticLayerConfiguration) info.getMetadata().get(KEY);
40 | if (layerConfig == null) {
41 | layerConfig = new ElasticLayerConfiguration(info.getName());
42 | }
43 |
44 | ((ElasticDataStore) dataAccess).setLayerConfiguration(layerConfig);
45 |
46 | return false;
47 | }
48 |
49 | @Override
50 | public void dispose(FeatureTypeInfo info,
51 | DataAccess extends FeatureType, ? extends Feature> dataAccess, Name temporaryName) {
52 | final ElasticLayerConfiguration layerConfig = (ElasticLayerConfiguration) info.getMetadata().get(KEY);
53 | if (layerConfig != null) {
54 | layerConfig.getAttributes().stream()
55 | .filter(attr -> attr.getName().equals(info.getName()))
56 | .findFirst()
57 | .ifPresent(attribute -> layerConfig.getAttributes().remove(attribute));
58 | ((ElasticDataStore) dataAccess).getDocTypes().remove(info.getQualifiedName());
59 | }
60 | }
61 |
62 | @Override
63 | public void flush(FeatureTypeInfo info,
64 | DataAccess extends FeatureType, ? extends Feature> dataAccess) {
65 | // nothing to do
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/gs-web-elasticsearch/src/main/java/mil/nga/giat/elasticsearch/ElasticXStreamInitializer.java:
--------------------------------------------------------------------------------
1 | /* (c) 2014 Open Source Geospatial Foundation - all rights reserved
2 | * (c) 2014 OpenPlans
3 | * This code is licensed under the GPL 2.0 license, available at the root
4 | * application directory.
5 | */
6 |
7 | package mil.nga.giat.elasticsearch;
8 |
9 | import mil.nga.giat.data.elasticsearch.ElasticAttribute;
10 | import mil.nga.giat.data.elasticsearch.ElasticLayerConfiguration;
11 |
12 | import org.geoserver.config.util.XStreamPersister;
13 | import org.geoserver.config.util.XStreamPersisterInitializer;
14 |
15 | import com.thoughtworks.xstream.XStream;
16 |
17 | /**
18 | *
19 | * Implementation of XStreamPersisterInitializer extension point to serialize ElasticLayerConfiguration
20 | *
21 | */
22 | class ElasticXStreamInitializer implements XStreamPersisterInitializer {
23 |
24 | @Override
25 | public void init(XStreamPersister persister) {
26 | persister.registerBreifMapComplexType("elasticLayerConfiguration",ElasticLayerConfiguration.class);
27 | XStream xs = persister.getXStream();
28 | xs.alias("esAttribute", ElasticAttribute.class);
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/gs-web-elasticsearch/src/main/java/mil/nga/giat/elasticsearch/ElasticXStreamPersisterInitializer.java:
--------------------------------------------------------------------------------
1 | package mil.nga.giat.elasticsearch;
2 |
3 | import org.geoserver.config.util.XStreamPersister;
4 | import org.geoserver.config.util.XStreamPersisterInitializer;
5 |
6 | class ElasticXStreamPersisterInitializer implements XStreamPersisterInitializer {
7 |
8 | @Override
9 | public void init(XStreamPersister persister) {
10 | persister.getXStream().allowTypes(new String[] {
11 | "mil.nga.giat.data.elasticsearch.ElasticAttribute"
12 | });
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/gs-web-elasticsearch/src/main/resources/GeoServerApplication.properties:
--------------------------------------------------------------------------------
1 | # suppress inspection "UnusedProperty" for whole file
2 | data.resource.config.elasticsearch = Elasticsearch
3 | ElasticConfigurationPanel.modalTitle = Elasticsearch fields configuration
4 | ElasticConfigurationPanel.edit = Configure Elasticsearch fields
5 | ElasticConfigurationPage.attributes = Attributes
6 | ElasticConfigurationPage.th.name = Name
7 | ElasticConfigurationPage.th.type = Type
8 | ElasticConfigurationPage.th.use = Use
9 | ElasticConfigurationPage.th.geometry = Geometry
10 | ElasticConfigurationPage.th.srid = SRID
11 | ElasticConfigurationPage.th.defaultGeometry = Default Geometry
12 | ElasticConfigurationPage.th.dateFormat = Date Format
13 | ElasticConfigurationPage.th.analyzed = Analyzed
14 | ElasticConfigurationPage.th.stored = Stored
15 | ElasticConfigurationPage.th.order = Order
16 | ElasticConfigurationPage.th.customName = Custom Name
17 | ElasticConfigurationPage.useAll = Use all
18 | ElasticConfigurationPage.useShortName = Short names
19 | ElasticConfigurationPage.es_save = Apply
20 | ElasticConfigurationPage.es_cancel = Cancel
21 | ElasticConfigurationPage.creationFailure = Creation failure
22 | ElasticConfigurationPage.geomEmptyFailure = Select field for geometry
23 |
--------------------------------------------------------------------------------
/gt-elasticsearch-process/LICENSE:
--------------------------------------------------------------------------------
1 | This module is licensed under the terms of the GNU Lesser General Public
2 | License (LGPL), version 2 or later. The directory containing this file should
3 | also contain a copy of the LGPL, as a file named LGPL.
4 |
5 | This library is distributed in the hope that it will be useful,
6 | but WITHOUT ANY WARRANTY; without even the implied warranty of
7 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8 | Lesser General Public License for more details.
9 |
--------------------------------------------------------------------------------
/gt-elasticsearch-process/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | elasticgeo
6 | mil.nga.giat
7 | 2.16-SNAPSHOT
8 |
9 | gt-elasticsearch-process
10 | 2.16-SNAPSHOT
11 | jar
12 | GeoTools Elasticsearch Processes
13 |
14 |
15 | com.fasterxml.jackson.core
16 | jackson-core
17 | ${jackson.version}
18 |
19 |
20 | com.fasterxml.jackson.core
21 | jackson-databind
22 | ${jackson.version}
23 |
24 |
25 | com.github.davidmoten
26 | geo
27 | 0.7.4
28 |
29 |
30 |
31 | org.geotools
32 | gt-process
33 | ${geotools.version}
34 | provided
35 |
36 |
37 | org.geoserver.extension
38 | gs-wps-core
39 | ${geoserver.version}
40 | provided
41 |
42 |
43 | org.geotools
44 | gt-grid
45 | ${geotools.version}
46 | provided
47 |
48 |
49 | org.geotools
50 | gt-process-feature
51 | ${geotools.version}
52 | provided
53 |
54 |
55 | org.geotools
56 | gt-sample-data
57 | ${geotools.version}
58 | test
59 |
60 |
61 | org.geotools
62 | gt-property
63 | ${geotools.version}
64 | test
65 |
66 |
67 | org.geotools
68 | gt-epsg-hsql
69 | ${geotools.version}
70 | test
71 |
72 |
73 | junit
74 | junit
75 | 4.11
76 | test
77 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/gt-elasticsearch-process/src/main/java/mil/nga/giat/process/elasticsearch/BBOXRemovingFilterVisitor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is hereby placed into the Public Domain. This means anyone is
3 | * free to do whatever they wish with this file.
4 | */
5 | package mil.nga.giat.process.elasticsearch;
6 |
7 | import org.geotools.filter.visitor.DuplicatingFilterVisitor;
8 | import org.opengis.filter.Filter;
9 | import org.opengis.filter.spatial.BBOX;
10 |
11 | class BBOXRemovingFilterVisitor extends DuplicatingFilterVisitor {
12 |
13 | private String geometryPropertyName;
14 |
15 | @Override
16 | public Object visit(BBOX filter, Object extraData) {
17 | geometryPropertyName = filter.getExpression1().toString();
18 | return Filter.INCLUDE;
19 | }
20 |
21 | public String getGeometryPropertyName() {
22 | return geometryPropertyName;
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/gt-elasticsearch-process/src/main/java/mil/nga/giat/process/elasticsearch/BasicGeoHashGrid.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is hereby placed into the Public Domain. This means anyone is
3 | * free to do whatever they wish with this file.
4 | */
5 | package mil.nga.giat.process.elasticsearch;
6 |
7 | import java.util.Map;
8 |
9 | public class BasicGeoHashGrid extends GeoHashGrid {
10 |
11 | @Override
12 | public Number computeCellValue(Map bucket) {
13 | return super.pluckDocCount(bucket);
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/gt-elasticsearch-process/src/main/java/mil/nga/giat/process/elasticsearch/GeoHashGridProcess.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is hereby placed into the Public Domain. This means anyone is
3 | * free to do whatever they wish with this file.
4 | */
5 | package mil.nga.giat.process.elasticsearch;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | import org.geotools.coverage.grid.GridCoverage2D;
11 | import org.geotools.coverage.processing.Operations;
12 | import org.geotools.data.Query;
13 | import org.geotools.data.simple.SimpleFeatureCollection;
14 | import org.geotools.factory.CommonFactoryFinder;
15 | import org.geotools.filter.visitor.SimplifyingFilterVisitor;
16 | import org.geotools.geometry.jts.ReferencedEnvelope;
17 | import org.geotools.process.ProcessException;
18 | import org.geotools.process.factory.DescribeParameter;
19 | import org.geotools.process.factory.DescribeProcess;
20 | import org.geotools.process.factory.DescribeResult;
21 | import org.geotools.process.vector.VectorProcess;
22 | import org.geotools.referencing.crs.DefaultGeographicCRS;
23 | import org.opengis.coverage.grid.GridGeometry;
24 | import org.opengis.filter.Filter;
25 | import org.opengis.filter.FilterFactory;
26 | import org.opengis.filter.expression.PropertyName;
27 | import org.opengis.filter.spatial.BBOX;
28 | import org.opengis.util.ProgressListener;
29 |
30 | @SuppressWarnings("unused")
31 | @DescribeProcess(title = "geoHashGridAgg", description = "Computes a grid from GeoHash grid aggregation buckets with values corresponding to doc_count values.")
32 | public class GeoHashGridProcess implements VectorProcess {
33 |
34 | private final static FilterFactory FILTER_FACTORY = CommonFactoryFinder.getFilterFactory(null);
35 |
36 | public enum Strategy {
37 |
38 | BASIC(BasicGeoHashGrid.class),
39 | METRIC(MetricGeoHashGrid.class),
40 | NESTED_AGG(NestedAggGeoHashGrid.class);
41 |
42 | private final Class extends GeoHashGrid> clazz;
43 |
44 | Strategy(Class extends GeoHashGrid> clazz) {
45 | this.clazz = clazz;
46 | }
47 |
48 | GeoHashGrid createNewInstance() throws ReflectiveOperationException {
49 | return clazz.getConstructor().newInstance();
50 | }
51 |
52 | }
53 |
54 | @DescribeResult(description = "Output raster")
55 | public GridCoverage2D execute(
56 |
57 | // process data
58 | @DescribeParameter(name = "data", description = "Input features") SimpleFeatureCollection obsFeatures,
59 |
60 | // process parameters
61 | @DescribeParameter(name = "pixelsPerCell", description = "Resolution used for upsampling (in pixels)", defaultValue="1", min = 1) Integer argPixelsPerCell,
62 | @DescribeParameter(name = "gridStrategy", description = "GeoHash grid strategy", defaultValue="Basic", min = 1) String gridStrategy,
63 | @DescribeParameter(name = "gridStrategyArgs", description = "Grid strategy arguments", min = 0) List gridStrategyArgs,
64 | @DescribeParameter(name = "emptyCellValue", description = "Default cell value", min = 0) Float emptyCellValue,
65 | @DescribeParameter(name = "scaleMin", description = "Scale minimum", defaultValue="0") Float scaleMin,
66 | @DescribeParameter(name = "scaleMax", description = "Scale maximum", min = 0) Float scaleMax,
67 | @DescribeParameter(name = "useLog", description = "Whether to use log values (default=false)", defaultValue="false") Boolean useLog,
68 |
69 | // output image parameters
70 | @DescribeParameter(name = "outputBBOX", description = "Bounding box of the output") ReferencedEnvelope argOutputEnv,
71 | @DescribeParameter(name = "outputWidth", description = "Width of output raster in pixels") Integer argOutputWidth,
72 | @DescribeParameter(name = "outputHeight", description = "Height of output raster in pixels") Integer argOutputHeight,
73 |
74 | ProgressListener monitor) throws ProcessException {
75 |
76 | try {
77 | // construct and populate grid
78 | final GeoHashGrid geoHashGrid = Strategy.valueOf(gridStrategy.toUpperCase()).createNewInstance();
79 | geoHashGrid.setParams(gridStrategyArgs);
80 | geoHashGrid.setEmptyCellValue(emptyCellValue);
81 | geoHashGrid.setScale(new RasterScale(scaleMin, scaleMax, useLog));
82 | geoHashGrid.initalize(argOutputEnv, obsFeatures);
83 | // convert to grid coverage
84 | final GridCoverage2D nativeCoverage = geoHashGrid.toGridCoverage2D();
85 |
86 | // reproject
87 | final GridCoverage2D transformedCoverage = (GridCoverage2D) Operations.DEFAULT.resample(nativeCoverage, argOutputEnv.getCoordinateReferenceSystem());
88 | // upscale to approximate output resolution
89 | final GridCoverage2D scaledCoverage = GridCoverageUtil.scale(transformedCoverage, argOutputWidth*argPixelsPerCell, argOutputHeight*argPixelsPerCell);
90 | // crop (geohash grid envelope will always contain output bbox)
91 | final GridCoverage2D croppedCoverage = GridCoverageUtil.crop(scaledCoverage, argOutputEnv);
92 | return GridCoverageUtil.scale(croppedCoverage, argOutputWidth, argOutputHeight);
93 | } catch (Exception e) {
94 | throw new ProcessException("Error executing GeoHashGridProcess", e);
95 | }
96 | }
97 |
98 | public Query invertQuery(
99 | @DescribeParameter(name = "outputBBOX", description = "Georeferenced bounding box of the output") ReferencedEnvelope envelope,
100 | Query targetQuery, GridGeometry targetGridGeometry
101 | ) throws ProcessException {
102 |
103 | final BBOXRemovingFilterVisitor visitor = new BBOXRemovingFilterVisitor();
104 | Filter filter = (Filter) targetQuery.getFilter().accept(visitor, null);
105 | final String geometryName = visitor.getGeometryPropertyName();
106 | if (geometryName != null) {
107 | final BBOX bbox;
108 | try {
109 | if (envelope.getCoordinateReferenceSystem() != null) {
110 | envelope = envelope.transform(DefaultGeographicCRS.WGS84,false);
111 | }
112 | bbox = FILTER_FACTORY.bbox(geometryName, envelope.getMinX(), envelope.getMinY(), envelope.getMaxX(), envelope.getMaxY(), "EPSG:4326");
113 | } catch (Exception e) {
114 | throw new ProcessException("Unable to create bbox filter for feature source", e);
115 | }
116 | filter = (Filter) FILTER_FACTORY.and(filter, bbox).accept(new SimplifyingFilterVisitor(), null);
117 | targetQuery.setFilter(filter);
118 | }
119 |
120 | final List properties = new ArrayList<>();
121 | properties.add(FILTER_FACTORY.property("_aggregation"));
122 | targetQuery.setProperties(properties);
123 | return targetQuery;
124 | }
125 |
126 | }
127 |
--------------------------------------------------------------------------------
/gt-elasticsearch-process/src/main/java/mil/nga/giat/process/elasticsearch/GridCell.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is hereby placed into the Public Domain. This means anyone is
3 | * free to do whatever they wish with this file.
4 | */
5 | package mil.nga.giat.process.elasticsearch;
6 |
7 | class GridCell {
8 |
9 | private final String geohash;
10 |
11 | private final Number value;
12 |
13 | public GridCell(String geohash, Number value) {
14 | this.geohash = geohash;
15 | this.value = value;
16 | }
17 |
18 | public String getGeohash() {
19 | return geohash;
20 | }
21 |
22 | public Number getValue() {
23 | return value;
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/gt-elasticsearch-process/src/main/java/mil/nga/giat/process/elasticsearch/GridCoverageUtil.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is hereby placed into the Public Domain. This means anyone is
3 | * free to do whatever they wish with this file.
4 | */
5 | package mil.nga.giat.process.elasticsearch;
6 |
7 | import java.awt.image.Raster;
8 | import java.awt.image.RenderedImage;
9 |
10 | import org.geotools.coverage.grid.GridCoverage2D;
11 | import org.geotools.coverage.processing.CoverageProcessor;
12 | import org.geotools.coverage.processing.Operations;
13 | import org.geotools.geometry.GeneralEnvelope;
14 | import org.opengis.geometry.Envelope;
15 | import org.opengis.parameter.ParameterValueGroup;
16 |
17 | class GridCoverageUtil {
18 |
19 | public static GridCoverage2D scale(GridCoverage2D coverage, float width, float height) {
20 | final RenderedImage renderedImage = coverage.getRenderedImage();
21 | final Raster renderedGrid = renderedImage.getData();
22 | float yScale = width/renderedGrid.getWidth();
23 | float xScale = height/renderedGrid.getHeight();
24 |
25 | final Operations ops = new Operations(null);
26 | return (GridCoverage2D) ops.scale(coverage, xScale, yScale, 0, 0);
27 | }
28 |
29 | public static GridCoverage2D crop(GridCoverage2D coverage, Envelope envelope) {
30 | final CoverageProcessor processor = new CoverageProcessor();
31 |
32 | final ParameterValueGroup param = processor.getOperation("CoverageCrop").getParameters();
33 |
34 | final GeneralEnvelope crop = new GeneralEnvelope(envelope);
35 | param.parameter("Source").setValue( coverage );
36 | param.parameter("Envelope").setValue( crop );
37 |
38 | return (GridCoverage2D) processor.doOperation(param);
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/gt-elasticsearch-process/src/main/java/mil/nga/giat/process/elasticsearch/MetricGeoHashGrid.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is hereby placed into the Public Domain. This means anyone is
3 | * free to do whatever they wish with this file.
4 | */
5 | package mil.nga.giat.process.elasticsearch;
6 |
7 | import java.util.List;
8 | import java.util.Map;
9 |
10 | public class MetricGeoHashGrid extends GeoHashGrid {
11 |
12 | public final static String DEFAULT_METRIC_KEY = "metric";
13 |
14 | private final static int METRIC_KEY_INDEX = 0;
15 |
16 | private final static int VALUE_KEY_INDEX = 1;
17 |
18 | private String metricKey = DEFAULT_METRIC_KEY;
19 |
20 | private String valueKey = GeoHashGrid.VALUE_KEY;
21 |
22 | @Override
23 | public void setParams(List params) {
24 | if (null != params) {
25 | if (params.size() >= 1) {
26 | metricKey = params.get(METRIC_KEY_INDEX);
27 | }
28 | if (params.size() >= 2) {
29 | valueKey = params.get(VALUE_KEY_INDEX);
30 | }
31 | }
32 | }
33 |
34 | @Override
35 | public Number computeCellValue(Map bucket) {
36 | return super.pluckMetricValue(bucket, metricKey, valueKey);
37 | }
38 |
39 | public String getMetricKey() {
40 | return metricKey;
41 | }
42 |
43 | public String getValueKey() {
44 | return valueKey;
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/gt-elasticsearch-process/src/main/java/mil/nga/giat/process/elasticsearch/NestedAggGeoHashGrid.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is hereby placed into the Public Domain. This means anyone is
3 | * free to do whatever they wish with this file.
4 | */
5 | package mil.nga.giat.process.elasticsearch;
6 |
7 | import java.util.HashMap;
8 | import java.util.List;
9 | import java.util.Map;
10 | import java.util.logging.Logger;
11 |
12 | import org.geotools.util.logging.Logging;
13 |
14 | public class NestedAggGeoHashGrid extends GeoHashGrid {
15 |
16 | private final static Logger LOGGER = Logging.getLogger(NestedAggGeoHashGrid.class);
17 |
18 | private final static int NESTED_KEY_INDEX = 0;
19 |
20 | private final static int METRIC_KEY_INDEX = 1;
21 |
22 | private final static int VALUE_KEY_INDEX = 2;
23 |
24 | private final static int SELECTION_STRATEGY_INDEX = 3;
25 |
26 | private final static int RASTER_STRATEGY_INDEX = 4;
27 |
28 | private final static int TERMS_MAP_INDEX = 5;
29 |
30 | final static String SELECT_LARGEST = "largest";
31 |
32 | final static String SELECT_SMALLEST = "smallest";
33 |
34 | final static String RASTER_FROM_VALUE = "value";
35 |
36 | final static String RASTER_FROM_KEY = "key";
37 |
38 | final static String DEFAULT_AGG_KEY = "nested";
39 |
40 | final static String DEFAULT_METRIC_KEY = "";
41 |
42 | private String nestedAggKey = DEFAULT_AGG_KEY;
43 |
44 | private String metricKey = DEFAULT_METRIC_KEY;
45 |
46 | private String valueKey = GeoHashGrid.VALUE_KEY;
47 |
48 | private String selectionStrategy = SELECT_LARGEST;
49 |
50 | private String rasterStrategy = RASTER_FROM_VALUE;
51 |
52 | private Map termsMap = null;
53 |
54 | @Override
55 | public void setParams(List params) {
56 | if (null != params) {
57 | if (params.size() < 5) {
58 | LOGGER.warning("Parameters list does not contain required length; you provided " + params.size() + ", expecting: 5 or more");
59 | throw new IllegalArgumentException();
60 | }
61 | nestedAggKey = params.get(NESTED_KEY_INDEX);
62 | metricKey = params.get(METRIC_KEY_INDEX);
63 | valueKey = params.get(VALUE_KEY_INDEX);
64 | switch (params.get(SELECTION_STRATEGY_INDEX)) {
65 | case SELECT_SMALLEST:
66 | selectionStrategy = params.get(SELECTION_STRATEGY_INDEX);
67 | break;
68 | case SELECT_LARGEST:
69 | selectionStrategy = params.get(SELECTION_STRATEGY_INDEX);
70 | break;
71 | default:
72 | LOGGER.warning("Unexpected buckets selection strategy parameter; you provided " + params.get(SELECTION_STRATEGY_INDEX) + ", defaulting to: " + selectionStrategy);
73 | }
74 | switch (params.get(RASTER_STRATEGY_INDEX)) {
75 | case RASTER_FROM_VALUE:
76 | rasterStrategy = params.get(RASTER_STRATEGY_INDEX);
77 | break;
78 | case RASTER_FROM_KEY:
79 | rasterStrategy = params.get(RASTER_STRATEGY_INDEX);
80 | break;
81 | default:
82 | LOGGER.warning("Unexpected raster strategy parameter; you provided " + params.get(RASTER_STRATEGY_INDEX) + ", defaulting to: " + rasterStrategy);
83 | }
84 | if (rasterStrategy.equals(RASTER_FROM_KEY) && params.size() >= 6) {
85 | termsMap = new HashMap<>();
86 | String[] terms = params.get(TERMS_MAP_INDEX).split(";");
87 | for (String term : terms) {
88 | String[] keyValueSplit = term.split(":");
89 | if (keyValueSplit.length != 2) {
90 | LOGGER.warning("Term " + term + " does not contain required format :");
91 | throw new IllegalArgumentException();
92 | }
93 | termsMap.put(keyValueSplit[0], new Integer(keyValueSplit[1]));
94 | }
95 | }
96 | }
97 | }
98 |
99 | @Override
100 | public Number computeCellValue(Map geogridBucket) {
101 | List