I have checked the bounds, and I am sure they are the same.
To make it sure again:
System.out.println("map bounds:" + map.getMaxBounds());
double[] box = getWGS84LngLat(9275, 21747, 16);
System.out.println(String.format("calculated box:%s %s %s %s", box[0],
box[1], box[2], box[3]));
ReferencedEnvelope bbox = new ReferencedEnvelope(box[0], box[2], box[1],
box[3], CRS.decode("EPSG:4326"));
System.out.println("render area:" + bbox);
print:
map bounds:ReferencedEnvelope[-154.80490576000002 : -154.20500785700011,
30.07774782000007 : 30.399098064000043]
calculated box:-154.52545166015625 30.267333984375 -154.522705078125
30.27008056640625
render area:ReferencedEnvelope[-154.52545166015625 : -154.522705078125,
30.267333984375 : 30.27008056640625]
The calculated box is inside the map bounds. And when I construct the
ReferencedEnvelope, I use the (minx,maxx,miny,maxy). I think the order is
right.
BTW, I use mapnik to generate image for this same box, and it worked.
So I think maybe I miss anything here?
On Wed, Jul 2, 2014 at 6:51 PM, Oleksandr Huziy <guziy.sa...@gmail.com>
wrote:
> Hi:
>
> Could you print map.getMaxBounds() and box and compare them? My guess is
> that the projection in your shape file is not epsg:4326 or something wrong
> with your order maybe it expects lat/lon order ie {bottom, left, top,
> right}??
>
> Cheers
>
>
> 2014-07-02 4:48 GMT-04:00 maven apache <apachemav...@gmail.com>:
>
>> Hi;
>>
>> I am trying to generate image according to the tile coordinate by
>> geotools, this is the code:
>>
>> * public static void main(String[] args) throws IOException,
>> FactoryException, CQLException {*
>> * long st = System.currentTimeMillis();*
>> * FileDataStore store = new ShapefileDataStore(new
>> File("data/landuase.shp").toURI().toURL());*
>>
>> * Style style = createPolygonStyle();*
>> * Layer layer = new FeatureLayer(store.getFeatureSource(), style);*
>>
>> * MapContent map = new MapContent();*
>> * map.addLayer(layer);*
>>
>>
>> * double[] box = getWGS84LngLat(9275, 21747, 16);*
>> * ReferencedEnvelope bbox = new ReferencedEnvelope(box[0], box[2],
>> box[1], box[3], CRS.decode("EPSG:4326"));*
>>
>>
>> * //arender*
>> * Rectangle paintArea = new Rectangle(0, 0, 256, 256);*
>> * BufferedImage image = new BufferedImage(paintArea.width,
>> paintArea.height, BufferedImage.TYPE_INT_RGB);*
>> * Graphics2D gr = image.createGraphics();*
>> * gr.setPaint(Color.WHITE);*
>> * gr.fill(paintArea);*
>>
>>
>> * GTRenderer renderer = new StreamingRenderer();*
>> * renderer.setMapContent(map);*
>> * renderer.paint(gr, paintArea, bbox);*
>>
>>
>> * File fileToSave = new File("D:/t.png");*
>> * ImageIO.write(image, "png", fileToSave);*
>>
>> * long ed = System.currentTimeMillis();*
>> * System.out.println("complete:" + (ed - st));*
>> * }*
>> * private static double[] getWGS84LngLat(int x, int y, int zoom) {*
>> * double padding = 0;*
>> * double left = (x - padding) * (360.0 / (1 << (zoom + 1))) - 180;*
>> * double right = (x + 1 + padding) * (360.0 / (1 << (zoom + 1))) - 180;*
>> * double top = 90 - (y - padding) * (180.0 / (1 << zoom));*
>> * double bottom = 90 - (y + 1 + padding) * (180.0 / (1 << zoom));*
>> * return new double[]{left, bottom, right, top};*
>> * }*
>>
>> However the above code does not work for the calculated bbox. Once I set:
>>
>> bbox = map.getMaxBounds()
>>
>> I will get the correct result.
>>
>> What's the problem?
>>
>>
>> ------------------------------------------------------------------------------
>> Open source business process management suite built on Java and Eclipse
>> Turn processes into business applications with Bonita BPM Community
>> Edition
>> Quickly connect people, data, and systems into organized workflows
>> Winner of BOSSIE, CODIE, OW2 and Gartner awards
>> http://p.sf.net/sfu/Bonitasoft
>> _______________________________________________
>> GeoTools-GT2-Users mailing list
>> GeoTools-GT2-Users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>>
>>
>
>
> --
> Sasha
>
------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users