Hello everybody!
I am trying to render maps in google mercator projection.
I use geotools 2.4.1 so this must not be a problem.
I found google mercator wkt
(
PROJCS["WGS84 / Google Mercator",
GEOGCS["WGS 84",
DATUM["World Geodetic System 1984",
SPHEROID["WGS 84", 6378137.0, 298.257223563, AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]],
UNIT["degree", 0.017453292519943295],
AXIS["Longitude", EAST],
AXIS["Latitude", NORTH],
AUTHORITY["EPSG","4326"]],
PROJECTION["Mercator_1SP"],
PARAMETER["semi_minor", 6378137.0],
PARAMETER["latitude_of_origin", 0.0],
PARAMETER["central_meridian", 0.0],
PARAMETER["scale_factor", 1.0],
PARAMETER["false_easting", 0.0],
PARAMETER["false_northing", 0.0],
UNIT["m", 1.0],
AXIS["x", EAST],
AXIS["y", NORTH],
AUTHORITY["EPSG","900913"]]
)
Geotools parses wkt without exceptions.
I attached example code which renders Russia map and some lines grid on
it (The code is minimized as possible). Grid step is 25 degrees.
Render resulting image can be found here:
http://ds.azcltd.com/quickStart/compareProjections.gif glued with google
map tile with same area ( latitude between 0 and 85 longitude between 0
and 180). Image size is also similar (256 x 256)
Why google and geotools does not give similar results ?
Why grid on my image is having equal vertical distances between grid
lines? Isn't mercator projection result in larger distances when
approaching to south pole?
If google maps would have a grid we will be seeing this effect on
google's tiles. Am I wrong?
What do I have to do with attached code to get same result as google gives?
Somebody, please, help me.
package com.azoft;
import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.LineString;
import com.vividsolutions.jts.io.ParseException;
import com.vividsolutions.jts.io.WKTReader;
import org.geotools.factory.FactoryConfigurationError;
import org.geotools.feature.*;
import org.geotools.geometry.jts.ReferencedEnvelope;
import org.geotools.map.DefaultMapContext;
import org.geotools.map.MapContext;
import org.geotools.renderer.lite.StreamingRenderer;
import org.geotools.styling.LineSymbolizer;
import org.geotools.styling.Style;
import org.geotools.styling.StyleBuilder;
import org.geotools.referencing.CRS;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import java.io.IOException;
import java.util.Arrays;
public class StreamingRendererTest2 {
public static void main(String[] args) throws FactoryConfigurationError,
SchemaException, IllegalAttributeException, ParseException,
InterruptedException, IOException {
// Set up GUI elements
JFrame frame = new JFrame();
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
e.getWindow().dispose();
}
});
JPanel p = new JPanel();
frame.getContentPane().add(p);
frame.setSize(264, 284);
frame.setVisible(true);
// feature attributes creation
AttributeType[] types = new AttributeType[1];
types[0] = AttributeTypeFactory.newAttributeType("centre",
LineString.class);
// feature type creation
FeatureType pointType = FeatureTypeFactory.newFeatureType(types,
"linefeature");
//feature instance creation
WKTReader wktReader = new WKTReader();
LineString[] lineStrings = new LineString[]{
(LineString) wktReader.read("LINESTRING (0 85, 180 85)"),
(LineString) wktReader.read("LINESTRING (0 75, 180 75)"),
(LineString) wktReader.read("LINESTRING (0 50, 180 50)"),
(LineString) wktReader.read("LINESTRING (0 25, 180 25)"),
(LineString) wktReader.read("LINESTRING (0 00, 180 00)"),
(LineString) wktReader.read("LINESTRING (000 85, 000 0)"),
(LineString) wktReader.read("LINESTRING (025 85, 025 0)"),
(LineString) wktReader.read("LINESTRING (050 85, 050 0)"),
(LineString) wktReader.read("LINESTRING (075 85, 075 0)"),
(LineString) wktReader.read("LINESTRING (100 85, 100 0)"),
(LineString) wktReader.read("LINESTRING (125 85, 125 0)"),
(LineString) wktReader.read("LINESTRING (150 85, 150 0)"),
(LineString) wktReader.read("LINESTRING (175 85, 175 0)"),
(LineString) wktReader.read("LINESTRING (180 85, 180 0)"),
// Russia, Novosibirsk
(LineString) wktReader.read("LINESTRING (82 54, 83 55)"),
};
Feature[] features = new Feature[lineStrings.length];
for (int i = 0; i < lineStrings.length; i++) {
features[i] = pointType.create(new Object[]{lineStrings[i]});
}
//feature collection creation
FeatureCollection aFeatureCollection =
FeatureCollections.newCollection();
aFeatureCollection.addAll(Arrays.asList(features));
// Prepare styles
StyleBuilder sb = new StyleBuilder();
// Create line symbolizer
LineSymbolizer lineSymb = sb.createLineSymbolizer(Color.RED, 2);
Style aStyle = sb.createStyle(lineSymb);
MapContext map = new DefaultMapContext(getCRS());
QuickStart.loadMapLayers("");
for (MapLayer mapLayer : QuickStart.mapLayers) {
for (Layer layer : mapLayer.layers) {
map.addLayer(layer.getFeatureSource(), layer.getStyle());
}
}
map.addLayer(aFeatureCollection, aStyle);
StreamingRenderer renderer = new StreamingRenderer();
renderer.setContext(map);
renderer.paint((Graphics2D) p.getGraphics(), new Rectangle(0, 0, 256,
256), new ReferencedEnvelope(new Envelope(0, 180, 0, 85), getCRS()));
// renderer.paint((Graphics2D) p.getGraphics(), new Rectangle(0, 0, 256,
256), new ReferencedEnvelope(new Envelope(0, 180, 0, 85), null));
// renderAs4Tiles(renderer, p.getGraphics());
}
private static CoordinateReferenceSystem crs = null;
public static CoordinateReferenceSystem getCRS() {
if (crs != null) {
return crs;
}
try {
String wkt1 = "PROJCS[\"Google Mercator\", \n" +
" GEOGCS[\"WGS 84\", \n" +
" DATUM[\"World Geodetic System 1984\", \n" +
" SPHEROID[\"WGS 84\", 6378137.0, 298.257223563,
AUTHORITY[\"EPSG\",\"7030\"]], \n" +
" AUTHORITY[\"EPSG\",\"6326\"]], \n" +
" PRIMEM[\"Greenwich\", 0.0,
AUTHORITY[\"EPSG\",\"8901\"]], \n" +
" UNIT[\"degree\", 0.017453292519943295], \n" +
" AXIS[\"Geodetic latitude\", NORTH], \n" +
" AXIS[\"Geodetic longitude\", EAST], \n" +
" AUTHORITY[\"EPSG\",\"4326\"]], \n" +
" PROJECTION[\"Mercator (1SP)\",
AUTHORITY[\"EPSG\",\"9804\"]], \n" +
" PARAMETER[\"semi_major\", 6378137.0], \n" +
" PARAMETER[\"semi_minor\", 6378137.0], \n" +
" PARAMETER[\"latitude_of_origin\", 0.0], \n" +
" PARAMETER[\"central_meridian\", 0.0], \n" +
" PARAMETER[\"scale_factor\", 1.0], \n" +
" PARAMETER[\"false_easting\", 0.0], \n" +
" PARAMETER[\"false_northing\", 0.0], \n" +
" UNIT[\"m\", 1.0], \n" +
" AXIS[\"Easting\", EAST], \n" +
" AXIS[\"Northing\", NORTH], \n" +
" AUTHORITY[\"EPSG\",\"900913\"]]";
crs = CRS.parseWKT(wkt1);
System.out.println("crs = '" + crs + "'");
return crs;
} catch (Throwable fe) {
System.out.println("FactoryException on prjCRS creation :" + fe);
fe.printStackTrace();
}
return null;
}
}-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users