|
From: Jan F. <ja...@ma...> - 2005-09-20 14:17:46
|
Hello,
I try to render a shapefile that represents the world costlines. The basic =
rendering centers the map on the greenwich meridian. I would like to center=
the rendering on the pacific ocean. I tried the setAreaOfInterest using a =
CRS with a PRIMEM at -180 but it doesn't work, the centering is still on th=
e Greenwich meridian. Do you have any hint ?
Here is the code I'm trying, basically it is a modified spearfish demo.
Jan.
public class SpearfishSample {
private static URL getResource(String path) {
return SpearfishSample.class.getClassLoader().getResource(path);
}
public static void main(String[] args) throws Exception {
URL wwURL =3D getResource("WVS - 43000000.shp");
ShapefileDataStore dsWW =3D new ShapefileDataStore(wwURL);
FeatureSource fsWW =3D dsWW.getFeatureSource("WVS - 43000000");
System.out.println(fsWW.getSchema().getDefaultGeometry().getCoordin=
ateSystem());
=20=20=20=20=20=20=20=20
StyleBuilder sb =3D new StyleBuilder();
=20=20=20=20=20=20=20=20
// ... WW style
LineSymbolizer lsWW =3D sb.createLineSymbolizer(Color.GREEN, 1);
Style wwStyle =3D sb.createStyle(lsWW);
// Build the map
MapContext map =3D new DefaultMapContext();
=20=20=20=20=20=20=20=20
Hints hints =3D new Hints(null);
CRSFactory crsFactory =3D FactoryFinder.getCRSFactory(hints);
MathTransformFactory mtFactory =3D FactoryFinder.getMathTransformFa=
ctory(hints);
GeographicCRS geoCRS =3D org.geotools.referencing.crs.DefaultGeogra=
phicCRS.WGS84;
System.out.println(geoCRS.toWKT());
DefaultCartesianCS cartCS =3D org.geotools.referencing.cs.DefaultCa=
rtesianCS.GENERIC_2D;
CoordinateReferenceSystem wtkCRS =3D crsFactory.createFromWKT("GEOG=
CS[\"WGS85\","
+ "DATUM[\"WGS85\","=20
+ "SPHEROID[\"WGS85\", 6378137.0, 298.257223563]],"=20
+ "PRIMEM[\"ch\", -180.0],"=20
+ "UNIT[\"degree\", 0.017453292519943295],"=20
+ "AXIS[\"Geodetic longitude\", EAST],"=20
+ "AXIS[\"Geodetic latitude\", NORTH]]"
+ "SPHEROID[\"WGS85\", 6378137.0, 298.257223563]");
map.addLayer(fsWW, wwStyle);
// Show the map
StyledMapPane mapPane =3D new StyledMapPane();
mapPane.setMapContext(map);
Envelope env =3D new Envelope();
env.init(new Coordinate(-180,90),new Coordinate(180,-90));
map.setAreaOfInterest(env,wtkCRS);
System.out.println(map.getCoordinateReferenceSystem());
// mapPane.getRenderer().setCoordinateSystem(org.geotools.cs=
.CoordinateSystem.fromGeoAPI(projCRS));
mapPane.getRenderer().addLayer(new RenderedMapScale());
JFrame frame =3D new JFrame();
frame.setTitle("WW map");
frame.setContentPane(mapPane.createScrollPane());
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setSize(640, 480);
frame.setVisible(true);
}
}
--=20
___________________________________________________________
Sign-up for Ads Free at Mail.com
http://promo.mail.com/adsfreejump.htm
|