├── .github
├── dependabot.yml
└── workflows
│ └── ci.yml
├── .gitignore
├── LICENSE
├── README.md
├── RELEASE_NOTES.md
├── generate-site.sh
├── grumpy-app
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── github
│ │ └── davidmoten
│ │ └── grumpy
│ │ └── wms
│ │ └── app
│ │ └── WmsServlet.java
│ └── webapp
│ ├── WEB-INF
│ ├── classes
│ │ └── log4j.properties
│ └── web.xml
│ ├── css
│ ├── style.css
│ └── theme-style.css
│ ├── index.html
│ ├── js
│ ├── base-layers-3857.js
│ ├── base-layers-4326.js
│ └── layers.js
│ ├── map-3857.jsp
│ └── map-4326.jsp
├── grumpy-core
├── README.md
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── com
│ │ └── github
│ │ └── davidmoten
│ │ └── grumpy
│ │ └── core
│ │ └── Position.java
│ └── test
│ ├── java
│ └── com
│ │ └── github
│ │ └── davidmoten
│ │ └── grumpy
│ │ └── core
│ │ └── PositionTest.java
│ └── resources
│ └── log4j.properties
├── grumpy-ogc-layers
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── github
│ │ └── davidmoten
│ │ └── grumpy
│ │ └── wms
│ │ └── layer
│ │ └── darkness
│ │ ├── DarknessLayer.java
│ │ ├── SunUtil.java
│ │ └── TimeUtil.java
│ └── resources
│ └── sunny.png
├── grumpy-ogc
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── davidmoten
│ │ │ ├── grumpy
│ │ │ ├── function
│ │ │ │ └── Function.java
│ │ │ └── wms
│ │ │ │ ├── Capabilities.java
│ │ │ │ ├── CapabilitiesLayer.java
│ │ │ │ ├── CapabilitiesProvider.java
│ │ │ │ ├── CapabilitiesProviderEmpty.java
│ │ │ │ ├── CapabilitiesProviderFromCapabilities.java
│ │ │ │ ├── CapabilitiesProviderFromClasspath.java
│ │ │ │ ├── HasLayerFeatures.java
│ │ │ │ ├── ImageCache.java
│ │ │ │ ├── ImageWriter.java
│ │ │ │ ├── ImageWriterDefault.java
│ │ │ │ ├── Layer.java
│ │ │ │ ├── LayerFeatures.java
│ │ │ │ ├── LayerManager.java
│ │ │ │ ├── Layers.java
│ │ │ │ ├── LayersBuilder.java
│ │ │ │ ├── MissingMandatoryParameterException.java
│ │ │ │ ├── RendererUtil.java
│ │ │ │ ├── UnknownParameterException.java
│ │ │ │ ├── WmsRequest.java
│ │ │ │ ├── WmsRequestProcessor.java
│ │ │ │ ├── WmsServletRequestProcessor.java
│ │ │ │ ├── WmsUtil.java
│ │ │ │ └── reduction
│ │ │ │ ├── RectangleSampler.java
│ │ │ │ ├── RectangleSamplerCorners.java
│ │ │ │ ├── RectangleSamplerGrid.java
│ │ │ │ ├── RectangleUtil.java
│ │ │ │ ├── Reducer.java
│ │ │ │ └── ValueRenderer.java
│ │ │ └── util
│ │ │ └── servlet
│ │ │ └── RequestUtil.java
│ └── resources
│ │ ├── wms-capabilities-empty.xml
│ │ └── wms-capabilities-template.xml
│ └── test
│ ├── java
│ └── com
│ │ └── github
│ │ └── davidmoten
│ │ └── grumpy
│ │ └── wms
│ │ ├── CapabilitiesProviderFromCapabilitiesTest.java
│ │ ├── RendererUtilTest.java
│ │ └── reduction
│ │ └── BoundsSamplerMaxSizeTest.java
│ └── resources
│ └── log4j.properties
├── grumpy-projection
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── davidmoten
│ │ │ └── grumpy
│ │ │ ├── projection
│ │ │ ├── FeatureUtil.java
│ │ │ ├── Projector.java
│ │ │ ├── ProjectorBounds.java
│ │ │ └── ProjectorTarget.java
│ │ │ └── util
│ │ │ └── NearBSpline.java
│ └── resources
│ │ └── epsg
│ │ ├── EPSG_102100.txt
│ │ └── EPSG_900913.txt
│ └── test
│ └── java
│ └── com
│ └── github
│ └── davidmoten
│ └── grumpy
│ └── ProjectorTest.java
├── pom.xml
├── src
└── docs
│ ├── craft.png
│ ├── demo.png
│ ├── demo2.png
│ ├── demo3.png
│ └── demo4.png
└── wms-demo
├── pom.xml
└── src
└── main
├── java
└── com
│ └── github
│ └── davidmoten
│ └── grumpy
│ └── wms
│ └── demo
│ ├── CustomLayer.java
│ ├── FiddleLayer.java
│ └── WmsServlet.java
├── resources
└── wms-capabilities.xml
└── webapp
├── WEB-INF
├── classes
│ └── log4j.properties
└── web.xml
├── css
├── style.css
└── theme-style.css
├── index.html
├── js
├── base-layers-3857.js
├── base-layers-4326.js
└── layers.js
├── map-3857.jsp
└── map-4326.jsp
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | # To get started with Dependabot version updates, you'll need to specify which
2 | # package ecosystems to update and where the package manifests are located.
3 | # Please see the documentation for all configuration options:
4 | # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5 |
6 | version: 2
7 | updates:
8 | - package-ecosystem: "maven" # See documentation for possible values
9 | directory: "/" # Location of package manifests
10 | schedule:
11 | interval: "daily"
12 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: ci
2 |
3 | on: [push, pull_request]
4 |
5 | jobs:
6 | build:
7 | uses: davidmoten/workflows/.github/workflows/ci.yml@master
8 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | pom.xml.tag
3 | pom.xml.releaseBackup
4 | pom.xml.next
5 | release.properties
6 | .classpath
7 | .project
8 | .settings
9 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | grumpy
2 | =============
3 |
4 | [](https://maven-badges.herokuapp.com/maven-central/com.github.davidmoten/grumpy)
5 | [](https://codecov.io/gh/davidmoten/grumpy)
6 |
7 | [OGC WMS](http://www.opengeospatial.org/standards/wms) 1.3.0 Server in java allowing custom rendering of WMS layers using projection utilities and Graphics2D.
8 |
9 | Status: *released to Maven Central*
10 |
11 | [Release Notes](RELEASE_NOTES.md)
12 |
13 |
14 |
15 | [Maven reports](http://davidmoten.github.io/grumpy/project-reports.html) including [javadocs](http://davidmoten.github.io/grumpy/apidocs/index.html).
16 |
17 | Features
18 | ----------
19 | * Great circle navigation utilities in ```grumpy-core```
20 | * Map projection utilities in ```grumpy-projection```
21 | * WMS Server utilities in ```grumpy-ogc```
22 | * Create a lightweight WMS server (about 12MB war)
23 | * Supports BBOX parameters handled differently by WMS 1.1.1 and 1.3
24 | * Handles boundary discontinuities with ```Reducer``` and ```RendererUtil``` methods
25 | * War artifact to deploy Darkness layer as WMS service (```grumpy-app```)
26 |
27 | Serverless AWS implementation of grumpy with OpenLayers 6 and ArcGIS base layers:
28 |
29 |
30 |
31 | Run demo locally
32 | ------------------
33 | ```
34 | git clone https://github.com/davidmoten/grumpy.git
35 | cd grumpy
36 | mvn clean install
37 | cd wms-demo
38 | mvn jetty:run
39 | ```
40 |
41 | Go to [http://localhost:8080](http://localhost:8080/wms-demo) with a browser.
42 |
43 | And at the map link you will see this:
44 |
45 |
46 |
47 | This demonstrates a custom filled shape and some text that is placed with transparency over the position of Canberra on the map. Notice that the borders are great circle paths.
48 |
49 | Click in the Canberra box and you will see a demo of WMS GetFeatureInfo:
50 |
51 |
52 |
53 | How is it all done? Easy!
54 |
55 | Getting started
56 | -------------------
57 | To make your own WMS service add this dependency to the pom.xml of your war project:
58 | ```xml
59 |
127 |
128 | The bands correspond to the following twilight categories:
129 |
130 | * Civil (the lightest)
131 | * Nautical
132 | * Astronomical
133 | * Night (the darkest)
134 |
135 | The layer is visible in the demo.
136 |
137 | The ```grumpy-app``` artifact is a war artifact that can be deployed to a java servlet container (tomcat, glassfish, jetty, jboss, others) to offer a WMS service with the Darkness layer (and any other layers that get added to ```grumpy-ogc-layers```).
138 |
139 | Why Grumpy?
140 | ---------------
141 | The project name was chosen at random and is no hint at the disposition of the primary developer! I'm very happy to receive contributions on this project. Just raise an issue.
142 |
--------------------------------------------------------------------------------
/RELEASE_NOTES.md:
--------------------------------------------------------------------------------
1 | Release Notes
2 | ---------------
3 | ###Version 0.2 ([Maven Central](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.github.davidmoten%22))
4 | * many breaking changes
5 | * added builder for capabilities
6 | * added ```Reducer`` to abstract reductionist drawing of regions
7 | * refactored Darkness layer
8 | * added grumpy-app artifact to offer Darkness layer in a war
9 | * simplified Darkness layer
10 |
11 | ###Version 0.1 ([Maven Central](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.github.davidmoten%22))
12 | * initial release
13 |
--------------------------------------------------------------------------------
/generate-site.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | set -e
3 | mvn site
4 | mvn site:stage
5 | cd ../davidmoten.github.io
6 | git pull
7 | mkdir grumpy
8 | cp -r ../grumpy/target/staging/* grumpy/
9 | git add .
10 | git commit -am "update site reports"
11 | git push
12 |
--------------------------------------------------------------------------------
/grumpy-app/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
" + entry.getKey() + "
").getBytes()); 166 | bos.write(entry.getValue().getBytes()); 167 | } 168 | bos.flush(); 169 | } 170 | 171 | } 172 | -------------------------------------------------------------------------------- /grumpy-ogc/src/main/java/com/github/davidmoten/grumpy/wms/WmsServletRequestProcessor.java: -------------------------------------------------------------------------------- 1 | package com.github.davidmoten.grumpy.wms; 2 | 3 | import java.io.IOException; 4 | import java.io.OutputStream; 5 | import java.text.DecimalFormat; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | import javax.servlet.ServletException; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import org.slf4j.LoggerFactory; 14 | 15 | /** 16 | * Processes a WMS {@link HttpServletRequest} and returns a 17 | * {@link HttpServletResponse}. 18 | */ 19 | public class WmsServletRequestProcessor { 20 | 21 | private static org.slf4j.Logger log = LoggerFactory.getLogger(WmsServletRequestProcessor.class); 22 | 23 | private static final String REQUEST_GET_MAP = "GetMap"; 24 | private static final String PARAMETER_REQUEST = "REQUEST"; 25 | private static final Object REQUEST_GET_CAPABILITIES = "GetCapabilities"; 26 | private static final Object REQUEST_GET_FEATURE_INFO = "GetFeatureInfo"; 27 | 28 | private final CapabilitiesProvider capabilitiesProvider; 29 | 30 | private WmsRequestProcessor processor; 31 | 32 | /** 33 | * Constructor. 34 | * 35 | * @param capabilitiesProvider 36 | * @param layers 37 | * @param imageCache 38 | * @param imageWriter 39 | */ 40 | public WmsServletRequestProcessor(CapabilitiesProvider capabilitiesProvider, 41 | WmsRequestProcessor processor) { 42 | this.capabilitiesProvider = capabilitiesProvider; 43 | this.processor = processor; 44 | } 45 | 46 | public static Builder builder() { 47 | return new Builder(); 48 | } 49 | 50 | public static class Builder { 51 | 52 | private CapabilitiesProvider capabilitiesProvider = new CapabilitiesProviderEmpty(); 53 | private ImageCache imageCache = new ImageCache(); 54 | private Layers layers; 55 | private final LayersBuilder layersBuilder = LayersBuilder.builder(); 56 | private final List
23 | * Set {@code Projector.forceXY = false} before instantiating any Projector if
24 | * you don't want the system property "org.geotools.referencing.forceXY" to be
25 | * set to truen (it will happen on first instantiation of a Projector by
26 | * default).
27 | *
28 | * @author dxm
29 | *
30 | */
31 | public class Projector {
32 |
33 | private static final AtomicBoolean initialized = new AtomicBoolean(false);
34 | public static volatile boolean forceXY = true;
35 |
36 | private final ProjectorTarget target;
37 | private final ProjectorBounds bounds;
38 |
39 | private final MathTransform transform;
40 | private final GeometryFactory geometryFactory;
41 |
42 | public Projector(ProjectorBounds bounds, ProjectorTarget target) {
43 | // perform one time initialization in a thread safe way
44 | if (initialized.compareAndSet(false, true)) {
45 | if (forceXY)
46 | System.setProperty("org.geotools.referencing.forceXY", "true");
47 | }
48 | this.target = target;
49 | this.bounds = bounds;
50 | try {
51 | transform = CRS.findMathTransform(FeatureUtil.getCrs(FeatureUtil.EPSG_4326),
52 | FeatureUtil.getCrs(bounds.getSrs()));
53 |
54 | } catch (FactoryException e) {
55 | throw new RuntimeException(e);
56 | }
57 | geometryFactory = new GeometryFactory();
58 | }
59 |
60 | public ProjectorBounds getBounds() {
61 | return bounds;
62 | }
63 |
64 | public ProjectorTarget getTarget() {
65 | return target;
66 | }
67 |
68 | public org.locationtech.jts.geom.Point getGeometryPointInSrs(double lat, double lon) {
69 | Coordinate coordinate = new Coordinate(lon, lat);
70 | org.locationtech.jts.geom.Point point = geometryFactory.createPoint(coordinate);
71 | try {
72 | return (org.locationtech.jts.geom.Point) JTS.transform(point, transform);
73 | } catch (MismatchedDimensionException e) {
74 | throw new RuntimeException(e);
75 | } catch (TransformException e) {
76 | throw new RuntimeException(e);
77 | }
78 | }
79 |
80 | public org.locationtech.jts.geom.Point getGeometryPointInSrsRelativeTo(double lat,
81 | double lon, double relativeLat, double relativeLon, double relativeX, double relativeY) {
82 |
83 | double diffLon1 = lon - relativeLon;
84 | double diffLon2 = lon - relativeLon + 360;
85 | if (Math.abs(diffLon1) > Math.abs(diffLon2))
86 | lon = lon + 360;
87 | double sign = Math.signum(lon - relativeLon);
88 |
89 | org.locationtech.jts.geom.Point point = getGeometryPointInSrs(lat, lon);
90 | double periodAtLat = periodAtLat(lat);
91 | double x = point.getX();
92 | // makes the assumption that increasing lon = increasing X
93 | // which is probably valid for most common projections
94 | // TODO determine when invalid or handle
95 | if (sign >= 0) {
96 | while (x - periodAtLat >= relativeX)
97 | x -= periodAtLat;
98 | while (x < relativeX)
99 | x += periodAtLat;
100 | } else {
101 | while (x >= relativeX)
102 | x -= periodAtLat;
103 | while (x + periodAtLat < relativeX)
104 | x += periodAtLat;
105 | }
106 |
107 | return createPoint(x, point.getY());
108 | }
109 |
110 | public org.locationtech.jts.geom.Point createPoint(double x, double y) {
111 | return geometryFactory.createPoint(new Coordinate(x, y));
112 | }
113 |
114 | public double periodAtLat(double lat) {
115 | return getGeometryPointInSrs(lat, 180).getX() - getGeometryPointInSrs(lat, -180).getX();
116 | }
117 |
118 | public Point2D.Double getTargetPoint(org.locationtech.jts.geom.Point point) {
119 | double proportionX = (point.getX() - bounds.getMinX())
120 | / (bounds.getMaxX() - bounds.getMinX());
121 | double proportionY = (bounds.getMaxY() - point.getY())
122 | / (bounds.getMaxY() - bounds.getMinY());
123 | double x = proportionX * target.getWidth();
124 | double y = proportionY * target.getHeight();
125 | return new Point2D.Double(x, y);
126 | }
127 |
128 | public org.locationtech.jts.geom.Point getFirstXAfter(Projector projector, double lat,
129 | double lon, double x) {
130 | org.locationtech.jts.geom.Point point = projector.getGeometryPointInSrs(lat, lon);
131 | double x2 = point.getX();
132 | double periodX = periodAtLat(lat);
133 | while (x2 - periodX >= x)
134 | x2 -= periodX;
135 | while (x2 + periodX < x)
136 | x2 += periodX;
137 | return createPoint(x2, point.getY());
138 | }
139 |
140 | public Point toPoint(double lat, double lon) {
141 | Point2D point2D = toPoint2D(lat, lon);
142 | Point p = new Point();
143 | p.x = (int) Math.round(point2D.getX());
144 | p.y = (int) Math.round(point2D.getY());
145 | return p;
146 | }
147 |
148 | public Point2D.Double toPointInSrs(double lat, double lon) {
149 | org.locationtech.jts.geom.Point point = getGeometryPointInSrs(lat, lon);
150 | return new Point2D.Double(point.getX(), point.getY());
151 | }
152 |
153 | public Point2D.Double toPoint2D(double lat, double lon) {
154 | Coordinate coordinate = new Coordinate(lon, lat);
155 | org.locationtech.jts.geom.Point point = geometryFactory.createPoint(coordinate);
156 | try {
157 | point = (org.locationtech.jts.geom.Point) JTS.transform(point, transform);
158 |
159 | double proportionX;
160 | if (point.getX() > bounds.getMaxX() || point.getX() < bounds.getMinX()) {
161 | // assume the maxX occurs at longitude 180 (true for EPSG 3857
162 | // spherical mercator) but maybe not true for other projections?
163 | Coordinate c = new Coordinate(180, 0);
164 | org.locationtech.jts.geom.Point pt = (org.locationtech.jts.geom.Point) JTS
165 | .transform(geometryFactory.createPoint(c), transform);
166 | double maximumX = pt.getX();
167 | if (point.getX() > bounds.getMaxX())
168 | proportionX = (point.getX() - 2 * maximumX - bounds.getMinX())
169 | / (bounds.getMaxX() - bounds.getMinX());
170 | else
171 | proportionX = (point.getX() + 2 * maximumX - bounds.getMinX())
172 | / (bounds.getMaxX() - bounds.getMinX());
173 | } else {
174 | proportionX = (point.getX() - bounds.getMinX())
175 | / (bounds.getMaxX() - bounds.getMinX());
176 | }
177 | double proportionY = (bounds.getMaxY() - point.getY())
178 | / (bounds.getMaxY() - bounds.getMinY());
179 | Point2D.Double point2D = new Point2D.Double(proportionX * target.getWidth(),
180 | proportionY * target.getHeight());
181 | return point2D;
182 | } catch (MismatchedDimensionException e) {
183 | throw new RuntimeException(e);
184 | } catch (TransformException e) {
185 | throw new RuntimeException(e);
186 | }
187 | }
188 |
189 | public Position toPosition(double targetX, double targetY) {
190 | double proportionX = targetX / target.getWidth();
191 | double proportionY = targetY / target.getHeight();
192 | double x = proportionX * (bounds.getMaxX() - bounds.getMinX()) + bounds.getMinX();
193 | double y = bounds.getMaxY() - proportionY * (bounds.getMaxY() - bounds.getMinY());
194 | Coordinate coordinate = new Coordinate(x, y);
195 | org.locationtech.jts.geom.Point point = geometryFactory.createPoint(coordinate);
196 | try {
197 | point = (org.locationtech.jts.geom.Point) JTS.transform(point, transform.inverse());
198 | } catch (MismatchedDimensionException e) {
199 | throw new RuntimeException(e);
200 | } catch (TransformException e) {
201 | throw new RuntimeException(e);
202 | }
203 | return new Position(point.getY(), point.getX());
204 | }
205 |
206 | public Position toPositionFromSrs(double x, double y) {
207 | return FeatureUtil.convertToLatLon(x, y, bounds.getSrs());
208 | }
209 |
210 | @Override
211 | public String toString() {
212 | return "ProjectorImpl [target=" + target + ", bounds=" + bounds + "]";
213 | }
214 |
215 | }
216 |
--------------------------------------------------------------------------------
/grumpy-projection/src/main/java/com/github/davidmoten/grumpy/projection/ProjectorBounds.java:
--------------------------------------------------------------------------------
1 | package com.github.davidmoten.grumpy.projection;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | public class ProjectorBounds {
7 | private final double minX;
8 | private final double minY;
9 | private final double maxX;
10 | private final double maxY;
11 | private final String srs;
12 |
13 | public String getSrs() {
14 | return srs;
15 | }
16 |
17 | public ProjectorBounds(String srs, double minX, double minY, double maxX, double maxY) {
18 | this.minX = minX;
19 | this.minY = minY;
20 | this.maxX = maxX;
21 | this.maxY = maxY;
22 | this.srs = srs;
23 | }
24 |
25 | public double getMinX() {
26 | return minX;
27 | }
28 |
29 | public double getMinY() {
30 | return minY;
31 | }
32 |
33 | public double getMaxX() {
34 | return maxX;
35 | }
36 |
37 | public double getMaxY() {
38 | return maxY;
39 | }
40 |
41 | public double getSizeX() {
42 | return this.maxX - this.minX;
43 | }
44 |
45 | public double getSizeY() {
46 | return maxY - minY;
47 | }
48 |
49 | public List Canberra is the capital city of Australia. With a population of 381,488, it is Australia's largest inland city and the eighth-largest city overall.
18 | *
24 | *
25 | */
26 | public class NearBSpline implements Shape, Cloneable {
27 | /** holds the combination of curve and line segments */
28 | private GeneralPath path;
29 |
30 | /** the last segment added to the path */
31 | private Shape lastPart;
32 |
33 | /** the individual segments of the path */
34 | private Shape[] segments;
35 |
36 | /**
37 | * Creates a new, empty b-spline
38 | */
39 | public NearBSpline() {
40 | }
41 |
42 | /**
43 | * Creates a new b-spline with the given control points
44 | *
45 | * @param points
46 | * the control points for the curve
47 | */
48 | public NearBSpline(Point2D[] points) {
49 | setLine(points);
50 | }
51 |
52 | /**
53 | * Sets the curve using control points given in integer precision
54 | *
55 | * @param points
56 | * the control points for the curve
57 | */
58 | public void setLine(int... points) {
59 | double[] pd = new double[points.length];
60 | for (int i = 0; i < points.length; i++) {
61 | pd[i] = points[i];
62 | }
63 | setLine(pd);
64 | }
65 |
66 | /**
67 | * Sets the curve using control points given in double precision
68 | *
69 | * @param points
70 | * the control points for the curve
71 | */
72 | public void setLine(double... points) {
73 | path = new GeneralPath();
74 | path.moveTo((float) points[0], (float) points[1]);
75 | segments = new Shape[points.length / 2 - 1];
76 |
77 | for (int i = 2; i < points.length;) {
78 | switch (points.length - i) {
79 | case 2:
80 | lastPart = new Line2D.Float((float) path.getCurrentPoint().getX(), (float) path
81 | .getCurrentPoint().getY(), (float) points[i], (float) points[i + 1]);
82 | path.append(lastPart, true);
83 | segments[i / 2 - 1] = lastPart;
84 | i += 2;
85 | break;
86 | case 4:
87 | lastPart = new QuadCurve2D.Float((float) path.getCurrentPoint().getX(),
88 | (float) path.getCurrentPoint().getY(), (float) points[i],
89 | (float) points[i + 1], (float) points[i + 2], (float) points[i + 3]);
90 | path.append(lastPart, true);
91 | segments[i / 2 - 1] = lastPart;
92 | segments[i / 2] = lastPart;
93 | i += 4;
94 | break;
95 | case 6:
96 | lastPart = new CubicCurve2D.Double(path.getCurrentPoint().getX(), path
97 | .getCurrentPoint().getY(), points[i], points[i + 1], points[i + 2],
98 | points[i + 3], points[i + 4], points[i + 5]);
99 | path.append(lastPart, true);
100 | segments[i / 2 - 1] = lastPart;
101 | segments[i / 2] = lastPart;
102 | segments[i / 2 + 1] = lastPart;
103 | i += 6;
104 | break;
105 | default: // use two points and add one extra between 2nd and 3rd
106 | float x = (float) (points[i + 2] + points[i + 4]) / 2F;
107 | float y = (float) (points[i + 3] + points[i + 5]) / 2F;
108 |
109 | lastPart = new CubicCurve2D.Double(path.getCurrentPoint().getX(), path
110 | .getCurrentPoint().getY(), points[i], points[i + 1], points[i + 2],
111 | points[i + 3], x, y);
112 |
113 | path.append(lastPart, true);
114 | segments[i / 2 - 1] = lastPart;
115 | segments[i / 2] = lastPart;
116 |
117 | i += 4;
118 | }
119 | }
120 | }
121 |
122 | /**
123 | * Sets the curve using control points given as Point2D objects
124 | *
125 | * @param points
126 | * the control points for the curve
127 | */
128 | public void setLine(Point2D[] points) {
129 | double[] pd = new double[points.length * 2];
130 | for (int i = 0; i < points.length; i++) {
131 | Point2D p = points[i];
132 | pd[i * 2] = p.getX();
133 | pd[i * 2 + 1] = p.getY();
134 | }
135 | setLine(pd);
136 | }
137 |
138 | public Rectangle getBounds() {
139 | return getBounds2D().getBounds();
140 | }
141 |
142 | public Rectangle2D getBounds2D() {
143 | return path.getBounds2D();
144 | }
145 |
146 | public boolean contains(double x, double y) {
147 | return path.contains(x, y);
148 | }
149 |
150 | public boolean contains(Point2D p) {
151 | return path.contains(p);
152 | }
153 |
154 | public boolean intersects(double x, double y, double w, double h) {
155 | return path.intersects(x, y, w, h);
156 | }
157 |
158 | public boolean intersects(Rectangle2D r) {
159 | return path.intersects(r);
160 | }
161 |
162 | public boolean contains(double x, double y, double w, double h) {
163 | return path.contains(x, y, w, h);
164 | }
165 |
166 | public boolean contains(Rectangle2D r) {
167 | return path.contains(r);
168 | }
169 |
170 | public PathIterator getPathIterator(AffineTransform at) {
171 | return path.getPathIterator(at);
172 | }
173 |
174 | public PathIterator getPathIterator(AffineTransform at, double flatness) {
175 | return path.getPathIterator(at, flatness);
176 | }
177 |
178 | /**
179 | * Returns the last piece of this curve, which should be the most likely
180 | * thing to intercept with rectangles at the end.
181 | *
182 | * @return a Line2D, QuadCurve2D, or CubicCurve2D object
183 | */
184 | public Shape getLastPart() {
185 | return lastPart;
186 | }
187 |
188 | /**
189 | * Return the segment of the path that should be adjacent to the control
190 | * point at the given index.
191 | *
192 | * @param i
193 | * the index of the control point
194 | * @return the path segment adjacent to the control point (a Line2D,
195 | * QuadCurve2D, or CubicCurve2D object)
196 | */
197 | public Shape getSegment(int i) {
198 | return segments[i];
199 | }
200 |
201 | public GeneralPath getPath() {
202 | return path;
203 | }
204 | }
205 |
--------------------------------------------------------------------------------
/grumpy-projection/src/main/resources/epsg/EPSG_102100.txt:
--------------------------------------------------------------------------------
1 | PROJCS["WGS 84 / Pseudo-Mercator",
2 | GEOGCS["Popular Visualisation CRS",
3 | DATUM["Popular_Visualisation_Datum",
4 | SPHEROID["Popular Visualisation Sphere",6378137,0,AUTHORITY["EPSG","7059"]],
5 | TOWGS84[0,0,0,0,0,0,0],
6 | AUTHORITY["EPSG","6055"]],
7 | PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],
8 | UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],
9 | AUTHORITY["EPSG","4055"]],
10 | UNIT["metre",1,AUTHORITY["EPSG","9001"]],
11 | PROJECTION["Mercator_1SP"],
12 | PARAMETER["central_meridian",0],
13 | PARAMETER["scale_factor",1],
14 | PARAMETER["false_easting",0],
15 | PARAMETER["false_northing",0],
16 | AUTHORITY["EPSG","3785"],
17 | AXIS["X",EAST],
18 | AXIS["Y",NORTH]]
--------------------------------------------------------------------------------
/grumpy-projection/src/main/resources/epsg/EPSG_900913.txt:
--------------------------------------------------------------------------------
1 | PROJCS["WGS84 / Google Mercator",
2 | GEOGCS["WGS 84",
3 | DATUM["World Geodetic System 1984",
4 | SPHEROID["WGS 84", 6378137.0, 298.257223563, AUTHORITY["EPSG","7030"]],
5 | AUTHORITY["EPSG","6326"]],
6 | PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]],
7 | UNIT["degree", 0.017453292519943295],
8 | AXIS["Longitude", EAST],
9 | AXIS["Latitude", NORTH],
10 | AUTHORITY["EPSG","4326"]],
11 | PROJECTION["Mercator_1SP"],
12 | PARAMETER["semi_major", 6378137.0],
13 | PARAMETER["semi_minor", 6378137.0],
14 | PARAMETER["latitude_of_origin", 0.0],
15 | PARAMETER["central_meridian", 0.0],
16 | PARAMETER["scale_factor", 1.0],
17 | PARAMETER["false_easting", 0.0],
18 | PARAMETER["false_northing", 0.0],
19 | UNIT["m", 1.0],
20 | AXIS["x", EAST],
21 | AXIS["y", NORTH],
22 | AUTHORITY["EPSG","900913"]]
--------------------------------------------------------------------------------
/grumpy-projection/src/test/java/com/github/davidmoten/grumpy/ProjectorTest.java:
--------------------------------------------------------------------------------
1 | package com.github.davidmoten.grumpy;
2 |
3 | import com.github.davidmoten.grumpy.projection.Projector;
4 | import com.github.davidmoten.grumpy.projection.ProjectorBounds;
5 | import com.github.davidmoten.grumpy.projection.ProjectorTarget;
6 | import org.junit.Test;
7 | import org.locationtech.jts.geom.Point;
8 |
9 | import java.awt.geom.Point2D.Double;
10 |
11 | import static org.junit.Assert.assertEquals;
12 |
13 | public class ProjectorTest {
14 |
15 | private static final double PRECISION = 1E-7;
16 |
17 | @Test
18 | public void testTransformWrapping() {
19 | ProjectorTarget target = new ProjectorTarget(300, 200);
20 | ProjectorBounds bounds = new ProjectorBounds("EPSG:3857", 18924313.4349, -4865942.2795,
21 | -18924313.4349, -3503549.8435);
22 | Projector projector = new Projector(bounds, target);
23 | Point p = projector.getGeometryPointInSrs(-35, 140);
24 | Double point = projector.getTargetPoint(p);
25 | System.out.println("x1=" + p.getX() + " point=" + point);
26 | assertEquals(26.470588235578038, point.getX(), PRECISION);
27 | assertEquals(96.93701801560695, point.getY(), PRECISION);
28 | Point p2 = projector
29 | .getGeometryPointInSrsRelativeTo(-35, 141, -35, 140, p.getX(), p.getY());
30 | System.out.println("x2=" + p2.getX());
31 | assertEquals(1.5696048201851575E7, p2.getX(), PRECISION);
32 | double x3 = p.getX() - projector.periodAtLat(-35);
33 | Double point3 = projector.getTargetPoint(projector.createPoint(x3, p.getY()));
34 | System.out.println("x3=" + x3 + " point=" + point3);
35 | double x4 = p.getX() + projector.periodAtLat(-35);
36 | Double point4 = projector.getTargetPoint(projector.createPoint(x4, p.getY()));
37 | System.out.println("x4=" + x4 + " point=" + point4);
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | "
104 | + "
WMS Demo
3 |
4 |
5 |
9 |
10 |
--------------------------------------------------------------------------------
/wms-demo/src/main/webapp/js/base-layers-3857.js:
--------------------------------------------------------------------------------
1 | var map;
2 |
3 | function init() {
4 |
5 | ///////////////////////////////////////////
6 | // setup the base map with google layers
7 | ///////////////////////////////////////////
8 |
9 | map = new OpenLayers.Map('map', {
10 | projection: 'EPSG:3857',
11 | layers: [
12 | new OpenLayers.Layer.OSM( "OpenStreetMap"),
13 | new OpenLayers.Layer.Google(
14 | "Google Physical",
15 | {type: google.maps.MapTypeId.TERRAIN}
16 | ),
17 | new OpenLayers.Layer.Google(
18 | "Google Streets", // the default
19 | {numZoomLevels: 20}
20 | ),
21 | new OpenLayers.Layer.Google(
22 | "Google Hybrid",
23 | {type: google.maps.MapTypeId.HYBRID, numZoomLevels: 20}
24 | ),
25 | new OpenLayers.Layer.Google(
26 | "Google Satellite",
27 | {type: google.maps.MapTypeId.SATELLITE, numZoomLevels: 22}
28 | )
29 | ],
30 | center: new OpenLayers.LonLat(149.1,-35.3)
31 | // Google.v3 uses web mercator as projection, so we have to
32 | // transform our coordinates
33 | .transform('EPSG:4326', 'EPSG:3857'),
34 | zoom: 6,
35 | zoomMethod: null
36 | });
37 |
38 | map.addControl(new OpenLayers.Control.LayerSwitcher());
39 |
40 | addLayers(map);
41 | }
42 |
43 |
--------------------------------------------------------------------------------
/wms-demo/src/main/webapp/js/base-layers-4326.js:
--------------------------------------------------------------------------------
1 |
2 |
3 | function init(){
4 | var lon = 140;
5 | var lat = -35;
6 | var zoom = 5;
7 | var map = new OpenLayers.Map('map');
8 | var layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
9 | "http://vmap0.tiles.osgeo.org/wms/vmap0", {layers: 'basic'} );
10 | map.addLayer(layer);
11 | map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
12 | addLayers(map);
13 | }
--------------------------------------------------------------------------------
/wms-demo/src/main/webapp/js/layers.js:
--------------------------------------------------------------------------------
1 |
2 | function addLayers(map) {
3 |
4 |
5 | ///////////////////////////////////////////
6 | // setup the custom wms layer
7 | ///////////////////////////////////////////
8 |
9 | var wmsUrl = "wms";
10 |
11 | var layer1 = new OpenLayers.Layer.WMS( "Custom WMS Layer",
12 | wmsUrl,
13 | {layers: 'Custom',transparent: "true", format: "image/png",styles:"Standard"},
14 | {gutter:15,singleTile:true, visibility:true,opacity: 0.5,animationEnabled: false});
15 |
16 | map.addLayer(layer1);
17 |
18 | ///////////////////////////////////////////
19 | // add the Darkness layer
20 | ///////////////////////////////////////////
21 | var layer2 = new OpenLayers.Layer.WMS( "Darkness",
22 | wmsUrl,
23 | {layers: 'Darkness',transparent: "true", format: "image/png",styles:"Standard"},
24 | {gutter:15,singleTile:true, visibility:true,opacity: 0.5,animationEnabled: true});
25 |
26 | map.addLayer(layer2);
27 |
28 | ///////////////////////////////////////////
29 | // add the Fiddle layer
30 | ///////////////////////////////////////////
31 | var layer3 = new OpenLayers.Layer.WMS( "Fiddle",
32 | wmsUrl,
33 | {layers: 'Fiddle',transparent: "true", format: "image/png"},
34 | {gutter:15,singleTile:true, visibility:true,opacity: 0.5,animationEnabled: true});
35 |
36 | map.addLayer(layer3);
37 |
38 | ////////////////////////////////////////////////////
39 | // setup getFeatureInfo on click for all layers
40 | ////////////////////////////////////////////////////s
41 |
42 | var click = new OpenLayers.Control.WMSGetFeatureInfo({
43 | url: wmsUrl,
44 | title: 'Identify features by clicking',
45 | layers: [layer1],
46 | queryVisible: true
47 | })
48 | click.events.register("getfeatureinfo", this, showInfo);
49 | map.addControl(click);
50 | click.activate();
51 |
52 | }
53 |
54 | function showInfo(event) {
55 | map.addPopup(new OpenLayers.Popup.FramedCloud(
56 | "chicken",
57 | map.getLonLatFromPixel(event.xy),
58 | null,
59 | event.text,
60 | null,
61 | true
62 | ));
63 | };
64 |
--------------------------------------------------------------------------------
/wms-demo/src/main/webapp/map-3857.jsp:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |